1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file implements a generic debugging format. We may eventually
23 have readers which convert different formats into this generic
24 format, and writers which write it out. The initial impetus for
25 this was writing a convertor from stabs to HP IEEE-695 debugging
33 #include "libiberty.h"
36 /* Global information we keep for debugging. A pointer to this
37 structure is the debugging handle passed to all the routines. */
41 /* A linked list of compilation units. */
42 struct debug_unit *units;
43 /* The current compilation unit. */
44 struct debug_unit *current_unit;
45 /* The current source file. */
46 struct debug_file *current_file;
47 /* The current function. */
48 struct debug_function *current_function;
49 /* The current block. */
50 struct debug_block *current_block;
51 /* The current line number information for the current unit. */
52 struct debug_lineno *current_lineno;
53 /* Mark. This is used by debug_write. */
55 /* A struct/class ID used by debug_write. */
56 unsigned int class_id;
57 /* The base for class_id for this call to debug_write. */
59 /* A list of classes which have assigned ID's during debug_write.
60 This is linked through the next_id field of debug_class_type. */
61 struct debug_class_id *id_list;
62 /* A list used to avoid recursion during debug_type_samep. */
63 struct debug_type_compare_list *compare_list;
66 /* Information we keep for a single compilation unit. */
70 /* The next compilation unit. */
71 struct debug_unit *next;
72 /* A list of files included in this compilation unit. The first
73 file is always the main one, and that is where the main file name
75 struct debug_file *files;
76 /* Line number information for this compilation unit. This is not
77 stored by function, because assembler code may have line number
78 information without function information. */
79 struct debug_lineno *linenos;
82 /* Information kept for a single source file. */
86 /* The next source file in this compilation unit. */
87 struct debug_file *next;
88 /* The name of the source file. */
90 /* Global functions, variables, types, etc. */
91 struct debug_namespace *globals;
99 enum debug_type_kind kind;
100 /* Size of type (0 if not known). */
102 /* Type which is a pointer to this type. */
104 /* Tagged union with additional information about the type. */
107 /* DEBUG_KIND_INDIRECT. */
108 struct debug_indirect_type *kindirect;
109 /* DEBUG_KIND_INT. */
110 /* Whether the integer is unsigned. */
112 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
113 DEBUG_KIND_UNION_CLASS. */
114 struct debug_class_type *kclass;
115 /* DEBUG_KIND_ENUM. */
116 struct debug_enum_type *kenum;
117 /* DEBUG_KIND_POINTER. */
118 struct debug_type *kpointer;
119 /* DEBUG_KIND_FUNCTION. */
120 struct debug_function_type *kfunction;
121 /* DEBUG_KIND_REFERENCE. */
122 struct debug_type *kreference;
123 /* DEBUG_KIND_RANGE. */
124 struct debug_range_type *krange;
125 /* DEBUG_KIND_ARRAY. */
126 struct debug_array_type *karray;
127 /* DEBUG_KIND_SET. */
128 struct debug_set_type *kset;
129 /* DEBUG_KIND_OFFSET. */
130 struct debug_offset_type *koffset;
131 /* DEBUG_KIND_METHOD. */
132 struct debug_method_type *kmethod;
133 /* DEBUG_KIND_CONST. */
134 struct debug_type *kconst;
135 /* DEBUG_KIND_VOLATILE. */
136 struct debug_type *kvolatile;
137 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
138 struct debug_named_type *knamed;
142 /* Information kept for an indirect type. */
144 struct debug_indirect_type
146 /* Slot where the final type will appear. */
152 /* Information kept for a struct, union, or class. */
154 struct debug_class_type
156 /* NULL terminated array of fields. */
158 /* A mark field which indicates whether the struct has already been
161 /* This is used to uniquely identify unnamed structs when printing. */
163 /* The remaining fields are only used for DEBUG_KIND_CLASS and
164 DEBUG_KIND_UNION_CLASS. */
165 /* NULL terminated array of base classes. */
166 debug_baseclass *baseclasses;
167 /* NULL terminated array of methods. */
168 debug_method *methods;
169 /* The type of the class providing the virtual function table for
170 this class. This may point to the type itself. */
174 /* Information kept for an enum. */
176 struct debug_enum_type
178 /* NULL terminated array of names. */
180 /* Array of corresponding values. */
181 bfd_signed_vma *values;
184 /* Information kept for a function. FIXME: We should be able to
185 record the parameter types. */
187 struct debug_function_type
190 debug_type return_type;
191 /* NULL terminated array of argument types. */
192 debug_type *arg_types;
193 /* Whether the function takes a variable number of arguments. */
197 /* Information kept for a range. */
199 struct debug_range_type
201 /* Range base type. */
204 bfd_signed_vma lower;
206 bfd_signed_vma upper;
209 /* Information kept for an array. */
211 struct debug_array_type
214 debug_type element_type;
216 debug_type range_type;
218 bfd_signed_vma lower;
220 bfd_signed_vma upper;
221 /* Whether this array is really a string. */
225 /* Information kept for a set. */
227 struct debug_set_type
231 /* Whether this set is really a bitstring. */
235 /* Information kept for an offset type (a based pointer). */
237 struct debug_offset_type
239 /* The type the pointer is an offset from. */
240 debug_type base_type;
241 /* The type the pointer points to. */
242 debug_type target_type;
245 /* Information kept for a method type. */
247 struct debug_method_type
249 /* The return type. */
250 debug_type return_type;
251 /* The object type which this method is for. */
252 debug_type domain_type;
253 /* A NULL terminated array of argument types. */
254 debug_type *arg_types;
255 /* Whether the method takes a variable number of arguments. */
259 /* Information kept for a named type. */
261 struct debug_named_type
264 struct debug_name *name;
269 /* A field in a struct or union. */
273 /* Name of the field. */
275 /* Type of the field. */
276 struct debug_type *type;
277 /* Visibility of the field. */
278 enum debug_visibility visibility;
279 /* Whether this is a static member. */
280 boolean static_member;
283 /* If static_member is false. */
286 /* Bit position of the field in the struct. */
288 /* Size of the field in bits. */
289 unsigned int bitsize;
291 /* If static_member is true. */
294 const char *physname;
299 /* A base class for an object. */
301 struct debug_baseclass
303 /* Type of the base class. */
304 struct debug_type *type;
305 /* Bit position of the base class in the object. */
307 /* Whether the base class is virtual. */
309 /* Visibility of the base class. */
310 enum debug_visibility visibility;
313 /* A method of an object. */
317 /* The name of the method. */
319 /* A NULL terminated array of different types of variants. */
320 struct debug_method_variant **variants;
323 /* The variants of a method function of an object. These indicate
324 which method to run. */
326 struct debug_method_variant
328 /* The physical name of the function. */
329 const char *physname;
330 /* The type of the function. */
331 struct debug_type *type;
332 /* The visibility of the function. */
333 enum debug_visibility visibility;
334 /* Whether the function is const. */
336 /* Whether the function is volatile. */
338 /* The offset to the function in the virtual function table. */
340 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
341 #define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
342 /* Context of a virtual method function. */
343 struct debug_type *context;
346 /* A variable. This is the information we keep for a variable object.
347 This has no name; a name is associated with a variable in a
348 debug_name structure. */
350 struct debug_variable
352 /* Kind of variable. */
353 enum debug_var_kind kind;
356 /* Value. The interpretation of the value depends upon kind. */
360 /* A function. This has no name; a name is associated with a function
361 in a debug_name structure. */
363 struct debug_function
366 debug_type return_type;
367 /* Parameter information. */
368 struct debug_parameter *parameters;
369 /* Block information. The first structure on the list is the main
370 block of the function, and describes function local variables. */
371 struct debug_block *blocks;
374 /* A function parameter. */
376 struct debug_parameter
378 /* Next parameter. */
379 struct debug_parameter *next;
385 enum debug_parm_kind kind;
386 /* Value (meaning depends upon kind). */
390 /* A typed constant. */
392 struct debug_typed_constant
396 /* Value. FIXME: We may eventually need to support non-integral
401 /* Information about a block within a function. */
405 /* Next block with the same parent. */
406 struct debug_block *next;
408 struct debug_block *parent;
409 /* List of child blocks. */
410 struct debug_block *children;
411 /* Start address of the block. */
413 /* End address of the block. */
415 /* Local variables. */
416 struct debug_namespace *locals;
419 /* Line number information we keep for a compilation unit. FIXME:
420 This structure is easy to create, but can be very space
425 /* More line number information for this block. */
426 struct debug_lineno *next;
428 struct debug_file *file;
429 /* Line numbers, terminated by a -1 or the end of the array. */
430 #define DEBUG_LINENO_COUNT 10
431 unsigned long linenos[DEBUG_LINENO_COUNT];
432 /* Addresses for the line numbers. */
433 bfd_vma addrs[DEBUG_LINENO_COUNT];
436 /* A namespace. This is a mapping from names to objects. FIXME: This
437 should be implemented as a hash table. */
439 struct debug_namespace
441 /* List of items in this namespace. */
442 struct debug_name *list;
443 /* Pointer to where the next item in this namespace should go. */
444 struct debug_name **tail;
447 /* Kinds of objects that appear in a namespace. */
449 enum debug_object_kind
453 /* A tagged type (really a different sort of namespace). */
456 DEBUG_OBJECT_VARIABLE,
458 DEBUG_OBJECT_FUNCTION,
459 /* An integer constant. */
460 DEBUG_OBJECT_INT_CONSTANT,
461 /* A floating point constant. */
462 DEBUG_OBJECT_FLOAT_CONSTANT,
463 /* A typed constant. */
464 DEBUG_OBJECT_TYPED_CONSTANT
467 /* Linkage of an object that appears in a namespace. */
469 enum debug_object_linkage
471 /* Local variable. */
472 DEBUG_LINKAGE_AUTOMATIC,
473 /* Static--either file static or function static, depending upon the
475 DEBUG_LINKAGE_STATIC,
477 DEBUG_LINKAGE_GLOBAL,
482 /* A name in a namespace. */
486 /* Next name in this namespace. */
487 struct debug_name *next;
490 /* Mark. This is used by debug_write. */
492 /* Kind of object. */
493 enum debug_object_kind kind;
494 /* Linkage of object. */
495 enum debug_object_linkage linkage;
496 /* Tagged union with additional information about the object. */
499 /* DEBUG_OBJECT_TYPE. */
500 struct debug_type *type;
501 /* DEBUG_OBJECT_TAG. */
502 struct debug_type *tag;
503 /* DEBUG_OBJECT_VARIABLE. */
504 struct debug_variable *variable;
505 /* DEBUG_OBJECT_FUNCTION. */
506 struct debug_function *function;
507 /* DEBUG_OBJECT_INT_CONSTANT. */
508 bfd_vma int_constant;
509 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
510 double float_constant;
511 /* DEBUG_OBJECT_TYPED_CONSTANT. */
512 struct debug_typed_constant *typed_constant;
516 /* During debug_write, a linked list of these structures is used to
517 keep track of ID numbers that have been assigned to classes. */
519 struct debug_class_id
521 /* Next ID number. */
522 struct debug_class_id *next;
523 /* The type with the ID. */
524 struct debug_type *type;
525 /* The tag; NULL if no tag. */
529 /* During debug_type_samep, a linked list of these structures is kept
530 on the stack to avoid infinite recursion. */
532 struct debug_type_compare_list
534 /* Next type on list. */
535 struct debug_type_compare_list *next;
536 /* The types we are comparing. */
537 struct debug_type *t1;
538 struct debug_type *t2;
541 /* Local functions. */
543 static void debug_error PARAMS ((const char *));
544 static struct debug_name *debug_add_to_namespace
545 PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
546 enum debug_object_kind, enum debug_object_linkage));
547 static struct debug_name *debug_add_to_current_namespace
548 PARAMS ((struct debug_handle *, const char *, enum debug_object_kind,
549 enum debug_object_linkage));
550 static struct debug_type *debug_make_type
551 PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
552 static struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type));
553 static boolean debug_write_name
554 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
555 struct debug_name *));
556 static boolean debug_write_type
557 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
558 struct debug_type *, struct debug_name *));
559 static boolean debug_write_class_type
560 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
561 struct debug_type *, const char *));
562 static boolean debug_write_function
563 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
564 const char *, enum debug_object_linkage, struct debug_function *));
565 static boolean debug_write_block
566 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
567 struct debug_block *));
568 static boolean debug_set_class_id
569 PARAMS ((struct debug_handle *, const char *, struct debug_type *));
570 static boolean debug_type_samep
571 PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
572 static boolean debug_class_type_samep
573 PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
575 /* Issue an error message. */
578 debug_error (message)
581 fprintf (stderr, "%s\n", message);
584 /* Add an object to a namespace. */
586 static struct debug_name *
587 debug_add_to_namespace (info, nsp, name, kind, linkage)
588 struct debug_handle *info;
589 struct debug_namespace **nsp;
591 enum debug_object_kind kind;
592 enum debug_object_linkage linkage;
594 struct debug_name *n;
595 struct debug_namespace *ns;
597 n = (struct debug_name *) xmalloc (sizeof *n);
598 memset (n, 0, sizeof *n);
602 n->linkage = linkage;
607 ns = (struct debug_namespace *) xmalloc (sizeof *ns);
608 memset (ns, 0, sizeof *ns);
610 ns->tail = &ns->list;
621 /* Add an object to the current namespace. */
623 static struct debug_name *
624 debug_add_to_current_namespace (info, name, kind, linkage)
625 struct debug_handle *info;
627 enum debug_object_kind kind;
628 enum debug_object_linkage linkage;
630 struct debug_namespace **nsp;
632 if (info->current_unit == NULL
633 || info->current_file == NULL)
635 debug_error ("debug_add_to_current_namespace: no current file");
639 if (info->current_block != NULL)
640 nsp = &info->current_block->locals;
642 nsp = &info->current_file->globals;
644 return debug_add_to_namespace (info, nsp, name, kind, linkage);
647 /* Return a handle for debugging information. */
652 struct debug_handle *ret;
654 ret = (struct debug_handle *) xmalloc (sizeof *ret);
655 memset (ret, 0, sizeof *ret);
659 /* Set the source filename. This implicitly starts a new compilation
663 debug_set_filename (handle, name)
667 struct debug_handle *info = (struct debug_handle *) handle;
668 struct debug_file *nfile;
669 struct debug_unit *nunit;
674 nfile = (struct debug_file *) xmalloc (sizeof *nfile);
675 memset (nfile, 0, sizeof *nfile);
677 nfile->filename = name;
679 nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
680 memset (nunit, 0, sizeof *nunit);
682 nunit->files = nfile;
683 info->current_file = nfile;
685 if (info->current_unit != NULL)
686 info->current_unit->next = nunit;
689 assert (info->units == NULL);
693 info->current_unit = nunit;
695 info->current_function = NULL;
696 info->current_block = NULL;
697 info->current_lineno = NULL;
702 /* Change source files to the given file name. This is used for
703 include files in a single compilation unit. */
706 debug_start_source (handle, name)
710 struct debug_handle *info = (struct debug_handle *) handle;
711 struct debug_file *f, **pf;
716 if (info->current_unit == NULL)
718 debug_error ("debug_start_source: no debug_set_filename call");
722 for (f = info->current_unit->files; f != NULL; f = f->next)
724 if (f->filename[0] == name[0]
725 && f->filename[1] == name[1]
726 && strcmp (f->filename, name) == 0)
728 info->current_file = f;
733 f = (struct debug_file *) xmalloc (sizeof *f);
734 memset (f, 0, sizeof *f);
738 for (pf = &info->current_file->next;
744 info->current_file = f;
749 /* Record a function definition. This implicitly starts a function
750 block. The debug_type argument is the type of the return value.
751 The boolean indicates whether the function is globally visible.
752 The bfd_vma is the address of the start of the function. Currently
753 the parameter types are specified by calls to
754 debug_record_parameter. FIXME: There is no way to specify nested
758 debug_record_function (handle, name, return_type, global, addr)
761 debug_type return_type;
765 struct debug_handle *info = (struct debug_handle *) handle;
766 struct debug_function *f;
767 struct debug_block *b;
768 struct debug_name *n;
772 if (return_type == NULL)
775 if (info->current_unit == NULL)
777 debug_error ("debug_record_function: no debug_set_filename call");
781 f = (struct debug_function *) xmalloc (sizeof *f);
782 memset (f, 0, sizeof *f);
784 f->return_type = return_type;
786 b = (struct debug_block *) xmalloc (sizeof *b);
787 memset (b, 0, sizeof *b);
790 b->end = (bfd_vma) -1;
794 info->current_function = f;
795 info->current_block = b;
797 /* FIXME: If we could handle nested functions, this would be the
798 place: we would want to use a different namespace. */
799 n = debug_add_to_namespace (info,
800 &info->current_file->globals,
802 DEBUG_OBJECT_FUNCTION,
804 ? DEBUG_LINKAGE_GLOBAL
805 : DEBUG_LINKAGE_STATIC));
814 /* Record a parameter for the current function. */
817 debug_record_parameter (handle, name, type, kind, val)
821 enum debug_parm_kind kind;
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 (handle, addr)
861 struct debug_handle *info = (struct debug_handle *) handle;
863 if (info->current_unit == NULL
864 || info->current_block == NULL
865 || info->current_function == NULL)
867 debug_error ("debug_end_function: no current function");
871 if (info->current_block->parent != NULL)
873 debug_error ("debug_end_function: some blocks were not closed");
877 info->current_block->end = addr;
879 info->current_function = NULL;
880 info->current_block = NULL;
885 /* Start a block in a function. All local information will be
886 recorded in this block, until the matching call to debug_end_block.
887 debug_start_block and debug_end_block may be nested. The bfd_vma
888 argument is the address at which this block starts. */
891 debug_start_block (handle, addr)
895 struct debug_handle *info = (struct debug_handle *) handle;
896 struct debug_block *b, **pb;
898 /* We must always have a current block: debug_record_function sets
900 if (info->current_unit == NULL
901 || info->current_block == NULL)
903 debug_error ("debug_start_block: no current block");
907 b = (struct debug_block *) xmalloc (sizeof *b);
908 memset (b, 0, sizeof *b);
910 b->parent = info->current_block;
912 b->end = (bfd_vma) -1;
914 /* This new block is a child of the current block. */
915 for (pb = &info->current_block->children;
921 info->current_block = b;
926 /* Finish a block in a function. This matches the call to
927 debug_start_block. The argument is the address at which this block
931 debug_end_block (handle, addr)
935 struct debug_handle *info = (struct debug_handle *) handle;
936 struct debug_block *parent;
938 if (info->current_unit == NULL
939 || info->current_block == NULL)
941 debug_error ("debug_end_block: no current block");
945 parent = info->current_block->parent;
948 debug_error ("debug_end_block: attempt to close top level block");
952 info->current_block->end = addr;
954 info->current_block = parent;
959 /* Associate a line number in the current source file and function
960 with a given address. */
963 debug_record_line (handle, lineno, addr)
965 unsigned long lineno;
968 struct debug_handle *info = (struct debug_handle *) handle;
969 struct debug_lineno *l;
972 if (info->current_unit == NULL)
974 debug_error ("debug_record_line: no current unit");
978 l = info->current_lineno;
979 if (l != NULL && l->file == info->current_file)
981 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
983 if (l->linenos[i] == (unsigned long) -1)
985 l->linenos[i] = lineno;
992 /* If we get here, then either 1) there is no current_lineno
993 structure, which means this is the first line number in this
994 compilation unit, 2) the current_lineno structure is for a
995 different file, or 3) the current_lineno structure is full.
996 Regardless, we want to allocate a new debug_lineno structure, put
997 it in the right place, and make it the new current_lineno
1000 l = (struct debug_lineno *) xmalloc (sizeof *l);
1001 memset (l, 0, sizeof *l);
1003 l->file = info->current_file;
1004 l->linenos[0] = lineno;
1006 for (i = 1; i < DEBUG_LINENO_COUNT; i++)
1007 l->linenos[i] = (unsigned long) -1;
1009 if (info->current_lineno != NULL)
1010 info->current_lineno->next = l;
1012 info->current_unit->linenos = l;
1014 info->current_lineno = l;
1019 /* Start a named common block. This is a block of variables that may
1023 debug_start_common_block (handle, name)
1028 debug_error ("debug_start_common_block: not implemented");
1032 /* End a named common block. */
1035 debug_end_common_block (handle, name)
1040 debug_error ("debug_end_common_block: not implemented");
1044 /* Record a named integer constant. */
1047 debug_record_int_const (handle, name, val)
1052 struct debug_handle *info = (struct debug_handle *) handle;
1053 struct debug_name *n;
1058 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
1059 DEBUG_LINKAGE_NONE);
1063 n->u.int_constant = val;
1068 /* Record a named floating point constant. */
1071 debug_record_float_const (handle, name, val)
1076 struct debug_handle *info = (struct debug_handle *) handle;
1077 struct debug_name *n;
1082 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
1083 DEBUG_LINKAGE_NONE);
1087 n->u.float_constant = val;
1092 /* Record a typed constant with an integral value. */
1095 debug_record_typed_const (handle, name, type, val)
1101 struct debug_handle *info = (struct debug_handle *) handle;
1102 struct debug_name *n;
1103 struct debug_typed_constant *tc;
1105 if (name == NULL || type == NULL)
1108 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
1109 DEBUG_LINKAGE_NONE);
1113 tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
1114 memset (tc, 0, sizeof *tc);
1119 n->u.typed_constant = tc;
1124 /* Record a label. */
1127 debug_record_label (handle, name, type, addr)
1134 debug_error ("debug_record_label not implemented");
1138 /* Record a variable. */
1141 debug_record_variable (handle, name, type, kind, val)
1145 enum debug_var_kind kind;
1148 struct debug_handle *info = (struct debug_handle *) handle;
1149 struct debug_namespace **nsp;
1150 enum debug_object_linkage linkage;
1151 struct debug_name *n;
1152 struct debug_variable *v;
1154 if (name == NULL || type == NULL)
1157 if (info->current_unit == NULL
1158 || info->current_file == NULL)
1160 debug_error ("debug_record_variable: no current file");
1164 if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
1166 nsp = &info->current_file->globals;
1167 if (kind == DEBUG_GLOBAL)
1168 linkage = DEBUG_LINKAGE_GLOBAL;
1170 linkage = DEBUG_LINKAGE_STATIC;
1174 if (info->current_block == NULL)
1176 debug_error ("debug_record_variable: no current block");
1179 nsp = &info->current_block->locals;
1180 linkage = DEBUG_LINKAGE_AUTOMATIC;
1183 n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
1187 v = (struct debug_variable *) xmalloc (sizeof *v);
1188 memset (v, 0, sizeof *v);
1199 /* Make a type with a given kind and size. */
1202 static struct debug_type *
1203 debug_make_type (info, kind, size)
1204 struct debug_handle *info;
1205 enum debug_type_kind kind;
1208 struct debug_type *t;
1210 t = (struct debug_type *) xmalloc (sizeof *t);
1211 memset (t, 0, sizeof *t);
1219 /* Make an indirect type which may be used as a placeholder for a type
1220 which is referenced before it is defined. */
1223 debug_make_indirect_type (handle, slot, tag)
1228 struct debug_handle *info = (struct debug_handle *) handle;
1229 struct debug_type *t;
1230 struct debug_indirect_type *i;
1232 t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
1234 return DEBUG_TYPE_NULL;
1236 i = (struct debug_indirect_type *) xmalloc (sizeof *i);
1237 memset (i, 0, sizeof *i);
1247 /* Make a void type. There is only one of these. */
1250 debug_make_void_type (handle)
1253 struct debug_handle *info = (struct debug_handle *) handle;
1255 return debug_make_type (info, DEBUG_KIND_VOID, 0);
1258 /* Make an integer type of a given size. The boolean argument is true
1259 if the integer is unsigned. */
1262 debug_make_int_type (handle, size, unsignedp)
1267 struct debug_handle *info = (struct debug_handle *) handle;
1268 struct debug_type *t;
1270 t = debug_make_type (info, DEBUG_KIND_INT, size);
1272 return DEBUG_TYPE_NULL;
1274 t->u.kint = unsignedp;
1279 /* Make a floating point type of a given size. FIXME: On some
1280 platforms, like an Alpha, you probably need to be able to specify
1284 debug_make_float_type (handle, size)
1288 struct debug_handle *info = (struct debug_handle *) handle;
1290 return debug_make_type (info, DEBUG_KIND_FLOAT, size);
1293 /* Make a boolean type of a given size. */
1296 debug_make_bool_type (handle, size)
1300 struct debug_handle *info = (struct debug_handle *) handle;
1302 return debug_make_type (info, DEBUG_KIND_BOOL, size);
1305 /* Make a complex type of a given size. */
1308 debug_make_complex_type (handle, size)
1312 struct debug_handle *info = (struct debug_handle *) handle;
1314 return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
1317 /* Make a structure type. The second argument is true for a struct,
1318 false for a union. The third argument is the size of the struct.
1319 The fourth argument is a NULL terminated array of fields. */
1322 debug_make_struct_type (handle, structp, size, fields)
1326 debug_field *fields;
1328 struct debug_handle *info = (struct debug_handle *) handle;
1329 struct debug_type *t;
1330 struct debug_class_type *c;
1332 t = debug_make_type (info,
1333 structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
1336 return DEBUG_TYPE_NULL;
1338 c = (struct debug_class_type *) xmalloc (sizeof *c);
1339 memset (c, 0, sizeof *c);
1348 /* Make an object type. The first three arguments after the handle
1349 are the same as for debug_make_struct_type. The next arguments are
1350 a NULL terminated array of base classes, a NULL terminated array of
1351 methods, the type of the object holding the virtual function table
1352 if it is not this object, and a boolean which is true if this
1353 object has its own virtual function table. */
1356 debug_make_object_type (handle, structp, size, fields, baseclasses,
1357 methods, vptrbase, ownvptr)
1361 debug_field *fields;
1362 debug_baseclass *baseclasses;
1363 debug_method *methods;
1364 debug_type vptrbase;
1367 struct debug_handle *info = (struct debug_handle *) handle;
1368 struct debug_type *t;
1369 struct debug_class_type *c;
1371 t = debug_make_type (info,
1372 structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
1375 return DEBUG_TYPE_NULL;
1377 c = (struct debug_class_type *) xmalloc (sizeof *c);
1378 memset (c, 0, sizeof *c);
1381 c->baseclasses = baseclasses;
1382 c->methods = methods;
1386 c->vptrbase = vptrbase;
1393 /* Make an enumeration type. The arguments are a null terminated
1394 array of strings, and an array of corresponding values. */
1397 debug_make_enum_type (handle, names, values)
1400 bfd_signed_vma *values;
1402 struct debug_handle *info = (struct debug_handle *) handle;
1403 struct debug_type *t;
1404 struct debug_enum_type *e;
1406 t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
1408 return DEBUG_TYPE_NULL;
1410 e = (struct debug_enum_type *) xmalloc (sizeof *e);
1411 memset (e, 0, sizeof *e);
1421 /* Make a pointer to a given type. */
1424 debug_make_pointer_type (handle, type)
1428 struct debug_handle *info = (struct debug_handle *) handle;
1429 struct debug_type *t;
1432 return DEBUG_TYPE_NULL;
1434 if (type->pointer != DEBUG_TYPE_NULL)
1435 return type->pointer;
1437 t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
1439 return DEBUG_TYPE_NULL;
1441 t->u.kpointer = type;
1448 /* Make a function returning a given type. FIXME: We should be able
1449 to record the parameter types. */
1452 debug_make_function_type (handle, type, arg_types, varargs)
1455 debug_type *arg_types;
1458 struct debug_handle *info = (struct debug_handle *) handle;
1459 struct debug_type *t;
1460 struct debug_function_type *f;
1463 return DEBUG_TYPE_NULL;
1465 t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
1467 return DEBUG_TYPE_NULL;
1469 f = (struct debug_function_type *) xmalloc (sizeof *f);
1470 memset (f, 0, sizeof *f);
1472 f->return_type = type;
1473 f->arg_types = arg_types;
1474 f->varargs = varargs;
1481 /* Make a reference to a given type. */
1484 debug_make_reference_type (handle, type)
1488 struct debug_handle *info = (struct debug_handle *) handle;
1489 struct debug_type *t;
1492 return DEBUG_TYPE_NULL;
1494 t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
1496 return DEBUG_TYPE_NULL;
1498 t->u.kreference = type;
1503 /* Make a range of a given type from a lower to an upper bound. */
1506 debug_make_range_type (handle, type, lower, upper)
1509 bfd_signed_vma lower;
1510 bfd_signed_vma upper;
1512 struct debug_handle *info = (struct debug_handle *) handle;
1513 struct debug_type *t;
1514 struct debug_range_type *r;
1517 return DEBUG_TYPE_NULL;
1519 t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
1521 return DEBUG_TYPE_NULL;
1523 r = (struct debug_range_type *) xmalloc (sizeof *r);
1524 memset (r, 0, sizeof *r);
1535 /* Make an array type. The second argument is the type of an element
1536 of the array. The third argument is the type of a range of the
1537 array. The fourth and fifth argument are the lower and upper
1538 bounds, respectively. The sixth argument is true if this array is
1539 actually a string, as in C. */
1542 debug_make_array_type (handle, element_type, range_type, lower, upper,
1545 debug_type element_type;
1546 debug_type range_type;
1547 bfd_signed_vma lower;
1548 bfd_signed_vma upper;
1551 struct debug_handle *info = (struct debug_handle *) handle;
1552 struct debug_type *t;
1553 struct debug_array_type *a;
1555 if (element_type == NULL || range_type == NULL)
1556 return DEBUG_TYPE_NULL;
1558 t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
1560 return DEBUG_TYPE_NULL;
1562 a = (struct debug_array_type *) xmalloc (sizeof *a);
1563 memset (a, 0, sizeof *a);
1565 a->element_type = element_type;
1566 a->range_type = range_type;
1569 a->stringp = stringp;
1576 /* Make a set of a given type. For example, a Pascal set type. The
1577 boolean argument is true if this set is actually a bitstring, as in
1581 debug_make_set_type (handle, type, bitstringp)
1586 struct debug_handle *info = (struct debug_handle *) handle;
1587 struct debug_type *t;
1588 struct debug_set_type *s;
1591 return DEBUG_TYPE_NULL;
1593 t = debug_make_type (info, DEBUG_KIND_SET, 0);
1595 return DEBUG_TYPE_NULL;
1597 s = (struct debug_set_type *) xmalloc (sizeof *s);
1598 memset (s, 0, sizeof *s);
1601 s->bitstringp = bitstringp;
1608 /* Make a type for a pointer which is relative to an object. The
1609 second argument is the type of the object to which the pointer is
1610 relative. The third argument is the type that the pointer points
1614 debug_make_offset_type (handle, base_type, target_type)
1616 debug_type base_type;
1617 debug_type target_type;
1619 struct debug_handle *info = (struct debug_handle *) handle;
1620 struct debug_type *t;
1621 struct debug_offset_type *o;
1623 if (base_type == NULL || target_type == NULL)
1624 return DEBUG_TYPE_NULL;
1626 t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
1628 return DEBUG_TYPE_NULL;
1630 o = (struct debug_offset_type *) xmalloc (sizeof *o);
1631 memset (o, 0, sizeof *o);
1633 o->base_type = base_type;
1634 o->target_type = target_type;
1641 /* Make a type for a method function. The second argument is the
1642 return type, the third argument is the domain, and the fourth
1643 argument is a NULL terminated array of argument types. */
1646 debug_make_method_type (handle, return_type, domain_type, arg_types, varargs)
1648 debug_type return_type;
1649 debug_type domain_type;
1650 debug_type *arg_types;
1653 struct debug_handle *info = (struct debug_handle *) handle;
1654 struct debug_type *t;
1655 struct debug_method_type *m;
1657 if (return_type == NULL)
1658 return DEBUG_TYPE_NULL;
1660 t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
1662 return DEBUG_TYPE_NULL;
1664 m = (struct debug_method_type *) xmalloc (sizeof *m);
1665 memset (m, 0, sizeof *m);
1667 m->return_type = return_type;
1668 m->domain_type = domain_type;
1669 m->arg_types = arg_types;
1670 m->varargs = varargs;
1677 /* Make a const qualified version of a given type. */
1680 debug_make_const_type (handle, type)
1684 struct debug_handle *info = (struct debug_handle *) handle;
1685 struct debug_type *t;
1688 return DEBUG_TYPE_NULL;
1690 t = debug_make_type (info, DEBUG_KIND_CONST, 0);
1692 return DEBUG_TYPE_NULL;
1699 /* Make a volatile qualified version of a given type. */
1702 debug_make_volatile_type (handle, type)
1706 struct debug_handle *info = (struct debug_handle *) handle;
1707 struct debug_type *t;
1710 return DEBUG_TYPE_NULL;
1712 t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
1714 return DEBUG_TYPE_NULL;
1716 t->u.kvolatile = type;
1721 /* Make an undefined tagged type. For example, a struct which has
1722 been mentioned, but not defined. */
1725 debug_make_undefined_tagged_type (handle, name, kind)
1728 enum debug_type_kind kind;
1730 struct debug_handle *info = (struct debug_handle *) handle;
1731 struct debug_type *t;
1734 return DEBUG_TYPE_NULL;
1738 case DEBUG_KIND_STRUCT:
1739 case DEBUG_KIND_UNION:
1740 case DEBUG_KIND_CLASS:
1741 case DEBUG_KIND_UNION_CLASS:
1742 case DEBUG_KIND_ENUM:
1746 debug_error ("debug_make_undefined_type: unsupported kind");
1747 return DEBUG_TYPE_NULL;
1750 t = debug_make_type (info, kind, 0);
1752 return DEBUG_TYPE_NULL;
1754 return debug_tag_type (handle, name, t);
1757 /* Make a base class for an object. The second argument is the base
1758 class type. The third argument is the bit position of this base
1759 class in the object (always 0 unless doing multiple inheritance).
1760 The fourth argument is whether this is a virtual class. The fifth
1761 argument is the visibility of the base class. */
1765 debug_make_baseclass (handle, type, bitpos, virtual, visibility)
1770 enum debug_visibility visibility;
1772 struct debug_baseclass *b;
1774 b = (struct debug_baseclass *) xmalloc (sizeof *b);
1775 memset (b, 0, sizeof *b);
1779 b->virtual = virtual;
1780 b->visibility = visibility;
1785 /* Make a field for a struct. The second argument is the name. The
1786 third argument is the type of the field. The fourth argument is
1787 the bit position of the field. The fifth argument is the size of
1788 the field (it may be zero). The sixth argument is the visibility
1793 debug_make_field (handle, name, type, bitpos, bitsize, visibility)
1799 enum debug_visibility visibility;
1801 struct debug_field *f;
1803 f = (struct debug_field *) xmalloc (sizeof *f);
1804 memset (f, 0, sizeof *f);
1808 f->static_member = false;
1809 f->u.f.bitpos = bitpos;
1810 f->u.f.bitsize = bitsize;
1811 f->visibility = visibility;
1816 /* Make a static member of an object. The second argument is the
1817 name. The third argument is the type of the member. The fourth
1818 argument is the physical name of the member (i.e., the name as a
1819 global variable). The fifth argument is the visibility of the
1824 debug_make_static_member (handle, name, type, physname, visibility)
1828 const char *physname;
1829 enum debug_visibility visibility;
1831 struct debug_field *f;
1833 f = (struct debug_field *) xmalloc (sizeof *f);
1834 memset (f, 0, sizeof *f);
1838 f->static_member = true;
1839 f->u.s.physname = physname;
1840 f->visibility = visibility;
1845 /* Make a method. The second argument is the name, and the third
1846 argument is a NULL terminated array of method variants. */
1850 debug_make_method (handle, name, variants)
1853 debug_method_variant *variants;
1855 struct debug_method *m;
1857 m = (struct debug_method *) xmalloc (sizeof *m);
1858 memset (m, 0, sizeof *m);
1861 m->variants = variants;
1866 /* Make a method argument. The second argument is the real name of
1867 the function. The third argument is the type of the function. The
1868 fourth argument is the visibility. The fifth argument is whether
1869 this is a const function. The sixth argument is whether this is a
1870 volatile function. The seventh argument is the offset in the
1871 virtual function table, if any. The eighth argument is the virtual
1872 function context. FIXME: Are the const and volatile arguments
1873 necessary? Could we just use debug_make_const_type? */
1876 debug_method_variant
1877 debug_make_method_variant (handle, physname, type, visibility, constp,
1878 volatilep, voffset, context)
1880 const char *physname;
1882 enum debug_visibility visibility;
1888 struct debug_method_variant *m;
1890 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1891 memset (m, 0, sizeof *m);
1893 m->physname = physname;
1895 m->visibility = visibility;
1897 m->volatilep = volatilep;
1898 m->voffset = voffset;
1899 m->context = context;
1904 /* Make a static method argument. The arguments are the same as for
1905 debug_make_method_variant, except that the last two are omitted
1906 since a static method can not also be virtual. */
1908 debug_method_variant
1909 debug_make_static_method_variant (handle, physname, type, visibility,
1912 const char *physname;
1914 enum debug_visibility visibility;
1918 struct debug_method_variant *m;
1920 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1921 memset (m, 0, sizeof *m);
1923 m->physname = physname;
1925 m->visibility = visibility;
1927 m->volatilep = volatilep;
1928 m->voffset = VOFFSET_STATIC_METHOD;
1936 debug_name_type (handle, name, type)
1941 struct debug_handle *info = (struct debug_handle *) handle;
1942 struct debug_type *t;
1943 struct debug_named_type *n;
1944 struct debug_name *nm;
1946 if (name == NULL || type == NULL)
1947 return DEBUG_TYPE_NULL;
1949 if (info->current_unit == NULL
1950 || info->current_file == NULL)
1952 debug_error ("debug_record_variable: no current file");
1956 t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1958 return DEBUG_TYPE_NULL;
1960 n = (struct debug_named_type *) xmalloc (sizeof *n);
1961 memset (n, 0, sizeof *n);
1967 /* We always add the name to the global namespace. This is probably
1968 wrong in some cases, but it seems to be right for stabs. FIXME. */
1970 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1971 DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
1985 debug_tag_type (handle, name, type)
1990 struct debug_handle *info = (struct debug_handle *) handle;
1991 struct debug_type *t;
1992 struct debug_named_type *n;
1993 struct debug_name *nm;
1995 if (name == NULL || type == NULL)
1996 return DEBUG_TYPE_NULL;
1998 if (info->current_file == NULL)
2000 debug_error ("debug_tag_type: no current file");
2001 return DEBUG_TYPE_NULL;
2004 if (type->kind == DEBUG_KIND_TAGGED)
2006 if (strcmp (type->u.knamed->name->name, name) == 0)
2008 debug_error ("debug_tag_type: extra tag attempted");
2009 return DEBUG_TYPE_NULL;
2012 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
2014 return DEBUG_TYPE_NULL;
2016 n = (struct debug_named_type *) xmalloc (sizeof *n);
2017 memset (n, 0, sizeof *n);
2023 /* We keep a global namespace of tags for each compilation unit. I
2024 don't know if that is the right thing to do. */
2026 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
2027 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
2038 /* Record the size of a given type. */
2042 debug_record_type_size (handle, type, size)
2047 if (type->size != 0 && type->size != size)
2048 fprintf (stderr, "Warning: changing type size from %d to %d\n",
2056 /* Find a named type. */
2059 debug_find_named_type (handle, name)
2063 struct debug_handle *info = (struct debug_handle *) handle;
2064 struct debug_block *b;
2065 struct debug_file *f;
2067 /* We only search the current compilation unit. I don't know if
2068 this is right or not. */
2070 if (info->current_unit == NULL)
2072 debug_error ("debug_find_named_type: no current compilation unit");
2073 return DEBUG_TYPE_NULL;
2076 for (b = info->current_block; b != NULL; b = b->parent)
2078 if (b->locals != NULL)
2080 struct debug_name *n;
2082 for (n = b->locals->list; n != NULL; n = n->next)
2084 if (n->kind == DEBUG_OBJECT_TYPE
2085 && n->name[0] == name[0]
2086 && strcmp (n->name, name) == 0)
2092 for (f = info->current_unit->files; f != NULL; f = f->next)
2094 if (f->globals != NULL)
2096 struct debug_name *n;
2098 for (n = f->globals->list; n != NULL; n = n->next)
2100 if (n->kind == DEBUG_OBJECT_TYPE
2101 && n->name[0] == name[0]
2102 && strcmp (n->name, name) == 0)
2108 return DEBUG_TYPE_NULL;
2111 /* Find a tagged type. */
2114 debug_find_tagged_type (handle, name, kind)
2117 enum debug_type_kind kind;
2119 struct debug_handle *info = (struct debug_handle *) handle;
2120 struct debug_unit *u;
2122 /* We search the globals of all the compilation units. I don't know
2123 if this is correct or not. It would be easy to change. */
2125 for (u = info->units; u != NULL; u = u->next)
2127 struct debug_file *f;
2129 for (f = u->files; f != NULL; f = f->next)
2131 struct debug_name *n;
2133 if (f->globals != NULL)
2135 for (n = f->globals->list; n != NULL; n = n->next)
2137 if (n->kind == DEBUG_OBJECT_TAG
2138 && (kind == DEBUG_KIND_ILLEGAL
2139 || n->u.tag->kind == kind)
2140 && n->name[0] == name[0]
2141 && strcmp (n->name, name) == 0)
2148 return DEBUG_TYPE_NULL;
2151 /* Get a base type. */
2153 static struct debug_type *
2154 debug_get_real_type (handle, type)
2162 case DEBUG_KIND_INDIRECT:
2163 if (*type->u.kindirect->slot != NULL)
2164 return debug_get_real_type (handle, *type->u.kindirect->slot);
2166 case DEBUG_KIND_NAMED:
2167 case DEBUG_KIND_TAGGED:
2168 return debug_get_real_type (handle, type->u.knamed->type);
2173 /* Get the kind of a type. */
2175 enum debug_type_kind
2176 debug_get_type_kind (handle, type)
2181 return DEBUG_KIND_ILLEGAL;
2182 type = debug_get_real_type (handle, type);
2186 /* Get the name of a type. */
2189 debug_get_type_name (handle, type)
2193 if (type->kind == DEBUG_KIND_INDIRECT)
2195 if (*type->u.kindirect->slot != NULL)
2196 return debug_get_type_name (handle, *type->u.kindirect->slot);
2197 return type->u.kindirect->tag;
2199 if (type->kind == DEBUG_KIND_NAMED
2200 || type->kind == DEBUG_KIND_TAGGED)
2201 return type->u.knamed->name->name;
2205 /* Get the size of a type. */
2208 debug_get_type_size (handle, type)
2215 /* We don't call debug_get_real_type, because somebody might have
2216 called debug_record_type_size on a named or indirect type. */
2218 if (type->size != 0)
2225 case DEBUG_KIND_INDIRECT:
2226 if (*type->u.kindirect->slot != NULL)
2227 return debug_get_type_size (handle, *type->u.kindirect->slot);
2229 case DEBUG_KIND_NAMED:
2230 case DEBUG_KIND_TAGGED:
2231 return debug_get_type_size (handle, type->u.knamed->type);
2236 /* Get the return type of a function or method type. */
2239 debug_get_return_type (handle, type)
2244 return DEBUG_TYPE_NULL;
2245 type = debug_get_real_type (handle, type);
2249 return DEBUG_TYPE_NULL;
2250 case DEBUG_KIND_FUNCTION:
2251 return type->u.kfunction->return_type;
2252 case DEBUG_KIND_METHOD:
2253 return type->u.kmethod->return_type;
2258 /* Get the parameter types of a function or method type (except that
2259 we don't currently store the parameter types of a function). */
2262 debug_get_parameter_types (handle, type, pvarargs)
2269 type = debug_get_real_type (handle, type);
2274 case DEBUG_KIND_FUNCTION:
2275 *pvarargs = type->u.kfunction->varargs;
2276 return type->u.kfunction->arg_types;
2277 case DEBUG_KIND_METHOD:
2278 *pvarargs = type->u.kmethod->varargs;
2279 return type->u.kmethod->arg_types;
2284 /* Get the target type of a type. */
2287 debug_get_target_type (handle, type)
2293 type = debug_get_real_type (handle, type);
2298 case DEBUG_KIND_POINTER:
2299 return type->u.kpointer;
2300 case DEBUG_KIND_REFERENCE:
2301 return type->u.kreference;
2302 case DEBUG_KIND_CONST:
2303 return type->u.kconst;
2304 case DEBUG_KIND_VOLATILE:
2305 return type->u.kvolatile;
2310 /* Get the NULL terminated array of fields for a struct, union, or
2314 debug_get_fields (handle, type)
2320 type = debug_get_real_type (handle, type);
2325 case DEBUG_KIND_STRUCT:
2326 case DEBUG_KIND_UNION:
2327 case DEBUG_KIND_CLASS:
2328 case DEBUG_KIND_UNION_CLASS:
2329 return type->u.kclass->fields;
2334 /* Get the type of a field. */
2338 debug_get_field_type (handle, field)
2347 /* Get the name of a field. */
2351 debug_get_field_name (handle, field)
2360 /* Get the bit position of a field. */
2364 debug_get_field_bitpos (handle, field)
2368 if (field == NULL || field->static_member)
2369 return (bfd_vma) -1;
2370 return field->u.f.bitpos;
2373 /* Get the bit size of a field. */
2377 debug_get_field_bitsize (handle, field)
2381 if (field == NULL || field->static_member)
2382 return (bfd_vma) -1;
2383 return field->u.f.bitsize;
2386 /* Get the visibility of a field. */
2389 enum debug_visibility
2390 debug_get_field_visibility (handle, field)
2395 return DEBUG_VISIBILITY_IGNORE;
2396 return field->visibility;
2399 /* Get the physical name of a field. */
2402 debug_get_field_physname (handle, field)
2406 if (field == NULL || ! field->static_member)
2408 return field->u.s.physname;
2411 /* Write out the debugging information. This is given a handle to
2412 debugging information, and a set of function pointers to call. */
2415 debug_write (handle, fns, fhandle)
2417 const struct debug_write_fns *fns;
2420 struct debug_handle *info = (struct debug_handle *) handle;
2421 struct debug_unit *u;
2423 /* We use a mark to tell whether we have already written out a
2424 particular name. We use an integer, so that we don't have to
2425 clear the mark fields if we happen to write out the same
2426 information more than once. */
2429 /* The base_id field holds an ID value which will never be used, so
2430 that we can tell whether we have assigned an ID during this call
2432 info->base_id = info->class_id;
2434 /* We keep a linked list of classes for which was have assigned ID's
2435 during this call to debug_write. */
2436 info->id_list = NULL;
2438 for (u = info->units; u != NULL; u = u->next)
2440 struct debug_file *f;
2442 struct debug_lineno *l;
2444 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2448 for (f = u->files; f != NULL; f = f->next)
2450 struct debug_name *n;
2456 if (! (*fns->start_source) (fhandle, f->filename))
2460 if (f->globals != NULL)
2462 for (n = f->globals->list; n != NULL; n = n->next)
2464 if (! debug_write_name (info, fns, fhandle, n))
2470 for (l = u->linenos; l != NULL; l = l->next)
2474 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
2476 if (l->linenos[i] == (unsigned long) -1)
2478 if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
2488 /* Write out an element in a namespace. */
2491 debug_write_name (info, fns, fhandle, n)
2492 struct debug_handle *info;
2493 const struct debug_write_fns *fns;
2495 struct debug_name *n;
2499 case DEBUG_OBJECT_TYPE:
2500 if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2501 || ! (*fns->typdef) (fhandle, n->name))
2504 case DEBUG_OBJECT_TAG:
2505 if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2507 return (*fns->tag) (fhandle, n->name);
2508 case DEBUG_OBJECT_VARIABLE:
2509 if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2510 (struct debug_name *) NULL))
2512 return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2513 n->u.variable->val);
2514 case DEBUG_OBJECT_FUNCTION:
2515 return debug_write_function (info, fns, fhandle, n->name,
2516 n->linkage, n->u.function);
2517 case DEBUG_OBJECT_INT_CONSTANT:
2518 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2519 case DEBUG_OBJECT_FLOAT_CONSTANT:
2520 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2521 case DEBUG_OBJECT_TYPED_CONSTANT:
2522 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2523 (struct debug_name *) NULL))
2525 return (*fns->typed_constant) (fhandle, n->name,
2526 n->u.typed_constant->val);
2534 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2535 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2536 are about to call typedef or tag. If the type is anything else,
2537 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2538 points to this one. */
2541 debug_write_type (info, fns, fhandle, type, name)
2542 struct debug_handle *info;
2543 const struct debug_write_fns *fns;
2545 struct debug_type *type;
2546 struct debug_name *name;
2552 /* If we have a name for this type, just output it. We only output
2553 typedef names after they have been defined. We output type tags
2554 whenever we are not actually defining them. */
2555 if ((type->kind == DEBUG_KIND_NAMED
2556 || type->kind == DEBUG_KIND_TAGGED)
2557 && (type->u.knamed->name->mark == info->mark
2558 || (type->kind == DEBUG_KIND_TAGGED
2559 && type->u.knamed->name != name)))
2561 if (type->kind == DEBUG_KIND_NAMED)
2562 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2565 struct debug_type *real;
2568 real = debug_get_real_type ((PTR) info, type);
2570 if ((real->kind == DEBUG_KIND_STRUCT
2571 || real->kind == DEBUG_KIND_UNION
2572 || real->kind == DEBUG_KIND_CLASS
2573 || real->kind == DEBUG_KIND_UNION_CLASS)
2574 && real->u.kclass != NULL)
2576 if (real->u.kclass->id <= info->base_id)
2578 if (! debug_set_class_id (info,
2579 type->u.knamed->name->name,
2583 id = real->u.kclass->id;
2586 return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
2591 /* Mark the name after we have already looked for a known name, so
2592 that we don't just define a type in terms of itself. We need to
2593 mark the name here so that a struct containing a pointer to
2594 itself will work. */
2596 name->mark = info->mark;
2600 && type->kind != DEBUG_KIND_NAMED
2601 && type->kind != DEBUG_KIND_TAGGED)
2603 assert (name->kind == DEBUG_OBJECT_TAG);
2609 case DEBUG_KIND_ILLEGAL:
2610 debug_error ("debug_write_type: illegal type encountered");
2612 case DEBUG_KIND_INDIRECT:
2613 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2614 return (*fns->empty_type) (fhandle);
2615 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2617 case DEBUG_KIND_VOID:
2618 return (*fns->void_type) (fhandle);
2619 case DEBUG_KIND_INT:
2620 return (*fns->int_type) (fhandle, type->size, type->u.kint);
2621 case DEBUG_KIND_FLOAT:
2622 return (*fns->float_type) (fhandle, type->size);
2623 case DEBUG_KIND_COMPLEX:
2624 return (*fns->complex_type) (fhandle, type->size);
2625 case DEBUG_KIND_BOOL:
2626 return (*fns->bool_type) (fhandle, type->size);
2627 case DEBUG_KIND_STRUCT:
2628 case DEBUG_KIND_UNION:
2629 if (type->u.kclass != NULL)
2631 if (type->u.kclass->id <= info->base_id)
2633 if (! debug_set_class_id (info, tag, type))
2637 if (info->mark == type->u.kclass->mark)
2639 /* We are currently outputting this struct, or we have
2640 already output it. I don't know if this can happen,
2641 but it can happen for a class. */
2642 assert (type->u.kclass->id > info->base_id);
2643 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2646 type->u.kclass->mark = info->mark;
2649 if (! (*fns->start_struct_type) (fhandle, tag,
2650 (type->u.kclass != NULL
2651 ? type->u.kclass->id
2653 type->kind == DEBUG_KIND_STRUCT,
2656 if (type->u.kclass != NULL
2657 && type->u.kclass->fields != NULL)
2659 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2661 struct debug_field *f;
2663 f = type->u.kclass->fields[i];
2664 if (! debug_write_type (info, fns, fhandle, f->type,
2665 (struct debug_name *) NULL)
2666 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2667 f->u.f.bitsize, f->visibility))
2671 return (*fns->end_struct_type) (fhandle);
2672 case DEBUG_KIND_CLASS:
2673 case DEBUG_KIND_UNION_CLASS:
2674 return debug_write_class_type (info, fns, fhandle, type, tag);
2675 case DEBUG_KIND_ENUM:
2676 if (type->u.kenum == NULL)
2677 return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
2678 (bfd_signed_vma *) NULL);
2679 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2680 type->u.kenum->values);
2681 case DEBUG_KIND_POINTER:
2682 if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2683 (struct debug_name *) NULL))
2685 return (*fns->pointer_type) (fhandle);
2686 case DEBUG_KIND_FUNCTION:
2687 if (type->u.kfunction->arg_types == NULL)
2691 for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
2692 if (! debug_write_type (info, fns, fhandle,
2693 type->u.kfunction->arg_types[is],
2694 (struct debug_name *) NULL))
2697 if (! debug_write_type (info, fns, fhandle,
2698 type->u.kfunction->return_type,
2699 (struct debug_name *) NULL))
2701 return (*fns->function_type) (fhandle, is,
2702 type->u.kfunction->varargs);
2703 case DEBUG_KIND_REFERENCE:
2704 if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2705 (struct debug_name *) NULL))
2707 return (*fns->reference_type) (fhandle);
2708 case DEBUG_KIND_RANGE:
2709 if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2710 (struct debug_name *) NULL))
2712 return (*fns->range_type) (fhandle, type->u.krange->lower,
2713 type->u.krange->upper);
2714 case DEBUG_KIND_ARRAY:
2715 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2716 (struct debug_name *) NULL)
2717 || ! debug_write_type (info, fns, fhandle,
2718 type->u.karray->range_type,
2719 (struct debug_name *) NULL))
2721 return (*fns->array_type) (fhandle, type->u.karray->lower,
2722 type->u.karray->upper,
2723 type->u.karray->stringp);
2724 case DEBUG_KIND_SET:
2725 if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2726 (struct debug_name *) NULL))
2728 return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2729 case DEBUG_KIND_OFFSET:
2730 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2731 (struct debug_name *) NULL)
2732 || ! debug_write_type (info, fns, fhandle,
2733 type->u.koffset->target_type,
2734 (struct debug_name *) NULL))
2736 return (*fns->offset_type) (fhandle);
2737 case DEBUG_KIND_METHOD:
2738 if (! debug_write_type (info, fns, fhandle,
2739 type->u.kmethod->return_type,
2740 (struct debug_name *) NULL))
2742 if (type->u.kmethod->arg_types == NULL)
2746 for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
2747 if (! debug_write_type (info, fns, fhandle,
2748 type->u.kmethod->arg_types[is],
2749 (struct debug_name *) NULL))
2752 if (type->u.kmethod->domain_type != NULL)
2754 if (! debug_write_type (info, fns, fhandle,
2755 type->u.kmethod->domain_type,
2756 (struct debug_name *) NULL))
2759 return (*fns->method_type) (fhandle,
2760 type->u.kmethod->domain_type != NULL,
2762 type->u.kmethod->varargs);
2763 case DEBUG_KIND_CONST:
2764 if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2765 (struct debug_name *) NULL))
2767 return (*fns->const_type) (fhandle);
2768 case DEBUG_KIND_VOLATILE:
2769 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2770 (struct debug_name *) NULL))
2772 return (*fns->volatile_type) (fhandle);
2773 case DEBUG_KIND_NAMED:
2774 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2775 (struct debug_name *) NULL);
2776 case DEBUG_KIND_TAGGED:
2777 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2778 type->u.knamed->name);
2785 /* Write out a class type. */
2788 debug_write_class_type (info, fns, fhandle, type, tag)
2789 struct debug_handle *info;
2790 const struct debug_write_fns *fns;
2792 struct debug_type *type;
2797 struct debug_type *vptrbase;
2799 if (type->u.kclass == NULL)
2806 if (type->u.kclass->id <= info->base_id)
2808 if (! debug_set_class_id (info, tag, type))
2812 if (info->mark == type->u.kclass->mark)
2814 /* We are currently outputting this class, or we have
2815 already output it. This can happen when there are
2816 methods for an anonymous class. */
2817 assert (type->u.kclass->id > info->base_id);
2818 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2821 type->u.kclass->mark = info->mark;
2822 id = type->u.kclass->id;
2824 vptrbase = type->u.kclass->vptrbase;
2825 if (vptrbase != NULL && vptrbase != type)
2827 if (! debug_write_type (info, fns, fhandle, vptrbase,
2828 (struct debug_name *) NULL))
2833 if (! (*fns->start_class_type) (fhandle, tag, id,
2834 type->kind == DEBUG_KIND_CLASS,
2840 if (type->u.kclass != NULL)
2842 if (type->u.kclass->fields != NULL)
2844 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2846 struct debug_field *f;
2848 f = type->u.kclass->fields[i];
2849 if (! debug_write_type (info, fns, fhandle, f->type,
2850 (struct debug_name *) NULL))
2852 if (f->static_member)
2854 if (! (*fns->class_static_member) (fhandle, f->name,
2861 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2862 f->u.f.bitsize, f->visibility))
2868 if (type->u.kclass->baseclasses != NULL)
2870 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2872 struct debug_baseclass *b;
2874 b = type->u.kclass->baseclasses[i];
2875 if (! debug_write_type (info, fns, fhandle, b->type,
2876 (struct debug_name *) NULL))
2878 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
2884 if (type->u.kclass->methods != NULL)
2886 for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2888 struct debug_method *m;
2891 m = type->u.kclass->methods[i];
2892 if (! (*fns->class_start_method) (fhandle, m->name))
2894 for (j = 0; m->variants[j] != NULL; j++)
2896 struct debug_method_variant *v;
2899 if (v->context != NULL)
2901 if (! debug_write_type (info, fns, fhandle, v->context,
2902 (struct debug_name *) NULL))
2905 if (! debug_write_type (info, fns, fhandle, v->type,
2906 (struct debug_name *) NULL))
2908 if (v->voffset != VOFFSET_STATIC_METHOD)
2910 if (! (*fns->class_method_variant) (fhandle, v->physname,
2915 v->context != NULL))
2920 if (! (*fns->class_static_method_variant) (fhandle,
2928 if (! (*fns->class_end_method) (fhandle))
2934 return (*fns->end_class_type) (fhandle);
2937 /* Write out information for a function. */
2940 debug_write_function (info, fns, fhandle, name, linkage, function)
2941 struct debug_handle *info;
2942 const struct debug_write_fns *fns;
2945 enum debug_object_linkage linkage;
2946 struct debug_function *function;
2948 struct debug_parameter *p;
2949 struct debug_block *b;
2951 if (! debug_write_type (info, fns, fhandle, function->return_type,
2952 (struct debug_name *) NULL))
2955 if (! (*fns->start_function) (fhandle, name,
2956 linkage == DEBUG_LINKAGE_GLOBAL))
2959 for (p = function->parameters; p != NULL; p = p->next)
2961 if (! debug_write_type (info, fns, fhandle, p->type,
2962 (struct debug_name *) NULL)
2963 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2967 for (b = function->blocks; b != NULL; b = b->next)
2969 if (! debug_write_block (info, fns, fhandle, b))
2973 return (*fns->end_function) (fhandle);
2976 /* Write out information for a block. */
2979 debug_write_block (info, fns, fhandle, block)
2980 struct debug_handle *info;
2981 const struct debug_write_fns *fns;
2983 struct debug_block *block;
2985 struct debug_name *n;
2986 struct debug_block *b;
2988 /* I can't see any point to writing out a block with no local
2989 variables, so we don't bother, except for the top level block. */
2990 if (block->locals != NULL || block->parent == NULL)
2992 if (! (*fns->start_block) (fhandle, block->start))
2996 if (block->locals != NULL)
2998 for (n = block->locals->list; n != NULL; n = n->next)
3000 if (! debug_write_name (info, fns, fhandle, n))
3005 for (b = block->children; b != NULL; b = b->next)
3007 if (! debug_write_block (info, fns, fhandle, b))
3011 if (block->locals != NULL || block->parent == NULL)
3013 if (! (*fns->end_block) (fhandle, block->end))
3020 /* Get the ID number for a class. If during the same call to
3021 debug_write we find a struct with the same definition with the same
3022 name, we use the same ID. This type of things happens because the
3023 same struct will be defined by multiple compilation units. */
3026 debug_set_class_id (info, tag, type)
3027 struct debug_handle *info;
3029 struct debug_type *type;
3031 struct debug_class_type *c;
3032 struct debug_class_id *l;
3034 assert (type->kind == DEBUG_KIND_STRUCT
3035 || type->kind == DEBUG_KIND_UNION
3036 || type->kind == DEBUG_KIND_CLASS
3037 || type->kind == DEBUG_KIND_UNION_CLASS);
3041 if (c->id > info->base_id)
3044 for (l = info->id_list; l != NULL; l = l->next)
3046 if (l->type->kind != type->kind)
3057 || l->tag[0] != tag[0]
3058 || strcmp (l->tag, tag) != 0)
3062 if (debug_type_samep (info, l->type, type))
3064 c->id = l->type->u.kclass->id;
3069 /* There are no identical types. Use a new ID, and add it to the
3072 c->id = info->class_id;
3074 l = (struct debug_class_id *) xmalloc (sizeof *l);
3075 memset (l, 0, sizeof *l);
3080 l->next = info->id_list;
3086 /* See if two types are the same. At this point, we don't care about
3087 tags and the like. */
3090 debug_type_samep (info, t1, t2)
3091 struct debug_handle *info;
3092 struct debug_type *t1;
3093 struct debug_type *t2;
3095 struct debug_type_compare_list *l;
3096 struct debug_type_compare_list top;
3099 while (t1->kind == DEBUG_KIND_INDIRECT)
3101 t1 = *t1->u.kindirect->slot;
3105 while (t2->kind == DEBUG_KIND_INDIRECT)
3107 t2 = *t2->u.kindirect->slot;
3115 /* As a special case, permit a typedef to match a tag, since C++
3116 debugging output will sometimes add a typedef where C debugging
3118 if (t1->kind == DEBUG_KIND_NAMED
3119 && t2->kind == DEBUG_KIND_TAGGED)
3120 return debug_type_samep (info, t1->u.knamed->type, t2);
3121 else if (t1->kind == DEBUG_KIND_TAGGED
3122 && t2->kind == DEBUG_KIND_NAMED)
3123 return debug_type_samep (info, t1, t2->u.knamed->type);
3125 if (t1->kind != t2->kind
3126 || t1->size != t2->size)
3129 /* Get rid of the trivial cases first. */
3134 case DEBUG_KIND_VOID:
3135 case DEBUG_KIND_FLOAT:
3136 case DEBUG_KIND_COMPLEX:
3137 case DEBUG_KIND_BOOL:
3139 case DEBUG_KIND_INT:
3140 return t1->u.kint == t2->u.kint;
3143 /* We have to avoid an infinite recursion. We do this by keeping a
3144 list of types which we are comparing. We just keep the list on
3145 the stack. If we encounter a pair of types we are currently
3146 comparing, we just assume that they are equal. */
3147 for (l = info->compare_list; l != NULL; l = l->next)
3149 if (l->t1 == t1 && l->t2 == t2)
3155 top.next = info->compare_list;
3156 info->compare_list = ⊤
3165 case DEBUG_KIND_STRUCT:
3166 case DEBUG_KIND_UNION:
3167 case DEBUG_KIND_CLASS:
3168 case DEBUG_KIND_UNION_CLASS:
3169 if (t1->u.kclass == NULL)
3170 ret = t2->u.kclass == NULL;
3171 else if (t2->u.kclass == NULL)
3173 else if (t1->u.kclass->id > info->base_id
3174 && t1->u.kclass->id == t2->u.kclass->id)
3177 ret = debug_class_type_samep (info, t1, t2);
3180 case DEBUG_KIND_ENUM:
3181 if (t1->u.kenum == NULL)
3182 ret = t2->u.kenum == NULL;
3183 else if (t2->u.kenum == NULL)
3187 const char **pn1, **pn2;
3188 bfd_signed_vma *pv1, *pv2;
3190 pn1 = t1->u.kenum->names;
3191 pn2 = t2->u.kenum->names;
3192 pv1 = t1->u.kenum->values;
3193 pv2 = t2->u.kenum->values;
3194 while (*pn1 != NULL && *pn2 != NULL)
3198 || strcmp (*pn1, *pn2) != 0)
3205 ret = *pn1 == NULL && *pn2 == NULL;
3209 case DEBUG_KIND_POINTER:
3210 ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
3213 case DEBUG_KIND_FUNCTION:
3214 if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
3215 || ! debug_type_samep (info, t1->u.kfunction->return_type,
3216 t2->u.kfunction->return_type)
3217 || ((t1->u.kfunction->arg_types == NULL)
3218 != (t2->u.kfunction->arg_types == NULL)))
3220 else if (t1->u.kfunction->arg_types == NULL)
3224 struct debug_type **a1, **a2;
3226 a1 = t1->u.kfunction->arg_types;
3227 a2 = t2->u.kfunction->arg_types;
3228 while (*a1 != NULL && *a2 != NULL)
3229 if (! debug_type_samep (info, *a1, *a2))
3231 ret = *a1 == NULL && *a2 == NULL;
3235 case DEBUG_KIND_REFERENCE:
3236 ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
3239 case DEBUG_KIND_RANGE:
3240 ret = (t1->u.krange->lower == t2->u.krange->lower
3241 && t1->u.krange->upper == t2->u.krange->upper
3242 && debug_type_samep (info, t1->u.krange->type,
3243 t2->u.krange->type));
3245 case DEBUG_KIND_ARRAY:
3246 ret = (t1->u.karray->lower == t2->u.karray->lower
3247 && t1->u.karray->upper == t2->u.karray->upper
3248 && t1->u.karray->stringp == t2->u.karray->stringp
3249 && debug_type_samep (info, t1->u.karray->element_type,
3250 t2->u.karray->element_type));
3253 case DEBUG_KIND_SET:
3254 ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
3255 && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
3258 case DEBUG_KIND_OFFSET:
3259 ret = (debug_type_samep (info, t1->u.koffset->base_type,
3260 t2->u.koffset->base_type)
3261 && debug_type_samep (info, t1->u.koffset->target_type,
3262 t2->u.koffset->target_type));
3265 case DEBUG_KIND_METHOD:
3266 if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
3267 || ! debug_type_samep (info, t1->u.kmethod->return_type,
3268 t2->u.kmethod->return_type)
3269 || ! debug_type_samep (info, t1->u.kmethod->domain_type,
3270 t2->u.kmethod->domain_type)
3271 || ((t1->u.kmethod->arg_types == NULL)
3272 != (t2->u.kmethod->arg_types == NULL)))
3274 else if (t1->u.kmethod->arg_types == NULL)
3278 struct debug_type **a1, **a2;
3280 a1 = t1->u.kmethod->arg_types;
3281 a2 = t2->u.kmethod->arg_types;
3282 while (*a1 != NULL && *a2 != NULL)
3283 if (! debug_type_samep (info, *a1, *a2))
3285 ret = *a1 == NULL && *a2 == NULL;
3289 case DEBUG_KIND_CONST:
3290 ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
3293 case DEBUG_KIND_VOLATILE:
3294 ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
3297 case DEBUG_KIND_NAMED:
3298 case DEBUG_KIND_TAGGED:
3299 ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
3300 && debug_type_samep (info, t1->u.knamed->type,
3301 t2->u.knamed->type));
3305 info->compare_list = top.next;
3310 /* See if two classes are the same. This is a subroutine of
3311 debug_type_samep. */
3314 debug_class_type_samep (info, t1, t2)
3315 struct debug_handle *info;
3316 struct debug_type *t1;
3317 struct debug_type *t2;
3319 struct debug_class_type *c1, *c2;
3324 if ((c1->fields == NULL) != (c2->fields == NULL)
3325 || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
3326 || (c1->methods == NULL) != (c2->methods == NULL)
3327 || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
3330 if (c1->fields != NULL)
3332 struct debug_field **pf1, **pf2;
3334 for (pf1 = c1->fields, pf2 = c2->fields;
3335 *pf1 != NULL && *pf2 != NULL;
3338 struct debug_field *f1, *f2;
3342 if (f1->name[0] != f2->name[0]
3343 || f1->visibility != f2->visibility
3344 || f1->static_member != f2->static_member)
3346 if (f1->static_member)
3348 if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
3353 if (f1->u.f.bitpos != f2->u.f.bitpos
3354 || f1->u.f.bitsize != f2->u.f.bitsize)
3357 /* We do the checks which require function calls last. We
3358 don't require that the types of fields have the same
3359 names, since that sometimes fails in the presence of
3360 typedefs and we really don't care. */
3361 if (strcmp (f1->name, f2->name) != 0
3362 || ! debug_type_samep (info,
3363 debug_get_real_type ((PTR) info,
3365 debug_get_real_type ((PTR) info,
3369 if (*pf1 != NULL || *pf2 != NULL)
3373 if (c1->vptrbase != NULL)
3375 if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
3379 if (c1->baseclasses != NULL)
3381 struct debug_baseclass **pb1, **pb2;
3383 for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
3384 *pb1 != NULL && *pb2 != NULL;
3387 struct debug_baseclass *b1, *b2;
3391 if (b1->bitpos != b2->bitpos
3392 || b1->virtual != b2->virtual
3393 || b1->visibility != b2->visibility
3394 || ! debug_type_samep (info, b1->type, b2->type))
3397 if (*pb1 != NULL || *pb2 != NULL)
3401 if (c1->methods != NULL)
3403 struct debug_method **pm1, **pm2;
3405 for (pm1 = c1->methods, pm2 = c2->methods;
3406 *pm1 != NULL && *pm2 != NULL;
3409 struct debug_method *m1, *m2;
3413 if (m1->name[0] != m2->name[0]
3414 || strcmp (m1->name, m2->name) != 0
3415 || (m1->variants == NULL) != (m2->variants == NULL))
3417 if (m1->variants == NULL)
3419 struct debug_method_variant **pv1, **pv2;
3421 for (pv1 = m1->variants, pv2 = m2->variants;
3422 *pv1 != NULL && *pv2 != NULL;
3425 struct debug_method_variant *v1, *v2;
3429 if (v1->physname[0] != v2->physname[0]
3430 || v1->visibility != v2->visibility
3431 || v1->constp != v2->constp
3432 || v1->volatilep != v2->volatilep
3433 || v1->voffset != v2->voffset
3434 || (v1->context == NULL) != (v2->context == NULL)
3435 || strcmp (v1->physname, v2->physname) != 0
3436 || ! debug_type_samep (info, v1->type, v2->type))
3438 if (v1->context != NULL)
3440 if (! debug_type_samep (info, v1->context,
3445 if (*pv1 != NULL || *pv2 != NULL)
3449 if (*pm1 != NULL || *pm2 != NULL)