1 /* debug.c -- Handle generic debugging information.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2005, 2007,
3 2009 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* This file implements a generic debugging format. We may eventually
25 have readers which convert different formats into this generic
26 format, and writers which write it out. The initial impetus for
27 this was writing a converter from stabs to HP IEEE-695 debugging
33 #include "libiberty.h"
34 #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 /* A linked list of compilation units. */
43 struct debug_unit *units;
44 /* The current compilation unit. */
45 struct debug_unit *current_unit;
46 /* The current source file. */
47 struct debug_file *current_file;
48 /* The current function. */
49 struct debug_function *current_function;
50 /* The current block. */
51 struct debug_block *current_block;
52 /* The current line number information for the current unit. */
53 struct debug_lineno *current_lineno;
54 /* Mark. This is used by debug_write. */
56 /* A struct/class ID used by debug_write. */
57 unsigned int class_id;
58 /* The base for class_id for this call to debug_write. */
60 /* The current line number in debug_write. */
61 struct debug_lineno *current_write_lineno;
62 unsigned int current_write_lineno_index;
63 /* A list of classes which have assigned ID's during debug_write.
64 This is linked through the next_id field of debug_class_type. */
65 struct debug_class_id *id_list;
66 /* A list used to avoid recursion during debug_type_samep. */
67 struct debug_type_compare_list *compare_list;
70 /* Information we keep for a single compilation unit. */
74 /* The next compilation unit. */
75 struct debug_unit *next;
76 /* A list of files included in this compilation unit. The first
77 file is always the main one, and that is where the main file name
79 struct debug_file *files;
80 /* Line number information for this compilation unit. This is not
81 stored by function, because assembler code may have line number
82 information without function information. */
83 struct debug_lineno *linenos;
86 /* Information kept for a single source file. */
90 /* The next source file in this compilation unit. */
91 struct debug_file *next;
92 /* The name of the source file. */
94 /* Global functions, variables, types, etc. */
95 struct debug_namespace *globals;
103 enum debug_type_kind kind;
104 /* Size of type (0 if not known). */
106 /* Type which is a pointer to this type. */
108 /* Tagged union with additional information about the type. */
111 /* DEBUG_KIND_INDIRECT. */
112 struct debug_indirect_type *kindirect;
113 /* DEBUG_KIND_INT. */
114 /* Whether the integer is unsigned. */
116 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
117 DEBUG_KIND_UNION_CLASS. */
118 struct debug_class_type *kclass;
119 /* DEBUG_KIND_ENUM. */
120 struct debug_enum_type *kenum;
121 /* DEBUG_KIND_POINTER. */
122 struct debug_type_s *kpointer;
123 /* DEBUG_KIND_FUNCTION. */
124 struct debug_function_type *kfunction;
125 /* DEBUG_KIND_REFERENCE. */
126 struct debug_type_s *kreference;
127 /* DEBUG_KIND_RANGE. */
128 struct debug_range_type *krange;
129 /* DEBUG_KIND_ARRAY. */
130 struct debug_array_type *karray;
131 /* DEBUG_KIND_SET. */
132 struct debug_set_type *kset;
133 /* DEBUG_KIND_OFFSET. */
134 struct debug_offset_type *koffset;
135 /* DEBUG_KIND_METHOD. */
136 struct debug_method_type *kmethod;
137 /* DEBUG_KIND_CONST. */
138 struct debug_type_s *kconst;
139 /* DEBUG_KIND_VOLATILE. */
140 struct debug_type_s *kvolatile;
141 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
142 struct debug_named_type *knamed;
146 /* Information kept for an indirect type. */
148 struct debug_indirect_type
150 /* Slot where the final type will appear. */
156 /* Information kept for a struct, union, or class. */
158 struct debug_class_type
160 /* NULL terminated array of fields. */
162 /* A mark field which indicates whether the struct has already been
165 /* This is used to uniquely identify unnamed structs when printing. */
167 /* The remaining fields are only used for DEBUG_KIND_CLASS and
168 DEBUG_KIND_UNION_CLASS. */
169 /* NULL terminated array of base classes. */
170 debug_baseclass *baseclasses;
171 /* NULL terminated array of methods. */
172 debug_method *methods;
173 /* The type of the class providing the virtual function table for
174 this class. This may point to the type itself. */
178 /* Information kept for an enum. */
180 struct debug_enum_type
182 /* NULL terminated array of names. */
184 /* Array of corresponding values. */
185 bfd_signed_vma *values;
188 /* Information kept for a function. FIXME: We should be able to
189 record the parameter types. */
191 struct debug_function_type
194 debug_type return_type;
195 /* NULL terminated array of argument types. */
196 debug_type *arg_types;
197 /* Whether the function takes a variable number of arguments. */
201 /* Information kept for a range. */
203 struct debug_range_type
205 /* Range base type. */
208 bfd_signed_vma lower;
210 bfd_signed_vma upper;
213 /* Information kept for an array. */
215 struct debug_array_type
218 debug_type element_type;
220 debug_type range_type;
222 bfd_signed_vma lower;
224 bfd_signed_vma upper;
225 /* Whether this array is really a string. */
229 /* Information kept for a set. */
231 struct debug_set_type
235 /* Whether this set is really a bitstring. */
236 bfd_boolean bitstringp;
239 /* Information kept for an offset type (a based pointer). */
241 struct debug_offset_type
243 /* The type the pointer is an offset from. */
244 debug_type base_type;
245 /* The type the pointer points to. */
246 debug_type target_type;
249 /* Information kept for a method type. */
251 struct debug_method_type
253 /* The return type. */
254 debug_type return_type;
255 /* The object type which this method is for. */
256 debug_type domain_type;
257 /* A NULL terminated array of argument types. */
258 debug_type *arg_types;
259 /* Whether the method takes a variable number of arguments. */
263 /* Information kept for a named type. */
265 struct debug_named_type
268 struct debug_name *name;
273 /* A field in a struct or union. */
277 /* Name of the field. */
279 /* Type of the field. */
280 struct debug_type_s *type;
281 /* Visibility of the field. */
282 enum debug_visibility visibility;
283 /* Whether this is a static member. */
284 bfd_boolean static_member;
287 /* If static_member is false. */
290 /* Bit position of the field in the struct. */
292 /* Size of the field in bits. */
293 unsigned int bitsize;
295 /* If static_member is true. */
298 const char *physname;
303 /* A base class for an object. */
305 struct debug_baseclass_s
307 /* Type of the base class. */
308 struct debug_type_s *type;
309 /* Bit position of the base class in the object. */
311 /* Whether the base class is virtual. */
312 bfd_boolean is_virtual;
313 /* Visibility of the base class. */
314 enum debug_visibility visibility;
317 /* A method of an object. */
319 struct debug_method_s
321 /* The name of the method. */
323 /* A NULL terminated array of different types of variants. */
324 struct debug_method_variant_s **variants;
327 /* The variants of a method function of an object. These indicate
328 which method to run. */
330 struct debug_method_variant_s
332 /* The physical name of the function. */
333 const char *physname;
334 /* The type of the function. */
335 struct debug_type_s *type;
336 /* The visibility of the function. */
337 enum debug_visibility visibility;
338 /* Whether the function is const. */
340 /* Whether the function is volatile. */
341 bfd_boolean volatilep;
342 /* The offset to the function in the virtual function table. */
344 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
345 #define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
346 /* Context of a virtual method function. */
347 struct debug_type_s *context;
350 /* A variable. This is the information we keep for a variable object.
351 This has no name; a name is associated with a variable in a
352 debug_name structure. */
354 struct debug_variable
356 /* Kind of variable. */
357 enum debug_var_kind kind;
360 /* Value. The interpretation of the value depends upon kind. */
364 /* A function. This has no name; a name is associated with a function
365 in a debug_name structure. */
367 struct debug_function
370 debug_type return_type;
371 /* Parameter information. */
372 struct debug_parameter *parameters;
373 /* Block information. The first structure on the list is the main
374 block of the function, and describes function local variables. */
375 struct debug_block *blocks;
378 /* A function parameter. */
380 struct debug_parameter
382 /* Next parameter. */
383 struct debug_parameter *next;
389 enum debug_parm_kind kind;
390 /* Value (meaning depends upon kind). */
394 /* A typed constant. */
396 struct debug_typed_constant
400 /* Value. FIXME: We may eventually need to support non-integral
405 /* Information about a block within a function. */
409 /* Next block with the same parent. */
410 struct debug_block *next;
412 struct debug_block *parent;
413 /* List of child blocks. */
414 struct debug_block *children;
415 /* Start address of the block. */
417 /* End address of the block. */
419 /* Local variables. */
420 struct debug_namespace *locals;
423 /* Line number information we keep for a compilation unit. FIXME:
424 This structure is easy to create, but can be very space
429 /* More line number information for this block. */
430 struct debug_lineno *next;
432 struct debug_file *file;
433 /* Line numbers, terminated by a -1 or the end of the array. */
434 #define DEBUG_LINENO_COUNT 10
435 unsigned long linenos[DEBUG_LINENO_COUNT];
436 /* Addresses for the line numbers. */
437 bfd_vma addrs[DEBUG_LINENO_COUNT];
440 /* A namespace. This is a mapping from names to objects. FIXME: This
441 should be implemented as a hash table. */
443 struct debug_namespace
445 /* List of items in this namespace. */
446 struct debug_name *list;
447 /* Pointer to where the next item in this namespace should go. */
448 struct debug_name **tail;
451 /* Kinds of objects that appear in a namespace. */
453 enum debug_object_kind
457 /* A tagged type (really a different sort of namespace). */
460 DEBUG_OBJECT_VARIABLE,
462 DEBUG_OBJECT_FUNCTION,
463 /* An integer constant. */
464 DEBUG_OBJECT_INT_CONSTANT,
465 /* A floating point constant. */
466 DEBUG_OBJECT_FLOAT_CONSTANT,
467 /* A typed constant. */
468 DEBUG_OBJECT_TYPED_CONSTANT
471 /* Linkage of an object that appears in a namespace. */
473 enum debug_object_linkage
475 /* Local variable. */
476 DEBUG_LINKAGE_AUTOMATIC,
477 /* Static--either file static or function static, depending upon the
479 DEBUG_LINKAGE_STATIC,
481 DEBUG_LINKAGE_GLOBAL,
486 /* A name in a namespace. */
490 /* Next name in this namespace. */
491 struct debug_name *next;
494 /* Mark. This is used by debug_write. */
496 /* Kind of object. */
497 enum debug_object_kind kind;
498 /* Linkage of object. */
499 enum debug_object_linkage linkage;
500 /* Tagged union with additional information about the object. */
503 /* DEBUG_OBJECT_TYPE. */
504 struct debug_type_s *type;
505 /* DEBUG_OBJECT_TAG. */
506 struct debug_type_s *tag;
507 /* DEBUG_OBJECT_VARIABLE. */
508 struct debug_variable *variable;
509 /* DEBUG_OBJECT_FUNCTION. */
510 struct debug_function *function;
511 /* DEBUG_OBJECT_INT_CONSTANT. */
512 bfd_vma int_constant;
513 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
514 double float_constant;
515 /* DEBUG_OBJECT_TYPED_CONSTANT. */
516 struct debug_typed_constant *typed_constant;
520 /* During debug_write, a linked list of these structures is used to
521 keep track of ID numbers that have been assigned to classes. */
523 struct debug_class_id
525 /* Next ID number. */
526 struct debug_class_id *next;
527 /* The type with the ID. */
528 struct debug_type_s *type;
529 /* The tag; NULL if no tag. */
533 /* During debug_type_samep, a linked list of these structures is kept
534 on the stack to avoid infinite recursion. */
536 struct debug_type_compare_list
538 /* Next type on list. */
539 struct debug_type_compare_list *next;
540 /* The types we are comparing. */
541 struct debug_type_s *t1;
542 struct debug_type_s *t2;
545 /* During debug_get_real_type, a linked list of these structures is
546 kept on the stack to avoid infinite recursion. */
548 struct debug_type_real_list
550 /* Next type on list. */
551 struct debug_type_real_list *next;
552 /* The type we are checking. */
553 struct debug_type_s *t;
556 /* Local functions. */
558 static void debug_error (const char *);
559 static struct debug_name *debug_add_to_namespace
560 (struct debug_handle *, struct debug_namespace **, const char *,
561 enum debug_object_kind, enum debug_object_linkage);
562 static struct debug_name *debug_add_to_current_namespace
563 (struct debug_handle *, const char *, enum debug_object_kind,
564 enum debug_object_linkage);
565 static struct debug_type_s *debug_make_type
566 (struct debug_handle *, enum debug_type_kind, unsigned int);
567 static struct debug_type_s *debug_get_real_type
568 (void *, debug_type, struct debug_type_real_list *);
569 static bfd_boolean debug_write_name
570 (struct debug_handle *, const struct debug_write_fns *, void *,
571 struct debug_name *);
572 static bfd_boolean debug_write_type
573 (struct debug_handle *, const struct debug_write_fns *, void *,
574 struct debug_type_s *, struct debug_name *);
575 static bfd_boolean debug_write_class_type
576 (struct debug_handle *, const struct debug_write_fns *, void *,
577 struct debug_type_s *, const char *);
578 static bfd_boolean debug_write_function
579 (struct debug_handle *, const struct debug_write_fns *, void *,
580 const char *, enum debug_object_linkage, struct debug_function *);
581 static bfd_boolean debug_write_block
582 (struct debug_handle *, const struct debug_write_fns *, void *,
583 struct debug_block *);
584 static bfd_boolean debug_write_linenos
585 (struct debug_handle *, const struct debug_write_fns *, void *, bfd_vma);
586 static bfd_boolean debug_set_class_id
587 (struct debug_handle *, const char *, struct debug_type_s *);
588 static bfd_boolean debug_type_samep
589 (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
590 static bfd_boolean debug_class_type_samep
591 (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
593 /* Issue an error message. */
596 debug_error (const char *message)
598 fprintf (stderr, "%s\n", message);
601 /* Add an object to a namespace. */
603 static struct debug_name *
604 debug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
605 struct debug_namespace **nsp, const char *name,
606 enum debug_object_kind kind,
607 enum debug_object_linkage linkage)
609 struct debug_name *n;
610 struct debug_namespace *ns;
612 n = (struct debug_name *) xmalloc (sizeof *n);
613 memset (n, 0, sizeof *n);
617 n->linkage = linkage;
622 ns = (struct debug_namespace *) xmalloc (sizeof *ns);
623 memset (ns, 0, sizeof *ns);
625 ns->tail = &ns->list;
636 /* Add an object to the current namespace. */
638 static struct debug_name *
639 debug_add_to_current_namespace (struct debug_handle *info, const char *name,
640 enum debug_object_kind kind,
641 enum debug_object_linkage linkage)
643 struct debug_namespace **nsp;
645 if (info->current_unit == NULL
646 || info->current_file == NULL)
648 debug_error (_("debug_add_to_current_namespace: no current file"));
652 if (info->current_block != NULL)
653 nsp = &info->current_block->locals;
655 nsp = &info->current_file->globals;
657 return debug_add_to_namespace (info, nsp, name, kind, linkage);
660 /* Return a handle for debugging information. */
665 struct debug_handle *ret;
667 ret = (struct debug_handle *) xmalloc (sizeof *ret);
668 memset (ret, 0, sizeof *ret);
672 /* Set the source filename. This implicitly starts a new compilation
676 debug_set_filename (void *handle, const char *name)
678 struct debug_handle *info = (struct debug_handle *) handle;
679 struct debug_file *nfile;
680 struct debug_unit *nunit;
685 nfile = (struct debug_file *) xmalloc (sizeof *nfile);
686 memset (nfile, 0, sizeof *nfile);
688 nfile->filename = name;
690 nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
691 memset (nunit, 0, sizeof *nunit);
693 nunit->files = nfile;
694 info->current_file = nfile;
696 if (info->current_unit != NULL)
697 info->current_unit->next = nunit;
700 assert (info->units == NULL);
704 info->current_unit = nunit;
706 info->current_function = NULL;
707 info->current_block = NULL;
708 info->current_lineno = NULL;
713 /* Change source files to the given file name. This is used for
714 include files in a single compilation unit. */
717 debug_start_source (void *handle, const char *name)
719 struct debug_handle *info = (struct debug_handle *) handle;
720 struct debug_file *f, **pf;
725 if (info->current_unit == NULL)
727 debug_error (_("debug_start_source: no debug_set_filename call"));
731 for (f = info->current_unit->files; f != NULL; f = f->next)
733 if (filename_cmp (f->filename, name) == 0)
735 info->current_file = f;
740 f = (struct debug_file *) xmalloc (sizeof *f);
741 memset (f, 0, sizeof *f);
745 for (pf = &info->current_file->next;
751 info->current_file = f;
756 /* Record a function definition. This implicitly starts a function
757 block. The debug_type argument is the type of the return value.
758 The boolean indicates whether the function is globally visible.
759 The bfd_vma is the address of the start of the function. Currently
760 the parameter types are specified by calls to
761 debug_record_parameter. FIXME: There is no way to specify nested
765 debug_record_function (void *handle, const char *name,
766 debug_type return_type, bfd_boolean global,
769 struct debug_handle *info = (struct debug_handle *) handle;
770 struct debug_function *f;
771 struct debug_block *b;
772 struct debug_name *n;
776 if (return_type == NULL)
779 if (info->current_unit == NULL)
781 debug_error (_("debug_record_function: no debug_set_filename call"));
785 f = (struct debug_function *) xmalloc (sizeof *f);
786 memset (f, 0, sizeof *f);
788 f->return_type = return_type;
790 b = (struct debug_block *) xmalloc (sizeof *b);
791 memset (b, 0, sizeof *b);
794 b->end = (bfd_vma) -1;
798 info->current_function = f;
799 info->current_block = b;
801 /* FIXME: If we could handle nested functions, this would be the
802 place: we would want to use a different namespace. */
803 n = debug_add_to_namespace (info,
804 &info->current_file->globals,
806 DEBUG_OBJECT_FUNCTION,
808 ? DEBUG_LINKAGE_GLOBAL
809 : DEBUG_LINKAGE_STATIC));
818 /* Record a parameter for the current function. */
821 debug_record_parameter (void *handle, const char *name, debug_type type,
822 enum debug_parm_kind kind, bfd_vma val)
824 struct debug_handle *info = (struct debug_handle *) handle;
825 struct debug_parameter *p, **pp;
827 if (name == NULL || type == NULL)
830 if (info->current_unit == NULL
831 || info->current_function == NULL)
833 debug_error (_("debug_record_parameter: no current function"));
837 p = (struct debug_parameter *) xmalloc (sizeof *p);
838 memset (p, 0, sizeof *p);
845 for (pp = &info->current_function->parameters;
854 /* End a function. FIXME: This should handle function nesting. */
857 debug_end_function (void *handle, bfd_vma addr)
859 struct debug_handle *info = (struct debug_handle *) handle;
861 if (info->current_unit == NULL
862 || info->current_block == NULL
863 || info->current_function == NULL)
865 debug_error (_("debug_end_function: no current function"));
869 if (info->current_block->parent != NULL)
871 debug_error (_("debug_end_function: some blocks were not closed"));
875 info->current_block->end = addr;
877 info->current_function = NULL;
878 info->current_block = NULL;
883 /* Start a block in a function. All local information will be
884 recorded in this block, until the matching call to debug_end_block.
885 debug_start_block and debug_end_block may be nested. The bfd_vma
886 argument is the address at which this block starts. */
889 debug_start_block (void *handle, bfd_vma addr)
891 struct debug_handle *info = (struct debug_handle *) handle;
892 struct debug_block *b, **pb;
894 /* We must always have a current block: debug_record_function sets
896 if (info->current_unit == NULL
897 || info->current_block == NULL)
899 debug_error (_("debug_start_block: no current block"));
903 b = (struct debug_block *) xmalloc (sizeof *b);
904 memset (b, 0, sizeof *b);
906 b->parent = info->current_block;
908 b->end = (bfd_vma) -1;
910 /* This new block is a child of the current block. */
911 for (pb = &info->current_block->children;
917 info->current_block = b;
922 /* Finish a block in a function. This matches the call to
923 debug_start_block. The argument is the address at which this block
927 debug_end_block (void *handle, bfd_vma addr)
929 struct debug_handle *info = (struct debug_handle *) handle;
930 struct debug_block *parent;
932 if (info->current_unit == NULL
933 || info->current_block == NULL)
935 debug_error (_("debug_end_block: no current block"));
939 parent = info->current_block->parent;
942 debug_error (_("debug_end_block: attempt to close top level block"));
946 info->current_block->end = addr;
948 info->current_block = parent;
953 /* Associate a line number in the current source file and function
954 with a given address. */
957 debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
959 struct debug_handle *info = (struct debug_handle *) handle;
960 struct debug_lineno *l;
963 if (info->current_unit == NULL)
965 debug_error (_("debug_record_line: no current unit"));
969 l = info->current_lineno;
970 if (l != NULL && l->file == info->current_file)
972 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
974 if (l->linenos[i] == (unsigned long) -1)
976 l->linenos[i] = lineno;
983 /* If we get here, then either 1) there is no current_lineno
984 structure, which means this is the first line number in this
985 compilation unit, 2) the current_lineno structure is for a
986 different file, or 3) the current_lineno structure is full.
987 Regardless, we want to allocate a new debug_lineno structure, put
988 it in the right place, and make it the new current_lineno
991 l = (struct debug_lineno *) xmalloc (sizeof *l);
992 memset (l, 0, sizeof *l);
994 l->file = info->current_file;
995 l->linenos[0] = lineno;
997 for (i = 1; i < DEBUG_LINENO_COUNT; i++)
998 l->linenos[i] = (unsigned long) -1;
1000 if (info->current_lineno != NULL)
1001 info->current_lineno->next = l;
1003 info->current_unit->linenos = l;
1005 info->current_lineno = l;
1010 /* Start a named common block. This is a block of variables that may
1014 debug_start_common_block (void *handle ATTRIBUTE_UNUSED,
1015 const char *name ATTRIBUTE_UNUSED)
1018 debug_error (_("debug_start_common_block: not implemented"));
1022 /* End a named common block. */
1025 debug_end_common_block (void *handle ATTRIBUTE_UNUSED,
1026 const char *name ATTRIBUTE_UNUSED)
1029 debug_error (_("debug_end_common_block: not implemented"));
1033 /* Record a named integer constant. */
1036 debug_record_int_const (void *handle, const char *name, bfd_vma val)
1038 struct debug_handle *info = (struct debug_handle *) handle;
1039 struct debug_name *n;
1044 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
1045 DEBUG_LINKAGE_NONE);
1049 n->u.int_constant = val;
1054 /* Record a named floating point constant. */
1057 debug_record_float_const (void *handle, const char *name, double val)
1059 struct debug_handle *info = (struct debug_handle *) handle;
1060 struct debug_name *n;
1065 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
1066 DEBUG_LINKAGE_NONE);
1070 n->u.float_constant = val;
1075 /* Record a typed constant with an integral value. */
1078 debug_record_typed_const (void *handle, const char *name, debug_type type,
1081 struct debug_handle *info = (struct debug_handle *) handle;
1082 struct debug_name *n;
1083 struct debug_typed_constant *tc;
1085 if (name == NULL || type == NULL)
1088 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
1089 DEBUG_LINKAGE_NONE);
1093 tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
1094 memset (tc, 0, sizeof *tc);
1099 n->u.typed_constant = tc;
1104 /* Record a label. */
1107 debug_record_label (void *handle ATTRIBUTE_UNUSED,
1108 const char *name ATTRIBUTE_UNUSED,
1109 debug_type type ATTRIBUTE_UNUSED,
1110 bfd_vma addr ATTRIBUTE_UNUSED)
1113 debug_error (_("debug_record_label: not implemented"));
1117 /* Record a variable. */
1120 debug_record_variable (void *handle, const char *name, debug_type type,
1121 enum debug_var_kind kind, bfd_vma val)
1123 struct debug_handle *info = (struct debug_handle *) handle;
1124 struct debug_namespace **nsp;
1125 enum debug_object_linkage linkage;
1126 struct debug_name *n;
1127 struct debug_variable *v;
1129 if (name == NULL || type == NULL)
1132 if (info->current_unit == NULL
1133 || info->current_file == NULL)
1135 debug_error (_("debug_record_variable: no current file"));
1139 if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
1141 nsp = &info->current_file->globals;
1142 if (kind == DEBUG_GLOBAL)
1143 linkage = DEBUG_LINKAGE_GLOBAL;
1145 linkage = DEBUG_LINKAGE_STATIC;
1149 if (info->current_block == NULL)
1150 nsp = &info->current_file->globals;
1152 nsp = &info->current_block->locals;
1153 linkage = DEBUG_LINKAGE_AUTOMATIC;
1156 n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
1160 v = (struct debug_variable *) xmalloc (sizeof *v);
1161 memset (v, 0, sizeof *v);
1172 /* Make a type with a given kind and size. */
1174 static struct debug_type_s *
1175 debug_make_type (struct debug_handle *info ATTRIBUTE_UNUSED,
1176 enum debug_type_kind kind, unsigned int size)
1178 struct debug_type_s *t;
1180 t = (struct debug_type_s *) xmalloc (sizeof *t);
1181 memset (t, 0, sizeof *t);
1189 /* Make an indirect type which may be used as a placeholder for a type
1190 which is referenced before it is defined. */
1193 debug_make_indirect_type (void *handle, debug_type *slot, const char *tag)
1195 struct debug_handle *info = (struct debug_handle *) handle;
1196 struct debug_type_s *t;
1197 struct debug_indirect_type *i;
1199 t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
1201 return DEBUG_TYPE_NULL;
1203 i = (struct debug_indirect_type *) xmalloc (sizeof *i);
1204 memset (i, 0, sizeof *i);
1214 /* Make a void type. There is only one of these. */
1217 debug_make_void_type (void *handle)
1219 struct debug_handle *info = (struct debug_handle *) handle;
1221 return debug_make_type (info, DEBUG_KIND_VOID, 0);
1224 /* Make an integer type of a given size. The boolean argument is true
1225 if the integer is unsigned. */
1228 debug_make_int_type (void *handle, unsigned int size, bfd_boolean unsignedp)
1230 struct debug_handle *info = (struct debug_handle *) handle;
1231 struct debug_type_s *t;
1233 t = debug_make_type (info, DEBUG_KIND_INT, size);
1235 return DEBUG_TYPE_NULL;
1237 t->u.kint = unsignedp;
1242 /* Make a floating point type of a given size. FIXME: On some
1243 platforms, like an Alpha, you probably need to be able to specify
1247 debug_make_float_type (void *handle, unsigned int size)
1249 struct debug_handle *info = (struct debug_handle *) handle;
1251 return debug_make_type (info, DEBUG_KIND_FLOAT, size);
1254 /* Make a boolean type of a given size. */
1257 debug_make_bool_type (void *handle, unsigned int size)
1259 struct debug_handle *info = (struct debug_handle *) handle;
1261 return debug_make_type (info, DEBUG_KIND_BOOL, size);
1264 /* Make a complex type of a given size. */
1267 debug_make_complex_type (void *handle, unsigned int size)
1269 struct debug_handle *info = (struct debug_handle *) handle;
1271 return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
1274 /* Make a structure type. The second argument is true for a struct,
1275 false for a union. The third argument is the size of the struct.
1276 The fourth argument is a NULL terminated array of fields. */
1279 debug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
1280 debug_field *fields)
1282 struct debug_handle *info = (struct debug_handle *) handle;
1283 struct debug_type_s *t;
1284 struct debug_class_type *c;
1286 t = debug_make_type (info,
1287 structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
1290 return DEBUG_TYPE_NULL;
1292 c = (struct debug_class_type *) xmalloc (sizeof *c);
1293 memset (c, 0, sizeof *c);
1302 /* Make an object type. The first three arguments after the handle
1303 are the same as for debug_make_struct_type. The next arguments are
1304 a NULL terminated array of base classes, a NULL terminated array of
1305 methods, the type of the object holding the virtual function table
1306 if it is not this object, and a boolean which is true if this
1307 object has its own virtual function table. */
1310 debug_make_object_type (void *handle, bfd_boolean structp, bfd_vma size,
1311 debug_field *fields, debug_baseclass *baseclasses,
1312 debug_method *methods, debug_type vptrbase,
1313 bfd_boolean ownvptr)
1315 struct debug_handle *info = (struct debug_handle *) handle;
1316 struct debug_type_s *t;
1317 struct debug_class_type *c;
1319 t = debug_make_type (info,
1320 structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
1323 return DEBUG_TYPE_NULL;
1325 c = (struct debug_class_type *) xmalloc (sizeof *c);
1326 memset (c, 0, sizeof *c);
1329 c->baseclasses = baseclasses;
1330 c->methods = methods;
1334 c->vptrbase = vptrbase;
1341 /* Make an enumeration type. The arguments are a null terminated
1342 array of strings, and an array of corresponding values. */
1345 debug_make_enum_type (void *handle, const char **names,
1346 bfd_signed_vma *values)
1348 struct debug_handle *info = (struct debug_handle *) handle;
1349 struct debug_type_s *t;
1350 struct debug_enum_type *e;
1352 t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
1354 return DEBUG_TYPE_NULL;
1356 e = (struct debug_enum_type *) xmalloc (sizeof *e);
1357 memset (e, 0, sizeof *e);
1367 /* Make a pointer to a given type. */
1370 debug_make_pointer_type (void *handle, debug_type type)
1372 struct debug_handle *info = (struct debug_handle *) handle;
1373 struct debug_type_s *t;
1376 return DEBUG_TYPE_NULL;
1378 if (type->pointer != DEBUG_TYPE_NULL)
1379 return type->pointer;
1381 t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
1383 return DEBUG_TYPE_NULL;
1385 t->u.kpointer = type;
1392 /* Make a function returning a given type. FIXME: We should be able
1393 to record the parameter types. */
1396 debug_make_function_type (void *handle, debug_type type,
1397 debug_type *arg_types, bfd_boolean varargs)
1399 struct debug_handle *info = (struct debug_handle *) handle;
1400 struct debug_type_s *t;
1401 struct debug_function_type *f;
1404 return DEBUG_TYPE_NULL;
1406 t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
1408 return DEBUG_TYPE_NULL;
1410 f = (struct debug_function_type *) xmalloc (sizeof *f);
1411 memset (f, 0, sizeof *f);
1413 f->return_type = type;
1414 f->arg_types = arg_types;
1415 f->varargs = varargs;
1422 /* Make a reference to a given type. */
1425 debug_make_reference_type (void *handle, debug_type type)
1427 struct debug_handle *info = (struct debug_handle *) handle;
1428 struct debug_type_s *t;
1431 return DEBUG_TYPE_NULL;
1433 t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
1435 return DEBUG_TYPE_NULL;
1437 t->u.kreference = type;
1442 /* Make a range of a given type from a lower to an upper bound. */
1445 debug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower,
1446 bfd_signed_vma upper)
1448 struct debug_handle *info = (struct debug_handle *) handle;
1449 struct debug_type_s *t;
1450 struct debug_range_type *r;
1453 return DEBUG_TYPE_NULL;
1455 t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
1457 return DEBUG_TYPE_NULL;
1459 r = (struct debug_range_type *) xmalloc (sizeof *r);
1460 memset (r, 0, sizeof *r);
1471 /* Make an array type. The second argument is the type of an element
1472 of the array. The third argument is the type of a range of the
1473 array. The fourth and fifth argument are the lower and upper
1474 bounds, respectively. The sixth argument is true if this array is
1475 actually a string, as in C. */
1478 debug_make_array_type (void *handle, debug_type element_type,
1479 debug_type range_type, bfd_signed_vma lower,
1480 bfd_signed_vma upper, bfd_boolean stringp)
1482 struct debug_handle *info = (struct debug_handle *) handle;
1483 struct debug_type_s *t;
1484 struct debug_array_type *a;
1486 if (element_type == NULL || range_type == NULL)
1487 return DEBUG_TYPE_NULL;
1489 t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
1491 return DEBUG_TYPE_NULL;
1493 a = (struct debug_array_type *) xmalloc (sizeof *a);
1494 memset (a, 0, 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, bfd_boolean 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 = (struct debug_set_type *) xmalloc (sizeof *s);
1526 memset (s, 0, sizeof *s);
1529 s->bitstringp = bitstringp;
1536 /* Make a type for a pointer which is relative to an object. The
1537 second argument is the type of the object to which the pointer is
1538 relative. The third argument is the type that the pointer points
1542 debug_make_offset_type (void *handle, debug_type base_type,
1543 debug_type target_type)
1545 struct debug_handle *info = (struct debug_handle *) handle;
1546 struct debug_type_s *t;
1547 struct debug_offset_type *o;
1549 if (base_type == NULL || target_type == NULL)
1550 return DEBUG_TYPE_NULL;
1552 t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
1554 return DEBUG_TYPE_NULL;
1556 o = (struct debug_offset_type *) xmalloc (sizeof *o);
1557 memset (o, 0, sizeof *o);
1559 o->base_type = base_type;
1560 o->target_type = target_type;
1567 /* Make a type for a method function. The second argument is the
1568 return type, the third argument is the domain, and the fourth
1569 argument is a NULL terminated array of argument types. */
1572 debug_make_method_type (void *handle, debug_type return_type,
1573 debug_type domain_type, debug_type *arg_types,
1574 bfd_boolean varargs)
1576 struct debug_handle *info = (struct debug_handle *) handle;
1577 struct debug_type_s *t;
1578 struct debug_method_type *m;
1580 if (return_type == NULL)
1581 return DEBUG_TYPE_NULL;
1583 t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
1585 return DEBUG_TYPE_NULL;
1587 m = (struct debug_method_type *) xmalloc (sizeof *m);
1588 memset (m, 0, sizeof *m);
1590 m->return_type = return_type;
1591 m->domain_type = domain_type;
1592 m->arg_types = arg_types;
1593 m->varargs = varargs;
1600 /* Make a const qualified version of a given type. */
1603 debug_make_const_type (void *handle, debug_type type)
1605 struct debug_handle *info = (struct debug_handle *) handle;
1606 struct debug_type_s *t;
1609 return DEBUG_TYPE_NULL;
1611 t = debug_make_type (info, DEBUG_KIND_CONST, 0);
1613 return DEBUG_TYPE_NULL;
1620 /* Make a volatile qualified version of a given type. */
1623 debug_make_volatile_type (void *handle, debug_type type)
1625 struct debug_handle *info = (struct debug_handle *) handle;
1626 struct debug_type_s *t;
1629 return DEBUG_TYPE_NULL;
1631 t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
1633 return DEBUG_TYPE_NULL;
1635 t->u.kvolatile = type;
1640 /* Make an undefined tagged type. For example, a struct which has
1641 been mentioned, but not defined. */
1644 debug_make_undefined_tagged_type (void *handle, const char *name,
1645 enum debug_type_kind kind)
1647 struct debug_handle *info = (struct debug_handle *) handle;
1648 struct debug_type_s *t;
1651 return DEBUG_TYPE_NULL;
1655 case DEBUG_KIND_STRUCT:
1656 case DEBUG_KIND_UNION:
1657 case DEBUG_KIND_CLASS:
1658 case DEBUG_KIND_UNION_CLASS:
1659 case DEBUG_KIND_ENUM:
1663 debug_error (_("debug_make_undefined_type: unsupported kind"));
1664 return DEBUG_TYPE_NULL;
1667 t = debug_make_type (info, kind, 0);
1669 return DEBUG_TYPE_NULL;
1671 return debug_tag_type (handle, name, t);
1674 /* Make a base class for an object. The second argument is the base
1675 class type. The third argument is the bit position of this base
1676 class in the object (always 0 unless doing multiple inheritance).
1677 The fourth argument is whether this is a virtual class. The fifth
1678 argument is the visibility of the base class. */
1681 debug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
1682 bfd_vma bitpos, bfd_boolean is_virtual,
1683 enum debug_visibility visibility)
1685 struct debug_baseclass_s *b;
1687 b = (struct debug_baseclass_s *) xmalloc (sizeof *b);
1688 memset (b, 0, sizeof *b);
1692 b->is_virtual = is_virtual;
1693 b->visibility = visibility;
1698 /* Make a field for a struct. The second argument is the name. The
1699 third argument is the type of the field. The fourth argument is
1700 the bit position of the field. The fifth argument is the size of
1701 the field (it may be zero). The sixth argument is the visibility
1705 debug_make_field (void *handle ATTRIBUTE_UNUSED, const char *name,
1706 debug_type type, bfd_vma bitpos, bfd_vma bitsize,
1707 enum debug_visibility visibility)
1709 struct debug_field_s *f;
1711 f = (struct debug_field_s *) xmalloc (sizeof *f);
1712 memset (f, 0, sizeof *f);
1716 f->static_member = FALSE;
1717 f->u.f.bitpos = bitpos;
1718 f->u.f.bitsize = bitsize;
1719 f->visibility = visibility;
1724 /* Make a static member of an object. The second argument is the
1725 name. The third argument is the type of the member. The fourth
1726 argument is the physical name of the member (i.e., the name as a
1727 global variable). The fifth argument is the visibility of the
1731 debug_make_static_member (void *handle ATTRIBUTE_UNUSED, const char *name,
1732 debug_type type, const char *physname,
1733 enum debug_visibility visibility)
1735 struct debug_field_s *f;
1737 f = (struct debug_field_s *) xmalloc (sizeof *f);
1738 memset (f, 0, sizeof *f);
1742 f->static_member = TRUE;
1743 f->u.s.physname = physname;
1744 f->visibility = visibility;
1749 /* Make a method. The second argument is the name, and the third
1750 argument is a NULL terminated array of method variants. */
1753 debug_make_method (void *handle ATTRIBUTE_UNUSED, const char *name,
1754 debug_method_variant *variants)
1756 struct debug_method_s *m;
1758 m = (struct debug_method_s *) xmalloc (sizeof *m);
1759 memset (m, 0, sizeof *m);
1762 m->variants = variants;
1767 /* Make a method argument. The second argument is the real name of
1768 the function. The third argument is the type of the function. The
1769 fourth argument is the visibility. The fifth argument is whether
1770 this is a const function. The sixth argument is whether this is a
1771 volatile function. The seventh argument is the offset in the
1772 virtual function table, if any. The eighth argument is the virtual
1773 function context. FIXME: Are the const and volatile arguments
1774 necessary? Could we just use debug_make_const_type? */
1776 debug_method_variant
1777 debug_make_method_variant (void *handle ATTRIBUTE_UNUSED,
1778 const char *physname, debug_type type,
1779 enum debug_visibility visibility,
1780 bfd_boolean constp, bfd_boolean volatilep,
1781 bfd_vma voffset, debug_type context)
1783 struct debug_method_variant_s *m;
1785 m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
1786 memset (m, 0, sizeof *m);
1788 m->physname = physname;
1790 m->visibility = visibility;
1792 m->volatilep = volatilep;
1793 m->voffset = voffset;
1794 m->context = context;
1799 /* Make a static method argument. The arguments are the same as for
1800 debug_make_method_variant, except that the last two are omitted
1801 since a static method can not also be virtual. */
1803 debug_method_variant
1804 debug_make_static_method_variant (void *handle ATTRIBUTE_UNUSED,
1805 const char *physname, debug_type type,
1806 enum debug_visibility visibility,
1807 bfd_boolean constp, bfd_boolean volatilep)
1809 struct debug_method_variant_s *m;
1811 m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
1812 memset (m, 0, sizeof *m);
1814 m->physname = physname;
1816 m->visibility = visibility;
1818 m->volatilep = volatilep;
1819 m->voffset = VOFFSET_STATIC_METHOD;
1827 debug_name_type (void *handle, const char *name, debug_type type)
1829 struct debug_handle *info = (struct debug_handle *) handle;
1830 struct debug_type_s *t;
1831 struct debug_named_type *n;
1832 struct debug_name *nm;
1834 if (name == NULL || type == NULL)
1835 return DEBUG_TYPE_NULL;
1837 if (info->current_unit == NULL
1838 || info->current_file == NULL)
1840 debug_error (_("debug_name_type: no current file"));
1841 return DEBUG_TYPE_NULL;
1844 t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1846 return DEBUG_TYPE_NULL;
1848 n = (struct debug_named_type *) xmalloc (sizeof *n);
1849 memset (n, 0, sizeof *n);
1855 /* We always add the name to the global namespace. This is probably
1856 wrong in some cases, but it seems to be right for stabs. FIXME. */
1858 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1859 DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
1861 return DEBUG_TYPE_NULL;
1873 debug_tag_type (void *handle, const char *name, debug_type type)
1875 struct debug_handle *info = (struct debug_handle *) handle;
1876 struct debug_type_s *t;
1877 struct debug_named_type *n;
1878 struct debug_name *nm;
1880 if (name == NULL || type == NULL)
1881 return DEBUG_TYPE_NULL;
1883 if (info->current_file == NULL)
1885 debug_error (_("debug_tag_type: no current file"));
1886 return DEBUG_TYPE_NULL;
1889 if (type->kind == DEBUG_KIND_TAGGED)
1891 if (strcmp (type->u.knamed->name->name, name) == 0)
1893 debug_error (_("debug_tag_type: extra tag attempted"));
1894 return DEBUG_TYPE_NULL;
1897 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
1899 return DEBUG_TYPE_NULL;
1901 n = (struct debug_named_type *) xmalloc (sizeof *n);
1902 memset (n, 0, sizeof *n);
1908 /* We keep a global namespace of tags for each compilation unit. I
1909 don't know if that is the right thing to do. */
1911 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1912 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
1914 return DEBUG_TYPE_NULL;
1923 /* Record the size of a given type. */
1926 debug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type,
1929 if (type->size != 0 && type->size != size)
1930 fprintf (stderr, _("Warning: changing type size from %d to %d\n"),
1938 /* Find a named type. */
1941 debug_find_named_type (void *handle, const char *name)
1943 struct debug_handle *info = (struct debug_handle *) handle;
1944 struct debug_block *b;
1945 struct debug_file *f;
1947 /* We only search the current compilation unit. I don't know if
1948 this is right or not. */
1950 if (info->current_unit == NULL)
1952 debug_error (_("debug_find_named_type: no current compilation unit"));
1953 return DEBUG_TYPE_NULL;
1956 for (b = info->current_block; b != NULL; b = b->parent)
1958 if (b->locals != NULL)
1960 struct debug_name *n;
1962 for (n = b->locals->list; n != NULL; n = n->next)
1964 if (n->kind == DEBUG_OBJECT_TYPE
1965 && n->name[0] == name[0]
1966 && strcmp (n->name, name) == 0)
1972 for (f = info->current_unit->files; f != NULL; f = f->next)
1974 if (f->globals != NULL)
1976 struct debug_name *n;
1978 for (n = f->globals->list; n != NULL; n = n->next)
1980 if (n->kind == DEBUG_OBJECT_TYPE
1981 && n->name[0] == name[0]
1982 && strcmp (n->name, name) == 0)
1988 return DEBUG_TYPE_NULL;
1991 /* Find a tagged type. */
1994 debug_find_tagged_type (void *handle, const char *name,
1995 enum debug_type_kind kind)
1997 struct debug_handle *info = (struct debug_handle *) handle;
1998 struct debug_unit *u;
2000 /* We search the globals of all the compilation units. I don't know
2001 if this is correct or not. It would be easy to change. */
2003 for (u = info->units; u != NULL; u = u->next)
2005 struct debug_file *f;
2007 for (f = u->files; f != NULL; f = f->next)
2009 struct debug_name *n;
2011 if (f->globals != NULL)
2013 for (n = f->globals->list; n != NULL; n = n->next)
2015 if (n->kind == DEBUG_OBJECT_TAG
2016 && (kind == DEBUG_KIND_ILLEGAL
2017 || n->u.tag->kind == kind)
2018 && n->name[0] == name[0]
2019 && strcmp (n->name, name) == 0)
2026 return DEBUG_TYPE_NULL;
2029 /* Get a base type. We build a linked list on the stack to avoid
2030 crashing if the type is defined circularly. */
2032 static struct debug_type_s *
2033 debug_get_real_type (void *handle, debug_type type,
2034 struct debug_type_real_list *list)
2036 struct debug_type_real_list *l;
2037 struct debug_type_real_list rl;
2044 case DEBUG_KIND_INDIRECT:
2045 case DEBUG_KIND_NAMED:
2046 case DEBUG_KIND_TAGGED:
2050 for (l = list; l != NULL; l = l->next)
2052 if (l->t == type || l == l->next)
2055 _("debug_get_real_type: circular debug information for %s\n"),
2056 debug_get_type_name (handle, type));
2066 /* The default case is just here to avoid warnings. */
2068 case DEBUG_KIND_INDIRECT:
2069 if (*type->u.kindirect->slot != NULL)
2070 return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
2072 case DEBUG_KIND_NAMED:
2073 case DEBUG_KIND_TAGGED:
2074 return debug_get_real_type (handle, type->u.knamed->type, &rl);
2079 /* Get the kind of a type. */
2081 enum debug_type_kind
2082 debug_get_type_kind (void *handle, debug_type type)
2085 return DEBUG_KIND_ILLEGAL;
2086 type = debug_get_real_type (handle, type, NULL);
2088 return DEBUG_KIND_ILLEGAL;
2092 /* Get the name of a type. */
2095 debug_get_type_name (void *handle, debug_type type)
2097 if (type->kind == DEBUG_KIND_INDIRECT)
2099 if (*type->u.kindirect->slot != NULL)
2100 return debug_get_type_name (handle, *type->u.kindirect->slot);
2101 return type->u.kindirect->tag;
2103 if (type->kind == DEBUG_KIND_NAMED
2104 || type->kind == DEBUG_KIND_TAGGED)
2105 return type->u.knamed->name->name;
2109 /* Get the size of a type. */
2112 debug_get_type_size (void *handle, debug_type type)
2117 /* We don't call debug_get_real_type, because somebody might have
2118 called debug_record_type_size on a named or indirect type. */
2120 if (type->size != 0)
2127 case DEBUG_KIND_INDIRECT:
2128 if (*type->u.kindirect->slot != NULL)
2129 return debug_get_type_size (handle, *type->u.kindirect->slot);
2131 case DEBUG_KIND_NAMED:
2132 case DEBUG_KIND_TAGGED:
2133 return debug_get_type_size (handle, type->u.knamed->type);
2138 /* Get the return type of a function or method type. */
2141 debug_get_return_type (void *handle, debug_type type)
2144 return DEBUG_TYPE_NULL;
2146 type = debug_get_real_type (handle, type, NULL);
2148 return DEBUG_TYPE_NULL;
2153 return DEBUG_TYPE_NULL;
2154 case DEBUG_KIND_FUNCTION:
2155 return type->u.kfunction->return_type;
2156 case DEBUG_KIND_METHOD:
2157 return type->u.kmethod->return_type;
2162 /* Get the parameter types of a function or method type (except that
2163 we don't currently store the parameter types of a function). */
2166 debug_get_parameter_types (void *handle, debug_type type,
2167 bfd_boolean *pvarargs)
2172 type = debug_get_real_type (handle, type, NULL);
2180 case DEBUG_KIND_FUNCTION:
2181 *pvarargs = type->u.kfunction->varargs;
2182 return type->u.kfunction->arg_types;
2183 case DEBUG_KIND_METHOD:
2184 *pvarargs = type->u.kmethod->varargs;
2185 return type->u.kmethod->arg_types;
2190 /* Get the target type of a type. */
2193 debug_get_target_type (void *handle, debug_type type)
2198 type = debug_get_real_type (handle, type, NULL);
2206 case DEBUG_KIND_POINTER:
2207 return type->u.kpointer;
2208 case DEBUG_KIND_REFERENCE:
2209 return type->u.kreference;
2210 case DEBUG_KIND_CONST:
2211 return type->u.kconst;
2212 case DEBUG_KIND_VOLATILE:
2213 return type->u.kvolatile;
2218 /* Get the NULL terminated array of fields for a struct, union, or
2222 debug_get_fields (void *handle, debug_type type)
2227 type = debug_get_real_type (handle, type, NULL);
2235 case DEBUG_KIND_STRUCT:
2236 case DEBUG_KIND_UNION:
2237 case DEBUG_KIND_CLASS:
2238 case DEBUG_KIND_UNION_CLASS:
2239 return type->u.kclass->fields;
2244 /* Get the type of a field. */
2247 debug_get_field_type (void *handle ATTRIBUTE_UNUSED, debug_field field)
2254 /* Get the name of a field. */
2257 debug_get_field_name (void *handle ATTRIBUTE_UNUSED, debug_field field)
2264 /* Get the bit position of a field. */
2267 debug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED, debug_field field)
2269 if (field == NULL || field->static_member)
2270 return (bfd_vma) -1;
2271 return field->u.f.bitpos;
2274 /* Get the bit size of a field. */
2277 debug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED, debug_field field)
2279 if (field == NULL || field->static_member)
2280 return (bfd_vma) -1;
2281 return field->u.f.bitsize;
2284 /* Get the visibility of a field. */
2286 enum debug_visibility
2287 debug_get_field_visibility (void *handle ATTRIBUTE_UNUSED, debug_field field)
2290 return DEBUG_VISIBILITY_IGNORE;
2291 return field->visibility;
2294 /* Get the physical name of a field. */
2297 debug_get_field_physname (void *handle ATTRIBUTE_UNUSED, debug_field field)
2299 if (field == NULL || ! field->static_member)
2301 return field->u.s.physname;
2304 /* Write out the debugging information. This is given a handle to
2305 debugging information, and a set of function pointers to call. */
2308 debug_write (void *handle, const struct debug_write_fns *fns, void *fhandle)
2310 struct debug_handle *info = (struct debug_handle *) handle;
2311 struct debug_unit *u;
2313 /* We use a mark to tell whether we have already written out a
2314 particular name. We use an integer, so that we don't have to
2315 clear the mark fields if we happen to write out the same
2316 information more than once. */
2319 /* The base_id field holds an ID value which will never be used, so
2320 that we can tell whether we have assigned an ID during this call
2322 info->base_id = info->class_id;
2324 /* We keep a linked list of classes for which was have assigned ID's
2325 during this call to debug_write. */
2326 info->id_list = NULL;
2328 for (u = info->units; u != NULL; u = u->next)
2330 struct debug_file *f;
2331 bfd_boolean first_file;
2333 info->current_write_lineno = u->linenos;
2334 info->current_write_lineno_index = 0;
2336 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2340 for (f = u->files; f != NULL; f = f->next)
2342 struct debug_name *n;
2346 else if (! (*fns->start_source) (fhandle, f->filename))
2349 if (f->globals != NULL)
2350 for (n = f->globals->list; n != NULL; n = n->next)
2351 if (! debug_write_name (info, fns, fhandle, n))
2355 /* Output any line number information which hasn't already been
2357 if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
2364 /* Write out an element in a namespace. */
2367 debug_write_name (struct debug_handle *info,
2368 const struct debug_write_fns *fns, void *fhandle,
2369 struct debug_name *n)
2373 case DEBUG_OBJECT_TYPE:
2374 if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2375 || ! (*fns->typdef) (fhandle, n->name))
2378 case DEBUG_OBJECT_TAG:
2379 if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2381 return (*fns->tag) (fhandle, n->name);
2382 case DEBUG_OBJECT_VARIABLE:
2383 if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2384 (struct debug_name *) NULL))
2386 return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2387 n->u.variable->val);
2388 case DEBUG_OBJECT_FUNCTION:
2389 return debug_write_function (info, fns, fhandle, n->name,
2390 n->linkage, n->u.function);
2391 case DEBUG_OBJECT_INT_CONSTANT:
2392 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2393 case DEBUG_OBJECT_FLOAT_CONSTANT:
2394 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2395 case DEBUG_OBJECT_TYPED_CONSTANT:
2396 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2397 (struct debug_name *) NULL))
2399 return (*fns->typed_constant) (fhandle, n->name,
2400 n->u.typed_constant->val);
2408 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2409 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2410 are about to call typedef or tag. If the type is anything else,
2411 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2412 points to this one. */
2415 debug_write_type (struct debug_handle *info,
2416 const struct debug_write_fns *fns, void *fhandle,
2417 struct debug_type_s *type, struct debug_name *name)
2421 const char *tag = NULL;
2423 /* If we have a name for this type, just output it. We only output
2424 typedef names after they have been defined. We output type tags
2425 whenever we are not actually defining them. */
2426 if ((type->kind == DEBUG_KIND_NAMED
2427 || type->kind == DEBUG_KIND_TAGGED)
2428 && (type->u.knamed->name->mark == info->mark
2429 || (type->kind == DEBUG_KIND_TAGGED
2430 && type->u.knamed->name != name)))
2432 if (type->kind == DEBUG_KIND_NAMED)
2433 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2436 struct debug_type_s *real;
2439 real = debug_get_real_type ((void *) info, type, NULL);
2441 return (*fns->empty_type) (fhandle);
2443 if ((real->kind == DEBUG_KIND_STRUCT
2444 || real->kind == DEBUG_KIND_UNION
2445 || real->kind == DEBUG_KIND_CLASS
2446 || real->kind == DEBUG_KIND_UNION_CLASS)
2447 && real->u.kclass != NULL)
2449 if (real->u.kclass->id <= info->base_id)
2451 if (! debug_set_class_id (info,
2452 type->u.knamed->name->name,
2456 id = real->u.kclass->id;
2459 return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
2464 /* Mark the name after we have already looked for a known name, so
2465 that we don't just define a type in terms of itself. We need to
2466 mark the name here so that a struct containing a pointer to
2467 itself will work. */
2469 name->mark = info->mark;
2472 && type->kind != DEBUG_KIND_NAMED
2473 && type->kind != DEBUG_KIND_TAGGED)
2475 assert (name->kind == DEBUG_OBJECT_TAG);
2481 case DEBUG_KIND_ILLEGAL:
2482 debug_error (_("debug_write_type: illegal type encountered"));
2484 case DEBUG_KIND_INDIRECT:
2485 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2486 return (*fns->empty_type) (fhandle);
2487 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2489 case DEBUG_KIND_VOID:
2490 return (*fns->void_type) (fhandle);
2491 case DEBUG_KIND_INT:
2492 return (*fns->int_type) (fhandle, type->size, type->u.kint);
2493 case DEBUG_KIND_FLOAT:
2494 return (*fns->float_type) (fhandle, type->size);
2495 case DEBUG_KIND_COMPLEX:
2496 return (*fns->complex_type) (fhandle, type->size);
2497 case DEBUG_KIND_BOOL:
2498 return (*fns->bool_type) (fhandle, type->size);
2499 case DEBUG_KIND_STRUCT:
2500 case DEBUG_KIND_UNION:
2501 if (type->u.kclass != NULL)
2503 if (type->u.kclass->id <= info->base_id)
2505 if (! debug_set_class_id (info, tag, type))
2509 if (info->mark == type->u.kclass->mark)
2511 /* We are currently outputting this struct, or we have
2512 already output it. I don't know if this can happen,
2513 but it can happen for a class. */
2514 assert (type->u.kclass->id > info->base_id);
2515 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2518 type->u.kclass->mark = info->mark;
2521 if (! (*fns->start_struct_type) (fhandle, tag,
2522 (type->u.kclass != NULL
2523 ? type->u.kclass->id
2525 type->kind == DEBUG_KIND_STRUCT,
2528 if (type->u.kclass != NULL
2529 && type->u.kclass->fields != NULL)
2531 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2533 struct debug_field_s *f;
2535 f = type->u.kclass->fields[i];
2536 if (! debug_write_type (info, fns, fhandle, f->type,
2537 (struct debug_name *) NULL)
2538 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2539 f->u.f.bitsize, f->visibility))
2543 return (*fns->end_struct_type) (fhandle);
2544 case DEBUG_KIND_CLASS:
2545 case DEBUG_KIND_UNION_CLASS:
2546 return debug_write_class_type (info, fns, fhandle, type, tag);
2547 case DEBUG_KIND_ENUM:
2548 if (type->u.kenum == NULL)
2549 return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
2550 (bfd_signed_vma *) NULL);
2551 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2552 type->u.kenum->values);
2553 case DEBUG_KIND_POINTER:
2554 if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2555 (struct debug_name *) NULL))
2557 return (*fns->pointer_type) (fhandle);
2558 case DEBUG_KIND_FUNCTION:
2559 if (! debug_write_type (info, fns, fhandle,
2560 type->u.kfunction->return_type,
2561 (struct debug_name *) NULL))
2563 if (type->u.kfunction->arg_types == NULL)
2567 for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
2568 if (! debug_write_type (info, fns, fhandle,
2569 type->u.kfunction->arg_types[is],
2570 (struct debug_name *) NULL))
2573 return (*fns->function_type) (fhandle, is,
2574 type->u.kfunction->varargs);
2575 case DEBUG_KIND_REFERENCE:
2576 if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2577 (struct debug_name *) NULL))
2579 return (*fns->reference_type) (fhandle);
2580 case DEBUG_KIND_RANGE:
2581 if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2582 (struct debug_name *) NULL))
2584 return (*fns->range_type) (fhandle, type->u.krange->lower,
2585 type->u.krange->upper);
2586 case DEBUG_KIND_ARRAY:
2587 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2588 (struct debug_name *) NULL)
2589 || ! debug_write_type (info, fns, fhandle,
2590 type->u.karray->range_type,
2591 (struct debug_name *) NULL))
2593 return (*fns->array_type) (fhandle, type->u.karray->lower,
2594 type->u.karray->upper,
2595 type->u.karray->stringp);
2596 case DEBUG_KIND_SET:
2597 if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2598 (struct debug_name *) NULL))
2600 return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2601 case DEBUG_KIND_OFFSET:
2602 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2603 (struct debug_name *) NULL)
2604 || ! debug_write_type (info, fns, fhandle,
2605 type->u.koffset->target_type,
2606 (struct debug_name *) NULL))
2608 return (*fns->offset_type) (fhandle);
2609 case DEBUG_KIND_METHOD:
2610 if (! debug_write_type (info, fns, fhandle,
2611 type->u.kmethod->return_type,
2612 (struct debug_name *) NULL))
2614 if (type->u.kmethod->arg_types == NULL)
2618 for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
2619 if (! debug_write_type (info, fns, fhandle,
2620 type->u.kmethod->arg_types[is],
2621 (struct debug_name *) NULL))
2624 if (type->u.kmethod->domain_type != NULL)
2626 if (! debug_write_type (info, fns, fhandle,
2627 type->u.kmethod->domain_type,
2628 (struct debug_name *) NULL))
2631 return (*fns->method_type) (fhandle,
2632 type->u.kmethod->domain_type != NULL,
2634 type->u.kmethod->varargs);
2635 case DEBUG_KIND_CONST:
2636 if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2637 (struct debug_name *) NULL))
2639 return (*fns->const_type) (fhandle);
2640 case DEBUG_KIND_VOLATILE:
2641 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2642 (struct debug_name *) NULL))
2644 return (*fns->volatile_type) (fhandle);
2645 case DEBUG_KIND_NAMED:
2646 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2647 (struct debug_name *) NULL);
2648 case DEBUG_KIND_TAGGED:
2649 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2650 type->u.knamed->name);
2657 /* Write out a class type. */
2660 debug_write_class_type (struct debug_handle *info,
2661 const struct debug_write_fns *fns, void *fhandle,
2662 struct debug_type_s *type, const char *tag)
2666 struct debug_type_s *vptrbase;
2668 if (type->u.kclass == NULL)
2675 if (type->u.kclass->id <= info->base_id)
2677 if (! debug_set_class_id (info, tag, type))
2681 if (info->mark == type->u.kclass->mark)
2683 /* We are currently outputting this class, or we have
2684 already output it. This can happen when there are
2685 methods for an anonymous class. */
2686 assert (type->u.kclass->id > info->base_id);
2687 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2690 type->u.kclass->mark = info->mark;
2691 id = type->u.kclass->id;
2693 vptrbase = type->u.kclass->vptrbase;
2694 if (vptrbase != NULL && vptrbase != type)
2696 if (! debug_write_type (info, fns, fhandle, vptrbase,
2697 (struct debug_name *) NULL))
2702 if (! (*fns->start_class_type) (fhandle, tag, id,
2703 type->kind == DEBUG_KIND_CLASS,
2709 if (type->u.kclass != NULL)
2711 if (type->u.kclass->fields != NULL)
2713 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2715 struct debug_field_s *f;
2717 f = type->u.kclass->fields[i];
2718 if (! debug_write_type (info, fns, fhandle, f->type,
2719 (struct debug_name *) NULL))
2721 if (f->static_member)
2723 if (! (*fns->class_static_member) (fhandle, f->name,
2730 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2731 f->u.f.bitsize, f->visibility))
2737 if (type->u.kclass->baseclasses != NULL)
2739 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2741 struct debug_baseclass_s *b;
2743 b = type->u.kclass->baseclasses[i];
2744 if (! debug_write_type (info, fns, fhandle, b->type,
2745 (struct debug_name *) NULL))
2747 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->is_virtual,
2753 if (type->u.kclass->methods != NULL)
2755 for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2757 struct debug_method_s *m;
2760 m = type->u.kclass->methods[i];
2761 if (! (*fns->class_start_method) (fhandle, m->name))
2763 for (j = 0; m->variants[j] != NULL; j++)
2765 struct debug_method_variant_s *v;
2768 if (v->context != NULL)
2770 if (! debug_write_type (info, fns, fhandle, v->context,
2771 (struct debug_name *) NULL))
2774 if (! debug_write_type (info, fns, fhandle, v->type,
2775 (struct debug_name *) NULL))
2777 if (v->voffset != VOFFSET_STATIC_METHOD)
2779 if (! (*fns->class_method_variant) (fhandle, v->physname,
2784 v->context != NULL))
2789 if (! (*fns->class_static_method_variant) (fhandle,
2797 if (! (*fns->class_end_method) (fhandle))
2803 return (*fns->end_class_type) (fhandle);
2806 /* Write out information for a function. */
2809 debug_write_function (struct debug_handle *info,
2810 const struct debug_write_fns *fns, void *fhandle,
2811 const char *name, enum debug_object_linkage linkage,
2812 struct debug_function *function)
2814 struct debug_parameter *p;
2815 struct debug_block *b;
2817 if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
2820 if (! debug_write_type (info, fns, fhandle, function->return_type,
2821 (struct debug_name *) NULL))
2824 if (! (*fns->start_function) (fhandle, name,
2825 linkage == DEBUG_LINKAGE_GLOBAL))
2828 for (p = function->parameters; p != NULL; p = p->next)
2830 if (! debug_write_type (info, fns, fhandle, p->type,
2831 (struct debug_name *) NULL)
2832 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2836 for (b = function->blocks; b != NULL; b = b->next)
2838 if (! debug_write_block (info, fns, fhandle, b))
2842 return (*fns->end_function) (fhandle);
2845 /* Write out information for a block. */
2848 debug_write_block (struct debug_handle *info,
2849 const struct debug_write_fns *fns, void *fhandle,
2850 struct debug_block *block)
2852 struct debug_name *n;
2853 struct debug_block *b;
2855 if (! debug_write_linenos (info, fns, fhandle, block->start))
2858 /* I can't see any point to writing out a block with no local
2859 variables, so we don't bother, except for the top level block. */
2860 if (block->locals != NULL || block->parent == NULL)
2862 if (! (*fns->start_block) (fhandle, block->start))
2866 if (block->locals != NULL)
2868 for (n = block->locals->list; n != NULL; n = n->next)
2870 if (! debug_write_name (info, fns, fhandle, n))
2875 for (b = block->children; b != NULL; b = b->next)
2877 if (! debug_write_block (info, fns, fhandle, b))
2881 if (! debug_write_linenos (info, fns, fhandle, block->end))
2884 if (block->locals != NULL || block->parent == NULL)
2886 if (! (*fns->end_block) (fhandle, block->end))
2893 /* Write out line number information up to ADDRESS. */
2896 debug_write_linenos (struct debug_handle *info,
2897 const struct debug_write_fns *fns, void *fhandle,
2900 while (info->current_write_lineno != NULL)
2902 struct debug_lineno *l;
2904 l = info->current_write_lineno;
2906 while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
2908 if (l->linenos[info->current_write_lineno_index]
2909 == (unsigned long) -1)
2912 if (l->addrs[info->current_write_lineno_index] >= address)
2915 if (! (*fns->lineno) (fhandle, l->file->filename,
2916 l->linenos[info->current_write_lineno_index],
2917 l->addrs[info->current_write_lineno_index]))
2920 ++info->current_write_lineno_index;
2923 info->current_write_lineno = l->next;
2924 info->current_write_lineno_index = 0;
2930 /* Get the ID number for a class. If during the same call to
2931 debug_write we find a struct with the same definition with the same
2932 name, we use the same ID. This type of things happens because the
2933 same struct will be defined by multiple compilation units. */
2936 debug_set_class_id (struct debug_handle *info, const char *tag,
2937 struct debug_type_s *type)
2939 struct debug_class_type *c;
2940 struct debug_class_id *l;
2942 assert (type->kind == DEBUG_KIND_STRUCT
2943 || type->kind == DEBUG_KIND_UNION
2944 || type->kind == DEBUG_KIND_CLASS
2945 || type->kind == DEBUG_KIND_UNION_CLASS);
2949 if (c->id > info->base_id)
2952 for (l = info->id_list; l != NULL; l = l->next)
2954 if (l->type->kind != type->kind)
2965 || l->tag[0] != tag[0]
2966 || strcmp (l->tag, tag) != 0)
2970 if (debug_type_samep (info, l->type, type))
2972 c->id = l->type->u.kclass->id;
2977 /* There are no identical types. Use a new ID, and add it to the
2980 c->id = info->class_id;
2982 l = (struct debug_class_id *) xmalloc (sizeof *l);
2983 memset (l, 0, sizeof *l);
2988 l->next = info->id_list;
2994 /* See if two types are the same. At this point, we don't care about
2995 tags and the like. */
2998 debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
2999 struct debug_type_s *t2)
3001 struct debug_type_compare_list *l;
3002 struct debug_type_compare_list top;
3010 while (t1->kind == DEBUG_KIND_INDIRECT)
3012 t1 = *t1->u.kindirect->slot;
3016 while (t2->kind == DEBUG_KIND_INDIRECT)
3018 t2 = *t2->u.kindirect->slot;
3026 /* As a special case, permit a typedef to match a tag, since C++
3027 debugging output will sometimes add a typedef where C debugging
3029 if (t1->kind == DEBUG_KIND_NAMED
3030 && t2->kind == DEBUG_KIND_TAGGED)
3031 return debug_type_samep (info, t1->u.knamed->type, t2);
3032 else if (t1->kind == DEBUG_KIND_TAGGED
3033 && t2->kind == DEBUG_KIND_NAMED)
3034 return debug_type_samep (info, t1, t2->u.knamed->type);
3036 if (t1->kind != t2->kind
3037 || t1->size != t2->size)
3040 /* Get rid of the trivial cases first. */
3045 case DEBUG_KIND_VOID:
3046 case DEBUG_KIND_FLOAT:
3047 case DEBUG_KIND_COMPLEX:
3048 case DEBUG_KIND_BOOL:
3050 case DEBUG_KIND_INT:
3051 return t1->u.kint == t2->u.kint;
3054 /* We have to avoid an infinite recursion. We do this by keeping a
3055 list of types which we are comparing. We just keep the list on
3056 the stack. If we encounter a pair of types we are currently
3057 comparing, we just assume that they are equal. */
3058 for (l = info->compare_list; l != NULL; l = l->next)
3060 if (l->t1 == t1 && l->t2 == t2)
3066 top.next = info->compare_list;
3067 info->compare_list = ⊤
3076 case DEBUG_KIND_STRUCT:
3077 case DEBUG_KIND_UNION:
3078 case DEBUG_KIND_CLASS:
3079 case DEBUG_KIND_UNION_CLASS:
3080 if (t1->u.kclass == NULL)
3081 ret = t2->u.kclass == NULL;
3082 else if (t2->u.kclass == NULL)
3084 else if (t1->u.kclass->id > info->base_id
3085 && t1->u.kclass->id == t2->u.kclass->id)
3088 ret = debug_class_type_samep (info, t1, t2);
3091 case DEBUG_KIND_ENUM:
3092 if (t1->u.kenum == NULL)
3093 ret = t2->u.kenum == NULL;
3094 else if (t2->u.kenum == NULL)
3098 const char **pn1, **pn2;
3099 bfd_signed_vma *pv1, *pv2;
3101 pn1 = t1->u.kenum->names;
3102 pn2 = t2->u.kenum->names;
3103 pv1 = t1->u.kenum->values;
3104 pv2 = t2->u.kenum->values;
3105 while (*pn1 != NULL && *pn2 != NULL)
3109 || strcmp (*pn1, *pn2) != 0)
3116 ret = *pn1 == NULL && *pn2 == NULL;
3120 case DEBUG_KIND_POINTER:
3121 ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
3124 case DEBUG_KIND_FUNCTION:
3125 if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
3126 || ! debug_type_samep (info, t1->u.kfunction->return_type,
3127 t2->u.kfunction->return_type)
3128 || ((t1->u.kfunction->arg_types == NULL)
3129 != (t2->u.kfunction->arg_types == NULL)))
3131 else if (t1->u.kfunction->arg_types == NULL)
3135 struct debug_type_s **a1, **a2;
3137 a1 = t1->u.kfunction->arg_types;
3138 a2 = t2->u.kfunction->arg_types;
3139 while (*a1 != NULL && *a2 != NULL)
3141 if (! debug_type_samep (info, *a1, *a2))
3146 ret = *a1 == NULL && *a2 == NULL;
3150 case DEBUG_KIND_REFERENCE:
3151 ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
3154 case DEBUG_KIND_RANGE:
3155 ret = (t1->u.krange->lower == t2->u.krange->lower
3156 && t1->u.krange->upper == t2->u.krange->upper
3157 && debug_type_samep (info, t1->u.krange->type,
3158 t2->u.krange->type));
3160 case DEBUG_KIND_ARRAY:
3161 ret = (t1->u.karray->lower == t2->u.karray->lower
3162 && t1->u.karray->upper == t2->u.karray->upper
3163 && t1->u.karray->stringp == t2->u.karray->stringp
3164 && debug_type_samep (info, t1->u.karray->element_type,
3165 t2->u.karray->element_type));
3168 case DEBUG_KIND_SET:
3169 ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
3170 && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
3173 case DEBUG_KIND_OFFSET:
3174 ret = (debug_type_samep (info, t1->u.koffset->base_type,
3175 t2->u.koffset->base_type)
3176 && debug_type_samep (info, t1->u.koffset->target_type,
3177 t2->u.koffset->target_type));
3180 case DEBUG_KIND_METHOD:
3181 if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
3182 || ! debug_type_samep (info, t1->u.kmethod->return_type,
3183 t2->u.kmethod->return_type)
3184 || ! debug_type_samep (info, t1->u.kmethod->domain_type,
3185 t2->u.kmethod->domain_type)
3186 || ((t1->u.kmethod->arg_types == NULL)
3187 != (t2->u.kmethod->arg_types == NULL)))
3189 else if (t1->u.kmethod->arg_types == NULL)
3193 struct debug_type_s **a1, **a2;
3195 a1 = t1->u.kmethod->arg_types;
3196 a2 = t2->u.kmethod->arg_types;
3197 while (*a1 != NULL && *a2 != NULL)
3199 if (! debug_type_samep (info, *a1, *a2))
3204 ret = *a1 == NULL && *a2 == NULL;
3208 case DEBUG_KIND_CONST:
3209 ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
3212 case DEBUG_KIND_VOLATILE:
3213 ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
3216 case DEBUG_KIND_NAMED:
3217 case DEBUG_KIND_TAGGED:
3218 ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
3219 && debug_type_samep (info, t1->u.knamed->type,
3220 t2->u.knamed->type));
3224 info->compare_list = top.next;
3229 /* See if two classes are the same. This is a subroutine of
3230 debug_type_samep. */
3233 debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
3234 struct debug_type_s *t2)
3236 struct debug_class_type *c1, *c2;
3241 if ((c1->fields == NULL) != (c2->fields == NULL)
3242 || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
3243 || (c1->methods == NULL) != (c2->methods == NULL)
3244 || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
3247 if (c1->fields != NULL)
3249 struct debug_field_s **pf1, **pf2;
3251 for (pf1 = c1->fields, pf2 = c2->fields;
3252 *pf1 != NULL && *pf2 != NULL;
3255 struct debug_field_s *f1, *f2;
3259 if (f1->name[0] != f2->name[0]
3260 || f1->visibility != f2->visibility
3261 || f1->static_member != f2->static_member)
3263 if (f1->static_member)
3265 if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
3270 if (f1->u.f.bitpos != f2->u.f.bitpos
3271 || f1->u.f.bitsize != f2->u.f.bitsize)
3274 /* We do the checks which require function calls last. We
3275 don't require that the types of fields have the same
3276 names, since that sometimes fails in the presence of
3277 typedefs and we really don't care. */
3278 if (strcmp (f1->name, f2->name) != 0
3279 || ! debug_type_samep (info,
3280 debug_get_real_type ((void *) info,
3282 debug_get_real_type ((void *) info,
3286 if (*pf1 != NULL || *pf2 != NULL)
3290 if (c1->vptrbase != NULL)
3292 if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
3296 if (c1->baseclasses != NULL)
3298 struct debug_baseclass_s **pb1, **pb2;
3300 for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
3301 *pb1 != NULL && *pb2 != NULL;
3304 struct debug_baseclass_s *b1, *b2;
3308 if (b1->bitpos != b2->bitpos
3309 || b1->is_virtual != b2->is_virtual
3310 || b1->visibility != b2->visibility
3311 || ! debug_type_samep (info, b1->type, b2->type))
3314 if (*pb1 != NULL || *pb2 != NULL)
3318 if (c1->methods != NULL)
3320 struct debug_method_s **pm1, **pm2;
3322 for (pm1 = c1->methods, pm2 = c2->methods;
3323 *pm1 != NULL && *pm2 != NULL;
3326 struct debug_method_s *m1, *m2;
3330 if (m1->name[0] != m2->name[0]
3331 || strcmp (m1->name, m2->name) != 0
3332 || (m1->variants == NULL) != (m2->variants == NULL))
3334 if (m1->variants == NULL)
3336 struct debug_method_variant_s **pv1, **pv2;
3338 for (pv1 = m1->variants, pv2 = m2->variants;
3339 *pv1 != NULL && *pv2 != NULL;
3342 struct debug_method_variant_s *v1, *v2;
3346 if (v1->physname[0] != v2->physname[0]
3347 || v1->visibility != v2->visibility
3348 || v1->constp != v2->constp
3349 || v1->volatilep != v2->volatilep
3350 || v1->voffset != v2->voffset
3351 || (v1->context == NULL) != (v2->context == NULL)
3352 || strcmp (v1->physname, v2->physname) != 0
3353 || ! debug_type_samep (info, v1->type, v2->type))
3355 if (v1->context != NULL)
3357 if (! debug_type_samep (info, v1->context,
3362 if (*pv1 != NULL || *pv2 != NULL)
3366 if (*pm1 != NULL || *pm2 != NULL)