1 /* debug.c -- Handle generic debugging information.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2005, 2007,
3 2009 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* This file implements a generic debugging format. We may eventually
25 have readers which convert different formats into this generic
26 format, and writers which write it out. The initial impetus for
27 this was writing a converter from stabs to HP IEEE-695 debugging
33 #include "libiberty.h"
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_s
*kpointer
;
122 /* DEBUG_KIND_FUNCTION. */
123 struct debug_function_type
*kfunction
;
124 /* DEBUG_KIND_REFERENCE. */
125 struct debug_type_s
*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_s
*kconst
;
138 /* DEBUG_KIND_VOLATILE. */
139 struct debug_type_s
*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. */
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. */
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_s
*type
;
280 /* Visibility of the field. */
281 enum debug_visibility visibility
;
282 /* Whether this is a static member. */
283 bfd_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_s
306 /* Type of the base class. */
307 struct debug_type_s
*type
;
308 /* Bit position of the base class in the object. */
310 /* Whether the base class is virtual. */
311 bfd_boolean is_virtual
;
312 /* Visibility of the base class. */
313 enum debug_visibility visibility
;
316 /* A method of an object. */
318 struct debug_method_s
320 /* The name of the method. */
322 /* A NULL terminated array of different types of variants. */
323 struct debug_method_variant_s
**variants
;
326 /* The variants of a method function of an object. These indicate
327 which method to run. */
329 struct debug_method_variant_s
331 /* The physical name of the function. */
332 const char *physname
;
333 /* The type of the function. */
334 struct debug_type_s
*type
;
335 /* The visibility of the function. */
336 enum debug_visibility visibility
;
337 /* Whether the function is const. */
339 /* Whether the function is volatile. */
340 bfd_boolean volatilep
;
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_s
*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_s
*type
;
504 /* DEBUG_OBJECT_TAG. */
505 struct debug_type_s
*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_s
*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_s
*t1
;
541 struct debug_type_s
*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_s
*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_s
*debug_make_type
565 (struct debug_handle
*, enum debug_type_kind
, unsigned int);
566 static struct debug_type_s
*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_s
*, 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_s
*, 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_s
*);
587 static bfd_boolean debug_type_samep
588 (struct debug_handle
*, struct debug_type_s
*, struct debug_type_s
*);
589 static bfd_boolean debug_class_type_samep
590 (struct debug_handle
*, struct debug_type_s
*, struct debug_type_s
*);
592 /* Issue an error message. */
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
);
616 n
->linkage
= linkage
;
621 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
622 memset (ns
, 0, sizeof *ns
);
624 ns
->tail
= &ns
->list
;
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"));
651 if (info
->current_block
!= NULL
)
652 nsp
= &info
->current_block
->locals
;
654 nsp
= &info
->current_file
->globals
;
656 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
659 /* Return a handle for debugging information. */
664 struct debug_handle
*ret
;
666 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
667 memset (ret
, 0, sizeof *ret
);
671 /* Set the source filename. This implicitly starts a new compilation
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
;
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
;
699 assert (info
->units
== NULL
);
703 info
->current_unit
= nunit
;
705 info
->current_function
= NULL
;
706 info
->current_block
= NULL
;
707 info
->current_lineno
= NULL
;
712 /* Change source files to the given file name. This is used for
713 include files in a single compilation unit. */
716 debug_start_source (void *handle
, const char *name
)
718 struct debug_handle
*info
= (struct debug_handle
*) handle
;
719 struct debug_file
*f
, **pf
;
724 if (info
->current_unit
== NULL
)
726 debug_error (_("debug_start_source: no debug_set_filename call"));
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
;
741 f
= (struct debug_file
*) xmalloc (sizeof *f
);
742 memset (f
, 0, sizeof *f
);
746 for (pf
= &info
->current_file
->next
;
752 info
->current_file
= f
;
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
766 debug_record_function (void *handle
, const char *name
,
767 debug_type return_type
, bfd_boolean global
,
770 struct debug_handle
*info
= (struct debug_handle
*) handle
;
771 struct debug_function
*f
;
772 struct debug_block
*b
;
773 struct debug_name
*n
;
777 if (return_type
== NULL
)
780 if (info
->current_unit
== NULL
)
782 debug_error (_("debug_record_function: no debug_set_filename call"));
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
);
795 b
->end
= (bfd_vma
) -1;
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
,
807 DEBUG_OBJECT_FUNCTION
,
809 ? DEBUG_LINKAGE_GLOBAL
810 : DEBUG_LINKAGE_STATIC
));
819 /* Record a parameter for the current function. */
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
)
831 if (info
->current_unit
== NULL
832 || info
->current_function
== NULL
)
834 debug_error (_("debug_record_parameter: no current function"));
838 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
839 memset (p
, 0, sizeof *p
);
846 for (pp
= &info
->current_function
->parameters
;
855 /* End a function. FIXME: This should handle function nesting. */
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"));
870 if (info
->current_block
->parent
!= NULL
)
872 debug_error (_("debug_end_function: some blocks were not closed"));
876 info
->current_block
->end
= addr
;
878 info
->current_function
= NULL
;
879 info
->current_block
= NULL
;
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. */
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
897 if (info
->current_unit
== NULL
898 || info
->current_block
== NULL
)
900 debug_error (_("debug_start_block: no current block"));
904 b
= (struct debug_block
*) xmalloc (sizeof *b
);
905 memset (b
, 0, sizeof *b
);
907 b
->parent
= info
->current_block
;
909 b
->end
= (bfd_vma
) -1;
911 /* This new block is a child of the current block. */
912 for (pb
= &info
->current_block
->children
;
918 info
->current_block
= b
;
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
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"));
940 parent
= info
->current_block
->parent
;
943 debug_error (_("debug_end_block: attempt to close top level block"));
947 info
->current_block
->end
= addr
;
949 info
->current_block
= parent
;
954 /* Associate a line number in the current source file and function
955 with a given address. */
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
;
964 if (info
->current_unit
== NULL
)
966 debug_error (_("debug_record_line: no current unit"));
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
;
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
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
;
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
;
1004 info
->current_unit
->linenos
= l
;
1006 info
->current_lineno
= l
;
1011 /* Start a named common block. This is a block of variables that may
1015 debug_start_common_block (void *handle ATTRIBUTE_UNUSED
,
1016 const char *name ATTRIBUTE_UNUSED
)
1019 debug_error (_("debug_start_common_block: not implemented"));
1023 /* End a named common block. */
1026 debug_end_common_block (void *handle ATTRIBUTE_UNUSED
,
1027 const char *name ATTRIBUTE_UNUSED
)
1030 debug_error (_("debug_end_common_block: not implemented"));
1034 /* Record a named integer constant. */
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
;
1045 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1046 DEBUG_LINKAGE_NONE
);
1050 n
->u
.int_constant
= val
;
1055 /* Record a named floating point constant. */
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
;
1066 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1067 DEBUG_LINKAGE_NONE
);
1071 n
->u
.float_constant
= val
;
1076 /* Record a typed constant with an integral value. */
1079 debug_record_typed_const (void *handle
, const char *name
, debug_type type
,
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
)
1089 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1090 DEBUG_LINKAGE_NONE
);
1094 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1095 memset (tc
, 0, sizeof *tc
);
1100 n
->u
.typed_constant
= tc
;
1105 /* Record a label. */
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
)
1114 debug_error (_("debug_record_label: not implemented"));
1118 /* Record a variable. */
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
)
1133 if (info
->current_unit
== NULL
1134 || info
->current_file
== NULL
)
1136 debug_error (_("debug_record_variable: no current file"));
1140 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1142 nsp
= &info
->current_file
->globals
;
1143 if (kind
== DEBUG_GLOBAL
)
1144 linkage
= DEBUG_LINKAGE_GLOBAL
;
1146 linkage
= DEBUG_LINKAGE_STATIC
;
1150 if (info
->current_block
== NULL
)
1151 nsp
= &info
->current_file
->globals
;
1153 nsp
= &info
->current_block
->locals
;
1154 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1157 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1161 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1162 memset (v
, 0, sizeof *v
);
1173 /* Make a type with a given kind and size. */
1175 static struct debug_type_s
*
1176 debug_make_type (struct debug_handle
*info ATTRIBUTE_UNUSED
,
1177 enum debug_type_kind kind
, unsigned int size
)
1179 struct debug_type_s
*t
;
1181 t
= (struct debug_type_s
*) xmalloc (sizeof *t
);
1182 memset (t
, 0, sizeof *t
);
1190 /* Make an indirect type which may be used as a placeholder for a type
1191 which is referenced before it is defined. */
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_s
*t
;
1198 struct debug_indirect_type
*i
;
1200 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1202 return DEBUG_TYPE_NULL
;
1204 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1205 memset (i
, 0, sizeof *i
);
1215 /* Make a void type. There is only one of these. */
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. */
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_s
*t
;
1234 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1236 return DEBUG_TYPE_NULL
;
1238 t
->u
.kint
= unsignedp
;
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
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. */
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. */
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. */
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_s
*t
;
1285 struct debug_class_type
*c
;
1287 t
= debug_make_type (info
,
1288 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1291 return DEBUG_TYPE_NULL
;
1293 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1294 memset (c
, 0, sizeof *c
);
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. */
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_s
*t
;
1318 struct debug_class_type
*c
;
1320 t
= debug_make_type (info
,
1321 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1324 return DEBUG_TYPE_NULL
;
1326 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1327 memset (c
, 0, sizeof *c
);
1330 c
->baseclasses
= baseclasses
;
1331 c
->methods
= methods
;
1335 c
->vptrbase
= vptrbase
;
1342 /* Make an enumeration type. The arguments are a null terminated
1343 array of strings, and an array of corresponding values. */
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_s
*t
;
1351 struct debug_enum_type
*e
;
1353 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1355 return DEBUG_TYPE_NULL
;
1357 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1358 memset (e
, 0, sizeof *e
);
1368 /* Make a pointer to a given type. */
1371 debug_make_pointer_type (void *handle
, debug_type type
)
1373 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1374 struct debug_type_s
*t
;
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);
1384 return DEBUG_TYPE_NULL
;
1386 t
->u
.kpointer
= type
;
1393 /* Make a function returning a given type. FIXME: We should be able
1394 to record the parameter types. */
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_s
*t
;
1402 struct debug_function_type
*f
;
1405 return DEBUG_TYPE_NULL
;
1407 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
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
;
1423 /* Make a reference to a given type. */
1426 debug_make_reference_type (void *handle
, debug_type type
)
1428 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1429 struct debug_type_s
*t
;
1432 return DEBUG_TYPE_NULL
;
1434 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1436 return DEBUG_TYPE_NULL
;
1438 t
->u
.kreference
= type
;
1443 /* Make a range of a given type from a lower to an upper bound. */
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_s
*t
;
1451 struct debug_range_type
*r
;
1454 return DEBUG_TYPE_NULL
;
1456 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1458 return DEBUG_TYPE_NULL
;
1460 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1461 memset (r
, 0, sizeof *r
);
1472 /* Make an array type. The second argument is the type of an element
1473 of the array. The third argument is the type of a range of the
1474 array. The fourth and fifth argument are the lower and upper
1475 bounds, respectively. The sixth argument is true if this array is
1476 actually a string, as in C. */
1479 debug_make_array_type (void *handle
, debug_type element_type
,
1480 debug_type range_type
, bfd_signed_vma lower
,
1481 bfd_signed_vma upper
, bfd_boolean stringp
)
1483 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1484 struct debug_type_s
*t
;
1485 struct debug_array_type
*a
;
1487 if (element_type
== NULL
|| range_type
== NULL
)
1488 return DEBUG_TYPE_NULL
;
1490 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1492 return DEBUG_TYPE_NULL
;
1494 a
= (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
;
1501 a
->stringp
= stringp
;
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
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_s
*t
;
1517 struct debug_set_type
*s
;
1520 return DEBUG_TYPE_NULL
;
1522 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1524 return DEBUG_TYPE_NULL
;
1526 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1527 memset (s
, 0, sizeof *s
);
1530 s
->bitstringp
= bitstringp
;
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
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_s
*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);
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
;
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. */
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_s
*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);
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
;
1601 /* Make a const qualified version of a given type. */
1604 debug_make_const_type (void *handle
, debug_type type
)
1606 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1607 struct debug_type_s
*t
;
1610 return DEBUG_TYPE_NULL
;
1612 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1614 return DEBUG_TYPE_NULL
;
1621 /* Make a volatile qualified version of a given type. */
1624 debug_make_volatile_type (void *handle
, debug_type type
)
1626 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1627 struct debug_type_s
*t
;
1630 return DEBUG_TYPE_NULL
;
1632 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1634 return DEBUG_TYPE_NULL
;
1636 t
->u
.kvolatile
= type
;
1641 /* Make an undefined tagged type. For example, a struct which has
1642 been mentioned, but not defined. */
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_s
*t
;
1652 return DEBUG_TYPE_NULL
;
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
:
1664 debug_error (_("debug_make_undefined_type: unsupported kind"));
1665 return DEBUG_TYPE_NULL
;
1668 t
= debug_make_type (info
, kind
, 0);
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. */
1682 debug_make_baseclass (void *handle ATTRIBUTE_UNUSED
, debug_type type
,
1683 bfd_vma bitpos
, bfd_boolean is_virtual
,
1684 enum debug_visibility visibility
)
1686 struct debug_baseclass_s
*b
;
1688 b
= (struct debug_baseclass_s
*) xmalloc (sizeof *b
);
1689 memset (b
, 0, sizeof *b
);
1693 b
->is_virtual
= is_virtual
;
1694 b
->visibility
= visibility
;
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
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_s
*f
;
1712 f
= (struct debug_field_s
*) xmalloc (sizeof *f
);
1713 memset (f
, 0, sizeof *f
);
1717 f
->static_member
= FALSE
;
1718 f
->u
.f
.bitpos
= bitpos
;
1719 f
->u
.f
.bitsize
= bitsize
;
1720 f
->visibility
= visibility
;
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
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_s
*f
;
1738 f
= (struct debug_field_s
*) xmalloc (sizeof *f
);
1739 memset (f
, 0, sizeof *f
);
1743 f
->static_member
= TRUE
;
1744 f
->u
.s
.physname
= physname
;
1745 f
->visibility
= visibility
;
1750 /* Make a method. The second argument is the name, and the third
1751 argument is a NULL terminated array of method variants. */
1754 debug_make_method (void *handle ATTRIBUTE_UNUSED
, const char *name
,
1755 debug_method_variant
*variants
)
1757 struct debug_method_s
*m
;
1759 m
= (struct debug_method_s
*) xmalloc (sizeof *m
);
1760 memset (m
, 0, sizeof *m
);
1763 m
->variants
= variants
;
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_s
*m
;
1786 m
= (struct debug_method_variant_s
*) xmalloc (sizeof *m
);
1787 memset (m
, 0, sizeof *m
);
1789 m
->physname
= physname
;
1791 m
->visibility
= visibility
;
1793 m
->volatilep
= volatilep
;
1794 m
->voffset
= voffset
;
1795 m
->context
= context
;
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_s
*m
;
1812 m
= (struct debug_method_variant_s
*) xmalloc (sizeof *m
);
1813 memset (m
, 0, sizeof *m
);
1815 m
->physname
= physname
;
1817 m
->visibility
= visibility
;
1819 m
->volatilep
= volatilep
;
1820 m
->voffset
= VOFFSET_STATIC_METHOD
;
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_s
*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);
1847 return DEBUG_TYPE_NULL
;
1849 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1850 memset (n
, 0, sizeof *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
);
1862 return DEBUG_TYPE_NULL
;
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_s
*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)
1894 debug_error (_("debug_tag_type: extra tag attempted"));
1895 return DEBUG_TYPE_NULL
;
1898 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
1900 return DEBUG_TYPE_NULL
;
1902 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1903 memset (n
, 0, sizeof *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
);
1915 return DEBUG_TYPE_NULL
;
1924 /* Record the size of a given type. */
1927 debug_record_type_size (void *handle ATTRIBUTE_UNUSED
, debug_type type
,
1930 if (type
->size
!= 0 && type
->size
!= size
)
1931 fprintf (stderr
, _("Warning: changing type size from %d to %d\n"),
1939 /* Find a named 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)
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)
1989 return DEBUG_TYPE_NULL
;
1992 /* Find a tagged 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)
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_s
*
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
;
2045 case DEBUG_KIND_INDIRECT
:
2046 case DEBUG_KIND_NAMED
:
2047 case DEBUG_KIND_TAGGED
:
2051 for (l
= list
; l
!= NULL
; l
= l
->next
)
2053 if (l
->t
== type
|| l
== l
->next
)
2056 _("debug_get_real_type: circular debug information for %s\n"),
2057 debug_get_type_name (handle
, type
));
2067 /* The default case is just here to avoid warnings. */
2069 case DEBUG_KIND_INDIRECT
:
2070 if (*type
->u
.kindirect
->slot
!= NULL
)
2071 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
, &rl
);
2073 case DEBUG_KIND_NAMED
:
2074 case DEBUG_KIND_TAGGED
:
2075 return debug_get_real_type (handle
, type
->u
.knamed
->type
, &rl
);
2080 /* Get the kind of a type. */
2082 enum debug_type_kind
2083 debug_get_type_kind (void *handle
, debug_type type
)
2086 return DEBUG_KIND_ILLEGAL
;
2087 type
= debug_get_real_type (handle
, type
, NULL
);
2089 return DEBUG_KIND_ILLEGAL
;
2093 /* Get the name of a type. */
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
;
2110 /* Get the size of a type. */
2113 debug_get_type_size (void *handle
, debug_type type
)
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)
2128 case DEBUG_KIND_INDIRECT
:
2129 if (*type
->u
.kindirect
->slot
!= NULL
)
2130 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2132 case DEBUG_KIND_NAMED
:
2133 case DEBUG_KIND_TAGGED
:
2134 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2139 /* Get the return type of a function or method type. */
2142 debug_get_return_type (void *handle
, debug_type type
)
2145 return DEBUG_TYPE_NULL
;
2147 type
= debug_get_real_type (handle
, type
, NULL
);
2149 return DEBUG_TYPE_NULL
;
2154 return DEBUG_TYPE_NULL
;
2155 case DEBUG_KIND_FUNCTION
:
2156 return type
->u
.kfunction
->return_type
;
2157 case DEBUG_KIND_METHOD
:
2158 return type
->u
.kmethod
->return_type
;
2163 /* Get the parameter types of a function or method type (except that
2164 we don't currently store the parameter types of a function). */
2167 debug_get_parameter_types (void *handle
, debug_type type
,
2168 bfd_boolean
*pvarargs
)
2173 type
= debug_get_real_type (handle
, type
, NULL
);
2181 case DEBUG_KIND_FUNCTION
:
2182 *pvarargs
= type
->u
.kfunction
->varargs
;
2183 return type
->u
.kfunction
->arg_types
;
2184 case DEBUG_KIND_METHOD
:
2185 *pvarargs
= type
->u
.kmethod
->varargs
;
2186 return type
->u
.kmethod
->arg_types
;
2191 /* Get the target type of a type. */
2194 debug_get_target_type (void *handle
, debug_type type
)
2199 type
= debug_get_real_type (handle
, type
, NULL
);
2207 case DEBUG_KIND_POINTER
:
2208 return type
->u
.kpointer
;
2209 case DEBUG_KIND_REFERENCE
:
2210 return type
->u
.kreference
;
2211 case DEBUG_KIND_CONST
:
2212 return type
->u
.kconst
;
2213 case DEBUG_KIND_VOLATILE
:
2214 return type
->u
.kvolatile
;
2219 /* Get the NULL terminated array of fields for a struct, union, or
2223 debug_get_fields (void *handle
, debug_type type
)
2228 type
= debug_get_real_type (handle
, type
, NULL
);
2236 case DEBUG_KIND_STRUCT
:
2237 case DEBUG_KIND_UNION
:
2238 case DEBUG_KIND_CLASS
:
2239 case DEBUG_KIND_UNION_CLASS
:
2240 return type
->u
.kclass
->fields
;
2245 /* Get the type of a field. */
2248 debug_get_field_type (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2255 /* Get the name of a field. */
2258 debug_get_field_name (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2265 /* Get the bit position of a field. */
2268 debug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2270 if (field
== NULL
|| field
->static_member
)
2271 return (bfd_vma
) -1;
2272 return field
->u
.f
.bitpos
;
2275 /* Get the bit size of a field. */
2278 debug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2280 if (field
== NULL
|| field
->static_member
)
2281 return (bfd_vma
) -1;
2282 return field
->u
.f
.bitsize
;
2285 /* Get the visibility of a field. */
2287 enum debug_visibility
2288 debug_get_field_visibility (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2291 return DEBUG_VISIBILITY_IGNORE
;
2292 return field
->visibility
;
2295 /* Get the physical name of a field. */
2298 debug_get_field_physname (void *handle ATTRIBUTE_UNUSED
, debug_field field
)
2300 if (field
== NULL
|| ! field
->static_member
)
2302 return field
->u
.s
.physname
;
2305 /* Write out the debugging information. This is given a handle to
2306 debugging information, and a set of function pointers to call. */
2309 debug_write (void *handle
, const struct debug_write_fns
*fns
, void *fhandle
)
2311 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2312 struct debug_unit
*u
;
2314 /* We use a mark to tell whether we have already written out a
2315 particular name. We use an integer, so that we don't have to
2316 clear the mark fields if we happen to write out the same
2317 information more than once. */
2320 /* The base_id field holds an ID value which will never be used, so
2321 that we can tell whether we have assigned an ID during this call
2323 info
->base_id
= info
->class_id
;
2325 /* We keep a linked list of classes for which was have assigned ID's
2326 during this call to debug_write. */
2327 info
->id_list
= NULL
;
2329 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2331 struct debug_file
*f
;
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
))
2341 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2343 struct debug_name
*n
;
2347 else if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2350 if (f
->globals
!= NULL
)
2351 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2352 if (! debug_write_name (info
, fns
, fhandle
, n
))
2356 /* Output any line number information which hasn't already been
2358 if (! debug_write_linenos (info
, fns
, fhandle
, (bfd_vma
) -1))
2365 /* Write out an element in a namespace. */
2368 debug_write_name (struct debug_handle
*info
,
2369 const struct debug_write_fns
*fns
, void *fhandle
,
2370 struct debug_name
*n
)
2374 case DEBUG_OBJECT_TYPE
:
2375 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2376 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2379 case DEBUG_OBJECT_TAG
:
2380 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2382 return (*fns
->tag
) (fhandle
, n
->name
);
2383 case DEBUG_OBJECT_VARIABLE
:
2384 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2385 (struct debug_name
*) NULL
))
2387 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2388 n
->u
.variable
->val
);
2389 case DEBUG_OBJECT_FUNCTION
:
2390 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2391 n
->linkage
, n
->u
.function
);
2392 case DEBUG_OBJECT_INT_CONSTANT
:
2393 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2394 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2395 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2396 case DEBUG_OBJECT_TYPED_CONSTANT
:
2397 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2398 (struct debug_name
*) NULL
))
2400 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2401 n
->u
.typed_constant
->val
);
2409 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2410 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2411 are about to call typedef or tag. If the type is anything else,
2412 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2413 points to this one. */
2416 debug_write_type (struct debug_handle
*info
,
2417 const struct debug_write_fns
*fns
, void *fhandle
,
2418 struct debug_type_s
*type
, struct debug_name
*name
)
2422 const char *tag
= NULL
;
2424 /* If 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
);
2437 struct debug_type_s
*real
;
2440 real
= debug_get_real_type ((void *) info
, type
, NULL
);
2442 return (*fns
->empty_type
) (fhandle
);
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
,
2457 id
= real
->u
.kclass
->id
;
2460 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, id
,
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. */
2470 name
->mark
= info
->mark
;
2473 && type
->kind
!= DEBUG_KIND_NAMED
2474 && type
->kind
!= DEBUG_KIND_TAGGED
)
2476 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2482 case DEBUG_KIND_ILLEGAL
:
2483 debug_error (_("debug_write_type: illegal type encountered"));
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
,
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
))
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
,
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
2526 type
->kind
== DEBUG_KIND_STRUCT
,
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_s
*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
))
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
))
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
))
2564 if (type
->u
.kfunction
->arg_types
== NULL
)
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
))
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
))
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
))
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
))
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
))
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
))
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
))
2615 if (type
->u
.kmethod
->arg_types
== NULL
)
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
))
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
))
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
))
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
))
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
);
2658 /* Write out a class type. */
2661 debug_write_class_type (struct debug_handle
*info
,
2662 const struct debug_write_fns
*fns
, void *fhandle
,
2663 struct debug_type_s
*type
, const char *tag
)
2667 struct debug_type_s
*vptrbase
;
2669 if (type
->u
.kclass
== NULL
)
2676 if (type
->u
.kclass
->id
<= info
->base_id
)
2678 if (! debug_set_class_id (info
, tag
, type
))
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
,
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
))
2703 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2704 type
->kind
== DEBUG_KIND_CLASS
,
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_s
*f
;
2718 f
= type
->u
.kclass
->fields
[i
];
2719 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2720 (struct debug_name
*) NULL
))
2722 if (f
->static_member
)
2724 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2731 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2732 f
->u
.f
.bitsize
, f
->visibility
))
2738 if (type
->u
.kclass
->baseclasses
!= NULL
)
2740 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2742 struct debug_baseclass_s
*b
;
2744 b
= type
->u
.kclass
->baseclasses
[i
];
2745 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2746 (struct debug_name
*) NULL
))
2748 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->is_virtual
,
2754 if (type
->u
.kclass
->methods
!= NULL
)
2756 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2758 struct debug_method_s
*m
;
2761 m
= type
->u
.kclass
->methods
[i
];
2762 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2764 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2766 struct debug_method_variant_s
*v
;
2769 if (v
->context
!= NULL
)
2771 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2772 (struct debug_name
*) NULL
))
2775 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2776 (struct debug_name
*) NULL
))
2778 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2780 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2785 v
->context
!= NULL
))
2790 if (! (*fns
->class_static_method_variant
) (fhandle
,
2798 if (! (*fns
->class_end_method
) (fhandle
))
2804 return (*fns
->end_class_type
) (fhandle
);
2807 /* Write out information for a function. */
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
))
2821 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2822 (struct debug_name
*) NULL
))
2825 if (! (*fns
->start_function
) (fhandle
, name
,
2826 linkage
== DEBUG_LINKAGE_GLOBAL
))
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
))
2837 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2839 if (! debug_write_block (info
, fns
, fhandle
, b
))
2843 return (*fns
->end_function
) (fhandle
);
2846 /* Write out information for a block. */
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
))
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
))
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
))
2876 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
2878 if (! debug_write_block (info
, fns
, fhandle
, b
))
2882 if (! debug_write_linenos (info
, fns
, fhandle
, block
->end
))
2885 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
2887 if (! (*fns
->end_block
) (fhandle
, block
->end
))
2894 /* Write out line number information up to ADDRESS. */
2897 debug_write_linenos (struct debug_handle
*info
,
2898 const struct debug_write_fns
*fns
, void *fhandle
,
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)
2913 if (l
->addrs
[info
->current_write_lineno_index
] >= address
)
2916 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
,
2917 l
->linenos
[info
->current_write_lineno_index
],
2918 l
->addrs
[info
->current_write_lineno_index
]))
2921 ++info
->current_write_lineno_index
;
2924 info
->current_write_lineno
= l
->next
;
2925 info
->current_write_lineno_index
= 0;
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. */
2937 debug_set_class_id (struct debug_handle
*info
, const char *tag
,
2938 struct debug_type_s
*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
);
2950 if (c
->id
> info
->base_id
)
2953 for (l
= info
->id_list
; l
!= NULL
; l
= l
->next
)
2955 if (l
->type
->kind
!= type
->kind
)
2966 || l
->tag
[0] != tag
[0]
2967 || strcmp (l
->tag
, tag
) != 0)
2971 if (debug_type_samep (info
, l
->type
, type
))
2973 c
->id
= l
->type
->u
.kclass
->id
;
2978 /* There are no identical types. Use a new ID, and add it to the
2981 c
->id
= info
->class_id
;
2983 l
= (struct debug_class_id
*) xmalloc (sizeof *l
);
2984 memset (l
, 0, sizeof *l
);
2989 l
->next
= info
->id_list
;
2995 /* See if two types are the same. At this point, we don't care about
2996 tags and the like. */
2999 debug_type_samep (struct debug_handle
*info
, struct debug_type_s
*t1
,
3000 struct debug_type_s
*t2
)
3002 struct debug_type_compare_list
*l
;
3003 struct debug_type_compare_list top
;
3011 while (t1
->kind
== DEBUG_KIND_INDIRECT
)
3013 t1
= *t1
->u
.kindirect
->slot
;
3017 while (t2
->kind
== DEBUG_KIND_INDIRECT
)
3019 t2
= *t2
->u
.kindirect
->slot
;
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
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
)
3041 /* Get rid of the trivial cases first. */
3046 case DEBUG_KIND_VOID
:
3047 case DEBUG_KIND_FLOAT
:
3048 case DEBUG_KIND_COMPLEX
:
3049 case DEBUG_KIND_BOOL
:
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
)
3067 top
.next
= info
->compare_list
;
3068 info
->compare_list
= &top
;
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
)
3085 else if (t1
->u
.kclass
->id
> info
->base_id
3086 && t1
->u
.kclass
->id
== t2
->u
.kclass
->id
)
3089 ret
= debug_class_type_samep (info
, t1
, t2
);
3092 case DEBUG_KIND_ENUM
:
3093 if (t1
->u
.kenum
== NULL
)
3094 ret
= t2
->u
.kenum
== NULL
;
3095 else if (t2
->u
.kenum
== NULL
)
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
)
3110 || strcmp (*pn1
, *pn2
) != 0)
3117 ret
= *pn1
== NULL
&& *pn2
== NULL
;
3121 case DEBUG_KIND_POINTER
:
3122 ret
= debug_type_samep (info
, t1
->u
.kpointer
, t2
->u
.kpointer
);
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
)))
3132 else if (t1
->u
.kfunction
->arg_types
== NULL
)
3136 struct debug_type_s
**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
))
3147 ret
= *a1
== NULL
&& *a2
== NULL
;
3151 case DEBUG_KIND_REFERENCE
:
3152 ret
= debug_type_samep (info
, t1
->u
.kreference
, t2
->u
.kreference
);
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
));
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
));
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
));
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
)))
3190 else if (t1
->u
.kmethod
->arg_types
== NULL
)
3194 struct debug_type_s
**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
))
3205 ret
= *a1
== NULL
&& *a2
== NULL
;
3209 case DEBUG_KIND_CONST
:
3210 ret
= debug_type_samep (info
, t1
->u
.kconst
, t2
->u
.kconst
);
3213 case DEBUG_KIND_VOLATILE
:
3214 ret
= debug_type_samep (info
, t1
->u
.kvolatile
, t2
->u
.kvolatile
);
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
));
3225 info
->compare_list
= top
.next
;
3230 /* See if two classes are the same. This is a subroutine of
3231 debug_type_samep. */
3234 debug_class_type_samep (struct debug_handle
*info
, struct debug_type_s
*t1
,
3235 struct debug_type_s
*t2
)
3237 struct debug_class_type
*c1
, *c2
;
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
))
3248 if (c1
->fields
!= NULL
)
3250 struct debug_field_s
**pf1
, **pf2
;
3252 for (pf1
= c1
->fields
, pf2
= c2
->fields
;
3253 *pf1
!= NULL
&& *pf2
!= NULL
;
3256 struct debug_field_s
*f1
, *f2
;
3260 if (f1
->name
[0] != f2
->name
[0]
3261 || f1
->visibility
!= f2
->visibility
3262 || f1
->static_member
!= f2
->static_member
)
3264 if (f1
->static_member
)
3266 if (strcmp (f1
->u
.s
.physname
, f2
->u
.s
.physname
) != 0)
3271 if (f1
->u
.f
.bitpos
!= f2
->u
.f
.bitpos
3272 || f1
->u
.f
.bitsize
!= f2
->u
.f
.bitsize
)
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
,
3283 debug_get_real_type ((void *) info
,
3287 if (*pf1
!= NULL
|| *pf2
!= NULL
)
3291 if (c1
->vptrbase
!= NULL
)
3293 if (! debug_type_samep (info
, c1
->vptrbase
, c2
->vptrbase
))
3297 if (c1
->baseclasses
!= NULL
)
3299 struct debug_baseclass_s
**pb1
, **pb2
;
3301 for (pb1
= c1
->baseclasses
, pb2
= c2
->baseclasses
;
3302 *pb1
!= NULL
&& *pb2
!= NULL
;
3305 struct debug_baseclass_s
*b1
, *b2
;
3309 if (b1
->bitpos
!= b2
->bitpos
3310 || b1
->is_virtual
!= b2
->is_virtual
3311 || b1
->visibility
!= b2
->visibility
3312 || ! debug_type_samep (info
, b1
->type
, b2
->type
))
3315 if (*pb1
!= NULL
|| *pb2
!= NULL
)
3319 if (c1
->methods
!= NULL
)
3321 struct debug_method_s
**pm1
, **pm2
;
3323 for (pm1
= c1
->methods
, pm2
= c2
->methods
;
3324 *pm1
!= NULL
&& *pm2
!= NULL
;
3327 struct debug_method_s
*m1
, *m2
;
3331 if (m1
->name
[0] != m2
->name
[0]
3332 || strcmp (m1
->name
, m2
->name
) != 0
3333 || (m1
->variants
== NULL
) != (m2
->variants
== NULL
))
3335 if (m1
->variants
== NULL
)
3337 struct debug_method_variant_s
**pv1
, **pv2
;
3339 for (pv1
= m1
->variants
, pv2
= m2
->variants
;
3340 *pv1
!= NULL
&& *pv2
!= NULL
;
3343 struct debug_method_variant_s
*v1
, *v2
;
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
))
3356 if (v1
->context
!= NULL
)
3358 if (! debug_type_samep (info
, v1
->context
,
3363 if (*pv1
!= NULL
|| *pv2
!= NULL
)
3367 if (*pm1
!= NULL
|| *pm2
!= NULL
)