1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995-2024 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 3 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., 51 Franklin Street - Fifth Floor, Boston, MA
23 /* This file implements a generic debugging format. We may eventually
24 have readers which convert different formats into this generic
25 format, and writers which write it out. The initial impetus for
26 this was writing a converter from stabs to HP IEEE-695 debugging
32 #include "libiberty.h"
33 #include "filenames.h"
37 /* Global information we keep for debugging. A pointer to this
38 structure is the debugging handle passed to all the routines. */
42 /* The bfd where we objalloc memory. */
44 /* A linked list of compilation units. */
45 struct debug_unit
*units
;
46 /* The current compilation unit. */
47 struct debug_unit
*current_unit
;
48 /* The current source file. */
49 struct debug_file
*current_file
;
50 /* The current function. */
51 struct debug_function
*current_function
;
52 /* The current block. */
53 struct debug_block
*current_block
;
54 /* The current line number information for the current unit. */
55 struct debug_lineno
*current_lineno
;
56 /* Mark. This is used by debug_write. */
58 /* A struct/class ID used by debug_write. */
59 unsigned int class_id
;
60 /* The base for class_id for this call to debug_write. */
62 /* The current line number in debug_write. */
63 struct debug_lineno
*current_write_lineno
;
64 unsigned int current_write_lineno_index
;
65 /* A list of classes which have assigned ID's during debug_write.
66 This is linked through the next_id field of debug_class_type. */
67 struct debug_class_id
*id_list
;
68 /* A list used to avoid recursion during debug_type_samep. */
69 struct debug_type_compare_list
*compare_list
;
72 /* Information we keep for a single compilation unit. */
76 /* The next compilation unit. */
77 struct debug_unit
*next
;
78 /* A list of files included in this compilation unit. The first
79 file is always the main one, and that is where the main file name
81 struct debug_file
*files
;
82 /* Line number information for this compilation unit. This is not
83 stored by function, because assembler code may have line number
84 information without function information. */
85 struct debug_lineno
*linenos
;
88 /* Information kept for a single source file. */
92 /* The next source file in this compilation unit. */
93 struct debug_file
*next
;
94 /* The name of the source file. */
96 /* Global functions, variables, types, etc. */
97 struct debug_namespace
*globals
;
105 enum debug_type_kind kind
;
106 /* Size of type (0 if not known). */
108 /* Used by debug_write to stop DEBUG_KIND_INDIRECT infinite recursion. */
110 /* Type which is a pointer to this type. */
112 /* Tagged union with additional information about the type. */
115 /* DEBUG_KIND_INDIRECT. */
116 struct debug_indirect_type
*kindirect
;
117 /* DEBUG_KIND_INT. */
118 /* Whether the integer is unsigned. */
120 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
121 DEBUG_KIND_UNION_CLASS. */
122 struct debug_class_type
*kclass
;
123 /* DEBUG_KIND_ENUM. */
124 struct debug_enum_type
*kenum
;
125 /* DEBUG_KIND_POINTER. */
126 struct debug_type_s
*kpointer
;
127 /* DEBUG_KIND_FUNCTION. */
128 struct debug_function_type
*kfunction
;
129 /* DEBUG_KIND_REFERENCE. */
130 struct debug_type_s
*kreference
;
131 /* DEBUG_KIND_RANGE. */
132 struct debug_range_type
*krange
;
133 /* DEBUG_KIND_ARRAY. */
134 struct debug_array_type
*karray
;
135 /* DEBUG_KIND_SET. */
136 struct debug_set_type
*kset
;
137 /* DEBUG_KIND_OFFSET. */
138 struct debug_offset_type
*koffset
;
139 /* DEBUG_KIND_METHOD. */
140 struct debug_method_type
*kmethod
;
141 /* DEBUG_KIND_CONST. */
142 struct debug_type_s
*kconst
;
143 /* DEBUG_KIND_VOLATILE. */
144 struct debug_type_s
*kvolatile
;
145 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
146 struct debug_named_type
*knamed
;
150 /* Information kept for an indirect type. */
152 struct debug_indirect_type
154 /* Slot where the final type will appear. */
160 /* Information kept for a struct, union, or class. */
162 struct debug_class_type
164 /* NULL terminated array of fields. */
166 /* A mark field which indicates whether the struct has already been
169 /* This is used to uniquely identify unnamed structs when printing. */
171 /* The remaining fields are only used for DEBUG_KIND_CLASS and
172 DEBUG_KIND_UNION_CLASS. */
173 /* NULL terminated array of base classes. */
174 debug_baseclass
*baseclasses
;
175 /* NULL terminated array of methods. */
176 debug_method
*methods
;
177 /* The type of the class providing the virtual function table for
178 this class. This may point to the type itself. */
182 /* Information kept for an enum. */
184 struct debug_enum_type
186 /* NULL terminated array of names. */
188 /* Array of corresponding values. */
189 bfd_signed_vma
*values
;
192 /* Information kept for a function. FIXME: We should be able to
193 record the parameter types. */
195 struct debug_function_type
198 debug_type return_type
;
199 /* NULL terminated array of argument types. */
200 debug_type
*arg_types
;
201 /* Whether the function takes a variable number of arguments. */
205 /* Information kept for a range. */
207 struct debug_range_type
209 /* Range base type. */
212 bfd_signed_vma lower
;
214 bfd_signed_vma upper
;
217 /* Information kept for an array. */
219 struct debug_array_type
222 debug_type element_type
;
224 debug_type range_type
;
226 bfd_signed_vma lower
;
228 bfd_signed_vma upper
;
229 /* Whether this array is really a string. */
233 /* Information kept for a set. */
235 struct debug_set_type
239 /* Whether this set is really a bitstring. */
243 /* Information kept for an offset type (a based pointer). */
245 struct debug_offset_type
247 /* The type the pointer is an offset from. */
248 debug_type base_type
;
249 /* The type the pointer points to. */
250 debug_type target_type
;
253 /* Information kept for a method type. */
255 struct debug_method_type
257 /* The return type. */
258 debug_type return_type
;
259 /* The object type which this method is for. */
260 debug_type domain_type
;
261 /* A NULL terminated array of argument types. */
262 debug_type
*arg_types
;
263 /* Whether the method takes a variable number of arguments. */
267 /* Information kept for a named type. */
269 struct debug_named_type
272 struct debug_name
*name
;
277 /* A field in a struct or union. */
281 /* Name of the field. */
283 /* Type of the field. */
284 struct debug_type_s
*type
;
285 /* Visibility of the field. */
286 enum debug_visibility visibility
;
287 /* Whether this is a static member. */
291 /* If static_member is false. */
294 /* Bit position of the field in the struct. */
296 /* Size of the field in bits. */
297 unsigned int bitsize
;
299 /* If static_member is true. */
302 const char *physname
;
307 /* A base class for an object. */
309 struct debug_baseclass_s
311 /* Type of the base class. */
312 struct debug_type_s
*type
;
313 /* Bit position of the base class in the object. */
315 /* Whether the base class is virtual. */
317 /* Visibility of the base class. */
318 enum debug_visibility visibility
;
321 /* A method of an object. */
323 struct debug_method_s
325 /* The name of the method. */
327 /* A NULL terminated array of different types of variants. */
328 struct debug_method_variant_s
**variants
;
331 /* The variants of a method function of an object. These indicate
332 which method to run. */
334 struct debug_method_variant_s
336 /* The physical name of the function. */
337 const char *physname
;
338 /* The type of the function. */
339 struct debug_type_s
*type
;
340 /* The visibility of the function. */
341 enum debug_visibility visibility
;
342 /* Whether the function is const. */
344 /* Whether the function is volatile. */
346 /* The offset to the function in the virtual function table. */
348 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
349 #define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
350 /* Context of a virtual method function. */
351 struct debug_type_s
*context
;
354 /* A variable. This is the information we keep for a variable object.
355 This has no name; a name is associated with a variable in a
356 debug_name structure. */
358 struct debug_variable
360 /* Kind of variable. */
361 enum debug_var_kind kind
;
364 /* Value. The interpretation of the value depends upon kind. */
368 /* A function. This has no name; a name is associated with a function
369 in a debug_name structure. */
371 struct debug_function
374 debug_type return_type
;
375 /* Parameter information. */
376 struct debug_parameter
*parameters
;
377 /* Block information. The first structure on the list is the main
378 block of the function, and describes function local variables. */
379 struct debug_block
*blocks
;
382 /* A function parameter. */
384 struct debug_parameter
386 /* Next parameter. */
387 struct debug_parameter
*next
;
393 enum debug_parm_kind kind
;
394 /* Value (meaning depends upon kind). */
398 /* A typed constant. */
400 struct debug_typed_constant
404 /* Value. FIXME: We may eventually need to support non-integral
409 /* Information about a block within a function. */
413 /* Next block with the same parent. */
414 struct debug_block
*next
;
416 struct debug_block
*parent
;
417 /* List of child blocks. */
418 struct debug_block
*children
;
419 /* Start address of the block. */
421 /* End address of the block. */
423 /* Local variables. */
424 struct debug_namespace
*locals
;
427 /* Line number information we keep for a compilation unit. FIXME:
428 This structure is easy to create, but can be very space
433 /* More line number information for this block. */
434 struct debug_lineno
*next
;
436 struct debug_file
*file
;
437 /* Line numbers, terminated by a -1 or the end of the array. */
438 #define DEBUG_LINENO_COUNT 10
439 unsigned long linenos
[DEBUG_LINENO_COUNT
];
440 /* Addresses for the line numbers. */
441 bfd_vma addrs
[DEBUG_LINENO_COUNT
];
444 /* A namespace. This is a mapping from names to objects. FIXME: This
445 should be implemented as a hash table. */
447 struct debug_namespace
449 /* List of items in this namespace. */
450 struct debug_name
*list
;
451 /* Pointer to where the next item in this namespace should go. */
452 struct debug_name
**tail
;
455 /* Kinds of objects that appear in a namespace. */
457 enum debug_object_kind
461 /* A tagged type (really a different sort of namespace). */
464 DEBUG_OBJECT_VARIABLE
,
466 DEBUG_OBJECT_FUNCTION
,
467 /* An integer constant. */
468 DEBUG_OBJECT_INT_CONSTANT
,
469 /* A floating point constant. */
470 DEBUG_OBJECT_FLOAT_CONSTANT
,
471 /* A typed constant. */
472 DEBUG_OBJECT_TYPED_CONSTANT
475 /* Linkage of an object that appears in a namespace. */
477 enum debug_object_linkage
479 /* Local variable. */
480 DEBUG_LINKAGE_AUTOMATIC
,
481 /* Static--either file static or function static, depending upon the
483 DEBUG_LINKAGE_STATIC
,
485 DEBUG_LINKAGE_GLOBAL
,
490 /* A name in a namespace. */
494 /* Next name in this namespace. */
495 struct debug_name
*next
;
498 /* Mark. This is used by debug_write. */
500 /* Kind of object. */
501 enum debug_object_kind kind
;
502 /* Linkage of object. */
503 enum debug_object_linkage linkage
;
504 /* Tagged union with additional information about the object. */
507 /* DEBUG_OBJECT_TYPE. */
508 struct debug_type_s
*type
;
509 /* DEBUG_OBJECT_TAG. */
510 struct debug_type_s
*tag
;
511 /* DEBUG_OBJECT_VARIABLE. */
512 struct debug_variable
*variable
;
513 /* DEBUG_OBJECT_FUNCTION. */
514 struct debug_function
*function
;
515 /* DEBUG_OBJECT_INT_CONSTANT. */
516 bfd_vma int_constant
;
517 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
518 double float_constant
;
519 /* DEBUG_OBJECT_TYPED_CONSTANT. */
520 struct debug_typed_constant
*typed_constant
;
524 /* During debug_write, a linked list of these structures is used to
525 keep track of ID numbers that have been assigned to classes. */
527 struct debug_class_id
529 /* Next ID number. */
530 struct debug_class_id
*next
;
531 /* The type with the ID. */
532 struct debug_type_s
*type
;
533 /* The tag; NULL if no tag. */
537 /* During debug_type_samep, a linked list of these structures is kept
538 on the stack to avoid infinite recursion. */
540 struct debug_type_compare_list
542 /* Next type on list. */
543 struct debug_type_compare_list
*next
;
544 /* The types we are comparing. */
545 struct debug_type_s
*t1
;
546 struct debug_type_s
*t2
;
549 /* During debug_get_real_type, a linked list of these structures is
550 kept on the stack to avoid infinite recursion. */
552 struct debug_type_real_list
554 /* Next type on list. */
555 struct debug_type_real_list
*next
;
556 /* The type we are checking. */
557 struct debug_type_s
*t
;
560 /* Local functions. */
562 static void debug_error (const char *);
563 static struct debug_name
*debug_add_to_namespace
564 (struct debug_handle
*, struct debug_namespace
**, const char *,
565 enum debug_object_kind
, enum debug_object_linkage
);
566 static struct debug_name
*debug_add_to_current_namespace
567 (struct debug_handle
*, const char *, enum debug_object_kind
,
568 enum debug_object_linkage
);
569 static struct debug_type_s
*debug_make_type
570 (struct debug_handle
*, enum debug_type_kind
, unsigned int);
571 static struct debug_type_s
*debug_get_real_type
572 (void *, debug_type
, struct debug_type_real_list
*);
573 static bool debug_write_name
574 (struct debug_handle
*, const struct debug_write_fns
*, void *,
575 struct debug_name
*);
576 static bool debug_write_type
577 (struct debug_handle
*, const struct debug_write_fns
*, void *,
578 struct debug_type_s
*, struct debug_name
*);
579 static bool debug_write_class_type
580 (struct debug_handle
*, const struct debug_write_fns
*, void *,
581 struct debug_type_s
*, const char *);
582 static bool debug_write_function
583 (struct debug_handle
*, const struct debug_write_fns
*, void *,
584 const char *, enum debug_object_linkage
, struct debug_function
*);
585 static bool debug_write_block
586 (struct debug_handle
*, const struct debug_write_fns
*, void *,
587 struct debug_block
*);
588 static bool debug_write_linenos
589 (struct debug_handle
*, const struct debug_write_fns
*, void *, bfd_vma
);
590 static bool debug_set_class_id
591 (struct debug_handle
*, const char *, struct debug_type_s
*);
592 static bool debug_type_samep
593 (struct debug_handle
*, struct debug_type_s
*, struct debug_type_s
*);
594 static bool debug_class_type_samep
595 (struct debug_handle
*, struct debug_type_s
*, struct debug_type_s
*);
597 /* Issue an error message. */
600 debug_error (const char *message
)
602 fprintf (stderr
, "%s\n", message
);
605 /* Add an object to a namespace. */
607 static struct debug_name
*
608 debug_add_to_namespace (struct debug_handle
*info
,
609 struct debug_namespace
**nsp
, const char *name
,
610 enum debug_object_kind kind
,
611 enum debug_object_linkage linkage
)
613 struct debug_name
*n
;
614 struct debug_namespace
*ns
;
616 n
= debug_xzalloc (info
, sizeof (*n
));
620 n
->linkage
= linkage
;
625 ns
= debug_xzalloc (info
, sizeof (*ns
));
627 ns
->tail
= &ns
->list
;
638 /* Add an object to the current namespace. */
640 static struct debug_name
*
641 debug_add_to_current_namespace (struct debug_handle
*info
, const char *name
,
642 enum debug_object_kind kind
,
643 enum debug_object_linkage linkage
)
645 struct debug_namespace
**nsp
;
647 if (info
->current_unit
== NULL
648 || info
->current_file
== NULL
)
650 debug_error (_("debug_add_to_current_namespace: no current file"));
654 if (info
->current_block
!= NULL
)
655 nsp
= &info
->current_block
->locals
;
657 nsp
= &info
->current_file
->globals
;
659 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
662 /* Return a handle for debugging information. */
665 debug_init (bfd
*abfd
)
667 struct debug_handle
*ret
;
669 ret
= bfd_xalloc (abfd
, sizeof (*ret
));
670 memset (ret
, 0, sizeof (*ret
));
676 debug_xalloc (void *handle
, size_t size
)
678 struct debug_handle
*info
= (struct debug_handle
*) handle
;
679 return bfd_xalloc (info
->abfd
, size
);
683 debug_xzalloc (void *handle
, size_t size
)
685 struct debug_handle
*info
= (struct debug_handle
*) handle
;
686 void *mem
= bfd_xalloc (info
->abfd
, size
);
687 memset (mem
, 0, size
);
691 /* Set the source filename. This implicitly starts a new compilation
695 debug_set_filename (void *handle
, const char *name
)
697 struct debug_handle
*info
= (struct debug_handle
*) handle
;
698 struct debug_file
*nfile
;
699 struct debug_unit
*nunit
;
704 nfile
= debug_xzalloc (info
, sizeof (*nfile
));
706 nfile
->filename
= name
;
708 nunit
= debug_xzalloc (info
, sizeof (*nunit
));
710 nunit
->files
= nfile
;
711 info
->current_file
= nfile
;
713 if (info
->current_unit
!= NULL
)
714 info
->current_unit
->next
= nunit
;
717 assert (info
->units
== NULL
);
721 info
->current_unit
= nunit
;
723 info
->current_function
= NULL
;
724 info
->current_block
= NULL
;
725 info
->current_lineno
= NULL
;
730 /* Change source files to the given file name. This is used for
731 include files in a single compilation unit. */
734 debug_start_source (void *handle
, const char *name
)
736 struct debug_handle
*info
= (struct debug_handle
*) handle
;
737 struct debug_file
*f
, **pf
;
742 if (info
->current_unit
== NULL
)
744 debug_error (_("debug_start_source: no debug_set_filename call"));
748 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
750 if (filename_cmp (f
->filename
, name
) == 0)
752 info
->current_file
= f
;
757 f
= debug_xzalloc (info
, sizeof (*f
));
760 for (pf
= &info
->current_file
->next
;
766 info
->current_file
= f
;
771 /* Record a function definition. This implicitly starts a function
772 block. The debug_type argument is the type of the return value.
773 The boolean indicates whether the function is globally visible.
774 The bfd_vma is the address of the start of the function. Currently
775 the parameter types are specified by calls to
776 debug_record_parameter. FIXME: There is no way to specify nested
780 debug_record_function (void *handle
, const char *name
,
781 debug_type return_type
, bool global
,
784 struct debug_handle
*info
= (struct debug_handle
*) handle
;
785 struct debug_function
*f
;
786 struct debug_block
*b
;
787 struct debug_name
*n
;
791 if (return_type
== NULL
)
794 if (info
->current_unit
== NULL
)
796 debug_error (_("debug_record_function: no debug_set_filename call"));
800 f
= debug_xzalloc (info
, sizeof (*f
));
802 f
->return_type
= return_type
;
804 b
= debug_xzalloc (info
, sizeof (*b
));
807 b
->end
= (bfd_vma
) -1;
811 info
->current_function
= f
;
812 info
->current_block
= b
;
814 /* FIXME: If we could handle nested functions, this would be the
815 place: we would want to use a different namespace. */
816 n
= debug_add_to_namespace (info
,
817 &info
->current_file
->globals
,
819 DEBUG_OBJECT_FUNCTION
,
821 ? DEBUG_LINKAGE_GLOBAL
822 : DEBUG_LINKAGE_STATIC
));
831 /* Record a parameter for the current function. */
834 debug_record_parameter (void *handle
, const char *name
, debug_type type
,
835 enum debug_parm_kind kind
, bfd_vma val
)
837 struct debug_handle
*info
= (struct debug_handle
*) handle
;
838 struct debug_parameter
*p
, **pp
;
840 if (name
== NULL
|| type
== NULL
)
843 if (info
->current_unit
== NULL
844 || info
->current_function
== NULL
)
846 debug_error (_("debug_record_parameter: no current function"));
850 p
= debug_xzalloc (info
, sizeof (*p
));
857 for (pp
= &info
->current_function
->parameters
;
866 /* End a function. FIXME: This should handle function nesting. */
869 debug_end_function (void *handle
, bfd_vma addr
)
871 struct debug_handle
*info
= (struct debug_handle
*) handle
;
873 if (info
->current_unit
== NULL
874 || info
->current_block
== NULL
875 || info
->current_function
== NULL
)
877 debug_error (_("debug_end_function: no current function"));
881 if (info
->current_block
->parent
!= NULL
)
883 debug_error (_("debug_end_function: some blocks were not closed"));
887 info
->current_block
->end
= addr
;
889 info
->current_function
= NULL
;
890 info
->current_block
= NULL
;
895 /* Start a block in a function. All local information will be
896 recorded in this block, until the matching call to debug_end_block.
897 debug_start_block and debug_end_block may be nested. The bfd_vma
898 argument is the address at which this block starts. */
901 debug_start_block (void *handle
, bfd_vma addr
)
903 struct debug_handle
*info
= (struct debug_handle
*) handle
;
904 struct debug_block
*b
, **pb
;
906 /* We must always have a current block: debug_record_function sets
908 if (info
->current_unit
== NULL
909 || info
->current_block
== NULL
)
911 debug_error (_("debug_start_block: no current block"));
915 b
= debug_xzalloc (info
, sizeof (*b
));
917 b
->parent
= info
->current_block
;
919 b
->end
= (bfd_vma
) -1;
921 /* This new block is a child of the current block. */
922 for (pb
= &info
->current_block
->children
;
928 info
->current_block
= b
;
933 /* Finish a block in a function. This matches the call to
934 debug_start_block. The argument is the address at which this block
938 debug_end_block (void *handle
, bfd_vma addr
)
940 struct debug_handle
*info
= (struct debug_handle
*) handle
;
941 struct debug_block
*parent
;
943 if (info
->current_unit
== NULL
944 || info
->current_block
== NULL
)
946 debug_error (_("debug_end_block: no current block"));
950 parent
= info
->current_block
->parent
;
953 debug_error (_("debug_end_block: attempt to close top level block"));
957 info
->current_block
->end
= addr
;
959 info
->current_block
= parent
;
964 /* Associate a line number in the current source file and function
965 with a given address. */
968 debug_record_line (void *handle
, unsigned long lineno
, bfd_vma addr
)
970 struct debug_handle
*info
= (struct debug_handle
*) handle
;
971 struct debug_lineno
*l
;
974 if (info
->current_unit
== NULL
)
976 debug_error (_("debug_record_line: no current unit"));
980 l
= info
->current_lineno
;
981 if (l
!= NULL
&& l
->file
== info
->current_file
)
983 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
985 if (l
->linenos
[i
] == (unsigned long) -1)
987 l
->linenos
[i
] = lineno
;
994 /* If we get here, then either 1) there is no current_lineno
995 structure, which means this is the first line number in this
996 compilation unit, 2) the current_lineno structure is for a
997 different file, or 3) the current_lineno structure is full.
998 Regardless, we want to allocate a new debug_lineno structure, put
999 it in the right place, and make it the new current_lineno
1002 l
= debug_xzalloc (info
, sizeof (*l
));
1004 l
->file
= info
->current_file
;
1005 l
->linenos
[0] = lineno
;
1007 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
1008 l
->linenos
[i
] = (unsigned long) -1;
1010 if (info
->current_lineno
!= NULL
)
1011 info
->current_lineno
->next
= l
;
1013 info
->current_unit
->linenos
= l
;
1015 info
->current_lineno
= l
;
1020 /* Start a named common block. This is a block of variables that may
1024 debug_start_common_block (void *handle ATTRIBUTE_UNUSED
,
1025 const char *name ATTRIBUTE_UNUSED
)
1028 debug_error (_("debug_start_common_block: not implemented"));
1032 /* End a named common block. */
1035 debug_end_common_block (void *handle ATTRIBUTE_UNUSED
,
1036 const char *name ATTRIBUTE_UNUSED
)
1039 debug_error (_("debug_end_common_block: not implemented"));
1043 /* Record a named integer constant. */
1046 debug_record_int_const (void *handle
, const char *name
, bfd_vma val
)
1048 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1049 struct debug_name
*n
;
1054 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1055 DEBUG_LINKAGE_NONE
);
1059 n
->u
.int_constant
= val
;
1064 /* Record a named floating point constant. */
1067 debug_record_float_const (void *handle
, const char *name
, double val
)
1069 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1070 struct debug_name
*n
;
1075 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1076 DEBUG_LINKAGE_NONE
);
1080 n
->u
.float_constant
= val
;
1085 /* Record a typed constant with an integral value. */
1088 debug_record_typed_const (void *handle
, const char *name
, debug_type type
,
1091 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1092 struct debug_name
*n
;
1093 struct debug_typed_constant
*tc
;
1095 if (name
== NULL
|| type
== NULL
)
1098 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1099 DEBUG_LINKAGE_NONE
);
1103 tc
= debug_xzalloc (info
, sizeof (*tc
));
1108 n
->u
.typed_constant
= tc
;
1113 /* Record a label. */
1116 debug_record_label (void *handle ATTRIBUTE_UNUSED
,
1117 const char *name ATTRIBUTE_UNUSED
,
1118 debug_type type ATTRIBUTE_UNUSED
,
1119 bfd_vma addr ATTRIBUTE_UNUSED
)
1122 debug_error (_("debug_record_label: not implemented"));
1126 /* Record a variable. */
1129 debug_record_variable (void *handle
, const char *name
, debug_type type
,
1130 enum debug_var_kind kind
, bfd_vma val
)
1132 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1133 struct debug_namespace
**nsp
;
1134 enum debug_object_linkage linkage
;
1135 struct debug_name
*n
;
1136 struct debug_variable
*v
;
1138 if (name
== NULL
|| type
== NULL
)
1141 if (info
->current_unit
== NULL
1142 || info
->current_file
== NULL
)
1144 debug_error (_("debug_record_variable: no current file"));
1148 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1150 nsp
= &info
->current_file
->globals
;
1151 if (kind
== DEBUG_GLOBAL
)
1152 linkage
= DEBUG_LINKAGE_GLOBAL
;
1154 linkage
= DEBUG_LINKAGE_STATIC
;
1158 if (info
->current_block
== NULL
)
1159 nsp
= &info
->current_file
->globals
;
1161 nsp
= &info
->current_block
->locals
;
1162 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1165 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1169 v
= debug_xzalloc (info
, sizeof (*v
));
1180 /* Make a type with a given kind and size. */
1182 static struct debug_type_s
*
1183 debug_make_type (struct debug_handle
*info
,
1184 enum debug_type_kind kind
, unsigned int size
)
1186 struct debug_type_s
*t
;
1188 t
= debug_xzalloc (info
, sizeof (*t
));
1196 /* Make an indirect type which may be used as a placeholder for a type
1197 which is referenced before it is defined. */
1200 debug_make_indirect_type (void *handle
, debug_type
*slot
, const char *tag
)
1202 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1203 struct debug_type_s
*t
;
1204 struct debug_indirect_type
*i
;
1206 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1208 return DEBUG_TYPE_NULL
;
1210 i
= debug_xzalloc (info
, sizeof (*i
));
1220 /* Make a void type. There is only one of these. */
1223 debug_make_void_type (void *handle
)
1225 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1227 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1230 /* Make an integer type of a given size. The boolean argument is true
1231 if the integer is unsigned. */
1234 debug_make_int_type (void *handle
, unsigned int size
, bool unsignedp
)
1236 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1237 struct debug_type_s
*t
;
1239 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1241 return DEBUG_TYPE_NULL
;
1243 t
->u
.kint
= unsignedp
;
1248 /* Make a floating point type of a given size. FIXME: On some
1249 platforms, like an Alpha, you probably need to be able to specify
1253 debug_make_float_type (void *handle
, unsigned int size
)
1255 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1257 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1260 /* Make a boolean type of a given size. */
1263 debug_make_bool_type (void *handle
, unsigned int 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 (void *handle
, unsigned int size
)
1275 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1277 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1280 /* Make a structure type. The second argument is true for a struct,
1281 false for a union. The third argument is the size of the struct.
1282 The fourth argument is a NULL terminated array of fields. */
1285 debug_make_struct_type (void *handle
, bool structp
, bfd_vma size
,
1286 debug_field
*fields
)
1288 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1289 struct debug_type_s
*t
;
1290 struct debug_class_type
*c
;
1292 t
= debug_make_type (info
,
1293 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1296 return DEBUG_TYPE_NULL
;
1298 c
= debug_xzalloc (info
, sizeof (*c
));
1307 /* Make an object type. The first three arguments after the handle
1308 are the same as for debug_make_struct_type. The next arguments are
1309 a NULL terminated array of base classes, a NULL terminated array of
1310 methods, the type of the object holding the virtual function table
1311 if it is not this object, and a boolean which is true if this
1312 object has its own virtual function table. */
1315 debug_make_object_type (void *handle
, bool structp
, bfd_vma size
,
1316 debug_field
*fields
, debug_baseclass
*baseclasses
,
1317 debug_method
*methods
, debug_type vptrbase
,
1320 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1321 struct debug_type_s
*t
;
1322 struct debug_class_type
*c
;
1324 t
= debug_make_type (info
,
1325 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1328 return DEBUG_TYPE_NULL
;
1330 c
= debug_xzalloc (info
, sizeof (*c
));
1333 c
->baseclasses
= baseclasses
;
1334 c
->methods
= methods
;
1338 c
->vptrbase
= vptrbase
;
1345 /* Make an enumeration type. The arguments are a null terminated
1346 array of strings, and an array of corresponding values. */
1349 debug_make_enum_type (void *handle
, const char **names
,
1350 bfd_signed_vma
*values
)
1352 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1353 struct debug_type_s
*t
;
1354 struct debug_enum_type
*e
;
1356 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1358 return DEBUG_TYPE_NULL
;
1360 e
= debug_xzalloc (info
, sizeof (*e
));
1370 /* Make a pointer to a given type. */
1373 debug_make_pointer_type (void *handle
, debug_type type
)
1375 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1376 struct debug_type_s
*t
;
1379 return DEBUG_TYPE_NULL
;
1381 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1382 return type
->pointer
;
1384 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1386 return DEBUG_TYPE_NULL
;
1388 t
->u
.kpointer
= type
;
1395 /* Make a function returning a given type. FIXME: We should be able
1396 to record the parameter types. */
1399 debug_make_function_type (void *handle
, debug_type type
,
1400 debug_type
*arg_types
, bool varargs
)
1402 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1403 struct debug_type_s
*t
;
1404 struct debug_function_type
*f
;
1407 return DEBUG_TYPE_NULL
;
1409 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1411 return DEBUG_TYPE_NULL
;
1413 f
= debug_xzalloc (info
, sizeof (*f
));
1415 f
->return_type
= type
;
1416 f
->arg_types
= arg_types
;
1417 f
->varargs
= varargs
;
1424 /* Make a reference to a given type. */
1427 debug_make_reference_type (void *handle
, debug_type type
)
1429 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1430 struct debug_type_s
*t
;
1433 return DEBUG_TYPE_NULL
;
1435 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1437 return DEBUG_TYPE_NULL
;
1439 t
->u
.kreference
= type
;
1444 /* Make a range of a given type from a lower to an upper bound. */
1447 debug_make_range_type (void *handle
, debug_type type
, bfd_signed_vma lower
,
1448 bfd_signed_vma upper
)
1450 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1451 struct debug_type_s
*t
;
1452 struct debug_range_type
*r
;
1455 return DEBUG_TYPE_NULL
;
1457 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1459 return DEBUG_TYPE_NULL
;
1461 r
= debug_xzalloc (info
, sizeof (*r
));
1472 /* Make an array type. The second argument is the type of an element
1473 of the array. The third argument is the type of a range of the
1474 array. The fourth and fifth argument are the lower and upper
1475 bounds, respectively. The sixth argument is true if this array is
1476 actually a string, as in C. */
1479 debug_make_array_type (void *handle
, debug_type element_type
,
1480 debug_type range_type
, bfd_signed_vma lower
,
1481 bfd_signed_vma upper
, bool stringp
)
1483 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1484 struct debug_type_s
*t
;
1485 struct debug_array_type
*a
;
1487 if (element_type
== NULL
|| range_type
== NULL
)
1488 return DEBUG_TYPE_NULL
;
1490 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1492 return DEBUG_TYPE_NULL
;
1494 a
= debug_xzalloc (info
, sizeof (*a
));
1496 a
->element_type
= element_type
;
1497 a
->range_type
= range_type
;
1500 a
->stringp
= stringp
;
1507 /* Make a set of a given type. For example, a Pascal set type. The
1508 boolean argument is true if this set is actually a bitstring, as in
1512 debug_make_set_type (void *handle
, debug_type type
, bool bitstringp
)
1514 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1515 struct debug_type_s
*t
;
1516 struct debug_set_type
*s
;
1519 return DEBUG_TYPE_NULL
;
1521 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1523 return DEBUG_TYPE_NULL
;
1525 s
= debug_xzalloc (info
, sizeof (*s
));
1528 s
->bitstringp
= bitstringp
;
1535 /* Make a type for a pointer which is relative to an object. The
1536 second argument is the type of the object to which the pointer is
1537 relative. The third argument is the type that the pointer points
1541 debug_make_offset_type (void *handle
, debug_type base_type
,
1542 debug_type target_type
)
1544 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1545 struct debug_type_s
*t
;
1546 struct debug_offset_type
*o
;
1548 if (base_type
== NULL
|| target_type
== NULL
)
1549 return DEBUG_TYPE_NULL
;
1551 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1553 return DEBUG_TYPE_NULL
;
1555 o
= debug_xzalloc (info
, sizeof (*o
));
1557 o
->base_type
= base_type
;
1558 o
->target_type
= target_type
;
1565 /* Make a type for a method function. The second argument is the
1566 return type, the third argument is the domain, and the fourth
1567 argument is a NULL terminated array of argument types. */
1570 debug_make_method_type (void *handle
, debug_type return_type
,
1571 debug_type domain_type
, debug_type
*arg_types
,
1574 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1575 struct debug_type_s
*t
;
1576 struct debug_method_type
*m
;
1578 if (return_type
== NULL
)
1579 return DEBUG_TYPE_NULL
;
1581 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1583 return DEBUG_TYPE_NULL
;
1585 m
= debug_xzalloc (info
, sizeof (*m
));
1587 m
->return_type
= return_type
;
1588 m
->domain_type
= domain_type
;
1589 m
->arg_types
= arg_types
;
1590 m
->varargs
= varargs
;
1597 /* Make a const qualified version of a given type. */
1600 debug_make_const_type (void *handle
, debug_type type
)
1602 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1603 struct debug_type_s
*t
;
1606 return DEBUG_TYPE_NULL
;
1608 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1610 return DEBUG_TYPE_NULL
;
1617 /* Make a volatile qualified version of a given type. */
1620 debug_make_volatile_type (void *handle
, debug_type type
)
1622 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1623 struct debug_type_s
*t
;
1626 return DEBUG_TYPE_NULL
;
1628 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1630 return DEBUG_TYPE_NULL
;
1632 t
->u
.kvolatile
= type
;
1637 /* Make an undefined tagged type. For example, a struct which has
1638 been mentioned, but not defined. */
1641 debug_make_undefined_tagged_type (void *handle
, const char *name
,
1642 enum debug_type_kind kind
)
1644 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1645 struct debug_type_s
*t
;
1648 return DEBUG_TYPE_NULL
;
1652 case DEBUG_KIND_STRUCT
:
1653 case DEBUG_KIND_UNION
:
1654 case DEBUG_KIND_CLASS
:
1655 case DEBUG_KIND_UNION_CLASS
:
1656 case DEBUG_KIND_ENUM
:
1660 debug_error (_("debug_make_undefined_type: unsupported kind"));
1661 return DEBUG_TYPE_NULL
;
1664 t
= debug_make_type (info
, kind
, 0);
1666 return DEBUG_TYPE_NULL
;
1668 return debug_tag_type (handle
, name
, t
);
1671 /* Make a base class for an object. The second argument is the base
1672 class type. The third argument is the bit position of this base
1673 class in the object (always 0 unless doing multiple inheritance).
1674 The fourth argument is whether this is a virtual class. The fifth
1675 argument is the visibility of the base class. */
1678 debug_make_baseclass (void *handle
, debug_type type
,
1679 bfd_vma bitpos
, bool is_virtual
,
1680 enum debug_visibility visibility
)
1682 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1683 struct debug_baseclass_s
*b
;
1685 b
= debug_xzalloc (info
, sizeof (*b
));
1689 b
->is_virtual
= is_virtual
;
1690 b
->visibility
= visibility
;
1695 /* Make a field for a struct. The second argument is the name. The
1696 third argument is the type of the field. The fourth argument is
1697 the bit position of the field. The fifth argument is the size of
1698 the field (it may be zero). The sixth argument is the visibility
1702 debug_make_field (void *handle
, const char *name
,
1703 debug_type type
, bfd_vma bitpos
, bfd_vma bitsize
,
1704 enum debug_visibility visibility
)
1706 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1707 struct debug_field_s
*f
;
1709 f
= debug_xzalloc (info
, sizeof (*f
));
1713 f
->static_member
= false;
1714 f
->u
.f
.bitpos
= bitpos
;
1715 f
->u
.f
.bitsize
= bitsize
;
1716 f
->visibility
= visibility
;
1721 /* Make a static member of an object. The second argument is the
1722 name. The third argument is the type of the member. The fourth
1723 argument is the physical name of the member (i.e., the name as a
1724 global variable). The fifth argument is the visibility of the
1728 debug_make_static_member (void *handle
, const char *name
,
1729 debug_type type
, const char *physname
,
1730 enum debug_visibility visibility
)
1732 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1733 struct debug_field_s
*f
;
1735 f
= debug_xzalloc (info
, sizeof (*f
));
1739 f
->static_member
= true;
1740 f
->u
.s
.physname
= physname
;
1741 f
->visibility
= visibility
;
1746 /* Make a method. The second argument is the name, and the third
1747 argument is a NULL terminated array of method variants. */
1750 debug_make_method (void *handle
, const char *name
,
1751 debug_method_variant
*variants
)
1753 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1754 struct debug_method_s
*m
;
1756 m
= debug_xzalloc (info
, sizeof (*m
));
1759 m
->variants
= variants
;
1764 /* Make a method argument. The second argument is the real name of
1765 the function. The third argument is the type of the function. The
1766 fourth argument is the visibility. The fifth argument is whether
1767 this is a const function. The sixth argument is whether this is a
1768 volatile function. The seventh argument is the offset in the
1769 virtual function table, if any. The eighth argument is the virtual
1770 function context. FIXME: Are the const and volatile arguments
1771 necessary? Could we just use debug_make_const_type? */
1773 debug_method_variant
1774 debug_make_method_variant (void *handle
,
1775 const char *physname
, debug_type type
,
1776 enum debug_visibility visibility
,
1777 bool constp
, bool volatilep
,
1778 bfd_vma voffset
, debug_type context
)
1780 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1781 struct debug_method_variant_s
*m
;
1783 m
= debug_xzalloc (info
, sizeof (*m
));
1785 m
->physname
= physname
;
1787 m
->visibility
= visibility
;
1789 m
->volatilep
= volatilep
;
1790 m
->voffset
= voffset
;
1791 m
->context
= context
;
1796 /* Make a static method argument. The arguments are the same as for
1797 debug_make_method_variant, except that the last two are omitted
1798 since a static method can not also be virtual. */
1800 debug_method_variant
1801 debug_make_static_method_variant (void *handle
,
1802 const char *physname
, debug_type type
,
1803 enum debug_visibility visibility
,
1804 bool constp
, bool volatilep
)
1806 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1807 struct debug_method_variant_s
*m
;
1809 m
= debug_xzalloc (info
, sizeof (*m
));
1811 m
->physname
= physname
;
1813 m
->visibility
= visibility
;
1815 m
->volatilep
= volatilep
;
1816 m
->voffset
= VOFFSET_STATIC_METHOD
;
1824 debug_name_type (void *handle
, const char *name
, debug_type type
)
1826 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1827 struct debug_type_s
*t
;
1828 struct debug_named_type
*n
;
1829 struct debug_name
*nm
;
1831 if (name
== NULL
|| type
== NULL
)
1832 return DEBUG_TYPE_NULL
;
1834 if (info
->current_unit
== NULL
1835 || info
->current_file
== NULL
)
1837 debug_error (_("debug_name_type: no current file"));
1838 return DEBUG_TYPE_NULL
;
1841 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1843 return DEBUG_TYPE_NULL
;
1845 n
= debug_xzalloc (info
, sizeof (*n
));
1851 /* We always add the name to the global namespace. This is probably
1852 wrong in some cases, but it seems to be right for stabs. FIXME. */
1854 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1855 DEBUG_OBJECT_TYPE
, DEBUG_LINKAGE_NONE
);
1857 return DEBUG_TYPE_NULL
;
1869 debug_tag_type (void *handle
, const char *name
, debug_type type
)
1871 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1872 struct debug_type_s
*t
;
1873 struct debug_named_type
*n
;
1874 struct debug_name
*nm
;
1876 if (name
== NULL
|| type
== NULL
)
1877 return DEBUG_TYPE_NULL
;
1879 if (info
->current_file
== NULL
)
1881 debug_error (_("debug_tag_type: no current file"));
1882 return DEBUG_TYPE_NULL
;
1885 if (type
->kind
== DEBUG_KIND_TAGGED
)
1887 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
1889 debug_error (_("debug_tag_type: extra tag attempted"));
1890 return DEBUG_TYPE_NULL
;
1893 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
1895 return DEBUG_TYPE_NULL
;
1897 n
= debug_xzalloc (info
, sizeof (*n
));
1903 /* We keep a global namespace of tags for each compilation unit. I
1904 don't know if that is the right thing to do. */
1906 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1907 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
1909 return DEBUG_TYPE_NULL
;
1918 /* Record the size of a given type. */
1921 debug_record_type_size (void *handle ATTRIBUTE_UNUSED
, debug_type type
,
1924 if (type
->size
!= 0 && type
->size
!= size
)
1925 fprintf (stderr
, _("Warning: changing type size from %d to %d\n"),
1933 /* Find a named type. */
1936 debug_find_named_type (void *handle
, const char *name
)
1938 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1939 struct debug_block
*b
;
1940 struct debug_file
*f
;
1942 /* We only search the current compilation unit. I don't know if
1943 this is right or not. */
1945 if (info
->current_unit
== NULL
)
1947 debug_error (_("debug_find_named_type: no current compilation unit"));
1948 return DEBUG_TYPE_NULL
;
1951 for (b
= info
->current_block
; b
!= NULL
; b
= b
->parent
)
1953 if (b
->locals
!= NULL
)
1955 struct debug_name
*n
;
1957 for (n
= b
->locals
->list
; n
!= NULL
; n
= n
->next
)
1959 if (n
->kind
== DEBUG_OBJECT_TYPE
1960 && n
->name
[0] == name
[0]
1961 && strcmp (n
->name
, name
) == 0)
1967 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
1969 if (f
->globals
!= NULL
)
1971 struct debug_name
*n
;
1973 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
1975 if (n
->kind
== DEBUG_OBJECT_TYPE
1976 && n
->name
[0] == name
[0]
1977 && strcmp (n
->name
, name
) == 0)
1983 return DEBUG_TYPE_NULL
;
1986 /* Find a tagged type. */
1989 debug_find_tagged_type (void *handle
, const char *name
,
1990 enum debug_type_kind kind
)
1992 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1993 struct debug_unit
*u
;
1995 /* We search the globals of all the compilation units. I don't know
1996 if this is correct or not. It would be easy to change. */
1998 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2000 struct debug_file
*f
;
2002 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2004 struct debug_name
*n
;
2006 if (f
->globals
!= NULL
)
2008 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2010 if (n
->kind
== DEBUG_OBJECT_TAG
2011 && (kind
== DEBUG_KIND_ILLEGAL
2012 || n
->u
.tag
->kind
== kind
)
2013 && n
->name
[0] == name
[0]
2014 && strcmp (n
->name
, name
) == 0)
2021 return DEBUG_TYPE_NULL
;
2024 /* Get a base type. We build a linked list on the stack to avoid
2025 crashing if the type is defined circularly. */
2027 static struct debug_type_s
*
2028 debug_get_real_type (void *handle
, debug_type type
,
2029 struct debug_type_real_list
*list
)
2031 struct debug_type_real_list
*l
;
2032 struct debug_type_real_list rl
;
2039 case DEBUG_KIND_INDIRECT
:
2040 case DEBUG_KIND_NAMED
:
2041 case DEBUG_KIND_TAGGED
:
2045 for (l
= list
; l
!= NULL
; l
= l
->next
)
2047 if (l
->t
== type
|| l
== l
->next
)
2050 _("debug_get_real_type: circular debug information for %s\n"),
2051 debug_get_type_name (handle
, type
));
2061 /* The default case is just here to avoid warnings. */
2063 case DEBUG_KIND_INDIRECT
:
2064 /* A valid non-self-referencing indirect type. */
2065 if (*type
->u
.kindirect
->slot
!= NULL
2066 && *type
->u
.kindirect
->slot
!= type
)
2067 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
, &rl
);
2069 case DEBUG_KIND_NAMED
:
2070 case DEBUG_KIND_TAGGED
:
2071 return debug_get_real_type (handle
, type
->u
.knamed
->type
, &rl
);
2076 /* Get the kind of a type. */
2078 enum debug_type_kind
2079 debug_get_type_kind (void *handle
, debug_type type
)
2082 return DEBUG_KIND_ILLEGAL
;
2083 type
= debug_get_real_type (handle
, type
, NULL
);
2085 return DEBUG_KIND_ILLEGAL
;
2089 /* Get the name of a type. */
2092 debug_get_type_name (void *handle
, debug_type type
)
2094 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2096 /* A valid non-self-referencing indirect type. */
2097 if (*type
->u
.kindirect
->slot
!= NULL
2098 && *type
->u
.kindirect
->slot
!= type
)
2099 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2100 return type
->u
.kindirect
->tag
;
2102 if (type
->kind
== DEBUG_KIND_NAMED
2103 || type
->kind
== DEBUG_KIND_TAGGED
)
2104 return type
->u
.knamed
->name
->name
;
2108 /* Get the size of a type. */
2111 debug_get_type_size (void *handle
, debug_type type
)
2116 /* We don't call debug_get_real_type, because somebody might have
2117 called debug_record_type_size on a named or indirect type. */
2119 if (type
->size
!= 0)
2126 case DEBUG_KIND_INDIRECT
:
2127 /* A valid non-self-referencing indirect type. */
2128 if (*type
->u
.kindirect
->slot
!= NULL
2129 && *type
->u
.kindirect
->slot
!= type
)
2130 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2132 case DEBUG_KIND_NAMED
:
2133 case DEBUG_KIND_TAGGED
:
2134 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2139 /* Get the return type of a function or method type. */
2142 debug_get_return_type (void *handle
, debug_type type
)
2145 return DEBUG_TYPE_NULL
;
2147 type
= debug_get_real_type (handle
, type
, NULL
);
2149 return DEBUG_TYPE_NULL
;
2154 return DEBUG_TYPE_NULL
;
2155 case DEBUG_KIND_FUNCTION
:
2156 return type
->u
.kfunction
->return_type
;
2157 case DEBUG_KIND_METHOD
:
2158 return type
->u
.kmethod
->return_type
;
2163 /* Get the parameter types of a function or method type (except that
2164 we don't currently store the parameter types of a function). */
2167 debug_get_parameter_types (void *handle
, debug_type type
,
2173 type
= debug_get_real_type (handle
, type
, NULL
);
2181 case DEBUG_KIND_FUNCTION
:
2182 *pvarargs
= type
->u
.kfunction
->varargs
;
2183 return type
->u
.kfunction
->arg_types
;
2184 case DEBUG_KIND_METHOD
:
2185 *pvarargs
= type
->u
.kmethod
->varargs
;
2186 return type
->u
.kmethod
->arg_types
;
2191 /* Get the target type of a type. */
2194 debug_get_target_type (void *handle
, debug_type type
)
2199 type
= debug_get_real_type (handle
, type
, NULL
);
2207 case DEBUG_KIND_POINTER
:
2208 return type
->u
.kpointer
;
2209 case DEBUG_KIND_REFERENCE
:
2210 return type
->u
.kreference
;
2211 case DEBUG_KIND_CONST
:
2212 return type
->u
.kconst
;
2213 case DEBUG_KIND_VOLATILE
:
2214 return type
->u
.kvolatile
;
2219 /* Get the NULL terminated array of fields for a struct, union, or
2223 debug_get_fields (void *handle
, debug_type type
)
2228 type
= debug_get_real_type (handle
, type
, NULL
);
2236 case DEBUG_KIND_STRUCT
:
2237 case DEBUG_KIND_UNION
:
2238 case DEBUG_KIND_CLASS
:
2239 case DEBUG_KIND_UNION_CLASS
:
2240 return type
->u
.kclass
->fields
;
2245 /* Get the type of a field. */
2248 debug_get_field_type (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2255 /* Get the name of a field. */
2258 debug_get_field_name (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2265 /* Get the bit position of a field. */
2268 debug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2270 if (field
== NULL
|| field
->static_member
)
2271 return (bfd_vma
) -1;
2272 return field
->u
.f
.bitpos
;
2275 /* Get the bit size of a field. */
2278 debug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2280 if (field
== NULL
|| field
->static_member
)
2281 return (bfd_vma
) -1;
2282 return field
->u
.f
.bitsize
;
2285 /* Get the visibility of a field. */
2287 enum debug_visibility
2288 debug_get_field_visibility (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2291 return DEBUG_VISIBILITY_IGNORE
;
2292 return field
->visibility
;
2295 /* Get the physical name of a field. */
2298 debug_get_field_physname (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2300 if (field
== NULL
|| ! field
->static_member
)
2302 return field
->u
.s
.physname
;
2305 /* Write out the debugging information. This is given a handle to
2306 debugging information, and a set of function pointers to call. */
2309 debug_write (void *handle
, const struct debug_write_fns
*fns
, void *fhandle
)
2311 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2312 struct debug_unit
*u
;
2314 /* We use a mark to tell whether we have already written out a
2315 particular name. We use an integer, so that we don't have to
2316 clear the mark fields if we happen to write out the same
2317 information more than once. */
2320 /* The base_id field holds an ID value which will never be used, so
2321 that we can tell whether we have assigned an ID during this call
2323 info
->base_id
= info
->class_id
;
2325 /* We keep a linked list of classes for which was have assigned ID's
2326 during this call to debug_write. */
2327 info
->id_list
= NULL
;
2329 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2331 struct debug_file
*f
;
2334 info
->current_write_lineno
= u
->linenos
;
2335 info
->current_write_lineno_index
= 0;
2337 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2341 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2343 struct debug_name
*n
;
2347 else if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2350 if (f
->globals
!= NULL
)
2351 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2352 if (! debug_write_name (info
, fns
, fhandle
, n
))
2356 /* Output any line number information which hasn't already been
2358 if (! debug_write_linenos (info
, fns
, fhandle
, (bfd_vma
) -1))
2365 /* Write out an element in a namespace. */
2368 debug_write_name (struct debug_handle
*info
,
2369 const struct debug_write_fns
*fns
, void *fhandle
,
2370 struct debug_name
*n
)
2374 case DEBUG_OBJECT_TYPE
:
2375 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2376 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2379 case DEBUG_OBJECT_TAG
:
2380 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2382 return (*fns
->tag
) (fhandle
, n
->name
);
2383 case DEBUG_OBJECT_VARIABLE
:
2384 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2385 (struct debug_name
*) NULL
))
2387 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2388 n
->u
.variable
->val
);
2389 case DEBUG_OBJECT_FUNCTION
:
2390 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2391 n
->linkage
, n
->u
.function
);
2392 case DEBUG_OBJECT_INT_CONSTANT
:
2393 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2394 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2395 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2396 case DEBUG_OBJECT_TYPED_CONSTANT
:
2397 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2398 (struct debug_name
*) NULL
))
2400 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2401 n
->u
.typed_constant
->val
);
2409 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2410 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2411 are about to call typedef or tag. If the type is anything else,
2412 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2413 points to this one. */
2416 debug_write_type (struct debug_handle
*info
,
2417 const struct debug_write_fns
*fns
, void *fhandle
,
2418 struct debug_type_s
*type
, struct debug_name
*name
)
2422 const char *tag
= NULL
;
2424 if (type
== DEBUG_TYPE_NULL
)
2425 return (*fns
->empty_type
) (fhandle
);
2427 /* Mark the type so that we don't define a type in terms of itself. */
2428 type
->mark
= info
->mark
;
2430 /* If we have a name for this type, just output it. We only output
2431 typedef names after they have been defined. We output type tags
2432 whenever we are not actually defining them. */
2433 if ((type
->kind
== DEBUG_KIND_NAMED
2434 || type
->kind
== DEBUG_KIND_TAGGED
)
2435 && (type
->u
.knamed
->name
->mark
== info
->mark
2436 || (type
->kind
== DEBUG_KIND_TAGGED
2437 && type
->u
.knamed
->name
!= name
)))
2439 if (type
->kind
== DEBUG_KIND_NAMED
)
2440 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2443 struct debug_type_s
*real
;
2446 real
= debug_get_real_type ((void *) info
, type
, NULL
);
2448 return (*fns
->empty_type
) (fhandle
);
2450 if ((real
->kind
== DEBUG_KIND_STRUCT
2451 || real
->kind
== DEBUG_KIND_UNION
2452 || real
->kind
== DEBUG_KIND_CLASS
2453 || real
->kind
== DEBUG_KIND_UNION_CLASS
)
2454 && real
->u
.kclass
!= NULL
)
2456 if (real
->u
.kclass
->id
<= info
->base_id
)
2458 if (! debug_set_class_id (info
,
2459 type
->u
.knamed
->name
->name
,
2463 id
= real
->u
.kclass
->id
;
2466 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, id
,
2471 /* Mark the name after we have already looked for a known name, so
2472 that we don't just define a type in terms of itself. We need to
2473 mark the name here so that a struct containing a pointer to
2474 itself will work. */
2476 name
->mark
= info
->mark
;
2479 && type
->kind
!= DEBUG_KIND_NAMED
2480 && type
->kind
!= DEBUG_KIND_TAGGED
)
2482 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2488 case DEBUG_KIND_ILLEGAL
:
2489 debug_error (_("debug_write_type: illegal type encountered"));
2491 case DEBUG_KIND_INDIRECT
:
2492 /* Prevent infinite recursion. */
2493 if (*type
->u
.kindirect
->slot
!= DEBUG_TYPE_NULL
2494 && (*type
->u
.kindirect
->slot
)->mark
== info
->mark
)
2495 return (*fns
->empty_type
) (fhandle
);
2496 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2498 case DEBUG_KIND_VOID
:
2499 return (*fns
->void_type
) (fhandle
);
2500 case DEBUG_KIND_INT
:
2501 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2502 case DEBUG_KIND_FLOAT
:
2503 return (*fns
->float_type
) (fhandle
, type
->size
);
2504 case DEBUG_KIND_COMPLEX
:
2505 return (*fns
->complex_type
) (fhandle
, type
->size
);
2506 case DEBUG_KIND_BOOL
:
2507 return (*fns
->bool_type
) (fhandle
, type
->size
);
2508 case DEBUG_KIND_STRUCT
:
2509 case DEBUG_KIND_UNION
:
2510 if (type
->u
.kclass
!= NULL
)
2512 if (type
->u
.kclass
->id
<= info
->base_id
)
2514 if (! debug_set_class_id (info
, tag
, type
))
2518 if (info
->mark
== type
->u
.kclass
->mark
)
2520 /* We are currently outputting this struct, or we have
2521 already output it. I don't know if this can happen,
2522 but it can happen for a class. */
2523 assert (type
->u
.kclass
->id
> info
->base_id
);
2524 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2527 type
->u
.kclass
->mark
= info
->mark
;
2530 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2531 (type
->u
.kclass
!= NULL
2532 ? type
->u
.kclass
->id
2534 type
->kind
== DEBUG_KIND_STRUCT
,
2537 if (type
->u
.kclass
!= NULL
2538 && type
->u
.kclass
->fields
!= NULL
)
2540 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2542 struct debug_field_s
*f
;
2544 f
= type
->u
.kclass
->fields
[i
];
2545 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2546 (struct debug_name
*) NULL
)
2547 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2548 f
->u
.f
.bitsize
, f
->visibility
))
2552 return (*fns
->end_struct_type
) (fhandle
);
2553 case DEBUG_KIND_CLASS
:
2554 case DEBUG_KIND_UNION_CLASS
:
2555 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2556 case DEBUG_KIND_ENUM
:
2557 if (type
->u
.kenum
== NULL
)
2558 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2559 (bfd_signed_vma
*) NULL
);
2560 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2561 type
->u
.kenum
->values
);
2562 case DEBUG_KIND_POINTER
:
2563 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2564 (struct debug_name
*) NULL
))
2566 return (*fns
->pointer_type
) (fhandle
);
2567 case DEBUG_KIND_FUNCTION
:
2568 if (! debug_write_type (info
, fns
, fhandle
,
2569 type
->u
.kfunction
->return_type
,
2570 (struct debug_name
*) NULL
))
2572 if (type
->u
.kfunction
->arg_types
== NULL
)
2576 for (is
= 0; type
->u
.kfunction
->arg_types
[is
] != NULL
; is
++)
2577 if (! debug_write_type (info
, fns
, fhandle
,
2578 type
->u
.kfunction
->arg_types
[is
],
2579 (struct debug_name
*) NULL
))
2582 return (*fns
->function_type
) (fhandle
, is
,
2583 type
->u
.kfunction
->varargs
);
2584 case DEBUG_KIND_REFERENCE
:
2585 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2586 (struct debug_name
*) NULL
))
2588 return (*fns
->reference_type
) (fhandle
);
2589 case DEBUG_KIND_RANGE
:
2590 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2591 (struct debug_name
*) NULL
))
2593 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2594 type
->u
.krange
->upper
);
2595 case DEBUG_KIND_ARRAY
:
2596 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2597 (struct debug_name
*) NULL
)
2598 || ! debug_write_type (info
, fns
, fhandle
,
2599 type
->u
.karray
->range_type
,
2600 (struct debug_name
*) NULL
))
2602 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2603 type
->u
.karray
->upper
,
2604 type
->u
.karray
->stringp
);
2605 case DEBUG_KIND_SET
:
2606 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2607 (struct debug_name
*) NULL
))
2609 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2610 case DEBUG_KIND_OFFSET
:
2611 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2612 (struct debug_name
*) NULL
)
2613 || ! debug_write_type (info
, fns
, fhandle
,
2614 type
->u
.koffset
->target_type
,
2615 (struct debug_name
*) NULL
))
2617 return (*fns
->offset_type
) (fhandle
);
2618 case DEBUG_KIND_METHOD
:
2619 if (! debug_write_type (info
, fns
, fhandle
,
2620 type
->u
.kmethod
->return_type
,
2621 (struct debug_name
*) NULL
))
2623 if (type
->u
.kmethod
->arg_types
== NULL
)
2627 for (is
= 0; type
->u
.kmethod
->arg_types
[is
] != NULL
; is
++)
2628 if (! debug_write_type (info
, fns
, fhandle
,
2629 type
->u
.kmethod
->arg_types
[is
],
2630 (struct debug_name
*) NULL
))
2633 if (type
->u
.kmethod
->domain_type
!= NULL
)
2635 if (! debug_write_type (info
, fns
, fhandle
,
2636 type
->u
.kmethod
->domain_type
,
2637 (struct debug_name
*) NULL
))
2640 return (*fns
->method_type
) (fhandle
,
2641 type
->u
.kmethod
->domain_type
!= NULL
,
2643 type
->u
.kmethod
->varargs
);
2644 case DEBUG_KIND_CONST
:
2645 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2646 (struct debug_name
*) NULL
))
2648 return (*fns
->const_type
) (fhandle
);
2649 case DEBUG_KIND_VOLATILE
:
2650 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2651 (struct debug_name
*) NULL
))
2653 return (*fns
->volatile_type
) (fhandle
);
2654 case DEBUG_KIND_NAMED
:
2655 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2656 (struct debug_name
*) NULL
);
2657 case DEBUG_KIND_TAGGED
:
2658 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2659 type
->u
.knamed
->name
);
2666 /* Write out a class type. */
2669 debug_write_class_type (struct debug_handle
*info
,
2670 const struct debug_write_fns
*fns
, void *fhandle
,
2671 struct debug_type_s
*type
, const char *tag
)
2675 struct debug_type_s
*vptrbase
;
2677 if (type
->u
.kclass
== NULL
)
2684 if (type
->u
.kclass
->id
<= info
->base_id
)
2686 if (! debug_set_class_id (info
, tag
, type
))
2690 if (info
->mark
== type
->u
.kclass
->mark
)
2692 /* We are currently outputting this class, or we have
2693 already output it. This can happen when there are
2694 methods for an anonymous class. */
2695 assert (type
->u
.kclass
->id
> info
->base_id
);
2696 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2699 type
->u
.kclass
->mark
= info
->mark
;
2700 id
= type
->u
.kclass
->id
;
2702 vptrbase
= type
->u
.kclass
->vptrbase
;
2703 if (vptrbase
!= NULL
&& vptrbase
!= type
)
2705 if (! debug_write_type (info
, fns
, fhandle
, vptrbase
,
2706 (struct debug_name
*) NULL
))
2711 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2712 type
->kind
== DEBUG_KIND_CLASS
,
2718 if (type
->u
.kclass
!= NULL
)
2720 if (type
->u
.kclass
->fields
!= NULL
)
2722 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2724 struct debug_field_s
*f
;
2726 f
= type
->u
.kclass
->fields
[i
];
2727 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2728 (struct debug_name
*) NULL
))
2730 if (f
->static_member
)
2732 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2739 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2740 f
->u
.f
.bitsize
, f
->visibility
))
2746 if (type
->u
.kclass
->baseclasses
!= NULL
)
2748 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2750 struct debug_baseclass_s
*b
;
2752 b
= type
->u
.kclass
->baseclasses
[i
];
2753 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2754 (struct debug_name
*) NULL
))
2756 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->is_virtual
,
2762 if (type
->u
.kclass
->methods
!= NULL
)
2764 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2766 struct debug_method_s
*m
;
2769 m
= type
->u
.kclass
->methods
[i
];
2770 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2772 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2774 struct debug_method_variant_s
*v
;
2777 if (v
->context
!= NULL
)
2779 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2780 (struct debug_name
*) NULL
))
2783 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2784 (struct debug_name
*) NULL
))
2786 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2788 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2793 v
->context
!= NULL
))
2798 if (! (*fns
->class_static_method_variant
) (fhandle
,
2806 if (! (*fns
->class_end_method
) (fhandle
))
2812 return (*fns
->end_class_type
) (fhandle
);
2815 /* Write out information for a function. */
2818 debug_write_function (struct debug_handle
*info
,
2819 const struct debug_write_fns
*fns
, void *fhandle
,
2820 const char *name
, enum debug_object_linkage linkage
,
2821 struct debug_function
*function
)
2823 struct debug_parameter
*p
;
2824 struct debug_block
*b
;
2826 if (! debug_write_linenos (info
, fns
, fhandle
, function
->blocks
->start
))
2829 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2830 (struct debug_name
*) NULL
))
2833 if (! (*fns
->start_function
) (fhandle
, name
,
2834 linkage
== DEBUG_LINKAGE_GLOBAL
))
2837 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
2839 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
2840 (struct debug_name
*) NULL
)
2841 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
2845 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2847 if (! debug_write_block (info
, fns
, fhandle
, b
))
2851 return (*fns
->end_function
) (fhandle
);
2854 /* Write out information for a block. */
2857 debug_write_block (struct debug_handle
*info
,
2858 const struct debug_write_fns
*fns
, void *fhandle
,
2859 struct debug_block
*block
)
2861 struct debug_name
*n
;
2862 struct debug_block
*b
;
2864 if (! debug_write_linenos (info
, fns
, fhandle
, block
->start
))
2867 /* I can't see any point to writing out a block with no local
2868 variables, so we don't bother, except for the top level block. */
2869 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
2871 if (! (*fns
->start_block
) (fhandle
, block
->start
))
2875 if (block
->locals
!= NULL
)
2877 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
2879 if (! debug_write_name (info
, fns
, fhandle
, n
))
2884 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
2886 if (! debug_write_block (info
, fns
, fhandle
, b
))
2890 if (! debug_write_linenos (info
, fns
, fhandle
, block
->end
))
2893 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
2895 if (! (*fns
->end_block
) (fhandle
, block
->end
))
2902 /* Write out line number information up to ADDRESS. */
2905 debug_write_linenos (struct debug_handle
*info
,
2906 const struct debug_write_fns
*fns
, void *fhandle
,
2909 while (info
->current_write_lineno
!= NULL
)
2911 struct debug_lineno
*l
;
2913 l
= info
->current_write_lineno
;
2915 while (info
->current_write_lineno_index
< DEBUG_LINENO_COUNT
)
2917 if (l
->linenos
[info
->current_write_lineno_index
]
2918 == (unsigned long) -1)
2921 if (l
->addrs
[info
->current_write_lineno_index
] >= address
)
2924 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
,
2925 l
->linenos
[info
->current_write_lineno_index
],
2926 l
->addrs
[info
->current_write_lineno_index
]))
2929 ++info
->current_write_lineno_index
;
2932 info
->current_write_lineno
= l
->next
;
2933 info
->current_write_lineno_index
= 0;
2939 /* Get the ID number for a class. If during the same call to
2940 debug_write we find a struct with the same definition with the same
2941 name, we use the same ID. This type of things happens because the
2942 same struct will be defined by multiple compilation units. */
2945 debug_set_class_id (struct debug_handle
*info
, const char *tag
,
2946 struct debug_type_s
*type
)
2948 struct debug_class_type
*c
;
2949 struct debug_class_id
*l
;
2951 assert (type
->kind
== DEBUG_KIND_STRUCT
2952 || type
->kind
== DEBUG_KIND_UNION
2953 || type
->kind
== DEBUG_KIND_CLASS
2954 || type
->kind
== DEBUG_KIND_UNION_CLASS
);
2958 if (c
->id
> info
->base_id
)
2961 for (l
= info
->id_list
; l
!= NULL
; l
= l
->next
)
2963 if (l
->type
->kind
!= type
->kind
)
2974 || l
->tag
[0] != tag
[0]
2975 || strcmp (l
->tag
, tag
) != 0)
2979 if (debug_type_samep (info
, l
->type
, type
))
2981 c
->id
= l
->type
->u
.kclass
->id
;
2986 /* There are no identical types. Use a new ID, and add it to the
2989 c
->id
= info
->class_id
;
2991 l
= debug_xzalloc (info
, sizeof (*l
));
2996 l
->next
= info
->id_list
;
3002 /* See if two types are the same. At this point, we don't care about
3003 tags and the like. */
3006 debug_type_samep (struct debug_handle
*info
, struct debug_type_s
*t1
,
3007 struct debug_type_s
*t2
)
3009 struct debug_type_compare_list
*l
;
3010 struct debug_type_compare_list top
;
3018 while (t1
->kind
== DEBUG_KIND_INDIRECT
)
3020 t1
= *t1
->u
.kindirect
->slot
;
3024 while (t2
->kind
== DEBUG_KIND_INDIRECT
)
3026 t2
= *t2
->u
.kindirect
->slot
;
3034 /* As a special case, permit a typedef to match a tag, since C++
3035 debugging output will sometimes add a typedef where C debugging
3037 if (t1
->kind
== DEBUG_KIND_NAMED
3038 && t2
->kind
== DEBUG_KIND_TAGGED
)
3039 return debug_type_samep (info
, t1
->u
.knamed
->type
, t2
);
3040 else if (t1
->kind
== DEBUG_KIND_TAGGED
3041 && t2
->kind
== DEBUG_KIND_NAMED
)
3042 return debug_type_samep (info
, t1
, t2
->u
.knamed
->type
);
3044 if (t1
->kind
!= t2
->kind
3045 || t1
->size
!= t2
->size
)
3048 /* Get rid of the trivial cases first. */
3053 case DEBUG_KIND_VOID
:
3054 case DEBUG_KIND_FLOAT
:
3055 case DEBUG_KIND_COMPLEX
:
3056 case DEBUG_KIND_BOOL
:
3058 case DEBUG_KIND_INT
:
3059 return t1
->u
.kint
== t2
->u
.kint
;
3062 /* We have to avoid an infinite recursion. We do this by keeping a
3063 list of types which we are comparing. We just keep the list on
3064 the stack. If we encounter a pair of types we are currently
3065 comparing, we just assume that they are equal. */
3066 for (l
= info
->compare_list
; l
!= NULL
; l
= l
->next
)
3068 if (l
->t1
== t1
&& l
->t2
== t2
)
3074 top
.next
= info
->compare_list
;
3075 info
->compare_list
= &top
;
3084 case DEBUG_KIND_STRUCT
:
3085 case DEBUG_KIND_UNION
:
3086 case DEBUG_KIND_CLASS
:
3087 case DEBUG_KIND_UNION_CLASS
:
3088 if (t1
->u
.kclass
== NULL
)
3089 ret
= t2
->u
.kclass
== NULL
;
3090 else if (t2
->u
.kclass
== NULL
)
3092 else if (t1
->u
.kclass
->id
> info
->base_id
3093 && t1
->u
.kclass
->id
== t2
->u
.kclass
->id
)
3096 ret
= debug_class_type_samep (info
, t1
, t2
);
3099 case DEBUG_KIND_ENUM
:
3100 if (t1
->u
.kenum
== NULL
)
3101 ret
= t2
->u
.kenum
== NULL
;
3102 else if (t2
->u
.kenum
== NULL
)
3106 const char **pn1
, **pn2
;
3107 bfd_signed_vma
*pv1
, *pv2
;
3109 pn1
= t1
->u
.kenum
->names
;
3110 pn2
= t2
->u
.kenum
->names
;
3111 pv1
= t1
->u
.kenum
->values
;
3112 pv2
= t2
->u
.kenum
->values
;
3113 while (*pn1
!= NULL
&& *pn2
!= NULL
)
3117 || strcmp (*pn1
, *pn2
) != 0)
3124 ret
= *pn1
== NULL
&& *pn2
== NULL
;
3128 case DEBUG_KIND_POINTER
:
3129 ret
= debug_type_samep (info
, t1
->u
.kpointer
, t2
->u
.kpointer
);
3132 case DEBUG_KIND_FUNCTION
:
3133 if (t1
->u
.kfunction
->varargs
!= t2
->u
.kfunction
->varargs
3134 || ! debug_type_samep (info
, t1
->u
.kfunction
->return_type
,
3135 t2
->u
.kfunction
->return_type
)
3136 || ((t1
->u
.kfunction
->arg_types
== NULL
)
3137 != (t2
->u
.kfunction
->arg_types
== NULL
)))
3139 else if (t1
->u
.kfunction
->arg_types
== NULL
)
3143 struct debug_type_s
**a1
, **a2
;
3145 a1
= t1
->u
.kfunction
->arg_types
;
3146 a2
= t2
->u
.kfunction
->arg_types
;
3147 while (*a1
!= NULL
&& *a2
!= NULL
)
3149 if (! debug_type_samep (info
, *a1
, *a2
))
3154 ret
= *a1
== NULL
&& *a2
== NULL
;
3158 case DEBUG_KIND_REFERENCE
:
3159 ret
= debug_type_samep (info
, t1
->u
.kreference
, t2
->u
.kreference
);
3162 case DEBUG_KIND_RANGE
:
3163 ret
= (t1
->u
.krange
->lower
== t2
->u
.krange
->lower
3164 && t1
->u
.krange
->upper
== t2
->u
.krange
->upper
3165 && debug_type_samep (info
, t1
->u
.krange
->type
,
3166 t2
->u
.krange
->type
));
3169 case DEBUG_KIND_ARRAY
:
3170 ret
= (t1
->u
.karray
->lower
== t2
->u
.karray
->lower
3171 && t1
->u
.karray
->upper
== t2
->u
.karray
->upper
3172 && t1
->u
.karray
->stringp
== t2
->u
.karray
->stringp
3173 && debug_type_samep (info
, t1
->u
.karray
->element_type
,
3174 t2
->u
.karray
->element_type
));
3177 case DEBUG_KIND_SET
:
3178 ret
= (t1
->u
.kset
->bitstringp
== t2
->u
.kset
->bitstringp
3179 && debug_type_samep (info
, t1
->u
.kset
->type
, t2
->u
.kset
->type
));
3182 case DEBUG_KIND_OFFSET
:
3183 ret
= (debug_type_samep (info
, t1
->u
.koffset
->base_type
,
3184 t2
->u
.koffset
->base_type
)
3185 && debug_type_samep (info
, t1
->u
.koffset
->target_type
,
3186 t2
->u
.koffset
->target_type
));
3189 case DEBUG_KIND_METHOD
:
3190 if (t1
->u
.kmethod
->varargs
!= t2
->u
.kmethod
->varargs
3191 || ! debug_type_samep (info
, t1
->u
.kmethod
->return_type
,
3192 t2
->u
.kmethod
->return_type
)
3193 || ! debug_type_samep (info
, t1
->u
.kmethod
->domain_type
,
3194 t2
->u
.kmethod
->domain_type
)
3195 || ((t1
->u
.kmethod
->arg_types
== NULL
)
3196 != (t2
->u
.kmethod
->arg_types
== NULL
)))
3198 else if (t1
->u
.kmethod
->arg_types
== NULL
)
3202 struct debug_type_s
**a1
, **a2
;
3204 a1
= t1
->u
.kmethod
->arg_types
;
3205 a2
= t2
->u
.kmethod
->arg_types
;
3206 while (*a1
!= NULL
&& *a2
!= NULL
)
3208 if (! debug_type_samep (info
, *a1
, *a2
))
3213 ret
= *a1
== NULL
&& *a2
== NULL
;
3217 case DEBUG_KIND_CONST
:
3218 ret
= debug_type_samep (info
, t1
->u
.kconst
, t2
->u
.kconst
);
3221 case DEBUG_KIND_VOLATILE
:
3222 ret
= debug_type_samep (info
, t1
->u
.kvolatile
, t2
->u
.kvolatile
);
3225 case DEBUG_KIND_NAMED
:
3226 case DEBUG_KIND_TAGGED
:
3227 ret
= (strcmp (t1
->u
.knamed
->name
->name
, t2
->u
.knamed
->name
->name
) == 0
3228 && debug_type_samep (info
, t1
->u
.knamed
->type
,
3229 t2
->u
.knamed
->type
));
3233 info
->compare_list
= top
.next
;
3238 /* See if two classes are the same. This is a subroutine of
3239 debug_type_samep. */
3242 debug_class_type_samep (struct debug_handle
*info
, struct debug_type_s
*t1
,
3243 struct debug_type_s
*t2
)
3245 struct debug_class_type
*c1
, *c2
;
3250 if ((c1
->fields
== NULL
) != (c2
->fields
== NULL
)
3251 || (c1
->baseclasses
== NULL
) != (c2
->baseclasses
== NULL
)
3252 || (c1
->methods
== NULL
) != (c2
->methods
== NULL
)
3253 || (c1
->vptrbase
== NULL
) != (c2
->vptrbase
== NULL
))
3256 if (c1
->fields
!= NULL
)
3258 struct debug_field_s
**pf1
, **pf2
;
3260 for (pf1
= c1
->fields
, pf2
= c2
->fields
;
3261 *pf1
!= NULL
&& *pf2
!= NULL
;
3264 struct debug_field_s
*f1
, *f2
;
3268 if (f1
->name
[0] != f2
->name
[0]
3269 || f1
->visibility
!= f2
->visibility
3270 || f1
->static_member
!= f2
->static_member
)
3272 if (f1
->static_member
)
3274 if (strcmp (f1
->u
.s
.physname
, f2
->u
.s
.physname
) != 0)
3279 if (f1
->u
.f
.bitpos
!= f2
->u
.f
.bitpos
3280 || f1
->u
.f
.bitsize
!= f2
->u
.f
.bitsize
)
3283 /* We do the checks which require function calls last. We
3284 don't require that the types of fields have the same
3285 names, since that sometimes fails in the presence of
3286 typedefs and we really don't care. */
3287 if (strcmp (f1
->name
, f2
->name
) != 0
3290 || ! debug_type_samep (info
,
3291 debug_get_real_type ((void *) info
,
3293 debug_get_real_type ((void *) info
,
3297 if (*pf1
!= NULL
|| *pf2
!= NULL
)
3301 if (c1
->vptrbase
!= NULL
)
3303 if (! debug_type_samep (info
, c1
->vptrbase
, c2
->vptrbase
))
3307 if (c1
->baseclasses
!= NULL
)
3309 struct debug_baseclass_s
**pb1
, **pb2
;
3311 for (pb1
= c1
->baseclasses
, pb2
= c2
->baseclasses
;
3312 *pb1
!= NULL
&& *pb2
!= NULL
;
3315 struct debug_baseclass_s
*b1
, *b2
;
3319 if (b1
->bitpos
!= b2
->bitpos
3320 || b1
->is_virtual
!= b2
->is_virtual
3321 || b1
->visibility
!= b2
->visibility
3322 || ! debug_type_samep (info
, b1
->type
, b2
->type
))
3325 if (*pb1
!= NULL
|| *pb2
!= NULL
)
3329 if (c1
->methods
!= NULL
)
3331 struct debug_method_s
**pm1
, **pm2
;
3333 for (pm1
= c1
->methods
, pm2
= c2
->methods
;
3334 *pm1
!= NULL
&& *pm2
!= NULL
;
3337 struct debug_method_s
*m1
, *m2
;
3341 if (m1
->name
[0] != m2
->name
[0]
3342 || strcmp (m1
->name
, m2
->name
) != 0
3343 || (m1
->variants
== NULL
) != (m2
->variants
== NULL
))
3345 if (m1
->variants
!= NULL
)
3347 struct debug_method_variant_s
**pv1
, **pv2
;
3349 for (pv1
= m1
->variants
, pv2
= m2
->variants
;
3350 *pv1
!= NULL
&& *pv2
!= NULL
;
3353 struct debug_method_variant_s
*v1
, *v2
;
3357 if (v1
->physname
[0] != v2
->physname
[0]
3358 || v1
->visibility
!= v2
->visibility
3359 || v1
->constp
!= v2
->constp
3360 || v1
->volatilep
!= v2
->volatilep
3361 || v1
->voffset
!= v2
->voffset
3362 || (v1
->context
== NULL
) != (v2
->context
== NULL
)
3363 || strcmp (v1
->physname
, v2
->physname
) != 0
3364 || ! debug_type_samep (info
, v1
->type
, v2
->type
))
3366 if (v1
->context
!= NULL
)
3368 if (! debug_type_samep (info
, v1
->context
,
3373 if (*pv1
!= NULL
|| *pv2
!= NULL
)
3377 if (*pm1
!= NULL
|| *pm2
!= NULL
)