Separate entries for common file changes so the automerge can find them.
[binutils.git] / binutils / debug.c
blob5d46b7810802537a27587d6b352b5579d3240cbf
1 /* debug.c -- Handle generic debugging information.
2 Copyright 1995, 1996, 1997, 1998, 2000, 2002, 2003 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
20 02111-1307, USA. */
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 converter from stabs to HP IEEE-695 debugging
26 format. */
28 #include <stdio.h>
29 #include <assert.h>
31 #include "bfd.h"
32 #include "bucomm.h"
33 #include "libiberty.h"
34 #include "debug.h"
36 /* Global information we keep for debugging. A pointer to this
37 structure is the debugging handle passed to all the routines. */
39 struct debug_handle
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. */
54 unsigned int mark;
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. */
58 unsigned int base_id;
59 /* The current line number in debug_write. */
60 struct debug_lineno *current_write_lineno;
61 unsigned int current_write_lineno_index;
62 /* A list of classes which have assigned ID's during debug_write.
63 This is linked through the next_id field of debug_class_type. */
64 struct debug_class_id *id_list;
65 /* A list used to avoid recursion during debug_type_samep. */
66 struct debug_type_compare_list *compare_list;
69 /* Information we keep for a single compilation unit. */
71 struct debug_unit
73 /* The next compilation unit. */
74 struct debug_unit *next;
75 /* A list of files included in this compilation unit. The first
76 file is always the main one, and that is where the main file name
77 is stored. */
78 struct debug_file *files;
79 /* Line number information for this compilation unit. This is not
80 stored by function, because assembler code may have line number
81 information without function information. */
82 struct debug_lineno *linenos;
85 /* Information kept for a single source file. */
87 struct debug_file
89 /* The next source file in this compilation unit. */
90 struct debug_file *next;
91 /* The name of the source file. */
92 const char *filename;
93 /* Global functions, variables, types, etc. */
94 struct debug_namespace *globals;
97 /* A type. */
99 struct debug_type
101 /* Kind of type. */
102 enum debug_type_kind kind;
103 /* Size of type (0 if not known). */
104 unsigned int size;
105 /* Type which is a pointer to this type. */
106 debug_type pointer;
107 /* Tagged union with additional information about the type. */
108 union
110 /* DEBUG_KIND_INDIRECT. */
111 struct debug_indirect_type *kindirect;
112 /* DEBUG_KIND_INT. */
113 /* Whether the integer is unsigned. */
114 bfd_boolean kint;
115 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
116 DEBUG_KIND_UNION_CLASS. */
117 struct debug_class_type *kclass;
118 /* DEBUG_KIND_ENUM. */
119 struct debug_enum_type *kenum;
120 /* DEBUG_KIND_POINTER. */
121 struct debug_type *kpointer;
122 /* DEBUG_KIND_FUNCTION. */
123 struct debug_function_type *kfunction;
124 /* DEBUG_KIND_REFERENCE. */
125 struct debug_type *kreference;
126 /* DEBUG_KIND_RANGE. */
127 struct debug_range_type *krange;
128 /* DEBUG_KIND_ARRAY. */
129 struct debug_array_type *karray;
130 /* DEBUG_KIND_SET. */
131 struct debug_set_type *kset;
132 /* DEBUG_KIND_OFFSET. */
133 struct debug_offset_type *koffset;
134 /* DEBUG_KIND_METHOD. */
135 struct debug_method_type *kmethod;
136 /* DEBUG_KIND_CONST. */
137 struct debug_type *kconst;
138 /* DEBUG_KIND_VOLATILE. */
139 struct debug_type *kvolatile;
140 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
141 struct debug_named_type *knamed;
142 } u;
145 /* Information kept for an indirect type. */
147 struct debug_indirect_type
149 /* Slot where the final type will appear. */
150 debug_type *slot;
151 /* Tag. */
152 const char *tag;
155 /* Information kept for a struct, union, or class. */
157 struct debug_class_type
159 /* NULL terminated array of fields. */
160 debug_field *fields;
161 /* A mark field which indicates whether the struct has already been
162 printed. */
163 unsigned int mark;
164 /* This is used to uniquely identify unnamed structs when printing. */
165 unsigned int id;
166 /* The remaining fields are only used for DEBUG_KIND_CLASS and
167 DEBUG_KIND_UNION_CLASS. */
168 /* NULL terminated array of base classes. */
169 debug_baseclass *baseclasses;
170 /* NULL terminated array of methods. */
171 debug_method *methods;
172 /* The type of the class providing the virtual function table for
173 this class. This may point to the type itself. */
174 debug_type vptrbase;
177 /* Information kept for an enum. */
179 struct debug_enum_type
181 /* NULL terminated array of names. */
182 const char **names;
183 /* Array of corresponding values. */
184 bfd_signed_vma *values;
187 /* Information kept for a function. FIXME: We should be able to
188 record the parameter types. */
190 struct debug_function_type
192 /* Return type. */
193 debug_type return_type;
194 /* NULL terminated array of argument types. */
195 debug_type *arg_types;
196 /* Whether the function takes a variable number of arguments. */
197 bfd_boolean varargs;
200 /* Information kept for a range. */
202 struct debug_range_type
204 /* Range base type. */
205 debug_type type;
206 /* Lower bound. */
207 bfd_signed_vma lower;
208 /* Upper bound. */
209 bfd_signed_vma upper;
212 /* Information kept for an array. */
214 struct debug_array_type
216 /* Element type. */
217 debug_type element_type;
218 /* Range type. */
219 debug_type range_type;
220 /* Lower bound. */
221 bfd_signed_vma lower;
222 /* Upper bound. */
223 bfd_signed_vma upper;
224 /* Whether this array is really a string. */
225 bfd_boolean stringp;
228 /* Information kept for a set. */
230 struct debug_set_type
232 /* Base type. */
233 debug_type type;
234 /* Whether this set is really a bitstring. */
235 bfd_boolean bitstringp;
238 /* Information kept for an offset type (a based pointer). */
240 struct debug_offset_type
242 /* The type the pointer is an offset from. */
243 debug_type base_type;
244 /* The type the pointer points to. */
245 debug_type target_type;
248 /* Information kept for a method type. */
250 struct debug_method_type
252 /* The return type. */
253 debug_type return_type;
254 /* The object type which this method is for. */
255 debug_type domain_type;
256 /* A NULL terminated array of argument types. */
257 debug_type *arg_types;
258 /* Whether the method takes a variable number of arguments. */
259 bfd_boolean varargs;
262 /* Information kept for a named type. */
264 struct debug_named_type
266 /* Name. */
267 struct debug_name *name;
268 /* Real type. */
269 debug_type type;
272 /* A field in a struct or union. */
274 struct debug_field
276 /* Name of the field. */
277 const char *name;
278 /* Type of the field. */
279 struct debug_type *type;
280 /* Visibility of the field. */
281 enum debug_visibility visibility;
282 /* Whether this is a static member. */
283 bfd_boolean static_member;
284 union
286 /* If static_member is false. */
287 struct
289 /* Bit position of the field in the struct. */
290 unsigned int bitpos;
291 /* Size of the field in bits. */
292 unsigned int bitsize;
293 } f;
294 /* If static_member is true. */
295 struct
297 const char *physname;
298 } s;
299 } u;
302 /* A base class for an object. */
304 struct debug_baseclass
306 /* Type of the base class. */
307 struct debug_type *type;
308 /* Bit position of the base class in the object. */
309 unsigned int bitpos;
310 /* Whether the base class is virtual. */
311 bfd_boolean virtual;
312 /* Visibility of the base class. */
313 enum debug_visibility visibility;
316 /* A method of an object. */
318 struct debug_method
320 /* The name of the method. */
321 const char *name;
322 /* A NULL terminated array of different types of variants. */
323 struct debug_method_variant **variants;
326 /* The variants of a method function of an object. These indicate
327 which method to run. */
329 struct debug_method_variant
331 /* The physical name of the function. */
332 const char *physname;
333 /* The type of the function. */
334 struct debug_type *type;
335 /* The visibility of the function. */
336 enum debug_visibility visibility;
337 /* Whether the function is const. */
338 bfd_boolean constp;
339 /* Whether the function is volatile. */
340 bfd_boolean volatilep;
341 /* The offset to the function in the virtual function table. */
342 bfd_vma voffset;
343 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
344 #define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
345 /* Context of a virtual method function. */
346 struct debug_type *context;
349 /* A variable. This is the information we keep for a variable object.
350 This has no name; a name is associated with a variable in a
351 debug_name structure. */
353 struct debug_variable
355 /* Kind of variable. */
356 enum debug_var_kind kind;
357 /* Type. */
358 debug_type type;
359 /* Value. The interpretation of the value depends upon kind. */
360 bfd_vma val;
363 /* A function. This has no name; a name is associated with a function
364 in a debug_name structure. */
366 struct debug_function
368 /* Return type. */
369 debug_type return_type;
370 /* Parameter information. */
371 struct debug_parameter *parameters;
372 /* Block information. The first structure on the list is the main
373 block of the function, and describes function local variables. */
374 struct debug_block *blocks;
377 /* A function parameter. */
379 struct debug_parameter
381 /* Next parameter. */
382 struct debug_parameter *next;
383 /* Name. */
384 const char *name;
385 /* Type. */
386 debug_type type;
387 /* Kind. */
388 enum debug_parm_kind kind;
389 /* Value (meaning depends upon kind). */
390 bfd_vma val;
393 /* A typed constant. */
395 struct debug_typed_constant
397 /* Type. */
398 debug_type type;
399 /* Value. FIXME: We may eventually need to support non-integral
400 values. */
401 bfd_vma val;
404 /* Information about a block within a function. */
406 struct debug_block
408 /* Next block with the same parent. */
409 struct debug_block *next;
410 /* Parent block. */
411 struct debug_block *parent;
412 /* List of child blocks. */
413 struct debug_block *children;
414 /* Start address of the block. */
415 bfd_vma start;
416 /* End address of the block. */
417 bfd_vma end;
418 /* Local variables. */
419 struct debug_namespace *locals;
422 /* Line number information we keep for a compilation unit. FIXME:
423 This structure is easy to create, but can be very space
424 inefficient. */
426 struct debug_lineno
428 /* More line number information for this block. */
429 struct debug_lineno *next;
430 /* Source file. */
431 struct debug_file *file;
432 /* Line numbers, terminated by a -1 or the end of the array. */
433 #define DEBUG_LINENO_COUNT 10
434 unsigned long linenos[DEBUG_LINENO_COUNT];
435 /* Addresses for the line numbers. */
436 bfd_vma addrs[DEBUG_LINENO_COUNT];
439 /* A namespace. This is a mapping from names to objects. FIXME: This
440 should be implemented as a hash table. */
442 struct debug_namespace
444 /* List of items in this namespace. */
445 struct debug_name *list;
446 /* Pointer to where the next item in this namespace should go. */
447 struct debug_name **tail;
450 /* Kinds of objects that appear in a namespace. */
452 enum debug_object_kind
454 /* A type. */
455 DEBUG_OBJECT_TYPE,
456 /* A tagged type (really a different sort of namespace). */
457 DEBUG_OBJECT_TAG,
458 /* A variable. */
459 DEBUG_OBJECT_VARIABLE,
460 /* A function. */
461 DEBUG_OBJECT_FUNCTION,
462 /* An integer constant. */
463 DEBUG_OBJECT_INT_CONSTANT,
464 /* A floating point constant. */
465 DEBUG_OBJECT_FLOAT_CONSTANT,
466 /* A typed constant. */
467 DEBUG_OBJECT_TYPED_CONSTANT
470 /* Linkage of an object that appears in a namespace. */
472 enum debug_object_linkage
474 /* Local variable. */
475 DEBUG_LINKAGE_AUTOMATIC,
476 /* Static--either file static or function static, depending upon the
477 namespace is. */
478 DEBUG_LINKAGE_STATIC,
479 /* Global. */
480 DEBUG_LINKAGE_GLOBAL,
481 /* No linkage. */
482 DEBUG_LINKAGE_NONE
485 /* A name in a namespace. */
487 struct debug_name
489 /* Next name in this namespace. */
490 struct debug_name *next;
491 /* Name. */
492 const char *name;
493 /* Mark. This is used by debug_write. */
494 unsigned int mark;
495 /* Kind of object. */
496 enum debug_object_kind kind;
497 /* Linkage of object. */
498 enum debug_object_linkage linkage;
499 /* Tagged union with additional information about the object. */
500 union
502 /* DEBUG_OBJECT_TYPE. */
503 struct debug_type *type;
504 /* DEBUG_OBJECT_TAG. */
505 struct debug_type *tag;
506 /* DEBUG_OBJECT_VARIABLE. */
507 struct debug_variable *variable;
508 /* DEBUG_OBJECT_FUNCTION. */
509 struct debug_function *function;
510 /* DEBUG_OBJECT_INT_CONSTANT. */
511 bfd_vma int_constant;
512 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
513 double float_constant;
514 /* DEBUG_OBJECT_TYPED_CONSTANT. */
515 struct debug_typed_constant *typed_constant;
516 } u;
519 /* During debug_write, a linked list of these structures is used to
520 keep track of ID numbers that have been assigned to classes. */
522 struct debug_class_id
524 /* Next ID number. */
525 struct debug_class_id *next;
526 /* The type with the ID. */
527 struct debug_type *type;
528 /* The tag; NULL if no tag. */
529 const char *tag;
532 /* During debug_type_samep, a linked list of these structures is kept
533 on the stack to avoid infinite recursion. */
535 struct debug_type_compare_list
537 /* Next type on list. */
538 struct debug_type_compare_list *next;
539 /* The types we are comparing. */
540 struct debug_type *t1;
541 struct debug_type *t2;
544 /* During debug_get_real_type, a linked list of these structures is
545 kept on the stack to avoid infinite recursion. */
547 struct debug_type_real_list
549 /* Next type on list. */
550 struct debug_type_real_list *next;
551 /* The type we are checking. */
552 struct debug_type *t;
555 /* Local functions. */
557 static void debug_error (const char *);
558 static struct debug_name *debug_add_to_namespace
559 (struct debug_handle *, struct debug_namespace **, const char *,
560 enum debug_object_kind, enum debug_object_linkage);
561 static struct debug_name *debug_add_to_current_namespace
562 (struct debug_handle *, const char *, enum debug_object_kind,
563 enum debug_object_linkage);
564 static struct debug_type *debug_make_type
565 (struct debug_handle *, enum debug_type_kind, unsigned int);
566 static struct debug_type *debug_get_real_type
567 (void *, debug_type, struct debug_type_real_list *);
568 static bfd_boolean debug_write_name
569 (struct debug_handle *, const struct debug_write_fns *, void *,
570 struct debug_name *);
571 static bfd_boolean debug_write_type
572 (struct debug_handle *, const struct debug_write_fns *, void *,
573 struct debug_type *, struct debug_name *);
574 static bfd_boolean debug_write_class_type
575 (struct debug_handle *, const struct debug_write_fns *, void *,
576 struct debug_type *, const char *);
577 static bfd_boolean debug_write_function
578 (struct debug_handle *, const struct debug_write_fns *, void *,
579 const char *, enum debug_object_linkage, struct debug_function *);
580 static bfd_boolean debug_write_block
581 (struct debug_handle *, const struct debug_write_fns *, void *,
582 struct debug_block *);
583 static bfd_boolean debug_write_linenos
584 (struct debug_handle *, const struct debug_write_fns *, void *, bfd_vma);
585 static bfd_boolean debug_set_class_id
586 (struct debug_handle *, const char *, struct debug_type *);
587 static bfd_boolean debug_type_samep
588 (struct debug_handle *, struct debug_type *, struct debug_type *);
589 static bfd_boolean debug_class_type_samep
590 (struct debug_handle *, struct debug_type *, struct debug_type *);
592 /* Issue an error message. */
594 static void
595 debug_error (const char *message)
597 fprintf (stderr, "%s\n", message);
600 /* Add an object to a namespace. */
602 static struct debug_name *
603 debug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
604 struct debug_namespace **nsp, const char *name,
605 enum debug_object_kind kind,
606 enum debug_object_linkage linkage)
608 struct debug_name *n;
609 struct debug_namespace *ns;
611 n = (struct debug_name *) xmalloc (sizeof *n);
612 memset (n, 0, sizeof *n);
614 n->name = name;
615 n->kind = kind;
616 n->linkage = linkage;
618 ns = *nsp;
619 if (ns == NULL)
621 ns = (struct debug_namespace *) xmalloc (sizeof *ns);
622 memset (ns, 0, sizeof *ns);
624 ns->tail = &ns->list;
626 *nsp = ns;
629 *ns->tail = n;
630 ns->tail = &n->next;
632 return n;
635 /* Add an object to the current namespace. */
637 static struct debug_name *
638 debug_add_to_current_namespace (struct debug_handle *info, const char *name,
639 enum debug_object_kind kind,
640 enum debug_object_linkage linkage)
642 struct debug_namespace **nsp;
644 if (info->current_unit == NULL
645 || info->current_file == NULL)
647 debug_error (_("debug_add_to_current_namespace: no current file"));
648 return NULL;
651 if (info->current_block != NULL)
652 nsp = &info->current_block->locals;
653 else
654 nsp = &info->current_file->globals;
656 return debug_add_to_namespace (info, nsp, name, kind, linkage);
659 /* Return a handle for debugging information. */
661 void *
662 debug_init (void)
664 struct debug_handle *ret;
666 ret = (struct debug_handle *) xmalloc (sizeof *ret);
667 memset (ret, 0, sizeof *ret);
668 return (void *) ret;
671 /* Set the source filename. This implicitly starts a new compilation
672 unit. */
674 bfd_boolean
675 debug_set_filename (void *handle, const char *name)
677 struct debug_handle *info = (struct debug_handle *) handle;
678 struct debug_file *nfile;
679 struct debug_unit *nunit;
681 if (name == NULL)
682 name = "";
684 nfile = (struct debug_file *) xmalloc (sizeof *nfile);
685 memset (nfile, 0, sizeof *nfile);
687 nfile->filename = name;
689 nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
690 memset (nunit, 0, sizeof *nunit);
692 nunit->files = nfile;
693 info->current_file = nfile;
695 if (info->current_unit != NULL)
696 info->current_unit->next = nunit;
697 else
699 assert (info->units == NULL);
700 info->units = nunit;
703 info->current_unit = nunit;
705 info->current_function = NULL;
706 info->current_block = NULL;
707 info->current_lineno = NULL;
709 return TRUE;
712 /* Change source files to the given file name. This is used for
713 include files in a single compilation unit. */
715 bfd_boolean
716 debug_start_source (void *handle, const char *name)
718 struct debug_handle *info = (struct debug_handle *) handle;
719 struct debug_file *f, **pf;
721 if (name == NULL)
722 name = "";
724 if (info->current_unit == NULL)
726 debug_error (_("debug_start_source: no debug_set_filename call"));
727 return FALSE;
730 for (f = info->current_unit->files; f != NULL; f = f->next)
732 if (f->filename[0] == name[0]
733 && f->filename[1] == name[1]
734 && strcmp (f->filename, name) == 0)
736 info->current_file = f;
737 return TRUE;
741 f = (struct debug_file *) xmalloc (sizeof *f);
742 memset (f, 0, sizeof *f);
744 f->filename = name;
746 for (pf = &info->current_file->next;
747 *pf != NULL;
748 pf = &(*pf)->next)
750 *pf = f;
752 info->current_file = f;
754 return TRUE;
757 /* Record a function definition. This implicitly starts a function
758 block. The debug_type argument is the type of the return value.
759 The boolean indicates whether the function is globally visible.
760 The bfd_vma is the address of the start of the function. Currently
761 the parameter types are specified by calls to
762 debug_record_parameter. FIXME: There is no way to specify nested
763 functions. */
765 bfd_boolean
766 debug_record_function (void *handle, const char *name,
767 debug_type return_type, bfd_boolean global,
768 bfd_vma addr)
770 struct debug_handle *info = (struct debug_handle *) handle;
771 struct debug_function *f;
772 struct debug_block *b;
773 struct debug_name *n;
775 if (name == NULL)
776 name = "";
777 if (return_type == NULL)
778 return FALSE;
780 if (info->current_unit == NULL)
782 debug_error (_("debug_record_function: no debug_set_filename call"));
783 return FALSE;
786 f = (struct debug_function *) xmalloc (sizeof *f);
787 memset (f, 0, sizeof *f);
789 f->return_type = return_type;
791 b = (struct debug_block *) xmalloc (sizeof *b);
792 memset (b, 0, sizeof *b);
794 b->start = addr;
795 b->end = (bfd_vma) -1;
797 f->blocks = b;
799 info->current_function = f;
800 info->current_block = b;
802 /* FIXME: If we could handle nested functions, this would be the
803 place: we would want to use a different namespace. */
804 n = debug_add_to_namespace (info,
805 &info->current_file->globals,
806 name,
807 DEBUG_OBJECT_FUNCTION,
808 (global
809 ? DEBUG_LINKAGE_GLOBAL
810 : DEBUG_LINKAGE_STATIC));
811 if (n == NULL)
812 return FALSE;
814 n->u.function = f;
816 return TRUE;
819 /* Record a parameter for the current function. */
821 bfd_boolean
822 debug_record_parameter (void *handle, const char *name, debug_type type,
823 enum debug_parm_kind kind, bfd_vma val)
825 struct debug_handle *info = (struct debug_handle *) handle;
826 struct debug_parameter *p, **pp;
828 if (name == NULL || type == NULL)
829 return FALSE;
831 if (info->current_unit == NULL
832 || info->current_function == NULL)
834 debug_error (_("debug_record_parameter: no current function"));
835 return FALSE;
838 p = (struct debug_parameter *) xmalloc (sizeof *p);
839 memset (p, 0, sizeof *p);
841 p->name = name;
842 p->type = type;
843 p->kind = kind;
844 p->val = val;
846 for (pp = &info->current_function->parameters;
847 *pp != NULL;
848 pp = &(*pp)->next)
850 *pp = p;
852 return TRUE;
855 /* End a function. FIXME: This should handle function nesting. */
857 bfd_boolean
858 debug_end_function (void *handle, bfd_vma addr)
860 struct debug_handle *info = (struct debug_handle *) handle;
862 if (info->current_unit == NULL
863 || info->current_block == NULL
864 || info->current_function == NULL)
866 debug_error (_("debug_end_function: no current function"));
867 return FALSE;
870 if (info->current_block->parent != NULL)
872 debug_error (_("debug_end_function: some blocks were not closed"));
873 return FALSE;
876 info->current_block->end = addr;
878 info->current_function = NULL;
879 info->current_block = NULL;
881 return TRUE;
884 /* Start a block in a function. All local information will be
885 recorded in this block, until the matching call to debug_end_block.
886 debug_start_block and debug_end_block may be nested. The bfd_vma
887 argument is the address at which this block starts. */
889 bfd_boolean
890 debug_start_block (void *handle, bfd_vma addr)
892 struct debug_handle *info = (struct debug_handle *) handle;
893 struct debug_block *b, **pb;
895 /* We must always have a current block: debug_record_function sets
896 one up. */
897 if (info->current_unit == NULL
898 || info->current_block == NULL)
900 debug_error (_("debug_start_block: no current block"));
901 return FALSE;
904 b = (struct debug_block *) xmalloc (sizeof *b);
905 memset (b, 0, sizeof *b);
907 b->parent = info->current_block;
908 b->start = addr;
909 b->end = (bfd_vma) -1;
911 /* This new block is a child of the current block. */
912 for (pb = &info->current_block->children;
913 *pb != NULL;
914 pb = &(*pb)->next)
916 *pb = b;
918 info->current_block = b;
920 return TRUE;
923 /* Finish a block in a function. This matches the call to
924 debug_start_block. The argument is the address at which this block
925 ends. */
927 bfd_boolean
928 debug_end_block (void *handle, bfd_vma addr)
930 struct debug_handle *info = (struct debug_handle *) handle;
931 struct debug_block *parent;
933 if (info->current_unit == NULL
934 || info->current_block == NULL)
936 debug_error (_("debug_end_block: no current block"));
937 return FALSE;
940 parent = info->current_block->parent;
941 if (parent == NULL)
943 debug_error (_("debug_end_block: attempt to close top level block"));
944 return FALSE;
947 info->current_block->end = addr;
949 info->current_block = parent;
951 return TRUE;
954 /* Associate a line number in the current source file and function
955 with a given address. */
957 bfd_boolean
958 debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
960 struct debug_handle *info = (struct debug_handle *) handle;
961 struct debug_lineno *l;
962 unsigned int i;
964 if (info->current_unit == NULL)
966 debug_error (_("debug_record_line: no current unit"));
967 return FALSE;
970 l = info->current_lineno;
971 if (l != NULL && l->file == info->current_file)
973 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
975 if (l->linenos[i] == (unsigned long) -1)
977 l->linenos[i] = lineno;
978 l->addrs[i] = addr;
979 return TRUE;
984 /* If we get here, then either 1) there is no current_lineno
985 structure, which means this is the first line number in this
986 compilation unit, 2) the current_lineno structure is for a
987 different file, or 3) the current_lineno structure is full.
988 Regardless, we want to allocate a new debug_lineno structure, put
989 it in the right place, and make it the new current_lineno
990 structure. */
992 l = (struct debug_lineno *) xmalloc (sizeof *l);
993 memset (l, 0, sizeof *l);
995 l->file = info->current_file;
996 l->linenos[0] = lineno;
997 l->addrs[0] = addr;
998 for (i = 1; i < DEBUG_LINENO_COUNT; i++)
999 l->linenos[i] = (unsigned long) -1;
1001 if (info->current_lineno != NULL)
1002 info->current_lineno->next = l;
1003 else
1004 info->current_unit->linenos = l;
1006 info->current_lineno = l;
1008 return TRUE;
1011 /* Start a named common block. This is a block of variables that may
1012 move in memory. */
1014 bfd_boolean
1015 debug_start_common_block (void *handle ATTRIBUTE_UNUSED,
1016 const char *name ATTRIBUTE_UNUSED)
1018 /* FIXME */
1019 debug_error (_("debug_start_common_block: not implemented"));
1020 return FALSE;
1023 /* End a named common block. */
1025 bfd_boolean
1026 debug_end_common_block (void *handle ATTRIBUTE_UNUSED,
1027 const char *name ATTRIBUTE_UNUSED)
1029 /* FIXME */
1030 debug_error (_("debug_end_common_block: not implemented"));
1031 return FALSE;
1034 /* Record a named integer constant. */
1036 bfd_boolean
1037 debug_record_int_const (void *handle, const char *name, bfd_vma val)
1039 struct debug_handle *info = (struct debug_handle *) handle;
1040 struct debug_name *n;
1042 if (name == NULL)
1043 return FALSE;
1045 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
1046 DEBUG_LINKAGE_NONE);
1047 if (n == NULL)
1048 return FALSE;
1050 n->u.int_constant = val;
1052 return TRUE;
1055 /* Record a named floating point constant. */
1057 bfd_boolean
1058 debug_record_float_const (void *handle, const char *name, double val)
1060 struct debug_handle *info = (struct debug_handle *) handle;
1061 struct debug_name *n;
1063 if (name == NULL)
1064 return FALSE;
1066 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
1067 DEBUG_LINKAGE_NONE);
1068 if (n == NULL)
1069 return FALSE;
1071 n->u.float_constant = val;
1073 return TRUE;
1076 /* Record a typed constant with an integral value. */
1078 bfd_boolean
1079 debug_record_typed_const (void *handle, const char *name, debug_type type,
1080 bfd_vma val)
1082 struct debug_handle *info = (struct debug_handle *) handle;
1083 struct debug_name *n;
1084 struct debug_typed_constant *tc;
1086 if (name == NULL || type == NULL)
1087 return FALSE;
1089 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
1090 DEBUG_LINKAGE_NONE);
1091 if (n == NULL)
1092 return FALSE;
1094 tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
1095 memset (tc, 0, sizeof *tc);
1097 tc->type = type;
1098 tc->val = val;
1100 n->u.typed_constant = tc;
1102 return TRUE;
1105 /* Record a label. */
1107 bfd_boolean
1108 debug_record_label (void *handle ATTRIBUTE_UNUSED,
1109 const char *name ATTRIBUTE_UNUSED,
1110 debug_type type ATTRIBUTE_UNUSED,
1111 bfd_vma addr ATTRIBUTE_UNUSED)
1113 /* FIXME. */
1114 debug_error (_("debug_record_label: not implemented"));
1115 return FALSE;
1118 /* Record a variable. */
1120 bfd_boolean
1121 debug_record_variable (void *handle, const char *name, debug_type type,
1122 enum debug_var_kind kind, bfd_vma val)
1124 struct debug_handle *info = (struct debug_handle *) handle;
1125 struct debug_namespace **nsp;
1126 enum debug_object_linkage linkage;
1127 struct debug_name *n;
1128 struct debug_variable *v;
1130 if (name == NULL || type == NULL)
1131 return FALSE;
1133 if (info->current_unit == NULL
1134 || info->current_file == NULL)
1136 debug_error (_("debug_record_variable: no current file"));
1137 return FALSE;
1140 if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
1142 nsp = &info->current_file->globals;
1143 if (kind == DEBUG_GLOBAL)
1144 linkage = DEBUG_LINKAGE_GLOBAL;
1145 else
1146 linkage = DEBUG_LINKAGE_STATIC;
1148 else
1150 if (info->current_block == NULL)
1151 nsp = &info->current_file->globals;
1152 else
1153 nsp = &info->current_block->locals;
1154 linkage = DEBUG_LINKAGE_AUTOMATIC;
1157 n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
1158 if (n == NULL)
1159 return FALSE;
1161 v = (struct debug_variable *) xmalloc (sizeof *v);
1162 memset (v, 0, sizeof *v);
1164 v->kind = kind;
1165 v->type = type;
1166 v->val = val;
1168 n->u.variable = v;
1170 return TRUE;
1173 /* Make a type with a given kind and size. */
1175 static struct debug_type *
1176 debug_make_type (struct debug_handle *info ATTRIBUTE_UNUSED,
1177 enum debug_type_kind kind, unsigned int size)
1179 struct debug_type *t;
1181 t = (struct debug_type *) xmalloc (sizeof *t);
1182 memset (t, 0, sizeof *t);
1184 t->kind = kind;
1185 t->size = size;
1187 return t;
1190 /* Make an indirect type which may be used as a placeholder for a type
1191 which is referenced before it is defined. */
1193 debug_type
1194 debug_make_indirect_type (void *handle, debug_type *slot, const char *tag)
1196 struct debug_handle *info = (struct debug_handle *) handle;
1197 struct debug_type *t;
1198 struct debug_indirect_type *i;
1200 t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
1201 if (t == NULL)
1202 return DEBUG_TYPE_NULL;
1204 i = (struct debug_indirect_type *) xmalloc (sizeof *i);
1205 memset (i, 0, sizeof *i);
1207 i->slot = slot;
1208 i->tag = tag;
1210 t->u.kindirect = i;
1212 return t;
1215 /* Make a void type. There is only one of these. */
1217 debug_type
1218 debug_make_void_type (void *handle)
1220 struct debug_handle *info = (struct debug_handle *) handle;
1222 return debug_make_type (info, DEBUG_KIND_VOID, 0);
1225 /* Make an integer type of a given size. The boolean argument is true
1226 if the integer is unsigned. */
1228 debug_type
1229 debug_make_int_type (void *handle, unsigned int size, bfd_boolean unsignedp)
1231 struct debug_handle *info = (struct debug_handle *) handle;
1232 struct debug_type *t;
1234 t = debug_make_type (info, DEBUG_KIND_INT, size);
1235 if (t == NULL)
1236 return DEBUG_TYPE_NULL;
1238 t->u.kint = unsignedp;
1240 return t;
1243 /* Make a floating point type of a given size. FIXME: On some
1244 platforms, like an Alpha, you probably need to be able to specify
1245 the format. */
1247 debug_type
1248 debug_make_float_type (void *handle, unsigned int size)
1250 struct debug_handle *info = (struct debug_handle *) handle;
1252 return debug_make_type (info, DEBUG_KIND_FLOAT, size);
1255 /* Make a boolean type of a given size. */
1257 debug_type
1258 debug_make_bool_type (void *handle, unsigned int size)
1260 struct debug_handle *info = (struct debug_handle *) handle;
1262 return debug_make_type (info, DEBUG_KIND_BOOL, size);
1265 /* Make a complex type of a given size. */
1267 debug_type
1268 debug_make_complex_type (void *handle, unsigned int size)
1270 struct debug_handle *info = (struct debug_handle *) handle;
1272 return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
1275 /* Make a structure type. The second argument is true for a struct,
1276 false for a union. The third argument is the size of the struct.
1277 The fourth argument is a NULL terminated array of fields. */
1279 debug_type
1280 debug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
1281 debug_field *fields)
1283 struct debug_handle *info = (struct debug_handle *) handle;
1284 struct debug_type *t;
1285 struct debug_class_type *c;
1287 t = debug_make_type (info,
1288 structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
1289 size);
1290 if (t == NULL)
1291 return DEBUG_TYPE_NULL;
1293 c = (struct debug_class_type *) xmalloc (sizeof *c);
1294 memset (c, 0, sizeof *c);
1296 c->fields = fields;
1298 t->u.kclass = c;
1300 return t;
1303 /* Make an object type. The first three arguments after the handle
1304 are the same as for debug_make_struct_type. The next arguments are
1305 a NULL terminated array of base classes, a NULL terminated array of
1306 methods, the type of the object holding the virtual function table
1307 if it is not this object, and a boolean which is true if this
1308 object has its own virtual function table. */
1310 debug_type
1311 debug_make_object_type (void *handle, bfd_boolean structp, bfd_vma size,
1312 debug_field *fields, debug_baseclass *baseclasses,
1313 debug_method *methods, debug_type vptrbase,
1314 bfd_boolean ownvptr)
1316 struct debug_handle *info = (struct debug_handle *) handle;
1317 struct debug_type *t;
1318 struct debug_class_type *c;
1320 t = debug_make_type (info,
1321 structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
1322 size);
1323 if (t == NULL)
1324 return DEBUG_TYPE_NULL;
1326 c = (struct debug_class_type *) xmalloc (sizeof *c);
1327 memset (c, 0, sizeof *c);
1329 c->fields = fields;
1330 c->baseclasses = baseclasses;
1331 c->methods = methods;
1332 if (ownvptr)
1333 c->vptrbase = t;
1334 else
1335 c->vptrbase = vptrbase;
1337 t->u.kclass = c;
1339 return t;
1342 /* Make an enumeration type. The arguments are a null terminated
1343 array of strings, and an array of corresponding values. */
1345 debug_type
1346 debug_make_enum_type (void *handle, const char **names,
1347 bfd_signed_vma *values)
1349 struct debug_handle *info = (struct debug_handle *) handle;
1350 struct debug_type *t;
1351 struct debug_enum_type *e;
1353 t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
1354 if (t == NULL)
1355 return DEBUG_TYPE_NULL;
1357 e = (struct debug_enum_type *) xmalloc (sizeof *e);
1358 memset (e, 0, sizeof *e);
1360 e->names = names;
1361 e->values = values;
1363 t->u.kenum = e;
1365 return t;
1368 /* Make a pointer to a given type. */
1370 debug_type
1371 debug_make_pointer_type (void *handle, debug_type type)
1373 struct debug_handle *info = (struct debug_handle *) handle;
1374 struct debug_type *t;
1376 if (type == NULL)
1377 return DEBUG_TYPE_NULL;
1379 if (type->pointer != DEBUG_TYPE_NULL)
1380 return type->pointer;
1382 t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
1383 if (t == NULL)
1384 return DEBUG_TYPE_NULL;
1386 t->u.kpointer = type;
1388 type->pointer = t;
1390 return t;
1393 /* Make a function returning a given type. FIXME: We should be able
1394 to record the parameter types. */
1396 debug_type
1397 debug_make_function_type (void *handle, debug_type type,
1398 debug_type *arg_types, bfd_boolean varargs)
1400 struct debug_handle *info = (struct debug_handle *) handle;
1401 struct debug_type *t;
1402 struct debug_function_type *f;
1404 if (type == NULL)
1405 return DEBUG_TYPE_NULL;
1407 t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
1408 if (t == NULL)
1409 return DEBUG_TYPE_NULL;
1411 f = (struct debug_function_type *) xmalloc (sizeof *f);
1412 memset (f, 0, sizeof *f);
1414 f->return_type = type;
1415 f->arg_types = arg_types;
1416 f->varargs = varargs;
1418 t->u.kfunction = f;
1420 return t;
1423 /* Make a reference to a given type. */
1425 debug_type
1426 debug_make_reference_type (void *handle, debug_type type)
1428 struct debug_handle *info = (struct debug_handle *) handle;
1429 struct debug_type *t;
1431 if (type == NULL)
1432 return DEBUG_TYPE_NULL;
1434 t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
1435 if (t == NULL)
1436 return DEBUG_TYPE_NULL;
1438 t->u.kreference = type;
1440 return t;
1443 /* Make a range of a given type from a lower to an upper bound. */
1445 debug_type
1446 debug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower,
1447 bfd_signed_vma upper)
1449 struct debug_handle *info = (struct debug_handle *) handle;
1450 struct debug_type *t;
1451 struct debug_range_type *r;
1453 if (type == NULL)
1454 return DEBUG_TYPE_NULL;
1456 t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
1457 if (t == NULL)
1458 return DEBUG_TYPE_NULL;
1460 r = (struct debug_range_type *) xmalloc (sizeof *r);
1461 memset (r, 0, sizeof *r);
1463 r->type = type;
1464 r->lower = lower;
1465 r->upper = upper;
1467 t->u.krange = r;
1469 return t;
1472 /* Make an array type. The second argument is the type of an element
1473 of the array. The third argument is the type of a range of the
1474 array. The fourth and fifth argument are the lower and upper
1475 bounds, respectively. The sixth argument is true if this array is
1476 actually a string, as in C. */
1478 debug_type
1479 debug_make_array_type (void *handle, debug_type element_type,
1480 debug_type range_type, bfd_signed_vma lower,
1481 bfd_signed_vma upper, bfd_boolean stringp)
1483 struct debug_handle *info = (struct debug_handle *) handle;
1484 struct debug_type *t;
1485 struct debug_array_type *a;
1487 if (element_type == NULL || range_type == NULL)
1488 return DEBUG_TYPE_NULL;
1490 t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
1491 if (t == NULL)
1492 return DEBUG_TYPE_NULL;
1494 a = (struct debug_array_type *) xmalloc (sizeof *a);
1495 memset (a, 0, sizeof *a);
1497 a->element_type = element_type;
1498 a->range_type = range_type;
1499 a->lower = lower;
1500 a->upper = upper;
1501 a->stringp = stringp;
1503 t->u.karray = a;
1505 return t;
1508 /* Make a set of a given type. For example, a Pascal set type. The
1509 boolean argument is true if this set is actually a bitstring, as in
1510 CHILL. */
1512 debug_type
1513 debug_make_set_type (void *handle, debug_type type, bfd_boolean bitstringp)
1515 struct debug_handle *info = (struct debug_handle *) handle;
1516 struct debug_type *t;
1517 struct debug_set_type *s;
1519 if (type == NULL)
1520 return DEBUG_TYPE_NULL;
1522 t = debug_make_type (info, DEBUG_KIND_SET, 0);
1523 if (t == NULL)
1524 return DEBUG_TYPE_NULL;
1526 s = (struct debug_set_type *) xmalloc (sizeof *s);
1527 memset (s, 0, sizeof *s);
1529 s->type = type;
1530 s->bitstringp = bitstringp;
1532 t->u.kset = s;
1534 return t;
1537 /* Make a type for a pointer which is relative to an object. The
1538 second argument is the type of the object to which the pointer is
1539 relative. The third argument is the type that the pointer points
1540 to. */
1542 debug_type
1543 debug_make_offset_type (void *handle, debug_type base_type,
1544 debug_type target_type)
1546 struct debug_handle *info = (struct debug_handle *) handle;
1547 struct debug_type *t;
1548 struct debug_offset_type *o;
1550 if (base_type == NULL || target_type == NULL)
1551 return DEBUG_TYPE_NULL;
1553 t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
1554 if (t == NULL)
1555 return DEBUG_TYPE_NULL;
1557 o = (struct debug_offset_type *) xmalloc (sizeof *o);
1558 memset (o, 0, sizeof *o);
1560 o->base_type = base_type;
1561 o->target_type = target_type;
1563 t->u.koffset = o;
1565 return t;
1568 /* Make a type for a method function. The second argument is the
1569 return type, the third argument is the domain, and the fourth
1570 argument is a NULL terminated array of argument types. */
1572 debug_type
1573 debug_make_method_type (void *handle, debug_type return_type,
1574 debug_type domain_type, debug_type *arg_types,
1575 bfd_boolean varargs)
1577 struct debug_handle *info = (struct debug_handle *) handle;
1578 struct debug_type *t;
1579 struct debug_method_type *m;
1581 if (return_type == NULL)
1582 return DEBUG_TYPE_NULL;
1584 t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
1585 if (t == NULL)
1586 return DEBUG_TYPE_NULL;
1588 m = (struct debug_method_type *) xmalloc (sizeof *m);
1589 memset (m, 0, sizeof *m);
1591 m->return_type = return_type;
1592 m->domain_type = domain_type;
1593 m->arg_types = arg_types;
1594 m->varargs = varargs;
1596 t->u.kmethod = m;
1598 return t;
1601 /* Make a const qualified version of a given type. */
1603 debug_type
1604 debug_make_const_type (void *handle, debug_type type)
1606 struct debug_handle *info = (struct debug_handle *) handle;
1607 struct debug_type *t;
1609 if (type == NULL)
1610 return DEBUG_TYPE_NULL;
1612 t = debug_make_type (info, DEBUG_KIND_CONST, 0);
1613 if (t == NULL)
1614 return DEBUG_TYPE_NULL;
1616 t->u.kconst = type;
1618 return t;
1621 /* Make a volatile qualified version of a given type. */
1623 debug_type
1624 debug_make_volatile_type (void *handle, debug_type type)
1626 struct debug_handle *info = (struct debug_handle *) handle;
1627 struct debug_type *t;
1629 if (type == NULL)
1630 return DEBUG_TYPE_NULL;
1632 t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
1633 if (t == NULL)
1634 return DEBUG_TYPE_NULL;
1636 t->u.kvolatile = type;
1638 return t;
1641 /* Make an undefined tagged type. For example, a struct which has
1642 been mentioned, but not defined. */
1644 debug_type
1645 debug_make_undefined_tagged_type (void *handle, const char *name,
1646 enum debug_type_kind kind)
1648 struct debug_handle *info = (struct debug_handle *) handle;
1649 struct debug_type *t;
1651 if (name == NULL)
1652 return DEBUG_TYPE_NULL;
1654 switch (kind)
1656 case DEBUG_KIND_STRUCT:
1657 case DEBUG_KIND_UNION:
1658 case DEBUG_KIND_CLASS:
1659 case DEBUG_KIND_UNION_CLASS:
1660 case DEBUG_KIND_ENUM:
1661 break;
1663 default:
1664 debug_error (_("debug_make_undefined_type: unsupported kind"));
1665 return DEBUG_TYPE_NULL;
1668 t = debug_make_type (info, kind, 0);
1669 if (t == NULL)
1670 return DEBUG_TYPE_NULL;
1672 return debug_tag_type (handle, name, t);
1675 /* Make a base class for an object. The second argument is the base
1676 class type. The third argument is the bit position of this base
1677 class in the object (always 0 unless doing multiple inheritance).
1678 The fourth argument is whether this is a virtual class. The fifth
1679 argument is the visibility of the base class. */
1681 debug_baseclass
1682 debug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
1683 bfd_vma bitpos, bfd_boolean virtual,
1684 enum debug_visibility visibility)
1686 struct debug_baseclass *b;
1688 b = (struct debug_baseclass *) xmalloc (sizeof *b);
1689 memset (b, 0, sizeof *b);
1691 b->type = type;
1692 b->bitpos = bitpos;
1693 b->virtual = virtual;
1694 b->visibility = visibility;
1696 return b;
1699 /* Make a field for a struct. The second argument is the name. The
1700 third argument is the type of the field. The fourth argument is
1701 the bit position of the field. The fifth argument is the size of
1702 the field (it may be zero). The sixth argument is the visibility
1703 of the field. */
1705 debug_field
1706 debug_make_field (void *handle ATTRIBUTE_UNUSED, const char *name,
1707 debug_type type, bfd_vma bitpos, bfd_vma bitsize,
1708 enum debug_visibility visibility)
1710 struct debug_field *f;
1712 f = (struct debug_field *) xmalloc (sizeof *f);
1713 memset (f, 0, sizeof *f);
1715 f->name = name;
1716 f->type = type;
1717 f->static_member = FALSE;
1718 f->u.f.bitpos = bitpos;
1719 f->u.f.bitsize = bitsize;
1720 f->visibility = visibility;
1722 return f;
1725 /* Make a static member of an object. The second argument is the
1726 name. The third argument is the type of the member. The fourth
1727 argument is the physical name of the member (i.e., the name as a
1728 global variable). The fifth argument is the visibility of the
1729 member. */
1731 debug_field
1732 debug_make_static_member (void *handle ATTRIBUTE_UNUSED, const char *name,
1733 debug_type type, const char *physname,
1734 enum debug_visibility visibility)
1736 struct debug_field *f;
1738 f = (struct debug_field *) xmalloc (sizeof *f);
1739 memset (f, 0, sizeof *f);
1741 f->name = name;
1742 f->type = type;
1743 f->static_member = TRUE;
1744 f->u.s.physname = physname;
1745 f->visibility = visibility;
1747 return f;
1750 /* Make a method. The second argument is the name, and the third
1751 argument is a NULL terminated array of method variants. */
1753 debug_method
1754 debug_make_method (void *handle ATTRIBUTE_UNUSED, const char *name,
1755 debug_method_variant *variants)
1757 struct debug_method *m;
1759 m = (struct debug_method *) xmalloc (sizeof *m);
1760 memset (m, 0, sizeof *m);
1762 m->name = name;
1763 m->variants = variants;
1765 return m;
1768 /* Make a method argument. The second argument is the real name of
1769 the function. The third argument is the type of the function. The
1770 fourth argument is the visibility. The fifth argument is whether
1771 this is a const function. The sixth argument is whether this is a
1772 volatile function. The seventh argument is the offset in the
1773 virtual function table, if any. The eighth argument is the virtual
1774 function context. FIXME: Are the const and volatile arguments
1775 necessary? Could we just use debug_make_const_type? */
1777 debug_method_variant
1778 debug_make_method_variant (void *handle ATTRIBUTE_UNUSED,
1779 const char *physname, debug_type type,
1780 enum debug_visibility visibility,
1781 bfd_boolean constp, bfd_boolean volatilep,
1782 bfd_vma voffset, debug_type context)
1784 struct debug_method_variant *m;
1786 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1787 memset (m, 0, sizeof *m);
1789 m->physname = physname;
1790 m->type = type;
1791 m->visibility = visibility;
1792 m->constp = constp;
1793 m->volatilep = volatilep;
1794 m->voffset = voffset;
1795 m->context = context;
1797 return m;
1800 /* Make a static method argument. The arguments are the same as for
1801 debug_make_method_variant, except that the last two are omitted
1802 since a static method can not also be virtual. */
1804 debug_method_variant
1805 debug_make_static_method_variant (void *handle ATTRIBUTE_UNUSED,
1806 const char *physname, debug_type type,
1807 enum debug_visibility visibility,
1808 bfd_boolean constp, bfd_boolean volatilep)
1810 struct debug_method_variant *m;
1812 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1813 memset (m, 0, sizeof *m);
1815 m->physname = physname;
1816 m->type = type;
1817 m->visibility = visibility;
1818 m->constp = constp;
1819 m->volatilep = volatilep;
1820 m->voffset = VOFFSET_STATIC_METHOD;
1822 return m;
1825 /* Name a type. */
1827 debug_type
1828 debug_name_type (void *handle, const char *name, debug_type type)
1830 struct debug_handle *info = (struct debug_handle *) handle;
1831 struct debug_type *t;
1832 struct debug_named_type *n;
1833 struct debug_name *nm;
1835 if (name == NULL || type == NULL)
1836 return DEBUG_TYPE_NULL;
1838 if (info->current_unit == NULL
1839 || info->current_file == NULL)
1841 debug_error (_("debug_name_type: no current file"));
1842 return DEBUG_TYPE_NULL;
1845 t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1846 if (t == NULL)
1847 return DEBUG_TYPE_NULL;
1849 n = (struct debug_named_type *) xmalloc (sizeof *n);
1850 memset (n, 0, sizeof *n);
1852 n->type = type;
1854 t->u.knamed = n;
1856 /* We always add the name to the global namespace. This is probably
1857 wrong in some cases, but it seems to be right for stabs. FIXME. */
1859 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1860 DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
1861 if (nm == NULL)
1862 return DEBUG_TYPE_NULL;
1864 nm->u.type = t;
1866 n->name = nm;
1868 return t;
1871 /* Tag a type. */
1873 debug_type
1874 debug_tag_type (void *handle, const char *name, debug_type type)
1876 struct debug_handle *info = (struct debug_handle *) handle;
1877 struct debug_type *t;
1878 struct debug_named_type *n;
1879 struct debug_name *nm;
1881 if (name == NULL || type == NULL)
1882 return DEBUG_TYPE_NULL;
1884 if (info->current_file == NULL)
1886 debug_error (_("debug_tag_type: no current file"));
1887 return DEBUG_TYPE_NULL;
1890 if (type->kind == DEBUG_KIND_TAGGED)
1892 if (strcmp (type->u.knamed->name->name, name) == 0)
1893 return type;
1894 debug_error (_("debug_tag_type: extra tag attempted"));
1895 return DEBUG_TYPE_NULL;
1898 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
1899 if (t == NULL)
1900 return DEBUG_TYPE_NULL;
1902 n = (struct debug_named_type *) xmalloc (sizeof *n);
1903 memset (n, 0, sizeof *n);
1905 n->type = type;
1907 t->u.knamed = n;
1909 /* We keep a global namespace of tags for each compilation unit. I
1910 don't know if that is the right thing to do. */
1912 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1913 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
1914 if (nm == NULL)
1915 return DEBUG_TYPE_NULL;
1917 nm->u.tag = t;
1919 n->name = nm;
1921 return t;
1924 /* Record the size of a given type. */
1926 bfd_boolean
1927 debug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type,
1928 unsigned int size)
1930 if (type->size != 0 && type->size != size)
1931 fprintf (stderr, _("Warning: changing type size from %d to %d\n"),
1932 type->size, size);
1934 type->size = size;
1936 return TRUE;
1939 /* Find a named type. */
1941 debug_type
1942 debug_find_named_type (void *handle, const char *name)
1944 struct debug_handle *info = (struct debug_handle *) handle;
1945 struct debug_block *b;
1946 struct debug_file *f;
1948 /* We only search the current compilation unit. I don't know if
1949 this is right or not. */
1951 if (info->current_unit == NULL)
1953 debug_error (_("debug_find_named_type: no current compilation unit"));
1954 return DEBUG_TYPE_NULL;
1957 for (b = info->current_block; b != NULL; b = b->parent)
1959 if (b->locals != NULL)
1961 struct debug_name *n;
1963 for (n = b->locals->list; n != NULL; n = n->next)
1965 if (n->kind == DEBUG_OBJECT_TYPE
1966 && n->name[0] == name[0]
1967 && strcmp (n->name, name) == 0)
1968 return n->u.type;
1973 for (f = info->current_unit->files; f != NULL; f = f->next)
1975 if (f->globals != NULL)
1977 struct debug_name *n;
1979 for (n = f->globals->list; n != NULL; n = n->next)
1981 if (n->kind == DEBUG_OBJECT_TYPE
1982 && n->name[0] == name[0]
1983 && strcmp (n->name, name) == 0)
1984 return n->u.type;
1989 return DEBUG_TYPE_NULL;
1992 /* Find a tagged type. */
1994 debug_type
1995 debug_find_tagged_type (void *handle, const char *name,
1996 enum debug_type_kind kind)
1998 struct debug_handle *info = (struct debug_handle *) handle;
1999 struct debug_unit *u;
2001 /* We search the globals of all the compilation units. I don't know
2002 if this is correct or not. It would be easy to change. */
2004 for (u = info->units; u != NULL; u = u->next)
2006 struct debug_file *f;
2008 for (f = u->files; f != NULL; f = f->next)
2010 struct debug_name *n;
2012 if (f->globals != NULL)
2014 for (n = f->globals->list; n != NULL; n = n->next)
2016 if (n->kind == DEBUG_OBJECT_TAG
2017 && (kind == DEBUG_KIND_ILLEGAL
2018 || n->u.tag->kind == kind)
2019 && n->name[0] == name[0]
2020 && strcmp (n->name, name) == 0)
2021 return n->u.tag;
2027 return DEBUG_TYPE_NULL;
2030 /* Get a base type. We build a linked list on the stack to avoid
2031 crashing if the type is defined circularly. */
2033 static struct debug_type *
2034 debug_get_real_type (void *handle, debug_type type,
2035 struct debug_type_real_list *list)
2037 struct debug_type_real_list *l;
2038 struct debug_type_real_list rl;
2040 switch (type->kind)
2042 default:
2043 return type;
2045 case DEBUG_KIND_INDIRECT:
2046 case DEBUG_KIND_NAMED:
2047 case DEBUG_KIND_TAGGED:
2048 break;
2051 for (l = list; l != NULL; l = l->next)
2053 if (l->t == type || l == l->next)
2055 fprintf (stderr,
2056 _("debug_get_real_type: circular debug information for %s\n"),
2057 debug_get_type_name (handle, type));
2058 return NULL;
2062 rl.next = list;
2063 rl.t = type;
2065 switch (type->kind)
2067 /* The default case is just here to avoid warnings. */
2068 default:
2069 case DEBUG_KIND_INDIRECT:
2070 if (*type->u.kindirect->slot != NULL)
2071 return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
2072 return type;
2073 case DEBUG_KIND_NAMED:
2074 case DEBUG_KIND_TAGGED:
2075 return debug_get_real_type (handle, type->u.knamed->type, &rl);
2077 /*NOTREACHED*/
2080 /* Get the kind of a type. */
2082 enum debug_type_kind
2083 debug_get_type_kind (void *handle, debug_type type)
2085 if (type == NULL)
2086 return DEBUG_KIND_ILLEGAL;
2087 type = debug_get_real_type (handle, type, NULL);
2088 if (type == NULL)
2089 return DEBUG_KIND_ILLEGAL;
2090 return type->kind;
2093 /* Get the name of a type. */
2095 const char *
2096 debug_get_type_name (void *handle, debug_type type)
2098 if (type->kind == DEBUG_KIND_INDIRECT)
2100 if (*type->u.kindirect->slot != NULL)
2101 return debug_get_type_name (handle, *type->u.kindirect->slot);
2102 return type->u.kindirect->tag;
2104 if (type->kind == DEBUG_KIND_NAMED
2105 || type->kind == DEBUG_KIND_TAGGED)
2106 return type->u.knamed->name->name;
2107 return NULL;
2110 /* Get the size of a type. */
2112 bfd_vma
2113 debug_get_type_size (void *handle, debug_type type)
2115 if (type == NULL)
2116 return 0;
2118 /* We don't call debug_get_real_type, because somebody might have
2119 called debug_record_type_size on a named or indirect type. */
2121 if (type->size != 0)
2122 return type->size;
2124 switch (type->kind)
2126 default:
2127 return 0;
2128 case DEBUG_KIND_INDIRECT:
2129 if (*type->u.kindirect->slot != NULL)
2130 return debug_get_type_size (handle, *type->u.kindirect->slot);
2131 return 0;
2132 case DEBUG_KIND_NAMED:
2133 case DEBUG_KIND_TAGGED:
2134 return debug_get_type_size (handle, type->u.knamed->type);
2136 /*NOTREACHED*/
2139 /* Get the return type of a function or method type. */
2141 debug_type
2142 debug_get_return_type (void *handle, debug_type type)
2144 if (type == NULL)
2145 return DEBUG_TYPE_NULL;
2147 type = debug_get_real_type (handle, type, NULL);
2148 if (type == NULL)
2149 return DEBUG_TYPE_NULL;
2151 switch (type->kind)
2153 default:
2154 return DEBUG_TYPE_NULL;
2155 case DEBUG_KIND_FUNCTION:
2156 return type->u.kfunction->return_type;
2157 case DEBUG_KIND_METHOD:
2158 return type->u.kmethod->return_type;
2160 /*NOTREACHED*/
2163 /* Get the parameter types of a function or method type (except that
2164 we don't currently store the parameter types of a function). */
2166 const debug_type *
2167 debug_get_parameter_types (void *handle, debug_type type,
2168 bfd_boolean *pvarargs)
2170 if (type == NULL)
2171 return NULL;
2173 type = debug_get_real_type (handle, type, NULL);
2174 if (type == NULL)
2175 return NULL;
2177 switch (type->kind)
2179 default:
2180 return NULL;
2181 case DEBUG_KIND_FUNCTION:
2182 *pvarargs = type->u.kfunction->varargs;
2183 return type->u.kfunction->arg_types;
2184 case DEBUG_KIND_METHOD:
2185 *pvarargs = type->u.kmethod->varargs;
2186 return type->u.kmethod->arg_types;
2188 /*NOTREACHED*/
2191 /* Get the target type of a type. */
2193 debug_type
2194 debug_get_target_type (void *handle, debug_type type)
2196 if (type == NULL)
2197 return NULL;
2199 type = debug_get_real_type (handle, type, NULL);
2200 if (type == NULL)
2201 return NULL;
2203 switch (type->kind)
2205 default:
2206 return NULL;
2207 case DEBUG_KIND_POINTER:
2208 return type->u.kpointer;
2209 case DEBUG_KIND_REFERENCE:
2210 return type->u.kreference;
2211 case DEBUG_KIND_CONST:
2212 return type->u.kconst;
2213 case DEBUG_KIND_VOLATILE:
2214 return type->u.kvolatile;
2216 /*NOTREACHED*/
2219 /* Get the NULL terminated array of fields for a struct, union, or
2220 class. */
2222 const debug_field *
2223 debug_get_fields (void *handle, debug_type type)
2225 if (type == NULL)
2226 return NULL;
2228 type = debug_get_real_type (handle, type, NULL);
2229 if (type == NULL)
2230 return NULL;
2232 switch (type->kind)
2234 default:
2235 return NULL;
2236 case DEBUG_KIND_STRUCT:
2237 case DEBUG_KIND_UNION:
2238 case DEBUG_KIND_CLASS:
2239 case DEBUG_KIND_UNION_CLASS:
2240 return type->u.kclass->fields;
2242 /*NOTREACHED*/
2245 /* Get the type of a field. */
2247 debug_type
2248 debug_get_field_type (void *handle ATTRIBUTE_UNUSED, debug_field field)
2250 if (field == NULL)
2251 return NULL;
2252 return field->type;
2255 /* Get the name of a field. */
2257 const char *
2258 debug_get_field_name (void *handle ATTRIBUTE_UNUSED, debug_field field)
2260 if (field == NULL)
2261 return NULL;
2262 return field->name;
2265 /* Get the bit position of a field. */
2267 bfd_vma
2268 debug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED, debug_field field)
2270 if (field == NULL || field->static_member)
2271 return (bfd_vma) -1;
2272 return field->u.f.bitpos;
2275 /* Get the bit size of a field. */
2277 bfd_vma
2278 debug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED, debug_field field)
2280 if (field == NULL || field->static_member)
2281 return (bfd_vma) -1;
2282 return field->u.f.bitsize;
2285 /* Get the visibility of a field. */
2287 enum debug_visibility
2288 debug_get_field_visibility (void *handle ATTRIBUTE_UNUSED, debug_field field)
2290 if (field == NULL)
2291 return DEBUG_VISIBILITY_IGNORE;
2292 return field->visibility;
2295 /* Get the physical name of a field. */
2297 const char *
2298 debug_get_field_physname (void *handle ATTRIBUTE_UNUSED, debug_field field)
2300 if (field == NULL || ! field->static_member)
2301 return NULL;
2302 return field->u.s.physname;
2305 /* Write out the debugging information. This is given a handle to
2306 debugging information, and a set of function pointers to call. */
2308 bfd_boolean
2309 debug_write (void *handle, const struct debug_write_fns *fns, void *fhandle)
2311 struct debug_handle *info = (struct debug_handle *) handle;
2312 struct debug_unit *u;
2314 /* We use a mark to tell whether we have already written out a
2315 particular name. We use an integer, so that we don't have to
2316 clear the mark fields if we happen to write out the same
2317 information more than once. */
2318 ++info->mark;
2320 /* The base_id field holds an ID value which will never be used, so
2321 that we can tell whether we have assigned an ID during this call
2322 to debug_write. */
2323 info->base_id = info->class_id;
2325 /* We keep a linked list of classes for which was have assigned ID's
2326 during this call to debug_write. */
2327 info->id_list = NULL;
2329 for (u = info->units; u != NULL; u = u->next)
2331 struct debug_file *f;
2332 bfd_boolean first_file;
2334 info->current_write_lineno = u->linenos;
2335 info->current_write_lineno_index = 0;
2337 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2338 return FALSE;
2340 first_file = TRUE;
2341 for (f = u->files; f != NULL; f = f->next)
2343 struct debug_name *n;
2345 if (first_file)
2346 first_file = FALSE;
2347 else if (! (*fns->start_source) (fhandle, f->filename))
2348 return FALSE;
2350 if (f->globals != NULL)
2351 for (n = f->globals->list; n != NULL; n = n->next)
2352 if (! debug_write_name (info, fns, fhandle, n))
2353 return FALSE;
2356 /* Output any line number information which hasn't already been
2357 handled. */
2358 if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
2359 return FALSE;
2362 return TRUE;
2365 /* Write out an element in a namespace. */
2367 static bfd_boolean
2368 debug_write_name (struct debug_handle *info,
2369 const struct debug_write_fns *fns, void *fhandle,
2370 struct debug_name *n)
2372 switch (n->kind)
2374 case DEBUG_OBJECT_TYPE:
2375 if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2376 || ! (*fns->typdef) (fhandle, n->name))
2377 return FALSE;
2378 return TRUE;
2379 case DEBUG_OBJECT_TAG:
2380 if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2381 return FALSE;
2382 return (*fns->tag) (fhandle, n->name);
2383 case DEBUG_OBJECT_VARIABLE:
2384 if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2385 (struct debug_name *) NULL))
2386 return FALSE;
2387 return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2388 n->u.variable->val);
2389 case DEBUG_OBJECT_FUNCTION:
2390 return debug_write_function (info, fns, fhandle, n->name,
2391 n->linkage, n->u.function);
2392 case DEBUG_OBJECT_INT_CONSTANT:
2393 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2394 case DEBUG_OBJECT_FLOAT_CONSTANT:
2395 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2396 case DEBUG_OBJECT_TYPED_CONSTANT:
2397 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2398 (struct debug_name *) NULL))
2399 return FALSE;
2400 return (*fns->typed_constant) (fhandle, n->name,
2401 n->u.typed_constant->val);
2402 default:
2403 abort ();
2404 return FALSE;
2406 /*NOTREACHED*/
2409 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2410 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2411 are about to call typedef or tag. If the type is anything else,
2412 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2413 points to this one. */
2415 static bfd_boolean
2416 debug_write_type (struct debug_handle *info,
2417 const struct debug_write_fns *fns, void *fhandle,
2418 struct debug_type *type, struct debug_name *name)
2420 unsigned int i;
2421 int is;
2422 const char *tag = NULL;
2424 /* If we have a name for this type, just output it. We only output
2425 typedef names after they have been defined. We output type tags
2426 whenever we are not actually defining them. */
2427 if ((type->kind == DEBUG_KIND_NAMED
2428 || type->kind == DEBUG_KIND_TAGGED)
2429 && (type->u.knamed->name->mark == info->mark
2430 || (type->kind == DEBUG_KIND_TAGGED
2431 && type->u.knamed->name != name)))
2433 if (type->kind == DEBUG_KIND_NAMED)
2434 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2435 else
2437 struct debug_type *real;
2438 unsigned int id;
2440 real = debug_get_real_type ((void *) info, type, NULL);
2441 if (real == NULL)
2442 return (*fns->empty_type) (fhandle);
2443 id = 0;
2444 if ((real->kind == DEBUG_KIND_STRUCT
2445 || real->kind == DEBUG_KIND_UNION
2446 || real->kind == DEBUG_KIND_CLASS
2447 || real->kind == DEBUG_KIND_UNION_CLASS)
2448 && real->u.kclass != NULL)
2450 if (real->u.kclass->id <= info->base_id)
2452 if (! debug_set_class_id (info,
2453 type->u.knamed->name->name,
2454 real))
2455 return FALSE;
2457 id = real->u.kclass->id;
2460 return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
2461 real->kind);
2465 /* Mark the name after we have already looked for a known name, so
2466 that we don't just define a type in terms of itself. We need to
2467 mark the name here so that a struct containing a pointer to
2468 itself will work. */
2469 if (name != NULL)
2470 name->mark = info->mark;
2472 if (name != NULL
2473 && type->kind != DEBUG_KIND_NAMED
2474 && type->kind != DEBUG_KIND_TAGGED)
2476 assert (name->kind == DEBUG_OBJECT_TAG);
2477 tag = name->name;
2480 switch (type->kind)
2482 case DEBUG_KIND_ILLEGAL:
2483 debug_error (_("debug_write_type: illegal type encountered"));
2484 return FALSE;
2485 case DEBUG_KIND_INDIRECT:
2486 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2487 return (*fns->empty_type) (fhandle);
2488 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2489 name);
2490 case DEBUG_KIND_VOID:
2491 return (*fns->void_type) (fhandle);
2492 case DEBUG_KIND_INT:
2493 return (*fns->int_type) (fhandle, type->size, type->u.kint);
2494 case DEBUG_KIND_FLOAT:
2495 return (*fns->float_type) (fhandle, type->size);
2496 case DEBUG_KIND_COMPLEX:
2497 return (*fns->complex_type) (fhandle, type->size);
2498 case DEBUG_KIND_BOOL:
2499 return (*fns->bool_type) (fhandle, type->size);
2500 case DEBUG_KIND_STRUCT:
2501 case DEBUG_KIND_UNION:
2502 if (type->u.kclass != NULL)
2504 if (type->u.kclass->id <= info->base_id)
2506 if (! debug_set_class_id (info, tag, type))
2507 return FALSE;
2510 if (info->mark == type->u.kclass->mark)
2512 /* We are currently outputting this struct, or we have
2513 already output it. I don't know if this can happen,
2514 but it can happen for a class. */
2515 assert (type->u.kclass->id > info->base_id);
2516 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2517 type->kind);
2519 type->u.kclass->mark = info->mark;
2522 if (! (*fns->start_struct_type) (fhandle, tag,
2523 (type->u.kclass != NULL
2524 ? type->u.kclass->id
2525 : 0),
2526 type->kind == DEBUG_KIND_STRUCT,
2527 type->size))
2528 return FALSE;
2529 if (type->u.kclass != NULL
2530 && type->u.kclass->fields != NULL)
2532 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2534 struct debug_field *f;
2536 f = type->u.kclass->fields[i];
2537 if (! debug_write_type (info, fns, fhandle, f->type,
2538 (struct debug_name *) NULL)
2539 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2540 f->u.f.bitsize, f->visibility))
2541 return FALSE;
2544 return (*fns->end_struct_type) (fhandle);
2545 case DEBUG_KIND_CLASS:
2546 case DEBUG_KIND_UNION_CLASS:
2547 return debug_write_class_type (info, fns, fhandle, type, tag);
2548 case DEBUG_KIND_ENUM:
2549 if (type->u.kenum == NULL)
2550 return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
2551 (bfd_signed_vma *) NULL);
2552 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2553 type->u.kenum->values);
2554 case DEBUG_KIND_POINTER:
2555 if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2556 (struct debug_name *) NULL))
2557 return FALSE;
2558 return (*fns->pointer_type) (fhandle);
2559 case DEBUG_KIND_FUNCTION:
2560 if (! debug_write_type (info, fns, fhandle,
2561 type->u.kfunction->return_type,
2562 (struct debug_name *) NULL))
2563 return FALSE;
2564 if (type->u.kfunction->arg_types == NULL)
2565 is = -1;
2566 else
2568 for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
2569 if (! debug_write_type (info, fns, fhandle,
2570 type->u.kfunction->arg_types[is],
2571 (struct debug_name *) NULL))
2572 return FALSE;
2574 return (*fns->function_type) (fhandle, is,
2575 type->u.kfunction->varargs);
2576 case DEBUG_KIND_REFERENCE:
2577 if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2578 (struct debug_name *) NULL))
2579 return FALSE;
2580 return (*fns->reference_type) (fhandle);
2581 case DEBUG_KIND_RANGE:
2582 if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2583 (struct debug_name *) NULL))
2584 return FALSE;
2585 return (*fns->range_type) (fhandle, type->u.krange->lower,
2586 type->u.krange->upper);
2587 case DEBUG_KIND_ARRAY:
2588 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2589 (struct debug_name *) NULL)
2590 || ! debug_write_type (info, fns, fhandle,
2591 type->u.karray->range_type,
2592 (struct debug_name *) NULL))
2593 return FALSE;
2594 return (*fns->array_type) (fhandle, type->u.karray->lower,
2595 type->u.karray->upper,
2596 type->u.karray->stringp);
2597 case DEBUG_KIND_SET:
2598 if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2599 (struct debug_name *) NULL))
2600 return FALSE;
2601 return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2602 case DEBUG_KIND_OFFSET:
2603 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2604 (struct debug_name *) NULL)
2605 || ! debug_write_type (info, fns, fhandle,
2606 type->u.koffset->target_type,
2607 (struct debug_name *) NULL))
2608 return FALSE;
2609 return (*fns->offset_type) (fhandle);
2610 case DEBUG_KIND_METHOD:
2611 if (! debug_write_type (info, fns, fhandle,
2612 type->u.kmethod->return_type,
2613 (struct debug_name *) NULL))
2614 return FALSE;
2615 if (type->u.kmethod->arg_types == NULL)
2616 is = -1;
2617 else
2619 for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
2620 if (! debug_write_type (info, fns, fhandle,
2621 type->u.kmethod->arg_types[is],
2622 (struct debug_name *) NULL))
2623 return FALSE;
2625 if (type->u.kmethod->domain_type != NULL)
2627 if (! debug_write_type (info, fns, fhandle,
2628 type->u.kmethod->domain_type,
2629 (struct debug_name *) NULL))
2630 return FALSE;
2632 return (*fns->method_type) (fhandle,
2633 type->u.kmethod->domain_type != NULL,
2635 type->u.kmethod->varargs);
2636 case DEBUG_KIND_CONST:
2637 if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2638 (struct debug_name *) NULL))
2639 return FALSE;
2640 return (*fns->const_type) (fhandle);
2641 case DEBUG_KIND_VOLATILE:
2642 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2643 (struct debug_name *) NULL))
2644 return FALSE;
2645 return (*fns->volatile_type) (fhandle);
2646 case DEBUG_KIND_NAMED:
2647 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2648 (struct debug_name *) NULL);
2649 case DEBUG_KIND_TAGGED:
2650 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2651 type->u.knamed->name);
2652 default:
2653 abort ();
2654 return FALSE;
2658 /* Write out a class type. */
2660 static bfd_boolean
2661 debug_write_class_type (struct debug_handle *info,
2662 const struct debug_write_fns *fns, void *fhandle,
2663 struct debug_type *type, const char *tag)
2665 unsigned int i;
2666 unsigned int id;
2667 struct debug_type *vptrbase;
2669 if (type->u.kclass == NULL)
2671 id = 0;
2672 vptrbase = NULL;
2674 else
2676 if (type->u.kclass->id <= info->base_id)
2678 if (! debug_set_class_id (info, tag, type))
2679 return FALSE;
2682 if (info->mark == type->u.kclass->mark)
2684 /* We are currently outputting this class, or we have
2685 already output it. This can happen when there are
2686 methods for an anonymous class. */
2687 assert (type->u.kclass->id > info->base_id);
2688 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2689 type->kind);
2691 type->u.kclass->mark = info->mark;
2692 id = type->u.kclass->id;
2694 vptrbase = type->u.kclass->vptrbase;
2695 if (vptrbase != NULL && vptrbase != type)
2697 if (! debug_write_type (info, fns, fhandle, vptrbase,
2698 (struct debug_name *) NULL))
2699 return FALSE;
2703 if (! (*fns->start_class_type) (fhandle, tag, id,
2704 type->kind == DEBUG_KIND_CLASS,
2705 type->size,
2706 vptrbase != NULL,
2707 vptrbase == type))
2708 return FALSE;
2710 if (type->u.kclass != NULL)
2712 if (type->u.kclass->fields != NULL)
2714 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2716 struct debug_field *f;
2718 f = type->u.kclass->fields[i];
2719 if (! debug_write_type (info, fns, fhandle, f->type,
2720 (struct debug_name *) NULL))
2721 return FALSE;
2722 if (f->static_member)
2724 if (! (*fns->class_static_member) (fhandle, f->name,
2725 f->u.s.physname,
2726 f->visibility))
2727 return FALSE;
2729 else
2731 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2732 f->u.f.bitsize, f->visibility))
2733 return FALSE;
2738 if (type->u.kclass->baseclasses != NULL)
2740 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2742 struct debug_baseclass *b;
2744 b = type->u.kclass->baseclasses[i];
2745 if (! debug_write_type (info, fns, fhandle, b->type,
2746 (struct debug_name *) NULL))
2747 return FALSE;
2748 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
2749 b->visibility))
2750 return FALSE;
2754 if (type->u.kclass->methods != NULL)
2756 for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2758 struct debug_method *m;
2759 unsigned int j;
2761 m = type->u.kclass->methods[i];
2762 if (! (*fns->class_start_method) (fhandle, m->name))
2763 return FALSE;
2764 for (j = 0; m->variants[j] != NULL; j++)
2766 struct debug_method_variant *v;
2768 v = m->variants[j];
2769 if (v->context != NULL)
2771 if (! debug_write_type (info, fns, fhandle, v->context,
2772 (struct debug_name *) NULL))
2773 return FALSE;
2775 if (! debug_write_type (info, fns, fhandle, v->type,
2776 (struct debug_name *) NULL))
2777 return FALSE;
2778 if (v->voffset != VOFFSET_STATIC_METHOD)
2780 if (! (*fns->class_method_variant) (fhandle, v->physname,
2781 v->visibility,
2782 v->constp,
2783 v->volatilep,
2784 v->voffset,
2785 v->context != NULL))
2786 return FALSE;
2788 else
2790 if (! (*fns->class_static_method_variant) (fhandle,
2791 v->physname,
2792 v->visibility,
2793 v->constp,
2794 v->volatilep))
2795 return FALSE;
2798 if (! (*fns->class_end_method) (fhandle))
2799 return FALSE;
2804 return (*fns->end_class_type) (fhandle);
2807 /* Write out information for a function. */
2809 static bfd_boolean
2810 debug_write_function (struct debug_handle *info,
2811 const struct debug_write_fns *fns, void *fhandle,
2812 const char *name, enum debug_object_linkage linkage,
2813 struct debug_function *function)
2815 struct debug_parameter *p;
2816 struct debug_block *b;
2818 if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
2819 return FALSE;
2821 if (! debug_write_type (info, fns, fhandle, function->return_type,
2822 (struct debug_name *) NULL))
2823 return FALSE;
2825 if (! (*fns->start_function) (fhandle, name,
2826 linkage == DEBUG_LINKAGE_GLOBAL))
2827 return FALSE;
2829 for (p = function->parameters; p != NULL; p = p->next)
2831 if (! debug_write_type (info, fns, fhandle, p->type,
2832 (struct debug_name *) NULL)
2833 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2834 return FALSE;
2837 for (b = function->blocks; b != NULL; b = b->next)
2839 if (! debug_write_block (info, fns, fhandle, b))
2840 return FALSE;
2843 return (*fns->end_function) (fhandle);
2846 /* Write out information for a block. */
2848 static bfd_boolean
2849 debug_write_block (struct debug_handle *info,
2850 const struct debug_write_fns *fns, void *fhandle,
2851 struct debug_block *block)
2853 struct debug_name *n;
2854 struct debug_block *b;
2856 if (! debug_write_linenos (info, fns, fhandle, block->start))
2857 return FALSE;
2859 /* I can't see any point to writing out a block with no local
2860 variables, so we don't bother, except for the top level block. */
2861 if (block->locals != NULL || block->parent == NULL)
2863 if (! (*fns->start_block) (fhandle, block->start))
2864 return FALSE;
2867 if (block->locals != NULL)
2869 for (n = block->locals->list; n != NULL; n = n->next)
2871 if (! debug_write_name (info, fns, fhandle, n))
2872 return FALSE;
2876 for (b = block->children; b != NULL; b = b->next)
2878 if (! debug_write_block (info, fns, fhandle, b))
2879 return FALSE;
2882 if (! debug_write_linenos (info, fns, fhandle, block->end))
2883 return FALSE;
2885 if (block->locals != NULL || block->parent == NULL)
2887 if (! (*fns->end_block) (fhandle, block->end))
2888 return FALSE;
2891 return TRUE;
2894 /* Write out line number information up to ADDRESS. */
2896 static bfd_boolean
2897 debug_write_linenos (struct debug_handle *info,
2898 const struct debug_write_fns *fns, void *fhandle,
2899 bfd_vma address)
2901 while (info->current_write_lineno != NULL)
2903 struct debug_lineno *l;
2905 l = info->current_write_lineno;
2907 while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
2909 if (l->linenos[info->current_write_lineno_index]
2910 == (unsigned long) -1)
2911 break;
2913 if (l->addrs[info->current_write_lineno_index] >= address)
2914 return TRUE;
2916 if (! (*fns->lineno) (fhandle, l->file->filename,
2917 l->linenos[info->current_write_lineno_index],
2918 l->addrs[info->current_write_lineno_index]))
2919 return FALSE;
2921 ++info->current_write_lineno_index;
2924 info->current_write_lineno = l->next;
2925 info->current_write_lineno_index = 0;
2928 return TRUE;
2931 /* Get the ID number for a class. If during the same call to
2932 debug_write we find a struct with the same definition with the same
2933 name, we use the same ID. This type of things happens because the
2934 same struct will be defined by multiple compilation units. */
2936 static bfd_boolean
2937 debug_set_class_id (struct debug_handle *info, const char *tag,
2938 struct debug_type *type)
2940 struct debug_class_type *c;
2941 struct debug_class_id *l;
2943 assert (type->kind == DEBUG_KIND_STRUCT
2944 || type->kind == DEBUG_KIND_UNION
2945 || type->kind == DEBUG_KIND_CLASS
2946 || type->kind == DEBUG_KIND_UNION_CLASS);
2948 c = type->u.kclass;
2950 if (c->id > info->base_id)
2951 return TRUE;
2953 for (l = info->id_list; l != NULL; l = l->next)
2955 if (l->type->kind != type->kind)
2956 continue;
2958 if (tag == NULL)
2960 if (l->tag != NULL)
2961 continue;
2963 else
2965 if (l->tag == NULL
2966 || l->tag[0] != tag[0]
2967 || strcmp (l->tag, tag) != 0)
2968 continue;
2971 if (debug_type_samep (info, l->type, type))
2973 c->id = l->type->u.kclass->id;
2974 return TRUE;
2978 /* There are no identical types. Use a new ID, and add it to the
2979 list. */
2980 ++info->class_id;
2981 c->id = info->class_id;
2983 l = (struct debug_class_id *) xmalloc (sizeof *l);
2984 memset (l, 0, sizeof *l);
2986 l->type = type;
2987 l->tag = tag;
2989 l->next = info->id_list;
2990 info->id_list = l;
2992 return TRUE;
2995 /* See if two types are the same. At this point, we don't care about
2996 tags and the like. */
2998 static bfd_boolean
2999 debug_type_samep (struct debug_handle *info, struct debug_type *t1,
3000 struct debug_type *t2)
3002 struct debug_type_compare_list *l;
3003 struct debug_type_compare_list top;
3004 bfd_boolean ret;
3006 if (t1 == NULL)
3007 return t2 == NULL;
3008 if (t2 == NULL)
3009 return FALSE;
3011 while (t1->kind == DEBUG_KIND_INDIRECT)
3013 t1 = *t1->u.kindirect->slot;
3014 if (t1 == NULL)
3015 return FALSE;
3017 while (t2->kind == DEBUG_KIND_INDIRECT)
3019 t2 = *t2->u.kindirect->slot;
3020 if (t2 == NULL)
3021 return FALSE;
3024 if (t1 == t2)
3025 return TRUE;
3027 /* As a special case, permit a typedef to match a tag, since C++
3028 debugging output will sometimes add a typedef where C debugging
3029 output will not. */
3030 if (t1->kind == DEBUG_KIND_NAMED
3031 && t2->kind == DEBUG_KIND_TAGGED)
3032 return debug_type_samep (info, t1->u.knamed->type, t2);
3033 else if (t1->kind == DEBUG_KIND_TAGGED
3034 && t2->kind == DEBUG_KIND_NAMED)
3035 return debug_type_samep (info, t1, t2->u.knamed->type);
3037 if (t1->kind != t2->kind
3038 || t1->size != t2->size)
3039 return FALSE;
3041 /* Get rid of the trivial cases first. */
3042 switch (t1->kind)
3044 default:
3045 break;
3046 case DEBUG_KIND_VOID:
3047 case DEBUG_KIND_FLOAT:
3048 case DEBUG_KIND_COMPLEX:
3049 case DEBUG_KIND_BOOL:
3050 return TRUE;
3051 case DEBUG_KIND_INT:
3052 return t1->u.kint == t2->u.kint;
3055 /* We have to avoid an infinite recursion. We do this by keeping a
3056 list of types which we are comparing. We just keep the list on
3057 the stack. If we encounter a pair of types we are currently
3058 comparing, we just assume that they are equal. */
3059 for (l = info->compare_list; l != NULL; l = l->next)
3061 if (l->t1 == t1 && l->t2 == t2)
3062 return TRUE;
3065 top.t1 = t1;
3066 top.t2 = t2;
3067 top.next = info->compare_list;
3068 info->compare_list = &top;
3070 switch (t1->kind)
3072 default:
3073 abort ();
3074 ret = FALSE;
3075 break;
3077 case DEBUG_KIND_STRUCT:
3078 case DEBUG_KIND_UNION:
3079 case DEBUG_KIND_CLASS:
3080 case DEBUG_KIND_UNION_CLASS:
3081 if (t1->u.kclass == NULL)
3082 ret = t2->u.kclass == NULL;
3083 else if (t2->u.kclass == NULL)
3084 ret = FALSE;
3085 else if (t1->u.kclass->id > info->base_id
3086 && t1->u.kclass->id == t2->u.kclass->id)
3087 ret = TRUE;
3088 else
3089 ret = debug_class_type_samep (info, t1, t2);
3090 break;
3092 case DEBUG_KIND_ENUM:
3093 if (t1->u.kenum == NULL)
3094 ret = t2->u.kenum == NULL;
3095 else if (t2->u.kenum == NULL)
3096 ret = FALSE;
3097 else
3099 const char **pn1, **pn2;
3100 bfd_signed_vma *pv1, *pv2;
3102 pn1 = t1->u.kenum->names;
3103 pn2 = t2->u.kenum->names;
3104 pv1 = t1->u.kenum->values;
3105 pv2 = t2->u.kenum->values;
3106 while (*pn1 != NULL && *pn2 != NULL)
3108 if (**pn1 != **pn2
3109 || *pv1 != *pv2
3110 || strcmp (*pn1, *pn2) != 0)
3111 break;
3112 ++pn1;
3113 ++pn2;
3114 ++pv1;
3115 ++pv2;
3117 ret = *pn1 == NULL && *pn2 == NULL;
3119 break;
3121 case DEBUG_KIND_POINTER:
3122 ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
3123 break;
3125 case DEBUG_KIND_FUNCTION:
3126 if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
3127 || ! debug_type_samep (info, t1->u.kfunction->return_type,
3128 t2->u.kfunction->return_type)
3129 || ((t1->u.kfunction->arg_types == NULL)
3130 != (t2->u.kfunction->arg_types == NULL)))
3131 ret = FALSE;
3132 else if (t1->u.kfunction->arg_types == NULL)
3133 ret = TRUE;
3134 else
3136 struct debug_type **a1, **a2;
3138 a1 = t1->u.kfunction->arg_types;
3139 a2 = t2->u.kfunction->arg_types;
3140 while (*a1 != NULL && *a2 != NULL)
3142 if (! debug_type_samep (info, *a1, *a2))
3143 break;
3144 ++a1;
3145 ++a2;
3147 ret = *a1 == NULL && *a2 == NULL;
3149 break;
3151 case DEBUG_KIND_REFERENCE:
3152 ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
3153 break;
3155 case DEBUG_KIND_RANGE:
3156 ret = (t1->u.krange->lower == t2->u.krange->lower
3157 && t1->u.krange->upper == t2->u.krange->upper
3158 && debug_type_samep (info, t1->u.krange->type,
3159 t2->u.krange->type));
3161 case DEBUG_KIND_ARRAY:
3162 ret = (t1->u.karray->lower == t2->u.karray->lower
3163 && t1->u.karray->upper == t2->u.karray->upper
3164 && t1->u.karray->stringp == t2->u.karray->stringp
3165 && debug_type_samep (info, t1->u.karray->element_type,
3166 t2->u.karray->element_type));
3167 break;
3169 case DEBUG_KIND_SET:
3170 ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
3171 && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
3172 break;
3174 case DEBUG_KIND_OFFSET:
3175 ret = (debug_type_samep (info, t1->u.koffset->base_type,
3176 t2->u.koffset->base_type)
3177 && debug_type_samep (info, t1->u.koffset->target_type,
3178 t2->u.koffset->target_type));
3179 break;
3181 case DEBUG_KIND_METHOD:
3182 if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
3183 || ! debug_type_samep (info, t1->u.kmethod->return_type,
3184 t2->u.kmethod->return_type)
3185 || ! debug_type_samep (info, t1->u.kmethod->domain_type,
3186 t2->u.kmethod->domain_type)
3187 || ((t1->u.kmethod->arg_types == NULL)
3188 != (t2->u.kmethod->arg_types == NULL)))
3189 ret = FALSE;
3190 else if (t1->u.kmethod->arg_types == NULL)
3191 ret = TRUE;
3192 else
3194 struct debug_type **a1, **a2;
3196 a1 = t1->u.kmethod->arg_types;
3197 a2 = t2->u.kmethod->arg_types;
3198 while (*a1 != NULL && *a2 != NULL)
3200 if (! debug_type_samep (info, *a1, *a2))
3201 break;
3202 ++a1;
3203 ++a2;
3205 ret = *a1 == NULL && *a2 == NULL;
3207 break;
3209 case DEBUG_KIND_CONST:
3210 ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
3211 break;
3213 case DEBUG_KIND_VOLATILE:
3214 ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
3215 break;
3217 case DEBUG_KIND_NAMED:
3218 case DEBUG_KIND_TAGGED:
3219 ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
3220 && debug_type_samep (info, t1->u.knamed->type,
3221 t2->u.knamed->type));
3222 break;
3225 info->compare_list = top.next;
3227 return ret;
3230 /* See if two classes are the same. This is a subroutine of
3231 debug_type_samep. */
3233 static bfd_boolean
3234 debug_class_type_samep (struct debug_handle *info, struct debug_type *t1,
3235 struct debug_type *t2)
3237 struct debug_class_type *c1, *c2;
3239 c1 = t1->u.kclass;
3240 c2 = t2->u.kclass;
3242 if ((c1->fields == NULL) != (c2->fields == NULL)
3243 || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
3244 || (c1->methods == NULL) != (c2->methods == NULL)
3245 || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
3246 return FALSE;
3248 if (c1->fields != NULL)
3250 struct debug_field **pf1, **pf2;
3252 for (pf1 = c1->fields, pf2 = c2->fields;
3253 *pf1 != NULL && *pf2 != NULL;
3254 pf1++, pf2++)
3256 struct debug_field *f1, *f2;
3258 f1 = *pf1;
3259 f2 = *pf2;
3260 if (f1->name[0] != f2->name[0]
3261 || f1->visibility != f2->visibility
3262 || f1->static_member != f2->static_member)
3263 return FALSE;
3264 if (f1->static_member)
3266 if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
3267 return FALSE;
3269 else
3271 if (f1->u.f.bitpos != f2->u.f.bitpos
3272 || f1->u.f.bitsize != f2->u.f.bitsize)
3273 return FALSE;
3275 /* We do the checks which require function calls last. We
3276 don't require that the types of fields have the same
3277 names, since that sometimes fails in the presence of
3278 typedefs and we really don't care. */
3279 if (strcmp (f1->name, f2->name) != 0
3280 || ! debug_type_samep (info,
3281 debug_get_real_type ((void *) info,
3282 f1->type, NULL),
3283 debug_get_real_type ((void *) info,
3284 f2->type, NULL)))
3285 return FALSE;
3287 if (*pf1 != NULL || *pf2 != NULL)
3288 return FALSE;
3291 if (c1->vptrbase != NULL)
3293 if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
3294 return FALSE;
3297 if (c1->baseclasses != NULL)
3299 struct debug_baseclass **pb1, **pb2;
3301 for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
3302 *pb1 != NULL && *pb2 != NULL;
3303 ++pb1, ++pb2)
3305 struct debug_baseclass *b1, *b2;
3307 b1 = *pb1;
3308 b2 = *pb2;
3309 if (b1->bitpos != b2->bitpos
3310 || b1->virtual != b2->virtual
3311 || b1->visibility != b2->visibility
3312 || ! debug_type_samep (info, b1->type, b2->type))
3313 return FALSE;
3315 if (*pb1 != NULL || *pb2 != NULL)
3316 return FALSE;
3319 if (c1->methods != NULL)
3321 struct debug_method **pm1, **pm2;
3323 for (pm1 = c1->methods, pm2 = c2->methods;
3324 *pm1 != NULL && *pm2 != NULL;
3325 ++pm1, ++pm2)
3327 struct debug_method *m1, *m2;
3329 m1 = *pm1;
3330 m2 = *pm2;
3331 if (m1->name[0] != m2->name[0]
3332 || strcmp (m1->name, m2->name) != 0
3333 || (m1->variants == NULL) != (m2->variants == NULL))
3334 return FALSE;
3335 if (m1->variants == NULL)
3337 struct debug_method_variant **pv1, **pv2;
3339 for (pv1 = m1->variants, pv2 = m2->variants;
3340 *pv1 != NULL && *pv2 != NULL;
3341 ++pv1, ++pv2)
3343 struct debug_method_variant *v1, *v2;
3345 v1 = *pv1;
3346 v2 = *pv2;
3347 if (v1->physname[0] != v2->physname[0]
3348 || v1->visibility != v2->visibility
3349 || v1->constp != v2->constp
3350 || v1->volatilep != v2->volatilep
3351 || v1->voffset != v2->voffset
3352 || (v1->context == NULL) != (v2->context == NULL)
3353 || strcmp (v1->physname, v2->physname) != 0
3354 || ! debug_type_samep (info, v1->type, v2->type))
3355 return FALSE;
3356 if (v1->context != NULL)
3358 if (! debug_type_samep (info, v1->context,
3359 v2->context))
3360 return FALSE;
3363 if (*pv1 != NULL || *pv2 != NULL)
3364 return FALSE;
3367 if (*pm1 != NULL || *pm2 != NULL)
3368 return FALSE;
3371 return TRUE;