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
723 debug_record_function (handle
, name
, return_type
, global
, addr
)
726 debug_type return_type
;
730 struct debug_handle
*info
= (struct debug_handle
*) handle
;
731 struct debug_function
*f
;
732 struct debug_block
*b
;
733 struct debug_name
*n
;
737 if (return_type
== NULL
)
740 if (info
->current_unit
== NULL
)
742 debug_error ("debug_record_function: no debug_set_filename call");
746 f
= (struct debug_function
*) xmalloc (sizeof *f
);
747 memset (f
, 0, sizeof *f
);
749 f
->return_type
= return_type
;
751 b
= (struct debug_block
*) xmalloc (sizeof *b
);
752 memset (b
, 0, sizeof *b
);
755 b
->end
= (bfd_vma
) -1;
759 info
->current_function
= f
;
760 info
->current_block
= b
;
762 /* FIXME: If we could handle nested functions, this would be the
763 place: we would want to use a different namespace. */
764 n
= debug_add_to_namespace (info
,
765 &info
->current_file
->globals
,
767 DEBUG_OBJECT_FUNCTION
,
769 ? DEBUG_LINKAGE_GLOBAL
770 : DEBUG_LINKAGE_STATIC
));
779 /* Record a parameter for the current function. */
782 debug_record_parameter (handle
, name
, type
, kind
, val
)
786 enum debug_parm_kind kind
;
789 struct debug_handle
*info
= (struct debug_handle
*) handle
;
790 struct debug_parameter
*p
, **pp
;
792 if (name
== NULL
|| type
== NULL
)
795 if (info
->current_unit
== NULL
796 || info
->current_function
== NULL
)
798 debug_error ("debug_record_parameter: no current function");
802 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
803 memset (p
, 0, sizeof *p
);
810 for (pp
= &info
->current_function
->parameters
;
819 /* End a function. FIXME: This should handle function nesting. */
822 debug_end_function (handle
, addr
)
826 struct debug_handle
*info
= (struct debug_handle
*) handle
;
828 if (info
->current_unit
== NULL
829 || info
->current_block
== NULL
830 || info
->current_function
== NULL
)
832 debug_error ("debug_end_function: no current function");
836 if (info
->current_block
->parent
!= NULL
)
838 debug_error ("debug_end_function: some blocks were not closed");
842 info
->current_block
->end
= addr
;
844 info
->current_function
= NULL
;
845 info
->current_block
= NULL
;
850 /* Start a block in a function. All local information will be
851 recorded in this block, until the matching call to debug_end_block.
852 debug_start_block and debug_end_block may be nested. The bfd_vma
853 argument is the address at which this block starts. */
856 debug_start_block (handle
, addr
)
860 struct debug_handle
*info
= (struct debug_handle
*) handle
;
861 struct debug_block
*b
, **pb
;
863 /* We must always have a current block: debug_record_function sets
865 if (info
->current_unit
== NULL
866 || info
->current_block
== NULL
)
868 debug_error ("debug_start_block: no current block");
872 b
= (struct debug_block
*) xmalloc (sizeof *b
);
873 memset (b
, 0, sizeof *b
);
875 b
->parent
= info
->current_block
;
877 b
->end
= (bfd_vma
) -1;
879 /* This new block is a child of the current block. */
880 for (pb
= &info
->current_block
->children
;
886 info
->current_block
= b
;
891 /* Finish a block in a function. This matches the call to
892 debug_start_block. The argument is the address at which this block
896 debug_end_block (handle
, addr
)
900 struct debug_handle
*info
= (struct debug_handle
*) handle
;
901 struct debug_block
*parent
;
903 if (info
->current_unit
== NULL
904 || info
->current_block
== NULL
)
906 debug_error ("debug_end_block: no current block");
910 parent
= info
->current_block
->parent
;
913 debug_error ("debug_end_block: attempt to close top level block");
917 info
->current_block
->end
= addr
;
919 info
->current_block
= parent
;
924 /* Associate a line number in the current source file and function
925 with a given address. */
928 debug_record_line (handle
, lineno
, addr
)
930 unsigned long lineno
;
933 struct debug_handle
*info
= (struct debug_handle
*) handle
;
934 struct debug_lineno
*l
;
937 if (info
->current_unit
== NULL
)
939 debug_error ("debug_record_line: no current unit");
943 l
= info
->current_lineno
;
944 if (l
!= NULL
&& l
->file
== info
->current_file
)
946 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
948 if (l
->linenos
[i
] == (unsigned long) -1)
950 l
->linenos
[i
] = lineno
;
957 /* If we get here, then either 1) there is no current_lineno
958 structure, which means this is the first line number in this
959 compilation unit, 2) the current_lineno structure is for a
960 different file, or 3) the current_lineno structure is full.
961 Regardless, we want to allocate a new debug_lineno structure, put
962 it in the right place, and make it the new current_lineno
965 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
966 memset (l
, 0, sizeof *l
);
968 l
->file
= info
->current_file
;
969 l
->linenos
[0] = lineno
;
971 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
972 l
->linenos
[i
] = (unsigned long) -1;
974 if (info
->current_lineno
!= NULL
)
975 info
->current_lineno
->next
= l
;
977 info
->current_unit
->linenos
= l
;
979 info
->current_lineno
= l
;
984 /* Start a named common block. This is a block of variables that may
988 debug_start_common_block (handle
, name
)
993 debug_error ("debug_start_common_block: not implemented");
997 /* End a named common block. */
1000 debug_end_common_block (handle
, name
)
1005 debug_error ("debug_end_common_block: not implemented");
1009 /* Record a named integer constant. */
1012 debug_record_int_const (handle
, name
, val
)
1017 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1018 struct debug_name
*n
;
1023 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1024 DEBUG_LINKAGE_NONE
);
1028 n
->u
.int_constant
= val
;
1033 /* Record a named floating point constant. */
1036 debug_record_float_const (handle
, name
, val
)
1041 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1042 struct debug_name
*n
;
1047 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1048 DEBUG_LINKAGE_NONE
);
1052 n
->u
.float_constant
= val
;
1057 /* Record a typed constant with an integral value. */
1060 debug_record_typed_const (handle
, name
, type
, val
)
1066 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1067 struct debug_name
*n
;
1068 struct debug_typed_constant
*tc
;
1070 if (name
== NULL
|| type
== NULL
)
1073 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1074 DEBUG_LINKAGE_NONE
);
1078 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1079 memset (tc
, 0, sizeof *tc
);
1084 n
->u
.typed_constant
= tc
;
1089 /* Record a label. */
1092 debug_record_label (handle
, name
, type
, addr
)
1099 debug_error ("debug_record_label not implemented");
1103 /* Record a variable. */
1106 debug_record_variable (handle
, name
, type
, kind
, val
)
1110 enum debug_var_kind kind
;
1113 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1114 struct debug_namespace
**nsp
;
1115 enum debug_object_linkage linkage
;
1116 struct debug_name
*n
;
1117 struct debug_variable
*v
;
1119 if (name
== NULL
|| type
== NULL
)
1122 if (info
->current_unit
== NULL
1123 || info
->current_file
== NULL
)
1125 debug_error ("debug_record_variable: no current file");
1129 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1131 nsp
= &info
->current_file
->globals
;
1132 if (kind
== DEBUG_GLOBAL
)
1133 linkage
= DEBUG_LINKAGE_GLOBAL
;
1135 linkage
= DEBUG_LINKAGE_STATIC
;
1139 if (info
->current_block
== NULL
)
1141 debug_error ("debug_record_variable: no current block");
1144 nsp
= &info
->current_block
->locals
;
1145 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1148 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1152 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1153 memset (v
, 0, sizeof *v
);
1164 /* Make a type with a given kind and size. */
1167 static struct debug_type
*
1168 debug_make_type (info
, kind
, size
)
1169 struct debug_handle
*info
;
1170 enum debug_type_kind kind
;
1173 struct debug_type
*t
;
1175 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1176 memset (t
, 0, sizeof *t
);
1184 /* Make an indirect type which may be used as a placeholder for a type
1185 which is referenced before it is defined. */
1188 debug_make_indirect_type (handle
, slot
, tag
)
1193 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1194 struct debug_type
*t
;
1195 struct debug_indirect_type
*i
;
1197 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1199 return DEBUG_TYPE_NULL
;
1201 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1202 memset (i
, 0, sizeof *i
);
1212 /* Make a void type. There is only one of these. */
1215 debug_make_void_type (handle
)
1218 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1220 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1223 /* Make an integer type of a given size. The boolean argument is true
1224 if the integer is unsigned. */
1227 debug_make_int_type (handle
, size
, unsignedp
)
1232 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1233 struct debug_type
*t
;
1235 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1237 return DEBUG_TYPE_NULL
;
1239 t
->u
.kint
= unsignedp
;
1244 /* Make a floating point type of a given size. FIXME: On some
1245 platforms, like an Alpha, you probably need to be able to specify
1249 debug_make_float_type (handle
, size
)
1253 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1255 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1258 /* Make a boolean type of a given size. */
1261 debug_make_bool_type (handle
, size
)
1265 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1267 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1270 /* Make a complex type of a given size. */
1273 debug_make_complex_type (handle
, size
)
1277 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1279 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1282 /* Make a structure type. The second argument is true for a struct,
1283 false for a union. The third argument is the size of the struct.
1284 The fourth argument is a NULL terminated array of fields. */
1287 debug_make_struct_type (handle
, structp
, size
, fields
)
1291 debug_field
*fields
;
1293 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1294 struct debug_type
*t
;
1295 struct debug_class_type
*c
;
1297 t
= debug_make_type (info
,
1298 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1301 return DEBUG_TYPE_NULL
;
1303 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1304 memset (c
, 0, sizeof *c
);
1313 /* Make an object type. The first three arguments after the handle
1314 are the same as for debug_make_struct_type. The next arguments are
1315 a NULL terminated array of base classes, a NULL terminated array of
1316 methods, the type of the object holding the virtual function table
1317 if it is not this object, and a boolean which is true if this
1318 object has its own virtual function table. */
1321 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1322 methods
, vptrbase
, ownvptr
)
1326 debug_field
*fields
;
1327 debug_baseclass
*baseclasses
;
1328 debug_method
*methods
;
1329 debug_type vptrbase
;
1332 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1333 struct debug_type
*t
;
1334 struct debug_class_type
*c
;
1336 t
= debug_make_type (info
,
1337 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1340 return DEBUG_TYPE_NULL
;
1342 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1343 memset (c
, 0, sizeof *c
);
1346 c
->baseclasses
= baseclasses
;
1347 c
->methods
= methods
;
1351 c
->vptrbase
= vptrbase
;
1358 /* Make an enumeration type. The arguments are a null terminated
1359 array of strings, and an array of corresponding values. */
1362 debug_make_enum_type (handle
, names
, values
)
1365 bfd_signed_vma
*values
;
1367 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1368 struct debug_type
*t
;
1369 struct debug_enum_type
*e
;
1371 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1373 return DEBUG_TYPE_NULL
;
1375 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1376 memset (e
, 0, sizeof *e
);
1386 /* Make a pointer to a given type. */
1389 debug_make_pointer_type (handle
, type
)
1393 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1394 struct debug_type
*t
;
1397 return DEBUG_TYPE_NULL
;
1399 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1400 return type
->pointer
;
1402 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1404 return DEBUG_TYPE_NULL
;
1406 t
->u
.kpointer
= type
;
1413 /* Make a function returning a given type. FIXME: We should be able
1414 to record the parameter types. */
1417 debug_make_function_type (handle
, type
, arg_types
, varargs
)
1420 debug_type
*arg_types
;
1423 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1424 struct debug_type
*t
;
1425 struct debug_function_type
*f
;
1428 return DEBUG_TYPE_NULL
;
1430 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1432 return DEBUG_TYPE_NULL
;
1434 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1435 memset (f
, 0, sizeof *f
);
1437 f
->return_type
= type
;
1438 f
->arg_types
= arg_types
;
1439 f
->varargs
= varargs
;
1446 /* Make a reference to a given type. */
1449 debug_make_reference_type (handle
, type
)
1453 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1454 struct debug_type
*t
;
1457 return DEBUG_TYPE_NULL
;
1459 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1461 return DEBUG_TYPE_NULL
;
1463 t
->u
.kreference
= type
;
1468 /* Make a range of a given type from a lower to an upper bound. */
1471 debug_make_range_type (handle
, type
, lower
, upper
)
1474 bfd_signed_vma lower
;
1475 bfd_signed_vma upper
;
1477 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1478 struct debug_type
*t
;
1479 struct debug_range_type
*r
;
1482 return DEBUG_TYPE_NULL
;
1484 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1486 return DEBUG_TYPE_NULL
;
1488 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1489 memset (r
, 0, sizeof *r
);
1500 /* Make an array type. The second argument is the type of an element
1501 of the array. The third argument is the type of a range of the
1502 array. The fourth and fifth argument are the lower and upper
1503 bounds, respectively. The sixth argument is true if this array is
1504 actually a string, as in C. */
1507 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1510 debug_type element_type
;
1511 debug_type range_type
;
1512 bfd_signed_vma lower
;
1513 bfd_signed_vma upper
;
1516 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1517 struct debug_type
*t
;
1518 struct debug_array_type
*a
;
1520 if (element_type
== NULL
|| range_type
== NULL
)
1521 return DEBUG_TYPE_NULL
;
1523 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1525 return DEBUG_TYPE_NULL
;
1527 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1528 memset (a
, 0, sizeof *a
);
1530 a
->element_type
= element_type
;
1531 a
->range_type
= range_type
;
1534 a
->stringp
= stringp
;
1541 /* Make a set of a given type. For example, a Pascal set type. The
1542 boolean argument is true if this set is actually a bitstring, as in
1546 debug_make_set_type (handle
, type
, bitstringp
)
1551 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1552 struct debug_type
*t
;
1553 struct debug_set_type
*s
;
1556 return DEBUG_TYPE_NULL
;
1558 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1560 return DEBUG_TYPE_NULL
;
1562 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1563 memset (s
, 0, sizeof *s
);
1566 s
->bitstringp
= bitstringp
;
1573 /* Make a type for a pointer which is relative to an object. The
1574 second argument is the type of the object to which the pointer is
1575 relative. The third argument is the type that the pointer points
1579 debug_make_offset_type (handle
, base_type
, target_type
)
1581 debug_type base_type
;
1582 debug_type target_type
;
1584 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1585 struct debug_type
*t
;
1586 struct debug_offset_type
*o
;
1588 if (base_type
== NULL
|| target_type
== NULL
)
1589 return DEBUG_TYPE_NULL
;
1591 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1593 return DEBUG_TYPE_NULL
;
1595 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1596 memset (o
, 0, sizeof *o
);
1598 o
->base_type
= base_type
;
1599 o
->target_type
= target_type
;
1606 /* Make a type for a method function. The second argument is the
1607 return type, the third argument is the domain, and the fourth
1608 argument is a NULL terminated array of argument types. */
1611 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
, varargs
)
1613 debug_type return_type
;
1614 debug_type domain_type
;
1615 debug_type
*arg_types
;
1618 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1619 struct debug_type
*t
;
1620 struct debug_method_type
*m
;
1622 if (return_type
== NULL
)
1623 return DEBUG_TYPE_NULL
;
1625 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1627 return DEBUG_TYPE_NULL
;
1629 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1630 memset (m
, 0, sizeof *m
);
1632 m
->return_type
= return_type
;
1633 m
->domain_type
= domain_type
;
1634 m
->arg_types
= arg_types
;
1635 m
->varargs
= varargs
;
1642 /* Make a const qualified version of a given type. */
1645 debug_make_const_type (handle
, type
)
1649 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1650 struct debug_type
*t
;
1653 return DEBUG_TYPE_NULL
;
1655 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1657 return DEBUG_TYPE_NULL
;
1664 /* Make a volatile qualified version of a given type. */
1667 debug_make_volatile_type (handle
, type
)
1671 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1672 struct debug_type
*t
;
1675 return DEBUG_TYPE_NULL
;
1677 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1679 return DEBUG_TYPE_NULL
;
1681 t
->u
.kvolatile
= type
;
1686 /* Make an undefined tagged type. For example, a struct which has
1687 been mentioned, but not defined. */
1690 debug_make_undefined_tagged_type (handle
, name
, kind
)
1693 enum debug_type_kind kind
;
1695 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1696 struct debug_type
*t
;
1699 return DEBUG_TYPE_NULL
;
1703 case DEBUG_KIND_STRUCT
:
1704 case DEBUG_KIND_UNION
:
1705 case DEBUG_KIND_CLASS
:
1706 case DEBUG_KIND_UNION_CLASS
:
1707 case DEBUG_KIND_ENUM
:
1711 debug_error ("debug_make_undefined_type: unsupported kind");
1712 return DEBUG_TYPE_NULL
;
1715 t
= debug_make_type (info
, kind
, 0);
1717 return DEBUG_TYPE_NULL
;
1719 return debug_tag_type (handle
, name
, t
);
1722 /* Make a base class for an object. The second argument is the base
1723 class type. The third argument is the bit position of this base
1724 class in the object (always 0 unless doing multiple inheritance).
1725 The fourth argument is whether this is a virtual class. The fifth
1726 argument is the visibility of the base class. */
1730 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1735 enum debug_visibility visibility
;
1737 struct debug_baseclass
*b
;
1739 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1740 memset (b
, 0, sizeof *b
);
1744 b
->virtual = virtual;
1745 b
->visibility
= visibility
;
1750 /* Make a field for a struct. The second argument is the name. The
1751 third argument is the type of the field. The fourth argument is
1752 the bit position of the field. The fifth argument is the size of
1753 the field (it may be zero). The sixth argument is the visibility
1758 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1764 enum debug_visibility visibility
;
1766 struct debug_field
*f
;
1768 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1769 memset (f
, 0, sizeof *f
);
1773 f
->static_member
= false;
1774 f
->u
.f
.bitpos
= bitpos
;
1775 f
->u
.f
.bitsize
= bitsize
;
1776 f
->visibility
= visibility
;
1781 /* Make a static member of an object. The second argument is the
1782 name. The third argument is the type of the member. The fourth
1783 argument is the physical name of the member (i.e., the name as a
1784 global variable). The fifth argument is the visibility of the
1789 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1793 const char *physname
;
1794 enum debug_visibility visibility
;
1796 struct debug_field
*f
;
1798 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1799 memset (f
, 0, sizeof *f
);
1803 f
->static_member
= true;
1804 f
->u
.s
.physname
= physname
;
1805 f
->visibility
= visibility
;
1810 /* Make a method. The second argument is the name, and the third
1811 argument is a NULL terminated array of method variants. */
1815 debug_make_method (handle
, name
, variants
)
1818 debug_method_variant
*variants
;
1820 struct debug_method
*m
;
1822 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1823 memset (m
, 0, sizeof *m
);
1826 m
->variants
= variants
;
1831 /* Make a method argument. The second argument is the real name of
1832 the function. The third argument is the type of the function. The
1833 fourth argument is the visibility. The fifth argument is whether
1834 this is a const function. The sixth argument is whether this is a
1835 volatile function. The seventh argument is the offset in the
1836 virtual function table, if any. The eighth argument is the virtual
1837 function context. FIXME: Are the const and volatile arguments
1838 necessary? Could we just use debug_make_const_type? */
1841 debug_method_variant
1842 debug_make_method_variant (handle
, physname
, type
, visibility
, constp
,
1843 volatilep
, voffset
, context
)
1845 const char *physname
;
1847 enum debug_visibility visibility
;
1853 struct debug_method_variant
*m
;
1855 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1856 memset (m
, 0, sizeof *m
);
1858 m
->physname
= physname
;
1860 m
->visibility
= visibility
;
1862 m
->volatilep
= volatilep
;
1863 m
->voffset
= voffset
;
1864 m
->context
= context
;
1869 /* Make a static method argument. The arguments are the same as for
1870 debug_make_method_variant, except that the last two are omitted
1871 since a static method can not also be virtual. */
1873 debug_method_variant
1874 debug_make_static_method_variant (handle
, physname
, type
, visibility
,
1877 const char *physname
;
1879 enum debug_visibility visibility
;
1883 struct debug_method_variant
*m
;
1885 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1886 memset (m
, 0, sizeof *m
);
1888 m
->physname
= physname
;
1890 m
->visibility
= visibility
;
1892 m
->volatilep
= volatilep
;
1893 m
->voffset
= VOFFSET_STATIC_METHOD
;
1901 debug_name_type (handle
, name
, type
)
1906 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1907 struct debug_type
*t
;
1908 struct debug_named_type
*n
;
1909 struct debug_name
*nm
;
1911 if (name
== NULL
|| type
== NULL
)
1912 return DEBUG_TYPE_NULL
;
1914 if (info
->current_unit
== NULL
1915 || info
->current_file
== NULL
)
1917 debug_error ("debug_record_variable: no current file");
1921 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1923 return DEBUG_TYPE_NULL
;
1925 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1926 memset (n
, 0, sizeof *n
);
1932 /* We always add the name to the global namespace. This is probably
1933 wrong in some cases, but it seems to be right for stabs. FIXME. */
1935 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1936 DEBUG_OBJECT_TYPE
, DEBUG_LINKAGE_NONE
);
1950 debug_tag_type (handle
, name
, type
)
1955 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1956 struct debug_type
*t
;
1957 struct debug_named_type
*n
;
1958 struct debug_name
*nm
;
1960 if (name
== NULL
|| type
== NULL
)
1961 return DEBUG_TYPE_NULL
;
1963 if (info
->current_file
== NULL
)
1965 debug_error ("debug_tag_type: no current file");
1966 return DEBUG_TYPE_NULL
;
1969 if (type
->kind
== DEBUG_KIND_TAGGED
)
1971 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
1973 debug_error ("debug_tag_type: extra tag attempted");
1974 return DEBUG_TYPE_NULL
;
1977 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
1979 return DEBUG_TYPE_NULL
;
1981 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1982 memset (n
, 0, sizeof *n
);
1988 /* We keep a global namespace of tags for each compilation unit. I
1989 don't know if that is the right thing to do. */
1991 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1992 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2003 /* Record the size of a given type. */
2007 debug_record_type_size (handle
, type
, size
)
2012 if (type
->size
!= 0 && type
->size
!= size
)
2013 fprintf (stderr
, "Warning: changing type size from %d to %d\n",
2021 /* Find a named type. */
2024 debug_find_named_type (handle
, name
)
2028 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2029 struct debug_block
*b
;
2030 struct debug_file
*f
;
2032 /* We only search the current compilation unit. I don't know if
2033 this is right or not. */
2035 if (info
->current_unit
== NULL
)
2037 debug_error ("debug_find_named_type: no current compilation unit");
2038 return DEBUG_TYPE_NULL
;
2041 for (b
= info
->current_block
; b
!= NULL
; b
= b
->parent
)
2043 if (b
->locals
!= NULL
)
2045 struct debug_name
*n
;
2047 for (n
= b
->locals
->list
; n
!= NULL
; n
= n
->next
)
2049 if (n
->kind
== DEBUG_OBJECT_TYPE
2050 && n
->name
[0] == name
[0]
2051 && strcmp (n
->name
, name
) == 0)
2057 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
2059 if (f
->globals
!= NULL
)
2061 struct debug_name
*n
;
2063 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2065 if (n
->kind
== DEBUG_OBJECT_TYPE
2066 && n
->name
[0] == name
[0]
2067 && strcmp (n
->name
, name
) == 0)
2073 return DEBUG_TYPE_NULL
;
2076 /* Find a tagged type. */
2079 debug_find_tagged_type (handle
, name
, kind
)
2082 enum debug_type_kind kind
;
2084 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2085 struct debug_unit
*u
;
2087 /* We search the globals of all the compilation units. I don't know
2088 if this is correct or not. It would be easy to change. */
2090 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2092 struct debug_file
*f
;
2094 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2096 struct debug_name
*n
;
2098 if (f
->globals
!= NULL
)
2100 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2102 if (n
->kind
== DEBUG_OBJECT_TAG
2103 && (kind
== DEBUG_KIND_ILLEGAL
2104 || n
->u
.tag
->kind
== kind
)
2105 && n
->name
[0] == name
[0]
2106 && strcmp (n
->name
, name
) == 0)
2113 return DEBUG_TYPE_NULL
;
2116 /* Get a base type. */
2118 static struct debug_type
*
2119 debug_get_real_type (handle
, type
)
2127 case DEBUG_KIND_INDIRECT
:
2128 if (*type
->u
.kindirect
->slot
!= NULL
)
2129 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
);
2131 case DEBUG_KIND_NAMED
:
2132 case DEBUG_KIND_TAGGED
:
2133 return debug_get_real_type (handle
, type
->u
.knamed
->type
);
2138 /* Get the kind of a type. */
2140 enum debug_type_kind
2141 debug_get_type_kind (handle
, type
)
2146 return DEBUG_KIND_ILLEGAL
;
2147 type
= debug_get_real_type (handle
, type
);
2151 /* Get the name of a type. */
2154 debug_get_type_name (handle
, type
)
2158 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2160 if (*type
->u
.kindirect
->slot
!= NULL
)
2161 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2162 return type
->u
.kindirect
->tag
;
2164 if (type
->kind
== DEBUG_KIND_NAMED
2165 || type
->kind
== DEBUG_KIND_TAGGED
)
2166 return type
->u
.knamed
->name
->name
;
2170 /* Get the size of a type. */
2173 debug_get_type_size (handle
, type
)
2180 /* We don't call debug_get_real_type, because somebody might have
2181 called debug_record_type_size on a named or indirect type. */
2183 if (type
->size
!= 0)
2190 case DEBUG_KIND_INDIRECT
:
2191 if (*type
->u
.kindirect
->slot
!= NULL
)
2192 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2194 case DEBUG_KIND_NAMED
:
2195 case DEBUG_KIND_TAGGED
:
2196 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2201 /* Get the return type of a function or method type. */
2204 debug_get_return_type (handle
, type
)
2209 return DEBUG_TYPE_NULL
;
2210 type
= debug_get_real_type (handle
, type
);
2214 return DEBUG_TYPE_NULL
;
2215 case DEBUG_KIND_FUNCTION
:
2216 return type
->u
.kfunction
->return_type
;
2217 case DEBUG_KIND_METHOD
:
2218 return type
->u
.kmethod
->return_type
;
2223 /* Get the parameter types of a function or method type (except that
2224 we don't currently store the parameter types of a function). */
2227 debug_get_parameter_types (handle
, type
, pvarargs
)
2234 type
= debug_get_real_type (handle
, type
);
2239 case DEBUG_KIND_FUNCTION
:
2240 *pvarargs
= type
->u
.kfunction
->varargs
;
2241 return type
->u
.kfunction
->arg_types
;
2242 case DEBUG_KIND_METHOD
:
2243 *pvarargs
= type
->u
.kmethod
->varargs
;
2244 return type
->u
.kmethod
->arg_types
;
2249 /* Get the target type of a type. */
2252 debug_get_target_type (handle
, type
)
2258 type
= debug_get_real_type (handle
, type
);
2263 case DEBUG_KIND_POINTER
:
2264 return type
->u
.kpointer
;
2265 case DEBUG_KIND_REFERENCE
:
2266 return type
->u
.kreference
;
2267 case DEBUG_KIND_CONST
:
2268 return type
->u
.kconst
;
2269 case DEBUG_KIND_VOLATILE
:
2270 return type
->u
.kvolatile
;
2275 /* Get the NULL terminated array of fields for a struct, union, or
2279 debug_get_fields (handle
, type
)
2285 type
= debug_get_real_type (handle
, type
);
2290 case DEBUG_KIND_STRUCT
:
2291 case DEBUG_KIND_UNION
:
2292 case DEBUG_KIND_CLASS
:
2293 case DEBUG_KIND_UNION_CLASS
:
2294 return type
->u
.kclass
->fields
;
2299 /* Get the type of a field. */
2303 debug_get_field_type (handle
, field
)
2312 /* Get the name of a field. */
2316 debug_get_field_name (handle
, field
)
2325 /* Get the bit position of a field. */
2329 debug_get_field_bitpos (handle
, field
)
2333 if (field
== NULL
|| field
->static_member
)
2334 return (bfd_vma
) -1;
2335 return field
->u
.f
.bitpos
;
2338 /* Get the bit size of a field. */
2342 debug_get_field_bitsize (handle
, field
)
2346 if (field
== NULL
|| field
->static_member
)
2347 return (bfd_vma
) -1;
2348 return field
->u
.f
.bitsize
;
2351 /* Get the visibility of a field. */
2354 enum debug_visibility
2355 debug_get_field_visibility (handle
, field
)
2360 return DEBUG_VISIBILITY_IGNORE
;
2361 return field
->visibility
;
2364 /* Get the physical name of a field. */
2367 debug_get_field_physname (handle
, field
)
2371 if (field
== NULL
|| ! field
->static_member
)
2373 return field
->u
.s
.physname
;
2376 /* Write out the debugging information. This is given a handle to
2377 debugging information, and a set of function pointers to call. */
2380 debug_write (handle
, fns
, fhandle
)
2382 const struct debug_write_fns
*fns
;
2385 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2386 struct debug_unit
*u
;
2388 /* We use a mark to tell whether we have already written out a
2389 particular name. We use an integer, so that we don't have to
2390 clear the mark fields if we happen to write out the same
2391 information more than once. */
2394 /* The base_id field holds an ID value which will never be used, so
2395 that we can tell whether we have assigned an ID during this call
2397 info
->base_id
= info
->class_id
;
2399 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2401 struct debug_file
*f
;
2403 struct debug_lineno
*l
;
2405 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2409 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2411 struct debug_name
*n
;
2417 if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2421 if (f
->globals
!= NULL
)
2423 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2425 if (! debug_write_name (info
, fns
, fhandle
, n
))
2431 for (l
= u
->linenos
; l
!= NULL
; l
= l
->next
)
2435 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
2437 if (l
->linenos
[i
] == (unsigned long) -1)
2439 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
, l
->linenos
[i
],
2449 /* Write out an element in a namespace. */
2452 debug_write_name (info
, fns
, fhandle
, n
)
2453 struct debug_handle
*info
;
2454 const struct debug_write_fns
*fns
;
2456 struct debug_name
*n
;
2458 /* The class_mark field is used to prevent recursively outputting a
2464 case DEBUG_OBJECT_TYPE
:
2465 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2466 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2469 case DEBUG_OBJECT_TAG
:
2470 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2472 return (*fns
->tag
) (fhandle
, n
->name
);
2473 case DEBUG_OBJECT_VARIABLE
:
2474 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2475 (struct debug_name
*) NULL
))
2477 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2478 n
->u
.variable
->val
);
2479 case DEBUG_OBJECT_FUNCTION
:
2480 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2481 n
->linkage
, n
->u
.function
);
2482 case DEBUG_OBJECT_INT_CONSTANT
:
2483 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2484 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2485 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2486 case DEBUG_OBJECT_TYPED_CONSTANT
:
2487 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2488 (struct debug_name
*) NULL
))
2490 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2491 n
->u
.typed_constant
->val
);
2499 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2500 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2501 are about to call typedef or tag. If the type is anything else,
2502 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2503 points to this one. */
2506 debug_write_type (info
, fns
, fhandle
, type
, name
)
2507 struct debug_handle
*info
;
2508 const struct debug_write_fns
*fns
;
2510 struct debug_type
*type
;
2511 struct debug_name
*name
;
2517 /* If we have a name for this type, just output it. We only output
2518 typedef names after they have been defined. We output type tags
2519 whenever we are not actually defining them. */
2520 if ((type
->kind
== DEBUG_KIND_NAMED
2521 || type
->kind
== DEBUG_KIND_TAGGED
)
2522 && (type
->u
.knamed
->name
->mark
== info
->mark
2523 || (type
->kind
== DEBUG_KIND_TAGGED
2524 && type
->u
.knamed
->name
!= name
)))
2526 if (type
->kind
== DEBUG_KIND_NAMED
)
2527 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2530 struct debug_type
*real
;
2532 real
= debug_get_real_type ((PTR
) info
, type
);
2533 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, 0,
2538 /* Mark the name after we have already looked for a known name, so
2539 that we don't just define a type in terms of itself. We need to
2540 mark the name here so that a struct containing a pointer to
2541 itself will work. */
2543 name
->mark
= info
->mark
;
2547 && type
->kind
!= DEBUG_KIND_NAMED
2548 && type
->kind
!= DEBUG_KIND_TAGGED
)
2550 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2556 case DEBUG_KIND_ILLEGAL
:
2557 debug_error ("debug_write_type: illegal type encountered");
2559 case DEBUG_KIND_INDIRECT
:
2560 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2561 return (*fns
->empty_type
) (fhandle
);
2562 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2564 case DEBUG_KIND_VOID
:
2565 return (*fns
->void_type
) (fhandle
);
2566 case DEBUG_KIND_INT
:
2567 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2568 case DEBUG_KIND_FLOAT
:
2569 return (*fns
->float_type
) (fhandle
, type
->size
);
2570 case DEBUG_KIND_COMPLEX
:
2571 return (*fns
->complex_type
) (fhandle
, type
->size
);
2572 case DEBUG_KIND_BOOL
:
2573 return (*fns
->bool_type
) (fhandle
, type
->size
);
2574 case DEBUG_KIND_STRUCT
:
2575 case DEBUG_KIND_UNION
:
2576 if (type
->u
.kclass
!= NULL
)
2578 if (info
->class_mark
== type
->u
.kclass
->mark
2579 || (tag
== NULL
&& type
->u
.kclass
->id
> info
->base_id
))
2581 /* We are currently outputting this struct, or we have
2582 already output it. I don't know if this can happen,
2583 but it can happen for a class. */
2584 assert (type
->u
.kclass
->id
> info
->base_id
);
2585 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2588 type
->u
.kclass
->mark
= info
->class_mark
;
2592 type
->u
.kclass
->id
= info
->class_id
;
2596 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2597 (type
->u
.kclass
!= NULL
2598 ? type
->u
.kclass
->id
2600 type
->kind
== DEBUG_KIND_STRUCT
,
2603 if (type
->u
.kclass
!= NULL
2604 && type
->u
.kclass
->fields
!= NULL
)
2606 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2608 struct debug_field
*f
;
2610 f
= type
->u
.kclass
->fields
[i
];
2611 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2612 (struct debug_name
*) NULL
)
2613 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2614 f
->u
.f
.bitsize
, f
->visibility
))
2618 return (*fns
->end_struct_type
) (fhandle
);
2619 case DEBUG_KIND_CLASS
:
2620 case DEBUG_KIND_UNION_CLASS
:
2621 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2622 case DEBUG_KIND_ENUM
:
2623 if (type
->u
.kenum
== NULL
)
2624 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2625 (bfd_signed_vma
*) NULL
);
2626 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2627 type
->u
.kenum
->values
);
2628 case DEBUG_KIND_POINTER
:
2629 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2630 (struct debug_name
*) NULL
))
2632 return (*fns
->pointer_type
) (fhandle
);
2633 case DEBUG_KIND_FUNCTION
:
2634 if (type
->u
.kfunction
->arg_types
== NULL
)
2638 for (is
= 0; type
->u
.kfunction
->arg_types
[is
] != NULL
; is
++)
2639 if (! debug_write_type (info
, fns
, fhandle
,
2640 type
->u
.kfunction
->arg_types
[is
],
2641 (struct debug_name
*) NULL
))
2644 if (! debug_write_type (info
, fns
, fhandle
,
2645 type
->u
.kfunction
->return_type
,
2646 (struct debug_name
*) NULL
))
2648 return (*fns
->function_type
) (fhandle
, is
,
2649 type
->u
.kfunction
->varargs
);
2650 case DEBUG_KIND_REFERENCE
:
2651 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2652 (struct debug_name
*) NULL
))
2654 return (*fns
->reference_type
) (fhandle
);
2655 case DEBUG_KIND_RANGE
:
2656 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2657 (struct debug_name
*) NULL
))
2659 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2660 type
->u
.krange
->upper
);
2661 case DEBUG_KIND_ARRAY
:
2662 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2663 (struct debug_name
*) NULL
)
2664 || ! debug_write_type (info
, fns
, fhandle
,
2665 type
->u
.karray
->range_type
,
2666 (struct debug_name
*) NULL
))
2668 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2669 type
->u
.karray
->upper
,
2670 type
->u
.karray
->stringp
);
2671 case DEBUG_KIND_SET
:
2672 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2673 (struct debug_name
*) NULL
))
2675 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2676 case DEBUG_KIND_OFFSET
:
2677 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2678 (struct debug_name
*) NULL
)
2679 || ! debug_write_type (info
, fns
, fhandle
,
2680 type
->u
.koffset
->target_type
,
2681 (struct debug_name
*) NULL
))
2683 return (*fns
->offset_type
) (fhandle
);
2684 case DEBUG_KIND_METHOD
:
2685 if (! debug_write_type (info
, fns
, fhandle
,
2686 type
->u
.kmethod
->return_type
,
2687 (struct debug_name
*) NULL
))
2689 if (type
->u
.kmethod
->arg_types
== NULL
)
2693 for (is
= 0; type
->u
.kmethod
->arg_types
[is
] != NULL
; is
++)
2694 if (! debug_write_type (info
, fns
, fhandle
,
2695 type
->u
.kmethod
->arg_types
[is
],
2696 (struct debug_name
*) NULL
))
2699 if (type
->u
.kmethod
->domain_type
!= NULL
)
2701 if (! debug_write_type (info
, fns
, fhandle
,
2702 type
->u
.kmethod
->domain_type
,
2703 (struct debug_name
*) NULL
))
2706 return (*fns
->method_type
) (fhandle
,
2707 type
->u
.kmethod
->domain_type
!= NULL
,
2709 type
->u
.kmethod
->varargs
);
2710 case DEBUG_KIND_CONST
:
2711 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2712 (struct debug_name
*) NULL
))
2714 return (*fns
->const_type
) (fhandle
);
2715 case DEBUG_KIND_VOLATILE
:
2716 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2717 (struct debug_name
*) NULL
))
2719 return (*fns
->volatile_type
) (fhandle
);
2720 case DEBUG_KIND_NAMED
:
2721 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2722 (struct debug_name
*) NULL
);
2723 case DEBUG_KIND_TAGGED
:
2724 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2725 type
->u
.knamed
->name
);
2732 /* Write out a class type. */
2735 debug_write_class_type (info
, fns
, fhandle
, type
, tag
)
2736 struct debug_handle
*info
;
2737 const struct debug_write_fns
*fns
;
2739 struct debug_type
*type
;
2744 struct debug_type
*vptrbase
;
2746 if (type
->u
.kclass
== NULL
)
2753 if (info
->class_mark
== type
->u
.kclass
->mark
2754 || (tag
== NULL
&& type
->u
.kclass
->id
> info
->base_id
))
2756 /* We are currently outputting this class, or we have
2757 already output it. This can happen when there are
2758 methods for an anonymous class. */
2759 assert (type
->u
.kclass
->id
> info
->base_id
);
2760 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2763 type
->u
.kclass
->mark
= info
->class_mark
;
2767 type
->u
.kclass
->id
= info
->class_id
;
2769 id
= type
->u
.kclass
->id
;
2771 vptrbase
= type
->u
.kclass
->vptrbase
;
2772 if (vptrbase
!= NULL
&& vptrbase
!= type
)
2774 if (! debug_write_type (info
, fns
, fhandle
, vptrbase
,
2775 (struct debug_name
*) NULL
))
2780 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2781 type
->kind
== DEBUG_KIND_CLASS
,
2787 if (type
->u
.kclass
!= NULL
)
2789 if (type
->u
.kclass
->fields
!= NULL
)
2791 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2793 struct debug_field
*f
;
2795 f
= type
->u
.kclass
->fields
[i
];
2796 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2797 (struct debug_name
*) NULL
))
2799 if (f
->static_member
)
2801 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2808 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2809 f
->u
.f
.bitsize
, f
->visibility
))
2815 if (type
->u
.kclass
->baseclasses
!= NULL
)
2817 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2819 struct debug_baseclass
*b
;
2821 b
= type
->u
.kclass
->baseclasses
[i
];
2822 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2823 (struct debug_name
*) NULL
))
2825 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2831 if (type
->u
.kclass
->methods
!= NULL
)
2833 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2835 struct debug_method
*m
;
2838 m
= type
->u
.kclass
->methods
[i
];
2839 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2841 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2843 struct debug_method_variant
*v
;
2846 if (v
->context
!= NULL
)
2848 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2849 (struct debug_name
*) NULL
))
2852 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2853 (struct debug_name
*) NULL
))
2855 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2857 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2862 v
->context
!= NULL
))
2867 if (! (*fns
->class_static_method_variant
) (fhandle
,
2875 if (! (*fns
->class_end_method
) (fhandle
))
2881 return (*fns
->end_class_type
) (fhandle
);
2884 /* Write out information for a function. */
2887 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2888 struct debug_handle
*info
;
2889 const struct debug_write_fns
*fns
;
2892 enum debug_object_linkage linkage
;
2893 struct debug_function
*function
;
2895 struct debug_parameter
*p
;
2896 struct debug_block
*b
;
2898 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2899 (struct debug_name
*) NULL
))
2902 if (! (*fns
->start_function
) (fhandle
, name
,
2903 linkage
== DEBUG_LINKAGE_GLOBAL
))
2906 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
2908 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
2909 (struct debug_name
*) NULL
)
2910 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
2914 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2916 if (! debug_write_block (info
, fns
, fhandle
, b
))
2920 return (*fns
->end_function
) (fhandle
);
2923 /* Write out information for a block. */
2926 debug_write_block (info
, fns
, fhandle
, block
)
2927 struct debug_handle
*info
;
2928 const struct debug_write_fns
*fns
;
2930 struct debug_block
*block
;
2932 struct debug_name
*n
;
2933 struct debug_block
*b
;
2935 if (! (*fns
->start_block
) (fhandle
, block
->start
))
2938 if (block
->locals
!= NULL
)
2940 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
2942 if (! debug_write_name (info
, fns
, fhandle
, n
))
2947 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
2949 if (! debug_write_block (info
, fns
, fhandle
, b
))
2953 return (*fns
->end_block
) (fhandle
, block
->end
);