1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995, 1996, 1998 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 /* 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. */
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
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. */
89 /* The next source file in this compilation unit. */
90 struct debug_file
*next
;
91 /* The name of the source file. */
93 /* Global functions, variables, types, etc. */
94 struct debug_namespace
*globals
;
102 enum debug_type_kind kind
;
103 /* Size of type (0 if not known). */
105 /* Type which is a pointer to this type. */
107 /* Tagged union with additional information about the type. */
110 /* DEBUG_KIND_INDIRECT. */
111 struct debug_indirect_type
*kindirect
;
112 /* DEBUG_KIND_INT. */
113 /* Whether the integer is unsigned. */
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
;
145 /* Information kept for an indirect type. */
147 struct debug_indirect_type
149 /* Slot where the final type will appear. */
155 /* Information kept for a struct, union, or class. */
157 struct debug_class_type
159 /* NULL terminated array of fields. */
161 /* A mark field which indicates whether the struct has already been
164 /* This is used to uniquely identify unnamed structs when printing. */
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. */
177 /* Information kept for an enum. */
179 struct debug_enum_type
181 /* NULL terminated array of 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
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. */
200 /* Information kept for a range. */
202 struct debug_range_type
204 /* Range base type. */
207 bfd_signed_vma lower
;
209 bfd_signed_vma upper
;
212 /* Information kept for an array. */
214 struct debug_array_type
217 debug_type element_type
;
219 debug_type range_type
;
221 bfd_signed_vma lower
;
223 bfd_signed_vma upper
;
224 /* Whether this array is really a string. */
228 /* Information kept for a set. */
230 struct debug_set_type
234 /* Whether this set is really a bitstring. */
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. */
262 /* Information kept for a named type. */
264 struct debug_named_type
267 struct debug_name
*name
;
272 /* A field in a struct or union. */
276 /* Name of the field. */
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 boolean static_member
;
286 /* If static_member is false. */
289 /* Bit position of the field in the struct. */
291 /* Size of the field in bits. */
292 unsigned int bitsize
;
294 /* If static_member is true. */
297 const char *physname
;
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. */
310 /* Whether the base class is virtual. */
312 /* Visibility of the base class. */
313 enum debug_visibility visibility
;
316 /* A method of an object. */
320 /* The name of the method. */
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. */
339 /* Whether the function is volatile. */
341 /* The offset to the function in the virtual function table. */
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
;
359 /* Value. The interpretation of the value depends upon kind. */
363 /* A function. This has no name; a name is associated with a function
364 in a debug_name structure. */
366 struct debug_function
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
;
388 enum debug_parm_kind kind
;
389 /* Value (meaning depends upon kind). */
393 /* A typed constant. */
395 struct debug_typed_constant
399 /* Value. FIXME: We may eventually need to support non-integral
404 /* Information about a block within a function. */
408 /* Next block with the same parent. */
409 struct debug_block
*next
;
411 struct debug_block
*parent
;
412 /* List of child blocks. */
413 struct debug_block
*children
;
414 /* Start address of the block. */
416 /* End address of the block. */
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
428 /* More line number information for this block. */
429 struct debug_lineno
*next
;
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
456 /* A tagged type (really a different sort of namespace). */
459 DEBUG_OBJECT_VARIABLE
,
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
478 DEBUG_LINKAGE_STATIC
,
480 DEBUG_LINKAGE_GLOBAL
,
485 /* A name in a namespace. */
489 /* Next name in this namespace. */
490 struct debug_name
*next
;
493 /* Mark. This is used by debug_write. */
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. */
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
;
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. */
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 /* Local functions. */
546 static void debug_error
PARAMS ((const char *));
547 static struct debug_name
*debug_add_to_namespace
548 PARAMS ((struct debug_handle
*, struct debug_namespace
**, const char *,
549 enum debug_object_kind
, enum debug_object_linkage
));
550 static struct debug_name
*debug_add_to_current_namespace
551 PARAMS ((struct debug_handle
*, const char *, enum debug_object_kind
,
552 enum debug_object_linkage
));
553 static struct debug_type
*debug_make_type
554 PARAMS ((struct debug_handle
*, enum debug_type_kind
, unsigned int));
555 static struct debug_type
*debug_get_real_type
PARAMS ((PTR
, debug_type
));
556 static boolean debug_write_name
557 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
558 struct debug_name
*));
559 static boolean debug_write_type
560 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
561 struct debug_type
*, struct debug_name
*));
562 static boolean debug_write_class_type
563 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
564 struct debug_type
*, const char *));
565 static boolean debug_write_function
566 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
567 const char *, enum debug_object_linkage
, struct debug_function
*));
568 static boolean debug_write_block
569 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
570 struct debug_block
*));
571 static boolean debug_write_linenos
572 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
574 static boolean debug_set_class_id
575 PARAMS ((struct debug_handle
*, const char *, struct debug_type
*));
576 static boolean debug_type_samep
577 PARAMS ((struct debug_handle
*, struct debug_type
*, struct debug_type
*));
578 static boolean debug_class_type_samep
579 PARAMS ((struct debug_handle
*, struct debug_type
*, struct debug_type
*));
581 /* Issue an error message. */
584 debug_error (message
)
587 fprintf (stderr
, "%s\n", message
);
590 /* Add an object to a namespace. */
592 static struct debug_name
*
593 debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
)
594 struct debug_handle
*info
;
595 struct debug_namespace
**nsp
;
597 enum debug_object_kind kind
;
598 enum debug_object_linkage linkage
;
600 struct debug_name
*n
;
601 struct debug_namespace
*ns
;
603 n
= (struct debug_name
*) xmalloc (sizeof *n
);
604 memset (n
, 0, sizeof *n
);
608 n
->linkage
= linkage
;
613 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
614 memset (ns
, 0, sizeof *ns
);
616 ns
->tail
= &ns
->list
;
627 /* Add an object to the current namespace. */
629 static struct debug_name
*
630 debug_add_to_current_namespace (info
, name
, kind
, linkage
)
631 struct debug_handle
*info
;
633 enum debug_object_kind kind
;
634 enum debug_object_linkage linkage
;
636 struct debug_namespace
**nsp
;
638 if (info
->current_unit
== NULL
639 || info
->current_file
== NULL
)
641 debug_error (_("debug_add_to_current_namespace: no current file"));
645 if (info
->current_block
!= NULL
)
646 nsp
= &info
->current_block
->locals
;
648 nsp
= &info
->current_file
->globals
;
650 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
653 /* Return a handle for debugging information. */
658 struct debug_handle
*ret
;
660 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
661 memset (ret
, 0, sizeof *ret
);
665 /* Set the source filename. This implicitly starts a new compilation
669 debug_set_filename (handle
, name
)
673 struct debug_handle
*info
= (struct debug_handle
*) handle
;
674 struct debug_file
*nfile
;
675 struct debug_unit
*nunit
;
680 nfile
= (struct debug_file
*) xmalloc (sizeof *nfile
);
681 memset (nfile
, 0, sizeof *nfile
);
683 nfile
->filename
= name
;
685 nunit
= (struct debug_unit
*) xmalloc (sizeof *nunit
);
686 memset (nunit
, 0, sizeof *nunit
);
688 nunit
->files
= nfile
;
689 info
->current_file
= nfile
;
691 if (info
->current_unit
!= NULL
)
692 info
->current_unit
->next
= nunit
;
695 assert (info
->units
== NULL
);
699 info
->current_unit
= nunit
;
701 info
->current_function
= NULL
;
702 info
->current_block
= NULL
;
703 info
->current_lineno
= NULL
;
708 /* Change source files to the given file name. This is used for
709 include files in a single compilation unit. */
712 debug_start_source (handle
, name
)
716 struct debug_handle
*info
= (struct debug_handle
*) handle
;
717 struct debug_file
*f
, **pf
;
722 if (info
->current_unit
== NULL
)
724 debug_error (_("debug_start_source: no debug_set_filename call"));
728 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
730 if (f
->filename
[0] == name
[0]
731 && f
->filename
[1] == name
[1]
732 && strcmp (f
->filename
, name
) == 0)
734 info
->current_file
= f
;
739 f
= (struct debug_file
*) xmalloc (sizeof *f
);
740 memset (f
, 0, sizeof *f
);
744 for (pf
= &info
->current_file
->next
;
750 info
->current_file
= f
;
755 /* Record a function definition. This implicitly starts a function
756 block. The debug_type argument is the type of the return value.
757 The boolean indicates whether the function is globally visible.
758 The bfd_vma is the address of the start of the function. Currently
759 the parameter types are specified by calls to
760 debug_record_parameter. FIXME: There is no way to specify nested
764 debug_record_function (handle
, name
, return_type
, global
, addr
)
767 debug_type return_type
;
771 struct debug_handle
*info
= (struct debug_handle
*) handle
;
772 struct debug_function
*f
;
773 struct debug_block
*b
;
774 struct debug_name
*n
;
778 if (return_type
== NULL
)
781 if (info
->current_unit
== NULL
)
783 debug_error (_("debug_record_function: no debug_set_filename call"));
787 f
= (struct debug_function
*) xmalloc (sizeof *f
);
788 memset (f
, 0, sizeof *f
);
790 f
->return_type
= return_type
;
792 b
= (struct debug_block
*) xmalloc (sizeof *b
);
793 memset (b
, 0, sizeof *b
);
796 b
->end
= (bfd_vma
) -1;
800 info
->current_function
= f
;
801 info
->current_block
= b
;
803 /* FIXME: If we could handle nested functions, this would be the
804 place: we would want to use a different namespace. */
805 n
= debug_add_to_namespace (info
,
806 &info
->current_file
->globals
,
808 DEBUG_OBJECT_FUNCTION
,
810 ? DEBUG_LINKAGE_GLOBAL
811 : DEBUG_LINKAGE_STATIC
));
820 /* Record a parameter for the current function. */
823 debug_record_parameter (handle
, name
, type
, kind
, val
)
827 enum debug_parm_kind kind
;
830 struct debug_handle
*info
= (struct debug_handle
*) handle
;
831 struct debug_parameter
*p
, **pp
;
833 if (name
== NULL
|| type
== NULL
)
836 if (info
->current_unit
== NULL
837 || info
->current_function
== NULL
)
839 debug_error (_("debug_record_parameter: no current function"));
843 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
844 memset (p
, 0, sizeof *p
);
851 for (pp
= &info
->current_function
->parameters
;
860 /* End a function. FIXME: This should handle function nesting. */
863 debug_end_function (handle
, addr
)
867 struct debug_handle
*info
= (struct debug_handle
*) handle
;
869 if (info
->current_unit
== NULL
870 || info
->current_block
== NULL
871 || info
->current_function
== NULL
)
873 debug_error (_("debug_end_function: no current function"));
877 if (info
->current_block
->parent
!= NULL
)
879 debug_error (_("debug_end_function: some blocks were not closed"));
883 info
->current_block
->end
= addr
;
885 info
->current_function
= NULL
;
886 info
->current_block
= NULL
;
891 /* Start a block in a function. All local information will be
892 recorded in this block, until the matching call to debug_end_block.
893 debug_start_block and debug_end_block may be nested. The bfd_vma
894 argument is the address at which this block starts. */
897 debug_start_block (handle
, addr
)
901 struct debug_handle
*info
= (struct debug_handle
*) handle
;
902 struct debug_block
*b
, **pb
;
904 /* We must always have a current block: debug_record_function sets
906 if (info
->current_unit
== NULL
907 || info
->current_block
== NULL
)
909 debug_error (_("debug_start_block: no current block"));
913 b
= (struct debug_block
*) xmalloc (sizeof *b
);
914 memset (b
, 0, sizeof *b
);
916 b
->parent
= info
->current_block
;
918 b
->end
= (bfd_vma
) -1;
920 /* This new block is a child of the current block. */
921 for (pb
= &info
->current_block
->children
;
927 info
->current_block
= b
;
932 /* Finish a block in a function. This matches the call to
933 debug_start_block. The argument is the address at which this block
937 debug_end_block (handle
, addr
)
941 struct debug_handle
*info
= (struct debug_handle
*) handle
;
942 struct debug_block
*parent
;
944 if (info
->current_unit
== NULL
945 || info
->current_block
== NULL
)
947 debug_error (_("debug_end_block: no current block"));
951 parent
= info
->current_block
->parent
;
954 debug_error (_("debug_end_block: attempt to close top level block"));
958 info
->current_block
->end
= addr
;
960 info
->current_block
= parent
;
965 /* Associate a line number in the current source file and function
966 with a given address. */
969 debug_record_line (handle
, lineno
, addr
)
971 unsigned long lineno
;
974 struct debug_handle
*info
= (struct debug_handle
*) handle
;
975 struct debug_lineno
*l
;
978 if (info
->current_unit
== NULL
)
980 debug_error (_("debug_record_line: no current unit"));
984 l
= info
->current_lineno
;
985 if (l
!= NULL
&& l
->file
== info
->current_file
)
987 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
989 if (l
->linenos
[i
] == (unsigned long) -1)
991 l
->linenos
[i
] = lineno
;
998 /* If we get here, then either 1) there is no current_lineno
999 structure, which means this is the first line number in this
1000 compilation unit, 2) the current_lineno structure is for a
1001 different file, or 3) the current_lineno structure is full.
1002 Regardless, we want to allocate a new debug_lineno structure, put
1003 it in the right place, and make it the new current_lineno
1006 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
1007 memset (l
, 0, sizeof *l
);
1009 l
->file
= info
->current_file
;
1010 l
->linenos
[0] = lineno
;
1012 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
1013 l
->linenos
[i
] = (unsigned long) -1;
1015 if (info
->current_lineno
!= NULL
)
1016 info
->current_lineno
->next
= l
;
1018 info
->current_unit
->linenos
= l
;
1020 info
->current_lineno
= l
;
1025 /* Start a named common block. This is a block of variables that may
1029 debug_start_common_block (handle
, name
)
1034 debug_error (_("debug_start_common_block: not implemented"));
1038 /* End a named common block. */
1041 debug_end_common_block (handle
, name
)
1046 debug_error (_("debug_end_common_block: not implemented"));
1050 /* Record a named integer constant. */
1053 debug_record_int_const (handle
, name
, val
)
1058 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1059 struct debug_name
*n
;
1064 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1065 DEBUG_LINKAGE_NONE
);
1069 n
->u
.int_constant
= val
;
1074 /* Record a named floating point constant. */
1077 debug_record_float_const (handle
, name
, val
)
1082 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1083 struct debug_name
*n
;
1088 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1089 DEBUG_LINKAGE_NONE
);
1093 n
->u
.float_constant
= val
;
1098 /* Record a typed constant with an integral value. */
1101 debug_record_typed_const (handle
, name
, type
, val
)
1107 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1108 struct debug_name
*n
;
1109 struct debug_typed_constant
*tc
;
1111 if (name
== NULL
|| type
== NULL
)
1114 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1115 DEBUG_LINKAGE_NONE
);
1119 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1120 memset (tc
, 0, sizeof *tc
);
1125 n
->u
.typed_constant
= tc
;
1130 /* Record a label. */
1133 debug_record_label (handle
, name
, type
, addr
)
1140 debug_error (_("debug_record_label not implemented"));
1144 /* Record a variable. */
1147 debug_record_variable (handle
, name
, type
, kind
, val
)
1151 enum debug_var_kind kind
;
1154 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1155 struct debug_namespace
**nsp
;
1156 enum debug_object_linkage linkage
;
1157 struct debug_name
*n
;
1158 struct debug_variable
*v
;
1160 if (name
== NULL
|| type
== NULL
)
1163 if (info
->current_unit
== NULL
1164 || info
->current_file
== NULL
)
1166 debug_error (_("debug_record_variable: no current file"));
1170 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1172 nsp
= &info
->current_file
->globals
;
1173 if (kind
== DEBUG_GLOBAL
)
1174 linkage
= DEBUG_LINKAGE_GLOBAL
;
1176 linkage
= DEBUG_LINKAGE_STATIC
;
1180 if (info
->current_block
== NULL
)
1182 debug_error (_("debug_record_variable: no current block"));
1185 nsp
= &info
->current_block
->locals
;
1186 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1189 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1193 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1194 memset (v
, 0, sizeof *v
);
1205 /* Make a type with a given kind and size. */
1208 static struct debug_type
*
1209 debug_make_type (info
, kind
, size
)
1210 struct debug_handle
*info
;
1211 enum debug_type_kind kind
;
1214 struct debug_type
*t
;
1216 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1217 memset (t
, 0, sizeof *t
);
1225 /* Make an indirect type which may be used as a placeholder for a type
1226 which is referenced before it is defined. */
1229 debug_make_indirect_type (handle
, slot
, tag
)
1234 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1235 struct debug_type
*t
;
1236 struct debug_indirect_type
*i
;
1238 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1240 return DEBUG_TYPE_NULL
;
1242 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1243 memset (i
, 0, sizeof *i
);
1253 /* Make a void type. There is only one of these. */
1256 debug_make_void_type (handle
)
1259 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1261 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1264 /* Make an integer type of a given size. The boolean argument is true
1265 if the integer is unsigned. */
1268 debug_make_int_type (handle
, size
, unsignedp
)
1273 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1274 struct debug_type
*t
;
1276 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1278 return DEBUG_TYPE_NULL
;
1280 t
->u
.kint
= unsignedp
;
1285 /* Make a floating point type of a given size. FIXME: On some
1286 platforms, like an Alpha, you probably need to be able to specify
1290 debug_make_float_type (handle
, size
)
1294 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1296 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1299 /* Make a boolean type of a given size. */
1302 debug_make_bool_type (handle
, size
)
1306 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1308 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1311 /* Make a complex type of a given size. */
1314 debug_make_complex_type (handle
, size
)
1318 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1320 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1323 /* Make a structure type. The second argument is true for a struct,
1324 false for a union. The third argument is the size of the struct.
1325 The fourth argument is a NULL terminated array of fields. */
1328 debug_make_struct_type (handle
, structp
, size
, fields
)
1332 debug_field
*fields
;
1334 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1335 struct debug_type
*t
;
1336 struct debug_class_type
*c
;
1338 t
= debug_make_type (info
,
1339 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1342 return DEBUG_TYPE_NULL
;
1344 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1345 memset (c
, 0, sizeof *c
);
1354 /* Make an object type. The first three arguments after the handle
1355 are the same as for debug_make_struct_type. The next arguments are
1356 a NULL terminated array of base classes, a NULL terminated array of
1357 methods, the type of the object holding the virtual function table
1358 if it is not this object, and a boolean which is true if this
1359 object has its own virtual function table. */
1362 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1363 methods
, vptrbase
, ownvptr
)
1367 debug_field
*fields
;
1368 debug_baseclass
*baseclasses
;
1369 debug_method
*methods
;
1370 debug_type vptrbase
;
1373 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1374 struct debug_type
*t
;
1375 struct debug_class_type
*c
;
1377 t
= debug_make_type (info
,
1378 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1381 return DEBUG_TYPE_NULL
;
1383 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1384 memset (c
, 0, sizeof *c
);
1387 c
->baseclasses
= baseclasses
;
1388 c
->methods
= methods
;
1392 c
->vptrbase
= vptrbase
;
1399 /* Make an enumeration type. The arguments are a null terminated
1400 array of strings, and an array of corresponding values. */
1403 debug_make_enum_type (handle
, names
, values
)
1406 bfd_signed_vma
*values
;
1408 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1409 struct debug_type
*t
;
1410 struct debug_enum_type
*e
;
1412 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1414 return DEBUG_TYPE_NULL
;
1416 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1417 memset (e
, 0, sizeof *e
);
1427 /* Make a pointer to a given type. */
1430 debug_make_pointer_type (handle
, type
)
1434 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1435 struct debug_type
*t
;
1438 return DEBUG_TYPE_NULL
;
1440 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1441 return type
->pointer
;
1443 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1445 return DEBUG_TYPE_NULL
;
1447 t
->u
.kpointer
= type
;
1454 /* Make a function returning a given type. FIXME: We should be able
1455 to record the parameter types. */
1458 debug_make_function_type (handle
, type
, arg_types
, varargs
)
1461 debug_type
*arg_types
;
1464 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1465 struct debug_type
*t
;
1466 struct debug_function_type
*f
;
1469 return DEBUG_TYPE_NULL
;
1471 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1473 return DEBUG_TYPE_NULL
;
1475 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1476 memset (f
, 0, sizeof *f
);
1478 f
->return_type
= type
;
1479 f
->arg_types
= arg_types
;
1480 f
->varargs
= varargs
;
1487 /* Make a reference to a given type. */
1490 debug_make_reference_type (handle
, type
)
1494 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1495 struct debug_type
*t
;
1498 return DEBUG_TYPE_NULL
;
1500 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1502 return DEBUG_TYPE_NULL
;
1504 t
->u
.kreference
= type
;
1509 /* Make a range of a given type from a lower to an upper bound. */
1512 debug_make_range_type (handle
, type
, lower
, upper
)
1515 bfd_signed_vma lower
;
1516 bfd_signed_vma upper
;
1518 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1519 struct debug_type
*t
;
1520 struct debug_range_type
*r
;
1523 return DEBUG_TYPE_NULL
;
1525 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1527 return DEBUG_TYPE_NULL
;
1529 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1530 memset (r
, 0, sizeof *r
);
1541 /* Make an array type. The second argument is the type of an element
1542 of the array. The third argument is the type of a range of the
1543 array. The fourth and fifth argument are the lower and upper
1544 bounds, respectively. The sixth argument is true if this array is
1545 actually a string, as in C. */
1548 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1551 debug_type element_type
;
1552 debug_type range_type
;
1553 bfd_signed_vma lower
;
1554 bfd_signed_vma upper
;
1557 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1558 struct debug_type
*t
;
1559 struct debug_array_type
*a
;
1561 if (element_type
== NULL
|| range_type
== NULL
)
1562 return DEBUG_TYPE_NULL
;
1564 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1566 return DEBUG_TYPE_NULL
;
1568 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1569 memset (a
, 0, sizeof *a
);
1571 a
->element_type
= element_type
;
1572 a
->range_type
= range_type
;
1575 a
->stringp
= stringp
;
1582 /* Make a set of a given type. For example, a Pascal set type. The
1583 boolean argument is true if this set is actually a bitstring, as in
1587 debug_make_set_type (handle
, type
, bitstringp
)
1592 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1593 struct debug_type
*t
;
1594 struct debug_set_type
*s
;
1597 return DEBUG_TYPE_NULL
;
1599 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1601 return DEBUG_TYPE_NULL
;
1603 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1604 memset (s
, 0, sizeof *s
);
1607 s
->bitstringp
= bitstringp
;
1614 /* Make a type for a pointer which is relative to an object. The
1615 second argument is the type of the object to which the pointer is
1616 relative. The third argument is the type that the pointer points
1620 debug_make_offset_type (handle
, base_type
, target_type
)
1622 debug_type base_type
;
1623 debug_type target_type
;
1625 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1626 struct debug_type
*t
;
1627 struct debug_offset_type
*o
;
1629 if (base_type
== NULL
|| target_type
== NULL
)
1630 return DEBUG_TYPE_NULL
;
1632 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1634 return DEBUG_TYPE_NULL
;
1636 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1637 memset (o
, 0, sizeof *o
);
1639 o
->base_type
= base_type
;
1640 o
->target_type
= target_type
;
1647 /* Make a type for a method function. The second argument is the
1648 return type, the third argument is the domain, and the fourth
1649 argument is a NULL terminated array of argument types. */
1652 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
, varargs
)
1654 debug_type return_type
;
1655 debug_type domain_type
;
1656 debug_type
*arg_types
;
1659 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1660 struct debug_type
*t
;
1661 struct debug_method_type
*m
;
1663 if (return_type
== NULL
)
1664 return DEBUG_TYPE_NULL
;
1666 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1668 return DEBUG_TYPE_NULL
;
1670 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1671 memset (m
, 0, sizeof *m
);
1673 m
->return_type
= return_type
;
1674 m
->domain_type
= domain_type
;
1675 m
->arg_types
= arg_types
;
1676 m
->varargs
= varargs
;
1683 /* Make a const qualified version of a given type. */
1686 debug_make_const_type (handle
, type
)
1690 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1691 struct debug_type
*t
;
1694 return DEBUG_TYPE_NULL
;
1696 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1698 return DEBUG_TYPE_NULL
;
1705 /* Make a volatile qualified version of a given type. */
1708 debug_make_volatile_type (handle
, type
)
1712 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1713 struct debug_type
*t
;
1716 return DEBUG_TYPE_NULL
;
1718 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1720 return DEBUG_TYPE_NULL
;
1722 t
->u
.kvolatile
= type
;
1727 /* Make an undefined tagged type. For example, a struct which has
1728 been mentioned, but not defined. */
1731 debug_make_undefined_tagged_type (handle
, name
, kind
)
1734 enum debug_type_kind kind
;
1736 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1737 struct debug_type
*t
;
1740 return DEBUG_TYPE_NULL
;
1744 case DEBUG_KIND_STRUCT
:
1745 case DEBUG_KIND_UNION
:
1746 case DEBUG_KIND_CLASS
:
1747 case DEBUG_KIND_UNION_CLASS
:
1748 case DEBUG_KIND_ENUM
:
1752 debug_error (_("debug_make_undefined_type: unsupported kind"));
1753 return DEBUG_TYPE_NULL
;
1756 t
= debug_make_type (info
, kind
, 0);
1758 return DEBUG_TYPE_NULL
;
1760 return debug_tag_type (handle
, name
, t
);
1763 /* Make a base class for an object. The second argument is the base
1764 class type. The third argument is the bit position of this base
1765 class in the object (always 0 unless doing multiple inheritance).
1766 The fourth argument is whether this is a virtual class. The fifth
1767 argument is the visibility of the base class. */
1771 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1776 enum debug_visibility visibility
;
1778 struct debug_baseclass
*b
;
1780 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1781 memset (b
, 0, sizeof *b
);
1785 b
->virtual = virtual;
1786 b
->visibility
= visibility
;
1791 /* Make a field for a struct. The second argument is the name. The
1792 third argument is the type of the field. The fourth argument is
1793 the bit position of the field. The fifth argument is the size of
1794 the field (it may be zero). The sixth argument is the visibility
1799 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1805 enum debug_visibility visibility
;
1807 struct debug_field
*f
;
1809 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1810 memset (f
, 0, sizeof *f
);
1814 f
->static_member
= false;
1815 f
->u
.f
.bitpos
= bitpos
;
1816 f
->u
.f
.bitsize
= bitsize
;
1817 f
->visibility
= visibility
;
1822 /* Make a static member of an object. The second argument is the
1823 name. The third argument is the type of the member. The fourth
1824 argument is the physical name of the member (i.e., the name as a
1825 global variable). The fifth argument is the visibility of the
1830 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1834 const char *physname
;
1835 enum debug_visibility visibility
;
1837 struct debug_field
*f
;
1839 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1840 memset (f
, 0, sizeof *f
);
1844 f
->static_member
= true;
1845 f
->u
.s
.physname
= physname
;
1846 f
->visibility
= visibility
;
1851 /* Make a method. The second argument is the name, and the third
1852 argument is a NULL terminated array of method variants. */
1856 debug_make_method (handle
, name
, variants
)
1859 debug_method_variant
*variants
;
1861 struct debug_method
*m
;
1863 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1864 memset (m
, 0, sizeof *m
);
1867 m
->variants
= variants
;
1872 /* Make a method argument. The second argument is the real name of
1873 the function. The third argument is the type of the function. The
1874 fourth argument is the visibility. The fifth argument is whether
1875 this is a const function. The sixth argument is whether this is a
1876 volatile function. The seventh argument is the offset in the
1877 virtual function table, if any. The eighth argument is the virtual
1878 function context. FIXME: Are the const and volatile arguments
1879 necessary? Could we just use debug_make_const_type? */
1882 debug_method_variant
1883 debug_make_method_variant (handle
, physname
, type
, visibility
, constp
,
1884 volatilep
, voffset
, context
)
1886 const char *physname
;
1888 enum debug_visibility visibility
;
1894 struct debug_method_variant
*m
;
1896 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1897 memset (m
, 0, sizeof *m
);
1899 m
->physname
= physname
;
1901 m
->visibility
= visibility
;
1903 m
->volatilep
= volatilep
;
1904 m
->voffset
= voffset
;
1905 m
->context
= context
;
1910 /* Make a static method argument. The arguments are the same as for
1911 debug_make_method_variant, except that the last two are omitted
1912 since a static method can not also be virtual. */
1914 debug_method_variant
1915 debug_make_static_method_variant (handle
, physname
, type
, visibility
,
1918 const char *physname
;
1920 enum debug_visibility visibility
;
1924 struct debug_method_variant
*m
;
1926 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1927 memset (m
, 0, sizeof *m
);
1929 m
->physname
= physname
;
1931 m
->visibility
= visibility
;
1933 m
->volatilep
= volatilep
;
1934 m
->voffset
= VOFFSET_STATIC_METHOD
;
1942 debug_name_type (handle
, name
, type
)
1947 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1948 struct debug_type
*t
;
1949 struct debug_named_type
*n
;
1950 struct debug_name
*nm
;
1952 if (name
== NULL
|| type
== NULL
)
1953 return DEBUG_TYPE_NULL
;
1955 if (info
->current_unit
== NULL
1956 || info
->current_file
== NULL
)
1958 debug_error (_("debug_name_type: no current file"));
1962 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1964 return DEBUG_TYPE_NULL
;
1966 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1967 memset (n
, 0, sizeof *n
);
1973 /* We always add the name to the global namespace. This is probably
1974 wrong in some cases, but it seems to be right for stabs. FIXME. */
1976 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1977 DEBUG_OBJECT_TYPE
, DEBUG_LINKAGE_NONE
);
1991 debug_tag_type (handle
, name
, type
)
1996 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1997 struct debug_type
*t
;
1998 struct debug_named_type
*n
;
1999 struct debug_name
*nm
;
2001 if (name
== NULL
|| type
== NULL
)
2002 return DEBUG_TYPE_NULL
;
2004 if (info
->current_file
== NULL
)
2006 debug_error (_("debug_tag_type: no current file"));
2007 return DEBUG_TYPE_NULL
;
2010 if (type
->kind
== DEBUG_KIND_TAGGED
)
2012 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
2014 debug_error (_("debug_tag_type: extra tag attempted"));
2015 return DEBUG_TYPE_NULL
;
2018 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
2020 return DEBUG_TYPE_NULL
;
2022 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
2023 memset (n
, 0, sizeof *n
);
2029 /* We keep a global namespace of tags for each compilation unit. I
2030 don't know if that is the right thing to do. */
2032 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
2033 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2044 /* Record the size of a given type. */
2048 debug_record_type_size (handle
, type
, size
)
2053 if (type
->size
!= 0 && type
->size
!= size
)
2054 fprintf (stderr
, _("Warning: changing type size from %d to %d\n"),
2062 /* Find a named type. */
2065 debug_find_named_type (handle
, name
)
2069 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2070 struct debug_block
*b
;
2071 struct debug_file
*f
;
2073 /* We only search the current compilation unit. I don't know if
2074 this is right or not. */
2076 if (info
->current_unit
== NULL
)
2078 debug_error (_("debug_find_named_type: no current compilation unit"));
2079 return DEBUG_TYPE_NULL
;
2082 for (b
= info
->current_block
; b
!= NULL
; b
= b
->parent
)
2084 if (b
->locals
!= NULL
)
2086 struct debug_name
*n
;
2088 for (n
= b
->locals
->list
; n
!= NULL
; n
= n
->next
)
2090 if (n
->kind
== DEBUG_OBJECT_TYPE
2091 && n
->name
[0] == name
[0]
2092 && strcmp (n
->name
, name
) == 0)
2098 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
2100 if (f
->globals
!= NULL
)
2102 struct debug_name
*n
;
2104 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2106 if (n
->kind
== DEBUG_OBJECT_TYPE
2107 && n
->name
[0] == name
[0]
2108 && strcmp (n
->name
, name
) == 0)
2114 return DEBUG_TYPE_NULL
;
2117 /* Find a tagged type. */
2120 debug_find_tagged_type (handle
, name
, kind
)
2123 enum debug_type_kind kind
;
2125 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2126 struct debug_unit
*u
;
2128 /* We search the globals of all the compilation units. I don't know
2129 if this is correct or not. It would be easy to change. */
2131 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2133 struct debug_file
*f
;
2135 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2137 struct debug_name
*n
;
2139 if (f
->globals
!= NULL
)
2141 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2143 if (n
->kind
== DEBUG_OBJECT_TAG
2144 && (kind
== DEBUG_KIND_ILLEGAL
2145 || n
->u
.tag
->kind
== kind
)
2146 && n
->name
[0] == name
[0]
2147 && strcmp (n
->name
, name
) == 0)
2154 return DEBUG_TYPE_NULL
;
2157 /* Get a base type. */
2159 static struct debug_type
*
2160 debug_get_real_type (handle
, type
)
2168 case DEBUG_KIND_INDIRECT
:
2169 if (*type
->u
.kindirect
->slot
!= NULL
)
2170 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
);
2172 case DEBUG_KIND_NAMED
:
2173 case DEBUG_KIND_TAGGED
:
2174 return debug_get_real_type (handle
, type
->u
.knamed
->type
);
2179 /* Get the kind of a type. */
2181 enum debug_type_kind
2182 debug_get_type_kind (handle
, type
)
2187 return DEBUG_KIND_ILLEGAL
;
2188 type
= debug_get_real_type (handle
, type
);
2192 /* Get the name of a type. */
2195 debug_get_type_name (handle
, type
)
2199 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2201 if (*type
->u
.kindirect
->slot
!= NULL
)
2202 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2203 return type
->u
.kindirect
->tag
;
2205 if (type
->kind
== DEBUG_KIND_NAMED
2206 || type
->kind
== DEBUG_KIND_TAGGED
)
2207 return type
->u
.knamed
->name
->name
;
2211 /* Get the size of a type. */
2214 debug_get_type_size (handle
, type
)
2221 /* We don't call debug_get_real_type, because somebody might have
2222 called debug_record_type_size on a named or indirect type. */
2224 if (type
->size
!= 0)
2231 case DEBUG_KIND_INDIRECT
:
2232 if (*type
->u
.kindirect
->slot
!= NULL
)
2233 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2235 case DEBUG_KIND_NAMED
:
2236 case DEBUG_KIND_TAGGED
:
2237 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2242 /* Get the return type of a function or method type. */
2245 debug_get_return_type (handle
, type
)
2250 return DEBUG_TYPE_NULL
;
2251 type
= debug_get_real_type (handle
, type
);
2255 return DEBUG_TYPE_NULL
;
2256 case DEBUG_KIND_FUNCTION
:
2257 return type
->u
.kfunction
->return_type
;
2258 case DEBUG_KIND_METHOD
:
2259 return type
->u
.kmethod
->return_type
;
2264 /* Get the parameter types of a function or method type (except that
2265 we don't currently store the parameter types of a function). */
2268 debug_get_parameter_types (handle
, type
, pvarargs
)
2275 type
= debug_get_real_type (handle
, type
);
2280 case DEBUG_KIND_FUNCTION
:
2281 *pvarargs
= type
->u
.kfunction
->varargs
;
2282 return type
->u
.kfunction
->arg_types
;
2283 case DEBUG_KIND_METHOD
:
2284 *pvarargs
= type
->u
.kmethod
->varargs
;
2285 return type
->u
.kmethod
->arg_types
;
2290 /* Get the target type of a type. */
2293 debug_get_target_type (handle
, type
)
2299 type
= debug_get_real_type (handle
, type
);
2304 case DEBUG_KIND_POINTER
:
2305 return type
->u
.kpointer
;
2306 case DEBUG_KIND_REFERENCE
:
2307 return type
->u
.kreference
;
2308 case DEBUG_KIND_CONST
:
2309 return type
->u
.kconst
;
2310 case DEBUG_KIND_VOLATILE
:
2311 return type
->u
.kvolatile
;
2316 /* Get the NULL terminated array of fields for a struct, union, or
2320 debug_get_fields (handle
, type
)
2326 type
= debug_get_real_type (handle
, type
);
2331 case DEBUG_KIND_STRUCT
:
2332 case DEBUG_KIND_UNION
:
2333 case DEBUG_KIND_CLASS
:
2334 case DEBUG_KIND_UNION_CLASS
:
2335 return type
->u
.kclass
->fields
;
2340 /* Get the type of a field. */
2344 debug_get_field_type (handle
, field
)
2353 /* Get the name of a field. */
2357 debug_get_field_name (handle
, field
)
2366 /* Get the bit position of a field. */
2370 debug_get_field_bitpos (handle
, field
)
2374 if (field
== NULL
|| field
->static_member
)
2375 return (bfd_vma
) -1;
2376 return field
->u
.f
.bitpos
;
2379 /* Get the bit size of a field. */
2383 debug_get_field_bitsize (handle
, field
)
2387 if (field
== NULL
|| field
->static_member
)
2388 return (bfd_vma
) -1;
2389 return field
->u
.f
.bitsize
;
2392 /* Get the visibility of a field. */
2395 enum debug_visibility
2396 debug_get_field_visibility (handle
, field
)
2401 return DEBUG_VISIBILITY_IGNORE
;
2402 return field
->visibility
;
2405 /* Get the physical name of a field. */
2408 debug_get_field_physname (handle
, field
)
2412 if (field
== NULL
|| ! field
->static_member
)
2414 return field
->u
.s
.physname
;
2417 /* Write out the debugging information. This is given a handle to
2418 debugging information, and a set of function pointers to call. */
2421 debug_write (handle
, fns
, fhandle
)
2423 const struct debug_write_fns
*fns
;
2426 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2427 struct debug_unit
*u
;
2429 /* We use a mark to tell whether we have already written out a
2430 particular name. We use an integer, so that we don't have to
2431 clear the mark fields if we happen to write out the same
2432 information more than once. */
2435 /* The base_id field holds an ID value which will never be used, so
2436 that we can tell whether we have assigned an ID during this call
2438 info
->base_id
= info
->class_id
;
2440 /* We keep a linked list of classes for which was have assigned ID's
2441 during this call to debug_write. */
2442 info
->id_list
= NULL
;
2444 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2446 struct debug_file
*f
;
2449 info
->current_write_lineno
= u
->linenos
;
2450 info
->current_write_lineno_index
= 0;
2452 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2456 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2458 struct debug_name
*n
;
2464 if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2468 if (f
->globals
!= NULL
)
2470 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2472 if (! debug_write_name (info
, fns
, fhandle
, n
))
2478 /* Output any line number information which hasn't already been
2480 if (! debug_write_linenos (info
, fns
, fhandle
, (bfd_vma
) -1))
2487 /* Write out an element in a namespace. */
2490 debug_write_name (info
, fns
, fhandle
, n
)
2491 struct debug_handle
*info
;
2492 const struct debug_write_fns
*fns
;
2494 struct debug_name
*n
;
2498 case DEBUG_OBJECT_TYPE
:
2499 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2500 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2503 case DEBUG_OBJECT_TAG
:
2504 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2506 return (*fns
->tag
) (fhandle
, n
->name
);
2507 case DEBUG_OBJECT_VARIABLE
:
2508 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2509 (struct debug_name
*) NULL
))
2511 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2512 n
->u
.variable
->val
);
2513 case DEBUG_OBJECT_FUNCTION
:
2514 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2515 n
->linkage
, n
->u
.function
);
2516 case DEBUG_OBJECT_INT_CONSTANT
:
2517 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2518 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2519 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2520 case DEBUG_OBJECT_TYPED_CONSTANT
:
2521 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2522 (struct debug_name
*) NULL
))
2524 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2525 n
->u
.typed_constant
->val
);
2533 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2534 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2535 are about to call typedef or tag. If the type is anything else,
2536 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2537 points to this one. */
2540 debug_write_type (info
, fns
, fhandle
, type
, name
)
2541 struct debug_handle
*info
;
2542 const struct debug_write_fns
*fns
;
2544 struct debug_type
*type
;
2545 struct debug_name
*name
;
2551 /* If we have a name for this type, just output it. We only output
2552 typedef names after they have been defined. We output type tags
2553 whenever we are not actually defining them. */
2554 if ((type
->kind
== DEBUG_KIND_NAMED
2555 || type
->kind
== DEBUG_KIND_TAGGED
)
2556 && (type
->u
.knamed
->name
->mark
== info
->mark
2557 || (type
->kind
== DEBUG_KIND_TAGGED
2558 && type
->u
.knamed
->name
!= name
)))
2560 if (type
->kind
== DEBUG_KIND_NAMED
)
2561 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2564 struct debug_type
*real
;
2567 real
= debug_get_real_type ((PTR
) info
, type
);
2569 if ((real
->kind
== DEBUG_KIND_STRUCT
2570 || real
->kind
== DEBUG_KIND_UNION
2571 || real
->kind
== DEBUG_KIND_CLASS
2572 || real
->kind
== DEBUG_KIND_UNION_CLASS
)
2573 && real
->u
.kclass
!= NULL
)
2575 if (real
->u
.kclass
->id
<= info
->base_id
)
2577 if (! debug_set_class_id (info
,
2578 type
->u
.knamed
->name
->name
,
2582 id
= real
->u
.kclass
->id
;
2585 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, id
,
2590 /* Mark the name after we have already looked for a known name, so
2591 that we don't just define a type in terms of itself. We need to
2592 mark the name here so that a struct containing a pointer to
2593 itself will work. */
2595 name
->mark
= info
->mark
;
2599 && type
->kind
!= DEBUG_KIND_NAMED
2600 && type
->kind
!= DEBUG_KIND_TAGGED
)
2602 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2608 case DEBUG_KIND_ILLEGAL
:
2609 debug_error (_("debug_write_type: illegal type encountered"));
2611 case DEBUG_KIND_INDIRECT
:
2612 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2613 return (*fns
->empty_type
) (fhandle
);
2614 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2616 case DEBUG_KIND_VOID
:
2617 return (*fns
->void_type
) (fhandle
);
2618 case DEBUG_KIND_INT
:
2619 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2620 case DEBUG_KIND_FLOAT
:
2621 return (*fns
->float_type
) (fhandle
, type
->size
);
2622 case DEBUG_KIND_COMPLEX
:
2623 return (*fns
->complex_type
) (fhandle
, type
->size
);
2624 case DEBUG_KIND_BOOL
:
2625 return (*fns
->bool_type
) (fhandle
, type
->size
);
2626 case DEBUG_KIND_STRUCT
:
2627 case DEBUG_KIND_UNION
:
2628 if (type
->u
.kclass
!= NULL
)
2630 if (type
->u
.kclass
->id
<= info
->base_id
)
2632 if (! debug_set_class_id (info
, tag
, type
))
2636 if (info
->mark
== type
->u
.kclass
->mark
)
2638 /* We are currently outputting this struct, or we have
2639 already output it. I don't know if this can happen,
2640 but it can happen for a class. */
2641 assert (type
->u
.kclass
->id
> info
->base_id
);
2642 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2645 type
->u
.kclass
->mark
= info
->mark
;
2648 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2649 (type
->u
.kclass
!= NULL
2650 ? type
->u
.kclass
->id
2652 type
->kind
== DEBUG_KIND_STRUCT
,
2655 if (type
->u
.kclass
!= NULL
2656 && type
->u
.kclass
->fields
!= NULL
)
2658 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2660 struct debug_field
*f
;
2662 f
= type
->u
.kclass
->fields
[i
];
2663 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2664 (struct debug_name
*) NULL
)
2665 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2666 f
->u
.f
.bitsize
, f
->visibility
))
2670 return (*fns
->end_struct_type
) (fhandle
);
2671 case DEBUG_KIND_CLASS
:
2672 case DEBUG_KIND_UNION_CLASS
:
2673 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2674 case DEBUG_KIND_ENUM
:
2675 if (type
->u
.kenum
== NULL
)
2676 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2677 (bfd_signed_vma
*) NULL
);
2678 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2679 type
->u
.kenum
->values
);
2680 case DEBUG_KIND_POINTER
:
2681 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2682 (struct debug_name
*) NULL
))
2684 return (*fns
->pointer_type
) (fhandle
);
2685 case DEBUG_KIND_FUNCTION
:
2686 if (! debug_write_type (info
, fns
, fhandle
,
2687 type
->u
.kfunction
->return_type
,
2688 (struct debug_name
*) NULL
))
2690 if (type
->u
.kfunction
->arg_types
== NULL
)
2694 for (is
= 0; type
->u
.kfunction
->arg_types
[is
] != NULL
; is
++)
2695 if (! debug_write_type (info
, fns
, fhandle
,
2696 type
->u
.kfunction
->arg_types
[is
],
2697 (struct debug_name
*) NULL
))
2700 return (*fns
->function_type
) (fhandle
, is
,
2701 type
->u
.kfunction
->varargs
);
2702 case DEBUG_KIND_REFERENCE
:
2703 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2704 (struct debug_name
*) NULL
))
2706 return (*fns
->reference_type
) (fhandle
);
2707 case DEBUG_KIND_RANGE
:
2708 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2709 (struct debug_name
*) NULL
))
2711 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2712 type
->u
.krange
->upper
);
2713 case DEBUG_KIND_ARRAY
:
2714 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2715 (struct debug_name
*) NULL
)
2716 || ! debug_write_type (info
, fns
, fhandle
,
2717 type
->u
.karray
->range_type
,
2718 (struct debug_name
*) NULL
))
2720 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2721 type
->u
.karray
->upper
,
2722 type
->u
.karray
->stringp
);
2723 case DEBUG_KIND_SET
:
2724 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2725 (struct debug_name
*) NULL
))
2727 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2728 case DEBUG_KIND_OFFSET
:
2729 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2730 (struct debug_name
*) NULL
)
2731 || ! debug_write_type (info
, fns
, fhandle
,
2732 type
->u
.koffset
->target_type
,
2733 (struct debug_name
*) NULL
))
2735 return (*fns
->offset_type
) (fhandle
);
2736 case DEBUG_KIND_METHOD
:
2737 if (! debug_write_type (info
, fns
, fhandle
,
2738 type
->u
.kmethod
->return_type
,
2739 (struct debug_name
*) NULL
))
2741 if (type
->u
.kmethod
->arg_types
== NULL
)
2745 for (is
= 0; type
->u
.kmethod
->arg_types
[is
] != NULL
; is
++)
2746 if (! debug_write_type (info
, fns
, fhandle
,
2747 type
->u
.kmethod
->arg_types
[is
],
2748 (struct debug_name
*) NULL
))
2751 if (type
->u
.kmethod
->domain_type
!= NULL
)
2753 if (! debug_write_type (info
, fns
, fhandle
,
2754 type
->u
.kmethod
->domain_type
,
2755 (struct debug_name
*) NULL
))
2758 return (*fns
->method_type
) (fhandle
,
2759 type
->u
.kmethod
->domain_type
!= NULL
,
2761 type
->u
.kmethod
->varargs
);
2762 case DEBUG_KIND_CONST
:
2763 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2764 (struct debug_name
*) NULL
))
2766 return (*fns
->const_type
) (fhandle
);
2767 case DEBUG_KIND_VOLATILE
:
2768 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2769 (struct debug_name
*) NULL
))
2771 return (*fns
->volatile_type
) (fhandle
);
2772 case DEBUG_KIND_NAMED
:
2773 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2774 (struct debug_name
*) NULL
);
2775 case DEBUG_KIND_TAGGED
:
2776 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2777 type
->u
.knamed
->name
);
2784 /* Write out a class type. */
2787 debug_write_class_type (info
, fns
, fhandle
, type
, tag
)
2788 struct debug_handle
*info
;
2789 const struct debug_write_fns
*fns
;
2791 struct debug_type
*type
;
2796 struct debug_type
*vptrbase
;
2798 if (type
->u
.kclass
== NULL
)
2805 if (type
->u
.kclass
->id
<= info
->base_id
)
2807 if (! debug_set_class_id (info
, tag
, type
))
2811 if (info
->mark
== type
->u
.kclass
->mark
)
2813 /* We are currently outputting this class, or we have
2814 already output it. This can happen when there are
2815 methods for an anonymous class. */
2816 assert (type
->u
.kclass
->id
> info
->base_id
);
2817 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2820 type
->u
.kclass
->mark
= info
->mark
;
2821 id
= type
->u
.kclass
->id
;
2823 vptrbase
= type
->u
.kclass
->vptrbase
;
2824 if (vptrbase
!= NULL
&& vptrbase
!= type
)
2826 if (! debug_write_type (info
, fns
, fhandle
, vptrbase
,
2827 (struct debug_name
*) NULL
))
2832 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2833 type
->kind
== DEBUG_KIND_CLASS
,
2839 if (type
->u
.kclass
!= NULL
)
2841 if (type
->u
.kclass
->fields
!= NULL
)
2843 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2845 struct debug_field
*f
;
2847 f
= type
->u
.kclass
->fields
[i
];
2848 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2849 (struct debug_name
*) NULL
))
2851 if (f
->static_member
)
2853 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2860 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2861 f
->u
.f
.bitsize
, f
->visibility
))
2867 if (type
->u
.kclass
->baseclasses
!= NULL
)
2869 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2871 struct debug_baseclass
*b
;
2873 b
= type
->u
.kclass
->baseclasses
[i
];
2874 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2875 (struct debug_name
*) NULL
))
2877 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2883 if (type
->u
.kclass
->methods
!= NULL
)
2885 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2887 struct debug_method
*m
;
2890 m
= type
->u
.kclass
->methods
[i
];
2891 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2893 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2895 struct debug_method_variant
*v
;
2898 if (v
->context
!= NULL
)
2900 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2901 (struct debug_name
*) NULL
))
2904 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2905 (struct debug_name
*) NULL
))
2907 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2909 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2914 v
->context
!= NULL
))
2919 if (! (*fns
->class_static_method_variant
) (fhandle
,
2927 if (! (*fns
->class_end_method
) (fhandle
))
2933 return (*fns
->end_class_type
) (fhandle
);
2936 /* Write out information for a function. */
2939 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2940 struct debug_handle
*info
;
2941 const struct debug_write_fns
*fns
;
2944 enum debug_object_linkage linkage
;
2945 struct debug_function
*function
;
2947 struct debug_parameter
*p
;
2948 struct debug_block
*b
;
2950 if (! debug_write_linenos (info
, fns
, fhandle
, function
->blocks
->start
))
2953 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2954 (struct debug_name
*) NULL
))
2957 if (! (*fns
->start_function
) (fhandle
, name
,
2958 linkage
== DEBUG_LINKAGE_GLOBAL
))
2961 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
2963 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
2964 (struct debug_name
*) NULL
)
2965 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
2969 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2971 if (! debug_write_block (info
, fns
, fhandle
, b
))
2975 return (*fns
->end_function
) (fhandle
);
2978 /* Write out information for a block. */
2981 debug_write_block (info
, fns
, fhandle
, block
)
2982 struct debug_handle
*info
;
2983 const struct debug_write_fns
*fns
;
2985 struct debug_block
*block
;
2987 struct debug_name
*n
;
2988 struct debug_block
*b
;
2990 if (! debug_write_linenos (info
, fns
, fhandle
, block
->start
))
2993 /* I can't see any point to writing out a block with no local
2994 variables, so we don't bother, except for the top level block. */
2995 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
2997 if (! (*fns
->start_block
) (fhandle
, block
->start
))
3001 if (block
->locals
!= NULL
)
3003 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
3005 if (! debug_write_name (info
, fns
, fhandle
, n
))
3010 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
3012 if (! debug_write_block (info
, fns
, fhandle
, b
))
3016 if (! debug_write_linenos (info
, fns
, fhandle
, block
->end
))
3019 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
3021 if (! (*fns
->end_block
) (fhandle
, block
->end
))
3028 /* Write out line number information up to ADDRESS. */
3031 debug_write_linenos (info
, fns
, fhandle
, address
)
3032 struct debug_handle
*info
;
3033 const struct debug_write_fns
*fns
;
3037 while (info
->current_write_lineno
!= NULL
)
3039 struct debug_lineno
*l
;
3041 l
= info
->current_write_lineno
;
3043 while (info
->current_write_lineno_index
< DEBUG_LINENO_COUNT
)
3045 if (l
->linenos
[info
->current_write_lineno_index
]
3046 == (unsigned long) -1)
3049 if (l
->addrs
[info
->current_write_lineno_index
] >= address
)
3052 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
,
3053 l
->linenos
[info
->current_write_lineno_index
],
3054 l
->addrs
[info
->current_write_lineno_index
]))
3057 ++info
->current_write_lineno_index
;
3060 info
->current_write_lineno
= l
->next
;
3061 info
->current_write_lineno_index
= 0;
3067 /* Get the ID number for a class. If during the same call to
3068 debug_write we find a struct with the same definition with the same
3069 name, we use the same ID. This type of things happens because the
3070 same struct will be defined by multiple compilation units. */
3073 debug_set_class_id (info
, tag
, type
)
3074 struct debug_handle
*info
;
3076 struct debug_type
*type
;
3078 struct debug_class_type
*c
;
3079 struct debug_class_id
*l
;
3081 assert (type
->kind
== DEBUG_KIND_STRUCT
3082 || type
->kind
== DEBUG_KIND_UNION
3083 || type
->kind
== DEBUG_KIND_CLASS
3084 || type
->kind
== DEBUG_KIND_UNION_CLASS
);
3088 if (c
->id
> info
->base_id
)
3091 for (l
= info
->id_list
; l
!= NULL
; l
= l
->next
)
3093 if (l
->type
->kind
!= type
->kind
)
3104 || l
->tag
[0] != tag
[0]
3105 || strcmp (l
->tag
, tag
) != 0)
3109 if (debug_type_samep (info
, l
->type
, type
))
3111 c
->id
= l
->type
->u
.kclass
->id
;
3116 /* There are no identical types. Use a new ID, and add it to the
3119 c
->id
= info
->class_id
;
3121 l
= (struct debug_class_id
*) xmalloc (sizeof *l
);
3122 memset (l
, 0, sizeof *l
);
3127 l
->next
= info
->id_list
;
3133 /* See if two types are the same. At this point, we don't care about
3134 tags and the like. */
3137 debug_type_samep (info
, t1
, t2
)
3138 struct debug_handle
*info
;
3139 struct debug_type
*t1
;
3140 struct debug_type
*t2
;
3142 struct debug_type_compare_list
*l
;
3143 struct debug_type_compare_list top
;
3151 while (t1
->kind
== DEBUG_KIND_INDIRECT
)
3153 t1
= *t1
->u
.kindirect
->slot
;
3157 while (t2
->kind
== DEBUG_KIND_INDIRECT
)
3159 t2
= *t2
->u
.kindirect
->slot
;
3167 /* As a special case, permit a typedef to match a tag, since C++
3168 debugging output will sometimes add a typedef where C debugging
3170 if (t1
->kind
== DEBUG_KIND_NAMED
3171 && t2
->kind
== DEBUG_KIND_TAGGED
)
3172 return debug_type_samep (info
, t1
->u
.knamed
->type
, t2
);
3173 else if (t1
->kind
== DEBUG_KIND_TAGGED
3174 && t2
->kind
== DEBUG_KIND_NAMED
)
3175 return debug_type_samep (info
, t1
, t2
->u
.knamed
->type
);
3177 if (t1
->kind
!= t2
->kind
3178 || t1
->size
!= t2
->size
)
3181 /* Get rid of the trivial cases first. */
3186 case DEBUG_KIND_VOID
:
3187 case DEBUG_KIND_FLOAT
:
3188 case DEBUG_KIND_COMPLEX
:
3189 case DEBUG_KIND_BOOL
:
3191 case DEBUG_KIND_INT
:
3192 return t1
->u
.kint
== t2
->u
.kint
;
3195 /* We have to avoid an infinite recursion. We do this by keeping a
3196 list of types which we are comparing. We just keep the list on
3197 the stack. If we encounter a pair of types we are currently
3198 comparing, we just assume that they are equal. */
3199 for (l
= info
->compare_list
; l
!= NULL
; l
= l
->next
)
3201 if (l
->t1
== t1
&& l
->t2
== t2
)
3207 top
.next
= info
->compare_list
;
3208 info
->compare_list
= &top
;
3217 case DEBUG_KIND_STRUCT
:
3218 case DEBUG_KIND_UNION
:
3219 case DEBUG_KIND_CLASS
:
3220 case DEBUG_KIND_UNION_CLASS
:
3221 if (t1
->u
.kclass
== NULL
)
3222 ret
= t2
->u
.kclass
== NULL
;
3223 else if (t2
->u
.kclass
== NULL
)
3225 else if (t1
->u
.kclass
->id
> info
->base_id
3226 && t1
->u
.kclass
->id
== t2
->u
.kclass
->id
)
3229 ret
= debug_class_type_samep (info
, t1
, t2
);
3232 case DEBUG_KIND_ENUM
:
3233 if (t1
->u
.kenum
== NULL
)
3234 ret
= t2
->u
.kenum
== NULL
;
3235 else if (t2
->u
.kenum
== NULL
)
3239 const char **pn1
, **pn2
;
3240 bfd_signed_vma
*pv1
, *pv2
;
3242 pn1
= t1
->u
.kenum
->names
;
3243 pn2
= t2
->u
.kenum
->names
;
3244 pv1
= t1
->u
.kenum
->values
;
3245 pv2
= t2
->u
.kenum
->values
;
3246 while (*pn1
!= NULL
&& *pn2
!= NULL
)
3250 || strcmp (*pn1
, *pn2
) != 0)
3257 ret
= *pn1
== NULL
&& *pn2
== NULL
;
3261 case DEBUG_KIND_POINTER
:
3262 ret
= debug_type_samep (info
, t1
->u
.kpointer
, t2
->u
.kpointer
);
3265 case DEBUG_KIND_FUNCTION
:
3266 if (t1
->u
.kfunction
->varargs
!= t2
->u
.kfunction
->varargs
3267 || ! debug_type_samep (info
, t1
->u
.kfunction
->return_type
,
3268 t2
->u
.kfunction
->return_type
)
3269 || ((t1
->u
.kfunction
->arg_types
== NULL
)
3270 != (t2
->u
.kfunction
->arg_types
== NULL
)))
3272 else if (t1
->u
.kfunction
->arg_types
== NULL
)
3276 struct debug_type
**a1
, **a2
;
3278 a1
= t1
->u
.kfunction
->arg_types
;
3279 a2
= t2
->u
.kfunction
->arg_types
;
3280 while (*a1
!= NULL
&& *a2
!= NULL
)
3282 if (! debug_type_samep (info
, *a1
, *a2
))
3287 ret
= *a1
== NULL
&& *a2
== NULL
;
3291 case DEBUG_KIND_REFERENCE
:
3292 ret
= debug_type_samep (info
, t1
->u
.kreference
, t2
->u
.kreference
);
3295 case DEBUG_KIND_RANGE
:
3296 ret
= (t1
->u
.krange
->lower
== t2
->u
.krange
->lower
3297 && t1
->u
.krange
->upper
== t2
->u
.krange
->upper
3298 && debug_type_samep (info
, t1
->u
.krange
->type
,
3299 t2
->u
.krange
->type
));
3301 case DEBUG_KIND_ARRAY
:
3302 ret
= (t1
->u
.karray
->lower
== t2
->u
.karray
->lower
3303 && t1
->u
.karray
->upper
== t2
->u
.karray
->upper
3304 && t1
->u
.karray
->stringp
== t2
->u
.karray
->stringp
3305 && debug_type_samep (info
, t1
->u
.karray
->element_type
,
3306 t2
->u
.karray
->element_type
));
3309 case DEBUG_KIND_SET
:
3310 ret
= (t1
->u
.kset
->bitstringp
== t2
->u
.kset
->bitstringp
3311 && debug_type_samep (info
, t1
->u
.kset
->type
, t2
->u
.kset
->type
));
3314 case DEBUG_KIND_OFFSET
:
3315 ret
= (debug_type_samep (info
, t1
->u
.koffset
->base_type
,
3316 t2
->u
.koffset
->base_type
)
3317 && debug_type_samep (info
, t1
->u
.koffset
->target_type
,
3318 t2
->u
.koffset
->target_type
));
3321 case DEBUG_KIND_METHOD
:
3322 if (t1
->u
.kmethod
->varargs
!= t2
->u
.kmethod
->varargs
3323 || ! debug_type_samep (info
, t1
->u
.kmethod
->return_type
,
3324 t2
->u
.kmethod
->return_type
)
3325 || ! debug_type_samep (info
, t1
->u
.kmethod
->domain_type
,
3326 t2
->u
.kmethod
->domain_type
)
3327 || ((t1
->u
.kmethod
->arg_types
== NULL
)
3328 != (t2
->u
.kmethod
->arg_types
== NULL
)))
3330 else if (t1
->u
.kmethod
->arg_types
== NULL
)
3334 struct debug_type
**a1
, **a2
;
3336 a1
= t1
->u
.kmethod
->arg_types
;
3337 a2
= t2
->u
.kmethod
->arg_types
;
3338 while (*a1
!= NULL
&& *a2
!= NULL
)
3340 if (! debug_type_samep (info
, *a1
, *a2
))
3345 ret
= *a1
== NULL
&& *a2
== NULL
;
3349 case DEBUG_KIND_CONST
:
3350 ret
= debug_type_samep (info
, t1
->u
.kconst
, t2
->u
.kconst
);
3353 case DEBUG_KIND_VOLATILE
:
3354 ret
= debug_type_samep (info
, t1
->u
.kvolatile
, t2
->u
.kvolatile
);
3357 case DEBUG_KIND_NAMED
:
3358 case DEBUG_KIND_TAGGED
:
3359 ret
= (strcmp (t1
->u
.knamed
->name
->name
, t2
->u
.knamed
->name
->name
) == 0
3360 && debug_type_samep (info
, t1
->u
.knamed
->type
,
3361 t2
->u
.knamed
->type
));
3365 info
->compare_list
= top
.next
;
3370 /* See if two classes are the same. This is a subroutine of
3371 debug_type_samep. */
3374 debug_class_type_samep (info
, t1
, t2
)
3375 struct debug_handle
*info
;
3376 struct debug_type
*t1
;
3377 struct debug_type
*t2
;
3379 struct debug_class_type
*c1
, *c2
;
3384 if ((c1
->fields
== NULL
) != (c2
->fields
== NULL
)
3385 || (c1
->baseclasses
== NULL
) != (c2
->baseclasses
== NULL
)
3386 || (c1
->methods
== NULL
) != (c2
->methods
== NULL
)
3387 || (c1
->vptrbase
== NULL
) != (c2
->vptrbase
== NULL
))
3390 if (c1
->fields
!= NULL
)
3392 struct debug_field
**pf1
, **pf2
;
3394 for (pf1
= c1
->fields
, pf2
= c2
->fields
;
3395 *pf1
!= NULL
&& *pf2
!= NULL
;
3398 struct debug_field
*f1
, *f2
;
3402 if (f1
->name
[0] != f2
->name
[0]
3403 || f1
->visibility
!= f2
->visibility
3404 || f1
->static_member
!= f2
->static_member
)
3406 if (f1
->static_member
)
3408 if (strcmp (f1
->u
.s
.physname
, f2
->u
.s
.physname
) != 0)
3413 if (f1
->u
.f
.bitpos
!= f2
->u
.f
.bitpos
3414 || f1
->u
.f
.bitsize
!= f2
->u
.f
.bitsize
)
3417 /* We do the checks which require function calls last. We
3418 don't require that the types of fields have the same
3419 names, since that sometimes fails in the presence of
3420 typedefs and we really don't care. */
3421 if (strcmp (f1
->name
, f2
->name
) != 0
3422 || ! debug_type_samep (info
,
3423 debug_get_real_type ((PTR
) info
,
3425 debug_get_real_type ((PTR
) info
,
3429 if (*pf1
!= NULL
|| *pf2
!= NULL
)
3433 if (c1
->vptrbase
!= NULL
)
3435 if (! debug_type_samep (info
, c1
->vptrbase
, c2
->vptrbase
))
3439 if (c1
->baseclasses
!= NULL
)
3441 struct debug_baseclass
**pb1
, **pb2
;
3443 for (pb1
= c1
->baseclasses
, pb2
= c2
->baseclasses
;
3444 *pb1
!= NULL
&& *pb2
!= NULL
;
3447 struct debug_baseclass
*b1
, *b2
;
3451 if (b1
->bitpos
!= b2
->bitpos
3452 || b1
->virtual != b2
->virtual
3453 || b1
->visibility
!= b2
->visibility
3454 || ! debug_type_samep (info
, b1
->type
, b2
->type
))
3457 if (*pb1
!= NULL
|| *pb2
!= NULL
)
3461 if (c1
->methods
!= NULL
)
3463 struct debug_method
**pm1
, **pm2
;
3465 for (pm1
= c1
->methods
, pm2
= c2
->methods
;
3466 *pm1
!= NULL
&& *pm2
!= NULL
;
3469 struct debug_method
*m1
, *m2
;
3473 if (m1
->name
[0] != m2
->name
[0]
3474 || strcmp (m1
->name
, m2
->name
) != 0
3475 || (m1
->variants
== NULL
) != (m2
->variants
== NULL
))
3477 if (m1
->variants
== NULL
)
3479 struct debug_method_variant
**pv1
, **pv2
;
3481 for (pv1
= m1
->variants
, pv2
= m2
->variants
;
3482 *pv1
!= NULL
&& *pv2
!= NULL
;
3485 struct debug_method_variant
*v1
, *v2
;
3489 if (v1
->physname
[0] != v2
->physname
[0]
3490 || v1
->visibility
!= v2
->visibility
3491 || v1
->constp
!= v2
->constp
3492 || v1
->volatilep
!= v2
->volatilep
3493 || v1
->voffset
!= v2
->voffset
3494 || (v1
->context
== NULL
) != (v2
->context
== NULL
)
3495 || strcmp (v1
->physname
, v2
->physname
) != 0
3496 || ! debug_type_samep (info
, v1
->type
, v2
->type
))
3498 if (v1
->context
!= NULL
)
3500 if (! debug_type_samep (info
, v1
->context
,
3505 if (*pv1
!= NULL
|| *pv2
!= NULL
)
3509 if (*pm1
!= NULL
|| *pm2
!= NULL
)