1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file implements a generic debugging format. We may eventually
23 have readers which convert different formats into this generic
24 format, and writers which write it out. The initial impetus for
25 this was writing a convertor from stabs to HP IEEE-695 debugging
33 #include "libiberty.h"
36 /* Global information we keep for debugging. A pointer to this
37 structure is the debugging handle passed to all the routines. */
41 /* A linked list of compilation units. */
42 struct debug_unit
*units
;
43 /* The current compilation unit. */
44 struct debug_unit
*current_unit
;
45 /* The current source file. */
46 struct debug_file
*current_file
;
47 /* The current function. */
48 struct debug_function
*current_function
;
49 /* The current block. */
50 struct debug_block
*current_block
;
51 /* The current line number information for the current unit. */
52 struct debug_lineno
*current_lineno
;
53 /* Mark. This is used by debug_write. */
55 /* Another mark used by debug_write. */
56 unsigned int class_mark
;
57 /* A struct/class ID used by debug_write. */
58 unsigned int class_id
;
59 /* The base for class_id for this call to debug_write. */
63 /* Information we keep for a single compilation unit. */
67 /* The next compilation unit. */
68 struct debug_unit
*next
;
69 /* A list of files included in this compilation unit. The first
70 file is always the main one, and that is where the main file name
72 struct debug_file
*files
;
73 /* Line number information for this compilation unit. This is not
74 stored by function, because assembler code may have line number
75 information without function information. */
76 struct debug_lineno
*linenos
;
79 /* Information kept for a single source file. */
83 /* The next source file in this compilation unit. */
84 struct debug_file
*next
;
85 /* The name of the source file. */
87 /* Global functions, variables, types, etc. */
88 struct debug_namespace
*globals
;
96 enum debug_type_kind kind
;
97 /* Size of type (0 if not known). */
99 /* Type which is a pointer to this type. */
101 /* Tagged union with additional information about the type. */
104 /* DEBUG_KIND_INDIRECT. */
105 struct debug_indirect_type
*kindirect
;
106 /* DEBUG_KIND_INT. */
107 /* Whether the integer is unsigned. */
109 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
110 DEBUG_KIND_UNION_CLASS. */
111 struct debug_class_type
*kclass
;
112 /* DEBUG_KIND_ENUM. */
113 struct debug_enum_type
*kenum
;
114 /* DEBUG_KIND_POINTER. */
115 struct debug_type
*kpointer
;
116 /* DEBUG_KIND_FUNCTION. */
117 struct debug_function_type
*kfunction
;
118 /* DEBUG_KIND_REFERENCE. */
119 struct debug_type
*kreference
;
120 /* DEBUG_KIND_RANGE. */
121 struct debug_range_type
*krange
;
122 /* DEBUG_KIND_ARRAY. */
123 struct debug_array_type
*karray
;
124 /* DEBUG_KIND_SET. */
125 struct debug_set_type
*kset
;
126 /* DEBUG_KIND_OFFSET. */
127 struct debug_offset_type
*koffset
;
128 /* DEBUG_KIND_METHOD. */
129 struct debug_method_type
*kmethod
;
130 /* DEBUG_KIND_CONST. */
131 struct debug_type
*kconst
;
132 /* DEBUG_KIND_VOLATILE. */
133 struct debug_type
*kvolatile
;
134 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
135 struct debug_named_type
*knamed
;
139 /* Information kept for an indirect type. */
141 struct debug_indirect_type
143 /* Slot where the final type will appear. */
149 /* Information kept for a struct, union, or class. */
151 struct debug_class_type
153 /* NULL terminated array of fields. */
155 /* A mark field used to avoid recursively printing out structs. */
157 /* This is used to uniquely identify unnamed structs when printing. */
159 /* The remaining fields are only used for DEBUG_KIND_CLASS and
160 DEBUG_KIND_UNION_CLASS. */
161 /* NULL terminated array of base classes. */
162 debug_baseclass
*baseclasses
;
163 /* NULL terminated array of methods. */
164 debug_method
*methods
;
165 /* The type of the class providing the virtual function table for
166 this class. This may point to the type itself. */
170 /* Information kept for an enum. */
172 struct debug_enum_type
174 /* NULL terminated array of names. */
176 /* Array of corresponding values. */
177 bfd_signed_vma
*values
;
180 /* Information kept for a function. FIXME: We should be able to
181 record the parameter types. */
183 struct debug_function_type
186 debug_type return_type
;
187 /* NULL terminated array of argument types. */
188 debug_type
*arg_types
;
189 /* Whether the function takes a variable number of arguments. */
193 /* Information kept for a range. */
195 struct debug_range_type
197 /* Range base type. */
200 bfd_signed_vma lower
;
202 bfd_signed_vma upper
;
205 /* Information kept for an array. */
207 struct debug_array_type
210 debug_type element_type
;
212 debug_type range_type
;
214 bfd_signed_vma lower
;
216 bfd_signed_vma upper
;
217 /* Whether this array is really a string. */
221 /* Information kept for a set. */
223 struct debug_set_type
227 /* Whether this set is really a bitstring. */
231 /* Information kept for an offset type (a based pointer). */
233 struct debug_offset_type
235 /* The type the pointer is an offset from. */
236 debug_type base_type
;
237 /* The type the pointer points to. */
238 debug_type target_type
;
241 /* Information kept for a method type. */
243 struct debug_method_type
245 /* The return type. */
246 debug_type return_type
;
247 /* The object type which this method is for. */
248 debug_type domain_type
;
249 /* A NULL terminated array of argument types. */
250 debug_type
*arg_types
;
251 /* Whether the method takes a variable number of arguments. */
255 /* Information kept for a named type. */
257 struct debug_named_type
260 struct debug_name
*name
;
265 /* A field in a struct or union. */
269 /* Name of the field. */
271 /* Type of the field. */
272 struct debug_type
*type
;
273 /* Visibility of the field. */
274 enum debug_visibility visibility
;
275 /* Whether this is a static member. */
276 boolean static_member
;
279 /* If static_member is false. */
282 /* Bit position of the field in the struct. */
284 /* Size of the field in bits. */
285 unsigned int bitsize
;
287 /* If static_member is true. */
290 const char *physname
;
295 /* A base class for an object. */
297 struct debug_baseclass
299 /* Type of the base class. */
300 struct debug_type
*type
;
301 /* Bit position of the base class in the object. */
303 /* Whether the base class is virtual. */
305 /* Visibility of the base class. */
306 enum debug_visibility visibility
;
309 /* A method of an object. */
313 /* The name of the method. */
315 /* A NULL terminated array of different types of variants. */
316 struct debug_method_variant
**variants
;
319 /* The variants of a method function of an object. These indicate
320 which method to run. */
322 struct debug_method_variant
324 /* The physical name of the function. */
325 const char *physname
;
326 /* The type of the function. */
327 struct debug_type
*type
;
328 /* The visibility of the function. */
329 enum debug_visibility visibility
;
330 /* Whether the function is const. */
332 /* Whether the function is volatile. */
334 /* The offset to the function in the virtual function table. */
336 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
337 #define VOFFSET_STATIC_METHOD (1)
338 /* Context of a virtual method function. */
339 struct debug_type
*context
;
342 /* A variable. This is the information we keep for a variable object.
343 This has no name; a name is associated with a variable in a
344 debug_name structure. */
346 struct debug_variable
348 /* Kind of variable. */
349 enum debug_var_kind kind
;
352 /* Value. The interpretation of the value depends upon kind. */
356 /* A function. This has no name; a name is associated with a function
357 in a debug_name structure. */
359 struct debug_function
362 debug_type return_type
;
363 /* Parameter information. */
364 struct debug_parameter
*parameters
;
365 /* Block information. The first structure on the list is the main
366 block of the function, and describes function local variables. */
367 struct debug_block
*blocks
;
370 /* A function parameter. */
372 struct debug_parameter
374 /* Next parameter. */
375 struct debug_parameter
*next
;
381 enum debug_parm_kind kind
;
382 /* Value (meaning depends upon kind). */
386 /* A typed constant. */
388 struct debug_typed_constant
392 /* Value. FIXME: We may eventually need to support non-integral
397 /* Information about a block within a function. */
401 /* Next block with the same parent. */
402 struct debug_block
*next
;
404 struct debug_block
*parent
;
405 /* List of child blocks. */
406 struct debug_block
*children
;
407 /* Start address of the block. */
409 /* End address of the block. */
411 /* Local variables. */
412 struct debug_namespace
*locals
;
415 /* Line number information we keep for a compilation unit. FIXME:
416 This structure is easy to create, but can be very space
421 /* More line number information for this block. */
422 struct debug_lineno
*next
;
424 struct debug_file
*file
;
425 /* Line numbers, terminated by a -1 or the end of the array. */
426 #define DEBUG_LINENO_COUNT 10
427 unsigned long linenos
[DEBUG_LINENO_COUNT
];
428 /* Addresses for the line numbers. */
429 bfd_vma addrs
[DEBUG_LINENO_COUNT
];
432 /* A namespace. This is a mapping from names to objects. FIXME: This
433 should be implemented as a hash table. */
435 struct debug_namespace
437 /* List of items in this namespace. */
438 struct debug_name
*list
;
439 /* Pointer to where the next item in this namespace should go. */
440 struct debug_name
**tail
;
443 /* Kinds of objects that appear in a namespace. */
445 enum debug_object_kind
449 /* A tagged type (really a different sort of namespace). */
452 DEBUG_OBJECT_VARIABLE
,
454 DEBUG_OBJECT_FUNCTION
,
455 /* An integer constant. */
456 DEBUG_OBJECT_INT_CONSTANT
,
457 /* A floating point constant. */
458 DEBUG_OBJECT_FLOAT_CONSTANT
,
459 /* A typed constant. */
460 DEBUG_OBJECT_TYPED_CONSTANT
463 /* Linkage of an object that appears in a namespace. */
465 enum debug_object_linkage
467 /* Local variable. */
468 DEBUG_LINKAGE_AUTOMATIC
,
469 /* Static--either file static or function static, depending upon the
471 DEBUG_LINKAGE_STATIC
,
473 DEBUG_LINKAGE_GLOBAL
,
478 /* A name in a namespace. */
482 /* Next name in this namespace. */
483 struct debug_name
*next
;
486 /* Mark. This is used by debug_write. */
488 /* Kind of object. */
489 enum debug_object_kind kind
;
490 /* Linkage of object. */
491 enum debug_object_linkage linkage
;
492 /* Tagged union with additional information about the object. */
495 /* DEBUG_OBJECT_TYPE. */
496 struct debug_type
*type
;
497 /* DEBUG_OBJECT_TAG. */
498 struct debug_type
*tag
;
499 /* DEBUG_OBJECT_VARIABLE. */
500 struct debug_variable
*variable
;
501 /* DEBUG_OBJECT_FUNCTION. */
502 struct debug_function
*function
;
503 /* DEBUG_OBJECT_INT_CONSTANT. */
504 bfd_vma int_constant
;
505 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
506 double float_constant
;
507 /* DEBUG_OBJECT_TYPED_CONSTANT. */
508 struct debug_typed_constant
*typed_constant
;
512 /* Local functions. */
514 static void debug_error
PARAMS ((const char *));
515 static struct debug_name
*debug_add_to_namespace
516 PARAMS ((struct debug_handle
*, struct debug_namespace
**, const char *,
517 enum debug_object_kind
, enum debug_object_linkage
));
518 static struct debug_name
*debug_add_to_current_namespace
519 PARAMS ((struct debug_handle
*, const char *, enum debug_object_kind
,
520 enum debug_object_linkage
));
521 static struct debug_type
*debug_make_type
522 PARAMS ((struct debug_handle
*, enum debug_type_kind
, unsigned int));
523 static struct debug_type
*debug_get_real_type
PARAMS ((PTR
, debug_type
));
524 static boolean debug_write_name
525 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
526 struct debug_name
*));
527 static boolean debug_write_type
528 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
529 struct debug_type
*, struct debug_name
*));
530 static boolean debug_write_class_type
531 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
532 struct debug_type
*, const char *));
533 static boolean debug_write_function
534 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
535 const char *, enum debug_object_linkage
, struct debug_function
*));
536 static boolean debug_write_block
537 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
538 struct debug_block
*));
540 /* Issue an error message. */
543 debug_error (message
)
546 fprintf (stderr
, "%s\n", message
);
549 /* Add an object to a namespace. */
551 static struct debug_name
*
552 debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
)
553 struct debug_handle
*info
;
554 struct debug_namespace
**nsp
;
556 enum debug_object_kind kind
;
557 enum debug_object_linkage linkage
;
559 struct debug_name
*n
;
560 struct debug_namespace
*ns
;
562 n
= (struct debug_name
*) xmalloc (sizeof *n
);
563 memset (n
, 0, sizeof *n
);
567 n
->linkage
= linkage
;
572 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
573 memset (ns
, 0, sizeof *ns
);
575 ns
->tail
= &ns
->list
;
586 /* Add an object to the current namespace. */
588 static struct debug_name
*
589 debug_add_to_current_namespace (info
, name
, kind
, linkage
)
590 struct debug_handle
*info
;
592 enum debug_object_kind kind
;
593 enum debug_object_linkage linkage
;
595 struct debug_namespace
**nsp
;
597 if (info
->current_unit
== NULL
598 || info
->current_file
== NULL
)
600 debug_error ("debug_add_to_current_namespace: no current file");
604 if (info
->current_block
!= NULL
)
605 nsp
= &info
->current_block
->locals
;
607 nsp
= &info
->current_file
->globals
;
609 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
612 /* Return a handle for debugging information. */
617 struct debug_handle
*ret
;
619 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
620 memset (ret
, 0, sizeof *ret
);
624 /* Set the source filename. This implicitly starts a new compilation
628 debug_set_filename (handle
, name
)
632 struct debug_handle
*info
= (struct debug_handle
*) handle
;
633 struct debug_file
*nfile
;
634 struct debug_unit
*nunit
;
639 nfile
= (struct debug_file
*) xmalloc (sizeof *nfile
);
640 memset (nfile
, 0, sizeof *nfile
);
642 nfile
->filename
= name
;
644 nunit
= (struct debug_unit
*) xmalloc (sizeof *nunit
);
645 memset (nunit
, 0, sizeof *nunit
);
647 nunit
->files
= nfile
;
648 info
->current_file
= nfile
;
650 if (info
->current_unit
!= NULL
)
651 info
->current_unit
->next
= nunit
;
654 assert (info
->units
== NULL
);
658 info
->current_unit
= nunit
;
660 info
->current_function
= NULL
;
661 info
->current_block
= NULL
;
662 info
->current_lineno
= NULL
;
667 /* Change source files to the given file name. This is used for
668 include files in a single compilation unit. */
671 debug_start_source (handle
, name
)
675 struct debug_handle
*info
= (struct debug_handle
*) handle
;
676 struct debug_file
*f
, **pf
;
681 if (info
->current_unit
== NULL
)
683 debug_error ("debug_start_source: no debug_set_filename call");
687 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
689 if (f
->filename
[0] == name
[0]
690 && f
->filename
[1] == name
[1]
691 && strcmp (f
->filename
, name
) == 0)
693 info
->current_file
= f
;
698 f
= (struct debug_file
*) xmalloc (sizeof *f
);
699 memset (f
, 0, sizeof *f
);
703 for (pf
= &info
->current_file
->next
;
709 info
->current_file
= f
;
714 /* Record a function definition. This implicitly starts a function
715 block. The debug_type argument is the type of the return value.
716 The boolean indicates whether the function is globally visible.
717 The bfd_vma is the address of the start of the function. Currently
718 the parameter types are specified by calls to
719 debug_record_parameter. FIXME: There is no way to specify nested
720 functions. FIXME: I don't think there is any way to record where a
724 debug_record_function (handle
, name
, return_type
, global
, addr
)
727 debug_type return_type
;
731 struct debug_handle
*info
= (struct debug_handle
*) handle
;
732 struct debug_function
*f
;
733 struct debug_block
*b
;
734 struct debug_name
*n
;
738 if (return_type
== NULL
)
741 if (info
->current_unit
== NULL
)
743 debug_error ("debug_record_function: no debug_set_filename call");
747 f
= (struct debug_function
*) xmalloc (sizeof *f
);
748 memset (f
, 0, sizeof *f
);
750 f
->return_type
= return_type
;
752 b
= (struct debug_block
*) xmalloc (sizeof *b
);
753 memset (b
, 0, sizeof *b
);
756 b
->end
= (bfd_vma
) -1;
760 info
->current_function
= f
;
761 info
->current_block
= b
;
763 /* FIXME: If we could handle nested functions, this would be the
764 place: we would want to use a different namespace. */
765 n
= debug_add_to_namespace (info
,
766 &info
->current_file
->globals
,
768 DEBUG_OBJECT_FUNCTION
,
770 ? DEBUG_LINKAGE_GLOBAL
771 : DEBUG_LINKAGE_STATIC
));
780 /* Record a parameter for the current function. */
783 debug_record_parameter (handle
, name
, type
, kind
, val
)
787 enum debug_parm_kind kind
;
790 struct debug_handle
*info
= (struct debug_handle
*) handle
;
791 struct debug_parameter
*p
, **pp
;
793 if (name
== NULL
|| type
== NULL
)
796 if (info
->current_unit
== NULL
797 || info
->current_function
== NULL
)
799 debug_error ("debug_record_parameter: no current function");
803 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
804 memset (p
, 0, sizeof *p
);
811 for (pp
= &info
->current_function
->parameters
;
820 /* End a function. FIXME: This should handle function nesting. */
823 debug_end_function (handle
, addr
)
827 struct debug_handle
*info
= (struct debug_handle
*) handle
;
829 if (info
->current_unit
== NULL
830 || info
->current_block
== NULL
831 || info
->current_function
== NULL
)
833 debug_error ("debug_end_function: no current function");
837 if (info
->current_block
->parent
!= NULL
)
839 debug_error ("debug_end_function: some blocks were not closed");
843 info
->current_block
->end
= addr
;
845 info
->current_function
= NULL
;
846 info
->current_block
= NULL
;
851 /* Start a block in a function. All local information will be
852 recorded in this block, until the matching call to debug_end_block.
853 debug_start_block and debug_end_block may be nested. The bfd_vma
854 argument is the address at which this block starts. */
857 debug_start_block (handle
, addr
)
861 struct debug_handle
*info
= (struct debug_handle
*) handle
;
862 struct debug_block
*b
, **pb
;
864 /* We must always have a current block: debug_record_function sets
866 if (info
->current_unit
== NULL
867 || info
->current_block
== NULL
)
869 debug_error ("debug_start_block: no current block");
873 b
= (struct debug_block
*) xmalloc (sizeof *b
);
874 memset (b
, 0, sizeof *b
);
876 b
->parent
= info
->current_block
;
878 b
->end
= (bfd_vma
) -1;
880 /* This new block is a child of the current block. */
881 for (pb
= &info
->current_block
->children
;
887 info
->current_block
= b
;
892 /* Finish a block in a function. This matches the call to
893 debug_start_block. The argument is the address at which this block
897 debug_end_block (handle
, addr
)
901 struct debug_handle
*info
= (struct debug_handle
*) handle
;
902 struct debug_block
*parent
;
904 if (info
->current_unit
== NULL
905 || info
->current_block
== NULL
)
907 debug_error ("debug_end_block: no current block");
911 parent
= info
->current_block
->parent
;
914 debug_error ("debug_end_block: attempt to close top level block");
918 info
->current_block
->end
= addr
;
920 info
->current_block
= parent
;
925 /* Associate a line number in the current source file and function
926 with a given address. */
929 debug_record_line (handle
, lineno
, addr
)
931 unsigned long lineno
;
934 struct debug_handle
*info
= (struct debug_handle
*) handle
;
935 struct debug_lineno
*l
;
938 if (info
->current_unit
== NULL
)
940 debug_error ("debug_record_line: no current unit");
944 l
= info
->current_lineno
;
945 if (l
!= NULL
&& l
->file
== info
->current_file
)
947 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
949 if (l
->linenos
[i
] == (unsigned long) -1)
951 l
->linenos
[i
] = lineno
;
958 /* If we get here, then either 1) there is no current_lineno
959 structure, which means this is the first line number in this
960 compilation unit, 2) the current_lineno structure is for a
961 different file, or 3) the current_lineno structure is full.
962 Regardless, we want to allocate a new debug_lineno structure, put
963 it in the right place, and make it the new current_lineno
966 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
967 memset (l
, 0, sizeof *l
);
969 l
->file
= info
->current_file
;
970 l
->linenos
[0] = lineno
;
972 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
973 l
->linenos
[i
] = (unsigned long) -1;
975 if (info
->current_lineno
!= NULL
)
976 info
->current_lineno
->next
= l
;
978 info
->current_unit
->linenos
= l
;
980 info
->current_lineno
= l
;
985 /* Start a named common block. This is a block of variables that may
989 debug_start_common_block (handle
, name
)
994 debug_error ("debug_start_common_block: not implemented");
998 /* End a named common block. */
1001 debug_end_common_block (handle
, name
)
1006 debug_error ("debug_end_common_block: not implemented");
1010 /* Record a named integer constant. */
1013 debug_record_int_const (handle
, name
, val
)
1018 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1019 struct debug_name
*n
;
1024 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1025 DEBUG_LINKAGE_NONE
);
1029 n
->u
.int_constant
= val
;
1034 /* Record a named floating point constant. */
1037 debug_record_float_const (handle
, name
, val
)
1042 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1043 struct debug_name
*n
;
1048 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1049 DEBUG_LINKAGE_NONE
);
1053 n
->u
.float_constant
= val
;
1058 /* Record a typed constant with an integral value. */
1061 debug_record_typed_const (handle
, name
, type
, val
)
1067 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1068 struct debug_name
*n
;
1069 struct debug_typed_constant
*tc
;
1071 if (name
== NULL
|| type
== NULL
)
1074 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1075 DEBUG_LINKAGE_NONE
);
1079 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1080 memset (tc
, 0, sizeof *tc
);
1085 n
->u
.typed_constant
= tc
;
1090 /* Record a label. */
1093 debug_record_label (handle
, name
, type
, addr
)
1100 debug_error ("debug_record_label not implemented");
1104 /* Record a variable. */
1107 debug_record_variable (handle
, name
, type
, kind
, val
)
1111 enum debug_var_kind kind
;
1114 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1115 struct debug_namespace
**nsp
;
1116 enum debug_object_linkage linkage
;
1117 struct debug_name
*n
;
1118 struct debug_variable
*v
;
1120 if (name
== NULL
|| type
== NULL
)
1123 if (info
->current_unit
== NULL
1124 || info
->current_file
== NULL
)
1126 debug_error ("debug_record_variable: no current file");
1130 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1132 nsp
= &info
->current_file
->globals
;
1133 if (kind
== DEBUG_GLOBAL
)
1134 linkage
= DEBUG_LINKAGE_GLOBAL
;
1136 linkage
= DEBUG_LINKAGE_STATIC
;
1140 if (info
->current_block
== NULL
)
1142 debug_error ("debug_record_variable: no current block");
1145 nsp
= &info
->current_block
->locals
;
1146 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1149 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1153 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1154 memset (v
, 0, sizeof *v
);
1165 /* Make a type with a given kind and size. */
1168 static struct debug_type
*
1169 debug_make_type (info
, kind
, size
)
1170 struct debug_handle
*info
;
1171 enum debug_type_kind kind
;
1174 struct debug_type
*t
;
1176 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1177 memset (t
, 0, sizeof *t
);
1185 /* Make an indirect type which may be used as a placeholder for a type
1186 which is referenced before it is defined. */
1189 debug_make_indirect_type (handle
, slot
, tag
)
1194 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1195 struct debug_type
*t
;
1196 struct debug_indirect_type
*i
;
1198 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1200 return DEBUG_TYPE_NULL
;
1202 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1203 memset (i
, 0, sizeof *i
);
1213 /* Make a void type. There is only one of these. */
1216 debug_make_void_type (handle
)
1219 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1221 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1224 /* Make an integer type of a given size. The boolean argument is true
1225 if the integer is unsigned. */
1228 debug_make_int_type (handle
, size
, unsignedp
)
1233 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1234 struct debug_type
*t
;
1236 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1238 return DEBUG_TYPE_NULL
;
1240 t
->u
.kint
= unsignedp
;
1245 /* Make a floating point type of a given size. FIXME: On some
1246 platforms, like an Alpha, you probably need to be able to specify
1250 debug_make_float_type (handle
, size
)
1254 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1256 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1259 /* Make a boolean type of a given size. */
1262 debug_make_bool_type (handle
, size
)
1266 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1268 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1271 /* Make a complex type of a given size. */
1274 debug_make_complex_type (handle
, size
)
1278 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1280 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1283 /* Make a structure type. The second argument is true for a struct,
1284 false for a union. The third argument is the size of the struct.
1285 The fourth argument is a NULL terminated array of fields. */
1288 debug_make_struct_type (handle
, structp
, size
, fields
)
1292 debug_field
*fields
;
1294 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1295 struct debug_type
*t
;
1296 struct debug_class_type
*c
;
1298 t
= debug_make_type (info
,
1299 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1302 return DEBUG_TYPE_NULL
;
1304 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1305 memset (c
, 0, sizeof *c
);
1314 /* Make an object type. The first three arguments after the handle
1315 are the same as for debug_make_struct_type. The next arguments are
1316 a NULL terminated array of base classes, a NULL terminated array of
1317 methods, the type of the object holding the virtual function table
1318 if it is not this object, and a boolean which is true if this
1319 object has its own virtual function table. */
1322 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1323 methods
, vptrbase
, ownvptr
)
1327 debug_field
*fields
;
1328 debug_baseclass
*baseclasses
;
1329 debug_method
*methods
;
1330 debug_type vptrbase
;
1333 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1334 struct debug_type
*t
;
1335 struct debug_class_type
*c
;
1337 t
= debug_make_type (info
,
1338 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1341 return DEBUG_TYPE_NULL
;
1343 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1344 memset (c
, 0, sizeof *c
);
1347 c
->baseclasses
= baseclasses
;
1348 c
->methods
= methods
;
1352 c
->vptrbase
= vptrbase
;
1359 /* Make an enumeration type. The arguments are a null terminated
1360 array of strings, and an array of corresponding values. */
1363 debug_make_enum_type (handle
, names
, values
)
1366 bfd_signed_vma
*values
;
1368 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1369 struct debug_type
*t
;
1370 struct debug_enum_type
*e
;
1372 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1374 return DEBUG_TYPE_NULL
;
1376 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1377 memset (e
, 0, sizeof *e
);
1387 /* Make a pointer to a given type. */
1390 debug_make_pointer_type (handle
, type
)
1394 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1395 struct debug_type
*t
;
1398 return DEBUG_TYPE_NULL
;
1400 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1401 return type
->pointer
;
1403 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1405 return DEBUG_TYPE_NULL
;
1407 t
->u
.kpointer
= type
;
1414 /* Make a function returning a given type. FIXME: We should be able
1415 to record the parameter types. */
1418 debug_make_function_type (handle
, type
, arg_types
, varargs
)
1421 debug_type
*arg_types
;
1424 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1425 struct debug_type
*t
;
1426 struct debug_function_type
*f
;
1429 return DEBUG_TYPE_NULL
;
1431 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1433 return DEBUG_TYPE_NULL
;
1435 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1436 memset (f
, 0, sizeof *f
);
1438 f
->return_type
= type
;
1439 f
->arg_types
= arg_types
;
1440 f
->varargs
= varargs
;
1447 /* Make a reference to a given type. */
1450 debug_make_reference_type (handle
, type
)
1454 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1455 struct debug_type
*t
;
1458 return DEBUG_TYPE_NULL
;
1460 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1462 return DEBUG_TYPE_NULL
;
1464 t
->u
.kreference
= type
;
1469 /* Make a range of a given type from a lower to an upper bound. */
1472 debug_make_range_type (handle
, type
, lower
, upper
)
1475 bfd_signed_vma lower
;
1476 bfd_signed_vma upper
;
1478 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1479 struct debug_type
*t
;
1480 struct debug_range_type
*r
;
1483 return DEBUG_TYPE_NULL
;
1485 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1487 return DEBUG_TYPE_NULL
;
1489 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1490 memset (r
, 0, sizeof *r
);
1501 /* Make an array type. The second argument is the type of an element
1502 of the array. The third argument is the type of a range of the
1503 array. The fourth and fifth argument are the lower and upper
1504 bounds, respectively. The sixth argument is true if this array is
1505 actually a string, as in C. */
1508 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1511 debug_type element_type
;
1512 debug_type range_type
;
1513 bfd_signed_vma lower
;
1514 bfd_signed_vma upper
;
1517 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1518 struct debug_type
*t
;
1519 struct debug_array_type
*a
;
1521 if (element_type
== NULL
|| range_type
== NULL
)
1522 return DEBUG_TYPE_NULL
;
1524 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1526 return DEBUG_TYPE_NULL
;
1528 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1529 memset (a
, 0, sizeof *a
);
1531 a
->element_type
= element_type
;
1532 a
->range_type
= range_type
;
1535 a
->stringp
= stringp
;
1542 /* Make a set of a given type. For example, a Pascal set type. The
1543 boolean argument is true if this set is actually a bitstring, as in
1547 debug_make_set_type (handle
, type
, bitstringp
)
1552 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1553 struct debug_type
*t
;
1554 struct debug_set_type
*s
;
1557 return DEBUG_TYPE_NULL
;
1559 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1561 return DEBUG_TYPE_NULL
;
1563 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1564 memset (s
, 0, sizeof *s
);
1567 s
->bitstringp
= bitstringp
;
1574 /* Make a type for a pointer which is relative to an object. The
1575 second argument is the type of the object to which the pointer is
1576 relative. The third argument is the type that the pointer points
1580 debug_make_offset_type (handle
, base_type
, target_type
)
1582 debug_type base_type
;
1583 debug_type target_type
;
1585 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1586 struct debug_type
*t
;
1587 struct debug_offset_type
*o
;
1589 if (base_type
== NULL
|| target_type
== NULL
)
1590 return DEBUG_TYPE_NULL
;
1592 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1594 return DEBUG_TYPE_NULL
;
1596 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1597 memset (o
, 0, sizeof *o
);
1599 o
->base_type
= base_type
;
1600 o
->target_type
= target_type
;
1607 /* Make a type for a method function. The second argument is the
1608 return type, the third argument is the domain, and the fourth
1609 argument is a NULL terminated array of argument types. */
1612 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
, varargs
)
1614 debug_type return_type
;
1615 debug_type domain_type
;
1616 debug_type
*arg_types
;
1619 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1620 struct debug_type
*t
;
1621 struct debug_method_type
*m
;
1623 if (return_type
== NULL
)
1624 return DEBUG_TYPE_NULL
;
1626 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1628 return DEBUG_TYPE_NULL
;
1630 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1631 memset (m
, 0, sizeof *m
);
1633 m
->return_type
= return_type
;
1634 m
->domain_type
= domain_type
;
1635 m
->arg_types
= arg_types
;
1636 m
->varargs
= varargs
;
1643 /* Make a const qualified version of a given type. */
1646 debug_make_const_type (handle
, type
)
1650 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1651 struct debug_type
*t
;
1654 return DEBUG_TYPE_NULL
;
1656 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1658 return DEBUG_TYPE_NULL
;
1665 /* Make a volatile qualified version of a given type. */
1668 debug_make_volatile_type (handle
, type
)
1672 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1673 struct debug_type
*t
;
1676 return DEBUG_TYPE_NULL
;
1678 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1680 return DEBUG_TYPE_NULL
;
1682 t
->u
.kvolatile
= type
;
1687 /* Make an undefined tagged type. For example, a struct which has
1688 been mentioned, but not defined. */
1691 debug_make_undefined_tagged_type (handle
, name
, kind
)
1694 enum debug_type_kind kind
;
1696 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1697 struct debug_type
*t
;
1700 return DEBUG_TYPE_NULL
;
1704 case DEBUG_KIND_STRUCT
:
1705 case DEBUG_KIND_UNION
:
1706 case DEBUG_KIND_CLASS
:
1707 case DEBUG_KIND_UNION_CLASS
:
1708 case DEBUG_KIND_ENUM
:
1712 debug_error ("debug_make_undefined_type: unsupported kind");
1713 return DEBUG_TYPE_NULL
;
1716 t
= debug_make_type (info
, kind
, 0);
1718 return DEBUG_TYPE_NULL
;
1720 return debug_tag_type (handle
, name
, t
);
1723 /* Make a base class for an object. The second argument is the base
1724 class type. The third argument is the bit position of this base
1725 class in the object (always 0 unless doing multiple inheritance).
1726 The fourth argument is whether this is a virtual class. The fifth
1727 argument is the visibility of the base class. */
1731 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1736 enum debug_visibility visibility
;
1738 struct debug_baseclass
*b
;
1740 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1741 memset (b
, 0, sizeof *b
);
1745 b
->virtual = virtual;
1746 b
->visibility
= visibility
;
1751 /* Make a field for a struct. The second argument is the name. The
1752 third argument is the type of the field. The fourth argument is
1753 the bit position of the field. The fifth argument is the size of
1754 the field (it may be zero). The sixth argument is the visibility
1759 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1765 enum debug_visibility visibility
;
1767 struct debug_field
*f
;
1769 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1770 memset (f
, 0, sizeof *f
);
1774 f
->static_member
= false;
1775 f
->u
.f
.bitpos
= bitpos
;
1776 f
->u
.f
.bitsize
= bitsize
;
1777 f
->visibility
= visibility
;
1782 /* Make a static member of an object. The second argument is the
1783 name. The third argument is the type of the member. The fourth
1784 argument is the physical name of the member (i.e., the name as a
1785 global variable). The fifth argument is the visibility of the
1790 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1794 const char *physname
;
1795 enum debug_visibility visibility
;
1797 struct debug_field
*f
;
1799 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1800 memset (f
, 0, sizeof *f
);
1804 f
->static_member
= true;
1805 f
->u
.s
.physname
= physname
;
1806 f
->visibility
= visibility
;
1811 /* Make a method. The second argument is the name, and the third
1812 argument is a NULL terminated array of method variants. */
1816 debug_make_method (handle
, name
, variants
)
1819 debug_method_variant
*variants
;
1821 struct debug_method
*m
;
1823 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1824 memset (m
, 0, sizeof *m
);
1827 m
->variants
= variants
;
1832 /* Make a method argument. The second argument is the real name of
1833 the function. The third argument is the type of the function. The
1834 fourth argument is the visibility. The fifth argument is whether
1835 this is a const function. The sixth argument is whether this is a
1836 volatile function. The seventh argument is the offset in the
1837 virtual function table, if any. The eighth argument is the virtual
1838 function context. FIXME: Are the const and volatile arguments
1839 necessary? Could we just use debug_make_const_type? */
1842 debug_method_variant
1843 debug_make_method_variant (handle
, physname
, type
, visibility
, constp
,
1844 volatilep
, voffset
, context
)
1846 const char *physname
;
1848 enum debug_visibility visibility
;
1854 struct debug_method_variant
*m
;
1856 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1857 memset (m
, 0, sizeof *m
);
1859 m
->physname
= physname
;
1861 m
->visibility
= visibility
;
1863 m
->volatilep
= volatilep
;
1864 m
->voffset
= voffset
;
1865 m
->context
= context
;
1870 /* Make a static method argument. The arguments are the same as for
1871 debug_make_method_variant, except that the last two are omitted
1872 since a static method can not also be virtual. */
1874 debug_method_variant
1875 debug_make_static_method_variant (handle
, physname
, type
, visibility
,
1878 const char *physname
;
1880 enum debug_visibility visibility
;
1884 struct debug_method_variant
*m
;
1886 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1887 memset (m
, 0, sizeof *m
);
1889 m
->physname
= physname
;
1891 m
->visibility
= visibility
;
1893 m
->volatilep
= volatilep
;
1894 m
->voffset
= VOFFSET_STATIC_METHOD
;
1902 debug_name_type (handle
, name
, type
)
1907 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1908 struct debug_type
*t
;
1909 struct debug_named_type
*n
;
1910 struct debug_name
*nm
;
1912 if (name
== NULL
|| type
== NULL
)
1913 return DEBUG_TYPE_NULL
;
1915 if (info
->current_unit
== NULL
1916 || info
->current_file
== NULL
)
1918 debug_error ("debug_record_variable: no current file");
1922 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1924 return DEBUG_TYPE_NULL
;
1926 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1927 memset (n
, 0, sizeof *n
);
1933 /* We always add the name to the global namespace. This is probably
1934 wrong in some cases, but it seems to be right for stabs. FIXME. */
1936 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1937 DEBUG_OBJECT_TYPE
, DEBUG_LINKAGE_NONE
);
1951 debug_tag_type (handle
, name
, type
)
1956 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1957 struct debug_type
*t
;
1958 struct debug_named_type
*n
;
1959 struct debug_name
*nm
;
1961 if (name
== NULL
|| type
== NULL
)
1962 return DEBUG_TYPE_NULL
;
1964 if (info
->current_file
== NULL
)
1966 debug_error ("debug_tag_type: no current file");
1967 return DEBUG_TYPE_NULL
;
1970 if (type
->kind
== DEBUG_KIND_TAGGED
)
1972 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
1974 debug_error ("debug_tag_type: extra tag attempted");
1975 return DEBUG_TYPE_NULL
;
1978 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
1980 return DEBUG_TYPE_NULL
;
1982 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1983 memset (n
, 0, sizeof *n
);
1989 /* We keep a global namespace of tags for each compilation unit. I
1990 don't know if that is the right thing to do. */
1992 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1993 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2004 /* Record the size of a given type. */
2008 debug_record_type_size (handle
, type
, size
)
2013 if (type
->size
!= 0 && type
->size
!= size
)
2014 fprintf (stderr
, "Warning: changing type size from %d to %d\n",
2022 /* Find a named type. */
2025 debug_find_named_type (handle
, name
)
2029 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2030 struct debug_block
*b
;
2031 struct debug_file
*f
;
2033 /* We only search the current compilation unit. I don't know if
2034 this is right or not. */
2036 if (info
->current_unit
== NULL
)
2038 debug_error ("debug_find_named_type: no current compilation unit");
2039 return DEBUG_TYPE_NULL
;
2042 for (b
= info
->current_block
; b
!= NULL
; b
= b
->parent
)
2044 if (b
->locals
!= NULL
)
2046 struct debug_name
*n
;
2048 for (n
= b
->locals
->list
; n
!= NULL
; n
= n
->next
)
2050 if (n
->kind
== DEBUG_OBJECT_TYPE
2051 && n
->name
[0] == name
[0]
2052 && strcmp (n
->name
, name
) == 0)
2058 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
2060 if (f
->globals
!= NULL
)
2062 struct debug_name
*n
;
2064 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2066 if (n
->kind
== DEBUG_OBJECT_TYPE
2067 && n
->name
[0] == name
[0]
2068 && strcmp (n
->name
, name
) == 0)
2074 return DEBUG_TYPE_NULL
;
2077 /* Find a tagged type. */
2080 debug_find_tagged_type (handle
, name
, kind
)
2083 enum debug_type_kind kind
;
2085 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2086 struct debug_unit
*u
;
2088 /* We search the globals of all the compilation units. I don't know
2089 if this is correct or not. It would be easy to change. */
2091 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2093 struct debug_file
*f
;
2095 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2097 struct debug_name
*n
;
2099 if (f
->globals
!= NULL
)
2101 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2103 if (n
->kind
== DEBUG_OBJECT_TAG
2104 && (kind
== DEBUG_KIND_ILLEGAL
2105 || n
->u
.tag
->kind
== kind
)
2106 && n
->name
[0] == name
[0]
2107 && strcmp (n
->name
, name
) == 0)
2114 return DEBUG_TYPE_NULL
;
2117 /* Get a base type. */
2119 static struct debug_type
*
2120 debug_get_real_type (handle
, type
)
2128 case DEBUG_KIND_INDIRECT
:
2129 if (*type
->u
.kindirect
->slot
!= NULL
)
2130 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
);
2132 case DEBUG_KIND_NAMED
:
2133 case DEBUG_KIND_TAGGED
:
2134 return debug_get_real_type (handle
, type
->u
.knamed
->type
);
2139 /* Get the kind of a type. */
2141 enum debug_type_kind
2142 debug_get_type_kind (handle
, type
)
2147 return DEBUG_KIND_ILLEGAL
;
2148 type
= debug_get_real_type (handle
, type
);
2152 /* Get the name of a type. */
2155 debug_get_type_name (handle
, type
)
2159 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2161 if (*type
->u
.kindirect
->slot
!= NULL
)
2162 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2163 return type
->u
.kindirect
->tag
;
2165 if (type
->kind
== DEBUG_KIND_NAMED
2166 || type
->kind
== DEBUG_KIND_TAGGED
)
2167 return type
->u
.knamed
->name
->name
;
2171 /* Get the size of a type. */
2174 debug_get_type_size (handle
, type
)
2181 /* We don't call debug_get_real_type, because somebody might have
2182 called debug_record_type_size on a named or indirect type. */
2184 if (type
->size
!= 0)
2191 case DEBUG_KIND_INDIRECT
:
2192 if (*type
->u
.kindirect
->slot
!= NULL
)
2193 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2195 case DEBUG_KIND_NAMED
:
2196 case DEBUG_KIND_TAGGED
:
2197 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2202 /* Get the return type of a function or method type. */
2205 debug_get_return_type (handle
, type
)
2210 return DEBUG_TYPE_NULL
;
2211 type
= debug_get_real_type (handle
, type
);
2215 return DEBUG_TYPE_NULL
;
2216 case DEBUG_KIND_FUNCTION
:
2217 return type
->u
.kfunction
->return_type
;
2218 case DEBUG_KIND_METHOD
:
2219 return type
->u
.kmethod
->return_type
;
2224 /* Get the parameter types of a function or method type (except that
2225 we don't currently store the parameter types of a function). */
2228 debug_get_parameter_types (handle
, type
, pvarargs
)
2235 type
= debug_get_real_type (handle
, type
);
2240 case DEBUG_KIND_METHOD
:
2241 *pvarargs
= type
->u
.kmethod
->varargs
;
2242 return type
->u
.kmethod
->arg_types
;
2247 /* Get the target type of a type. */
2250 debug_get_target_type (handle
, type
)
2256 type
= debug_get_real_type (handle
, type
);
2261 case DEBUG_KIND_POINTER
:
2262 return type
->u
.kpointer
;
2263 case DEBUG_KIND_REFERENCE
:
2264 return type
->u
.kreference
;
2265 case DEBUG_KIND_CONST
:
2266 return type
->u
.kconst
;
2267 case DEBUG_KIND_VOLATILE
:
2268 return type
->u
.kvolatile
;
2273 /* Get the NULL terminated array of fields for a struct, union, or
2277 debug_get_fields (handle
, type
)
2283 type
= debug_get_real_type (handle
, type
);
2288 case DEBUG_KIND_STRUCT
:
2289 case DEBUG_KIND_UNION
:
2290 case DEBUG_KIND_CLASS
:
2291 case DEBUG_KIND_UNION_CLASS
:
2292 return type
->u
.kclass
->fields
;
2297 /* Get the type of a field. */
2301 debug_get_field_type (handle
, field
)
2310 /* Get the name of a field. */
2314 debug_get_field_name (handle
, field
)
2323 /* Get the bit position of a field. */
2327 debug_get_field_bitpos (handle
, field
)
2331 if (field
== NULL
|| field
->static_member
)
2332 return (bfd_vma
) -1;
2333 return field
->u
.f
.bitpos
;
2336 /* Get the bit size of a field. */
2340 debug_get_field_bitsize (handle
, field
)
2344 if (field
== NULL
|| field
->static_member
)
2345 return (bfd_vma
) -1;
2346 return field
->u
.f
.bitsize
;
2349 /* Get the visibility of a field. */
2352 enum debug_visibility
2353 debug_get_field_visibility (handle
, field
)
2358 return DEBUG_VISIBILITY_IGNORE
;
2359 return field
->visibility
;
2362 /* Get the physical name of a field. */
2365 debug_get_field_physname (handle
, field
)
2369 if (field
== NULL
|| ! field
->static_member
)
2371 return field
->u
.s
.physname
;
2374 /* Write out the debugging information. This is given a handle to
2375 debugging information, and a set of function pointers to call. */
2378 debug_write (handle
, fns
, fhandle
)
2380 const struct debug_write_fns
*fns
;
2383 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2384 struct debug_unit
*u
;
2386 /* We use a mark to tell whether we have already written out a
2387 particular name. We use an integer, so that we don't have to
2388 clear the mark fields if we happen to write out the same
2389 information more than once. */
2392 /* The base_id field holds an ID value which will never be used, so
2393 that we can tell whether we have assigned an ID during this call
2395 info
->base_id
= info
->class_id
;
2397 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2399 struct debug_file
*f
;
2401 struct debug_lineno
*l
;
2403 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2407 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2409 struct debug_name
*n
;
2415 if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2419 if (f
->globals
!= NULL
)
2421 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2423 if (! debug_write_name (info
, fns
, fhandle
, n
))
2429 for (l
= u
->linenos
; l
!= NULL
; l
= l
->next
)
2433 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
2435 if (l
->linenos
[i
] == (unsigned long) -1)
2437 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
, l
->linenos
[i
],
2447 /* Write out an element in a namespace. */
2450 debug_write_name (info
, fns
, fhandle
, n
)
2451 struct debug_handle
*info
;
2452 const struct debug_write_fns
*fns
;
2454 struct debug_name
*n
;
2456 /* The class_mark field is used to prevent recursively outputting a
2462 case DEBUG_OBJECT_TYPE
:
2463 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2464 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2467 case DEBUG_OBJECT_TAG
:
2468 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2470 return (*fns
->tag
) (fhandle
, n
->name
);
2471 case DEBUG_OBJECT_VARIABLE
:
2472 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2473 (struct debug_name
*) NULL
))
2475 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2476 n
->u
.variable
->val
);
2477 case DEBUG_OBJECT_FUNCTION
:
2478 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2479 n
->linkage
, n
->u
.function
);
2480 case DEBUG_OBJECT_INT_CONSTANT
:
2481 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2482 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2483 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2484 case DEBUG_OBJECT_TYPED_CONSTANT
:
2485 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2486 (struct debug_name
*) NULL
))
2488 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2489 n
->u
.typed_constant
->val
);
2497 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2498 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2499 are about to call typedef or tag. If the type is anything else,
2500 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2501 points to this one. */
2504 debug_write_type (info
, fns
, fhandle
, type
, name
)
2505 struct debug_handle
*info
;
2506 const struct debug_write_fns
*fns
;
2508 struct debug_type
*type
;
2509 struct debug_name
*name
;
2515 /* If we have a name for this type, just output it. We only output
2516 typedef names after they have been defined. We output type tags
2517 whenever we are not actually defining them. */
2518 if ((type
->kind
== DEBUG_KIND_NAMED
2519 || type
->kind
== DEBUG_KIND_TAGGED
)
2520 && (type
->u
.knamed
->name
->mark
== info
->mark
2521 || (type
->kind
== DEBUG_KIND_TAGGED
2522 && type
->u
.knamed
->name
!= name
)))
2524 if (type
->kind
== DEBUG_KIND_NAMED
)
2525 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2528 struct debug_type
*real
;
2530 real
= debug_get_real_type ((PTR
) info
, type
);
2531 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, 0,
2536 /* Mark the name after we have already looked for a known name, so
2537 that we don't just define a type in terms of itself. We need to
2538 mark the name here so that a struct containing a pointer to
2539 itself will work. */
2541 name
->mark
= info
->mark
;
2545 && type
->kind
!= DEBUG_KIND_NAMED
2546 && type
->kind
!= DEBUG_KIND_TAGGED
)
2548 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2554 case DEBUG_KIND_ILLEGAL
:
2555 debug_error ("debug_write_type: illegal type encountered");
2557 case DEBUG_KIND_INDIRECT
:
2558 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2559 return (*fns
->empty_type
) (fhandle
);
2560 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2562 case DEBUG_KIND_VOID
:
2563 return (*fns
->void_type
) (fhandle
);
2564 case DEBUG_KIND_INT
:
2565 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2566 case DEBUG_KIND_FLOAT
:
2567 return (*fns
->float_type
) (fhandle
, type
->size
);
2568 case DEBUG_KIND_COMPLEX
:
2569 return (*fns
->complex_type
) (fhandle
, type
->size
);
2570 case DEBUG_KIND_BOOL
:
2571 return (*fns
->bool_type
) (fhandle
, type
->size
);
2572 case DEBUG_KIND_STRUCT
:
2573 case DEBUG_KIND_UNION
:
2574 if (type
->u
.kclass
!= NULL
)
2576 if (info
->class_mark
== type
->u
.kclass
->mark
2577 || type
->u
.kclass
->id
> info
->base_id
)
2579 /* We are currently outputting this struct, or we have
2580 already output it. I don't know if this can happen,
2581 but it can happen for a class. */
2582 assert (type
->u
.kclass
->id
> info
->base_id
);
2583 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2586 type
->u
.kclass
->mark
= info
->class_mark
;
2588 type
->u
.kclass
->id
= info
->class_id
;
2591 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2592 (type
->u
.kclass
!= NULL
2593 ? type
->u
.kclass
->id
2595 type
->kind
== DEBUG_KIND_STRUCT
,
2598 if (type
->u
.kclass
!= NULL
2599 && type
->u
.kclass
->fields
!= NULL
)
2601 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2603 struct debug_field
*f
;
2605 f
= type
->u
.kclass
->fields
[i
];
2606 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2607 (struct debug_name
*) NULL
)
2608 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2609 f
->u
.f
.bitsize
, f
->visibility
))
2613 return (*fns
->end_struct_type
) (fhandle
);
2614 case DEBUG_KIND_CLASS
:
2615 case DEBUG_KIND_UNION_CLASS
:
2616 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2617 case DEBUG_KIND_ENUM
:
2618 if (type
->u
.kenum
== NULL
)
2619 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2620 (bfd_signed_vma
*) NULL
);
2621 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2622 type
->u
.kenum
->values
);
2623 case DEBUG_KIND_POINTER
:
2624 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2625 (struct debug_name
*) NULL
))
2627 return (*fns
->pointer_type
) (fhandle
);
2628 case DEBUG_KIND_FUNCTION
:
2629 if (type
->u
.kfunction
->arg_types
== NULL
)
2633 for (is
= 0; type
->u
.kfunction
->arg_types
[is
] != NULL
; is
++)
2634 if (! debug_write_type (info
, fns
, fhandle
,
2635 type
->u
.kfunction
->arg_types
[is
],
2636 (struct debug_name
*) NULL
))
2639 if (! debug_write_type (info
, fns
, fhandle
,
2640 type
->u
.kfunction
->return_type
,
2641 (struct debug_name
*) NULL
))
2643 return (*fns
->function_type
) (fhandle
, is
,
2644 type
->u
.kfunction
->varargs
);
2645 case DEBUG_KIND_REFERENCE
:
2646 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2647 (struct debug_name
*) NULL
))
2649 return (*fns
->reference_type
) (fhandle
);
2650 case DEBUG_KIND_RANGE
:
2651 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2652 (struct debug_name
*) NULL
))
2654 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2655 type
->u
.krange
->upper
);
2656 case DEBUG_KIND_ARRAY
:
2657 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2658 (struct debug_name
*) NULL
)
2659 || ! debug_write_type (info
, fns
, fhandle
,
2660 type
->u
.karray
->range_type
,
2661 (struct debug_name
*) NULL
))
2663 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2664 type
->u
.karray
->upper
,
2665 type
->u
.karray
->stringp
);
2666 case DEBUG_KIND_SET
:
2667 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2668 (struct debug_name
*) NULL
))
2670 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2671 case DEBUG_KIND_OFFSET
:
2672 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2673 (struct debug_name
*) NULL
)
2674 || ! debug_write_type (info
, fns
, fhandle
,
2675 type
->u
.koffset
->target_type
,
2676 (struct debug_name
*) NULL
))
2678 return (*fns
->offset_type
) (fhandle
);
2679 case DEBUG_KIND_METHOD
:
2680 if (! debug_write_type (info
, fns
, fhandle
,
2681 type
->u
.kmethod
->return_type
,
2682 (struct debug_name
*) NULL
))
2684 if (type
->u
.kmethod
->arg_types
== NULL
)
2688 for (is
= 0; type
->u
.kmethod
->arg_types
[is
] != NULL
; is
++)
2689 if (! debug_write_type (info
, fns
, fhandle
,
2690 type
->u
.kmethod
->arg_types
[is
],
2691 (struct debug_name
*) NULL
))
2694 if (type
->u
.kmethod
->domain_type
!= NULL
)
2696 if (! debug_write_type (info
, fns
, fhandle
,
2697 type
->u
.kmethod
->domain_type
,
2698 (struct debug_name
*) NULL
))
2701 return (*fns
->method_type
) (fhandle
,
2702 type
->u
.kmethod
->domain_type
!= NULL
,
2704 type
->u
.kmethod
->varargs
);
2705 case DEBUG_KIND_CONST
:
2706 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2707 (struct debug_name
*) NULL
))
2709 return (*fns
->const_type
) (fhandle
);
2710 case DEBUG_KIND_VOLATILE
:
2711 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2712 (struct debug_name
*) NULL
))
2714 return (*fns
->volatile_type
) (fhandle
);
2715 case DEBUG_KIND_NAMED
:
2716 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2717 (struct debug_name
*) NULL
);
2718 case DEBUG_KIND_TAGGED
:
2719 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2720 type
->u
.knamed
->name
);
2727 /* Write out a class type. */
2730 debug_write_class_type (info
, fns
, fhandle
, type
, tag
)
2731 struct debug_handle
*info
;
2732 const struct debug_write_fns
*fns
;
2734 struct debug_type
*type
;
2739 struct debug_type
*vptrbase
;
2741 if (type
->u
.kclass
== NULL
)
2748 if (info
->class_mark
== type
->u
.kclass
->mark
2749 || type
->u
.kclass
->id
> info
->base_id
)
2751 /* We are currently outputting this class, or we have
2752 already output it. This can happen when there are
2753 methods for an anonymous class. */
2754 assert (type
->u
.kclass
->id
> info
->base_id
);
2755 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2758 type
->u
.kclass
->mark
= info
->class_mark
;
2760 id
= info
->class_id
;
2761 type
->u
.kclass
->id
= id
;
2763 vptrbase
= type
->u
.kclass
->vptrbase
;
2764 if (vptrbase
!= NULL
&& vptrbase
!= type
)
2766 if (! debug_write_type (info
, fns
, fhandle
, vptrbase
,
2767 (struct debug_name
*) NULL
))
2772 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2773 type
->kind
== DEBUG_KIND_CLASS
,
2779 if (type
->u
.kclass
!= NULL
)
2781 if (type
->u
.kclass
->fields
!= NULL
)
2783 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2785 struct debug_field
*f
;
2787 f
= type
->u
.kclass
->fields
[i
];
2788 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2789 (struct debug_name
*) NULL
))
2791 if (f
->static_member
)
2793 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2800 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2801 f
->u
.f
.bitsize
, f
->visibility
))
2807 if (type
->u
.kclass
->baseclasses
!= NULL
)
2809 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2811 struct debug_baseclass
*b
;
2813 b
= type
->u
.kclass
->baseclasses
[i
];
2814 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2815 (struct debug_name
*) NULL
))
2817 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2823 if (type
->u
.kclass
->methods
!= NULL
)
2825 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2827 struct debug_method
*m
;
2830 m
= type
->u
.kclass
->methods
[i
];
2831 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2833 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2835 struct debug_method_variant
*v
;
2838 if (v
->context
!= NULL
)
2840 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2841 (struct debug_name
*) NULL
))
2844 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2845 (struct debug_name
*) NULL
))
2847 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2849 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2854 v
->context
!= NULL
))
2859 if (! (*fns
->class_static_method_variant
) (fhandle
,
2867 if (! (*fns
->class_end_method
) (fhandle
))
2873 return (*fns
->end_class_type
) (fhandle
);
2876 /* Write out information for a function. */
2879 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2880 struct debug_handle
*info
;
2881 const struct debug_write_fns
*fns
;
2884 enum debug_object_linkage linkage
;
2885 struct debug_function
*function
;
2887 struct debug_parameter
*p
;
2888 struct debug_block
*b
;
2890 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2891 (struct debug_name
*) NULL
))
2894 if (! (*fns
->start_function
) (fhandle
, name
,
2895 linkage
== DEBUG_LINKAGE_GLOBAL
))
2898 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
2900 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
2901 (struct debug_name
*) NULL
)
2902 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
2906 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2908 if (! debug_write_block (info
, fns
, fhandle
, b
))
2912 return (*fns
->end_function
) (fhandle
);
2915 /* Write out information for a block. */
2918 debug_write_block (info
, fns
, fhandle
, block
)
2919 struct debug_handle
*info
;
2920 const struct debug_write_fns
*fns
;
2922 struct debug_block
*block
;
2924 struct debug_name
*n
;
2925 struct debug_block
*b
;
2927 if (! (*fns
->start_block
) (fhandle
, block
->start
))
2930 if (block
->locals
!= NULL
)
2932 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
2934 if (! debug_write_name (info
, fns
, fhandle
, n
))
2939 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
2941 if (! debug_write_block (info
, fns
, fhandle
, b
))
2945 return (*fns
->end_block
) (fhandle
, block
->end
);