1 /* debug.c -- Handle generic debugging information.
2 Copyright 1995, 1996, 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
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. */
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
*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
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. */
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
*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 /* During debug_get_real_type, a linked list of these structures is
545 kept on the stack to avoid infinite recursion. */
547 struct debug_type_real_list
549 /* Next type on list. */
550 struct debug_type_real_list
*next
;
551 /* The type we are checking. */
552 struct debug_type
*t
;
555 /* Local functions. */
557 static void debug_error
558 PARAMS ((const char *));
559 static struct debug_name
*debug_add_to_namespace
560 PARAMS ((struct debug_handle
*, struct debug_namespace
**, const char *,
561 enum debug_object_kind
, enum debug_object_linkage
));
562 static struct debug_name
*debug_add_to_current_namespace
563 PARAMS ((struct debug_handle
*, const char *, enum debug_object_kind
,
564 enum debug_object_linkage
));
565 static struct debug_type
*debug_make_type
566 PARAMS ((struct debug_handle
*, enum debug_type_kind
, unsigned int));
567 static struct debug_type
*debug_get_real_type
568 PARAMS ((PTR
, debug_type
, struct debug_type_real_list
*));
569 static bfd_boolean debug_write_name
570 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
571 struct debug_name
*));
572 static bfd_boolean debug_write_type
573 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
574 struct debug_type
*, struct debug_name
*));
575 static bfd_boolean debug_write_class_type
576 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
577 struct debug_type
*, const char *));
578 static bfd_boolean debug_write_function
579 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
580 const char *, enum debug_object_linkage
, struct debug_function
*));
581 static bfd_boolean debug_write_block
582 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
583 struct debug_block
*));
584 static bfd_boolean debug_write_linenos
585 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
587 static bfd_boolean debug_set_class_id
588 PARAMS ((struct debug_handle
*, const char *, struct debug_type
*));
589 static bfd_boolean debug_type_samep
590 PARAMS ((struct debug_handle
*, struct debug_type
*, struct debug_type
*));
591 static bfd_boolean debug_class_type_samep
592 PARAMS ((struct debug_handle
*, struct debug_type
*, struct debug_type
*));
594 /* Issue an error message. */
597 debug_error (message
)
600 fprintf (stderr
, "%s\n", message
);
603 /* Add an object to a namespace. */
605 static struct debug_name
*
606 debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
)
607 struct debug_handle
*info ATTRIBUTE_UNUSED
;
608 struct debug_namespace
**nsp
;
610 enum debug_object_kind kind
;
611 enum debug_object_linkage linkage
;
613 struct debug_name
*n
;
614 struct debug_namespace
*ns
;
616 n
= (struct debug_name
*) xmalloc (sizeof *n
);
617 memset (n
, 0, sizeof *n
);
621 n
->linkage
= linkage
;
626 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
627 memset (ns
, 0, sizeof *ns
);
629 ns
->tail
= &ns
->list
;
640 /* Add an object to the current namespace. */
642 static struct debug_name
*
643 debug_add_to_current_namespace (info
, name
, kind
, linkage
)
644 struct debug_handle
*info
;
646 enum debug_object_kind kind
;
647 enum debug_object_linkage linkage
;
649 struct debug_namespace
**nsp
;
651 if (info
->current_unit
== NULL
652 || info
->current_file
== NULL
)
654 debug_error (_("debug_add_to_current_namespace: no current file"));
658 if (info
->current_block
!= NULL
)
659 nsp
= &info
->current_block
->locals
;
661 nsp
= &info
->current_file
->globals
;
663 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
666 /* Return a handle for debugging information. */
671 struct debug_handle
*ret
;
673 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
674 memset (ret
, 0, sizeof *ret
);
678 /* Set the source filename. This implicitly starts a new compilation
682 debug_set_filename (handle
, name
)
686 struct debug_handle
*info
= (struct debug_handle
*) handle
;
687 struct debug_file
*nfile
;
688 struct debug_unit
*nunit
;
693 nfile
= (struct debug_file
*) xmalloc (sizeof *nfile
);
694 memset (nfile
, 0, sizeof *nfile
);
696 nfile
->filename
= name
;
698 nunit
= (struct debug_unit
*) xmalloc (sizeof *nunit
);
699 memset (nunit
, 0, sizeof *nunit
);
701 nunit
->files
= nfile
;
702 info
->current_file
= nfile
;
704 if (info
->current_unit
!= NULL
)
705 info
->current_unit
->next
= nunit
;
708 assert (info
->units
== NULL
);
712 info
->current_unit
= nunit
;
714 info
->current_function
= NULL
;
715 info
->current_block
= NULL
;
716 info
->current_lineno
= NULL
;
721 /* Change source files to the given file name. This is used for
722 include files in a single compilation unit. */
725 debug_start_source (handle
, name
)
729 struct debug_handle
*info
= (struct debug_handle
*) handle
;
730 struct debug_file
*f
, **pf
;
735 if (info
->current_unit
== NULL
)
737 debug_error (_("debug_start_source: no debug_set_filename call"));
741 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
743 if (f
->filename
[0] == name
[0]
744 && f
->filename
[1] == name
[1]
745 && strcmp (f
->filename
, name
) == 0)
747 info
->current_file
= f
;
752 f
= (struct debug_file
*) xmalloc (sizeof *f
);
753 memset (f
, 0, sizeof *f
);
757 for (pf
= &info
->current_file
->next
;
763 info
->current_file
= f
;
768 /* Record a function definition. This implicitly starts a function
769 block. The debug_type argument is the type of the return value.
770 The boolean indicates whether the function is globally visible.
771 The bfd_vma is the address of the start of the function. Currently
772 the parameter types are specified by calls to
773 debug_record_parameter. FIXME: There is no way to specify nested
777 debug_record_function (handle
, name
, return_type
, global
, addr
)
780 debug_type return_type
;
784 struct debug_handle
*info
= (struct debug_handle
*) handle
;
785 struct debug_function
*f
;
786 struct debug_block
*b
;
787 struct debug_name
*n
;
791 if (return_type
== NULL
)
794 if (info
->current_unit
== NULL
)
796 debug_error (_("debug_record_function: no debug_set_filename call"));
800 f
= (struct debug_function
*) xmalloc (sizeof *f
);
801 memset (f
, 0, sizeof *f
);
803 f
->return_type
= return_type
;
805 b
= (struct debug_block
*) xmalloc (sizeof *b
);
806 memset (b
, 0, sizeof *b
);
809 b
->end
= (bfd_vma
) -1;
813 info
->current_function
= f
;
814 info
->current_block
= b
;
816 /* FIXME: If we could handle nested functions, this would be the
817 place: we would want to use a different namespace. */
818 n
= debug_add_to_namespace (info
,
819 &info
->current_file
->globals
,
821 DEBUG_OBJECT_FUNCTION
,
823 ? DEBUG_LINKAGE_GLOBAL
824 : DEBUG_LINKAGE_STATIC
));
833 /* Record a parameter for the current function. */
836 debug_record_parameter (handle
, name
, type
, kind
, val
)
840 enum debug_parm_kind kind
;
843 struct debug_handle
*info
= (struct debug_handle
*) handle
;
844 struct debug_parameter
*p
, **pp
;
846 if (name
== NULL
|| type
== NULL
)
849 if (info
->current_unit
== NULL
850 || info
->current_function
== NULL
)
852 debug_error (_("debug_record_parameter: no current function"));
856 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
857 memset (p
, 0, sizeof *p
);
864 for (pp
= &info
->current_function
->parameters
;
873 /* End a function. FIXME: This should handle function nesting. */
876 debug_end_function (handle
, addr
)
880 struct debug_handle
*info
= (struct debug_handle
*) handle
;
882 if (info
->current_unit
== NULL
883 || info
->current_block
== NULL
884 || info
->current_function
== NULL
)
886 debug_error (_("debug_end_function: no current function"));
890 if (info
->current_block
->parent
!= NULL
)
892 debug_error (_("debug_end_function: some blocks were not closed"));
896 info
->current_block
->end
= addr
;
898 info
->current_function
= NULL
;
899 info
->current_block
= NULL
;
904 /* Start a block in a function. All local information will be
905 recorded in this block, until the matching call to debug_end_block.
906 debug_start_block and debug_end_block may be nested. The bfd_vma
907 argument is the address at which this block starts. */
910 debug_start_block (handle
, addr
)
914 struct debug_handle
*info
= (struct debug_handle
*) handle
;
915 struct debug_block
*b
, **pb
;
917 /* We must always have a current block: debug_record_function sets
919 if (info
->current_unit
== NULL
920 || info
->current_block
== NULL
)
922 debug_error (_("debug_start_block: no current block"));
926 b
= (struct debug_block
*) xmalloc (sizeof *b
);
927 memset (b
, 0, sizeof *b
);
929 b
->parent
= info
->current_block
;
931 b
->end
= (bfd_vma
) -1;
933 /* This new block is a child of the current block. */
934 for (pb
= &info
->current_block
->children
;
940 info
->current_block
= b
;
945 /* Finish a block in a function. This matches the call to
946 debug_start_block. The argument is the address at which this block
950 debug_end_block (handle
, addr
)
954 struct debug_handle
*info
= (struct debug_handle
*) handle
;
955 struct debug_block
*parent
;
957 if (info
->current_unit
== NULL
958 || info
->current_block
== NULL
)
960 debug_error (_("debug_end_block: no current block"));
964 parent
= info
->current_block
->parent
;
967 debug_error (_("debug_end_block: attempt to close top level block"));
971 info
->current_block
->end
= addr
;
973 info
->current_block
= parent
;
978 /* Associate a line number in the current source file and function
979 with a given address. */
982 debug_record_line (handle
, lineno
, addr
)
984 unsigned long lineno
;
987 struct debug_handle
*info
= (struct debug_handle
*) handle
;
988 struct debug_lineno
*l
;
991 if (info
->current_unit
== NULL
)
993 debug_error (_("debug_record_line: no current unit"));
997 l
= info
->current_lineno
;
998 if (l
!= NULL
&& l
->file
== info
->current_file
)
1000 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
1002 if (l
->linenos
[i
] == (unsigned long) -1)
1004 l
->linenos
[i
] = lineno
;
1011 /* If we get here, then either 1) there is no current_lineno
1012 structure, which means this is the first line number in this
1013 compilation unit, 2) the current_lineno structure is for a
1014 different file, or 3) the current_lineno structure is full.
1015 Regardless, we want to allocate a new debug_lineno structure, put
1016 it in the right place, and make it the new current_lineno
1019 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
1020 memset (l
, 0, sizeof *l
);
1022 l
->file
= info
->current_file
;
1023 l
->linenos
[0] = lineno
;
1025 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
1026 l
->linenos
[i
] = (unsigned long) -1;
1028 if (info
->current_lineno
!= NULL
)
1029 info
->current_lineno
->next
= l
;
1031 info
->current_unit
->linenos
= l
;
1033 info
->current_lineno
= l
;
1038 /* Start a named common block. This is a block of variables that may
1042 debug_start_common_block (handle
, name
)
1043 PTR handle ATTRIBUTE_UNUSED
;
1044 const char *name ATTRIBUTE_UNUSED
;
1047 debug_error (_("debug_start_common_block: not implemented"));
1051 /* End a named common block. */
1054 debug_end_common_block (handle
, name
)
1055 PTR handle ATTRIBUTE_UNUSED
;
1056 const char *name ATTRIBUTE_UNUSED
;
1059 debug_error (_("debug_end_common_block: not implemented"));
1063 /* Record a named integer constant. */
1066 debug_record_int_const (handle
, name
, val
)
1071 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1072 struct debug_name
*n
;
1077 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1078 DEBUG_LINKAGE_NONE
);
1082 n
->u
.int_constant
= val
;
1087 /* Record a named floating point constant. */
1090 debug_record_float_const (handle
, name
, val
)
1095 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1096 struct debug_name
*n
;
1101 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1102 DEBUG_LINKAGE_NONE
);
1106 n
->u
.float_constant
= val
;
1111 /* Record a typed constant with an integral value. */
1114 debug_record_typed_const (handle
, name
, type
, val
)
1120 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1121 struct debug_name
*n
;
1122 struct debug_typed_constant
*tc
;
1124 if (name
== NULL
|| type
== NULL
)
1127 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1128 DEBUG_LINKAGE_NONE
);
1132 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1133 memset (tc
, 0, sizeof *tc
);
1138 n
->u
.typed_constant
= tc
;
1143 /* Record a label. */
1146 debug_record_label (handle
, name
, type
, addr
)
1147 PTR handle ATTRIBUTE_UNUSED
;
1148 const char *name ATTRIBUTE_UNUSED
;
1149 debug_type type ATTRIBUTE_UNUSED
;
1150 bfd_vma addr ATTRIBUTE_UNUSED
;
1153 debug_error (_("debug_record_label: not implemented"));
1157 /* Record a variable. */
1160 debug_record_variable (handle
, name
, type
, kind
, val
)
1164 enum debug_var_kind kind
;
1167 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1168 struct debug_namespace
**nsp
;
1169 enum debug_object_linkage linkage
;
1170 struct debug_name
*n
;
1171 struct debug_variable
*v
;
1173 if (name
== NULL
|| type
== NULL
)
1176 if (info
->current_unit
== NULL
1177 || info
->current_file
== NULL
)
1179 debug_error (_("debug_record_variable: no current file"));
1183 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1185 nsp
= &info
->current_file
->globals
;
1186 if (kind
== DEBUG_GLOBAL
)
1187 linkage
= DEBUG_LINKAGE_GLOBAL
;
1189 linkage
= DEBUG_LINKAGE_STATIC
;
1193 if (info
->current_block
== NULL
)
1194 nsp
= &info
->current_file
->globals
;
1196 nsp
= &info
->current_block
->locals
;
1197 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1200 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1204 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1205 memset (v
, 0, sizeof *v
);
1216 /* Make a type with a given kind and size. */
1218 static struct debug_type
*
1219 debug_make_type (info
, kind
, size
)
1220 struct debug_handle
*info ATTRIBUTE_UNUSED
;
1221 enum debug_type_kind kind
;
1224 struct debug_type
*t
;
1226 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1227 memset (t
, 0, sizeof *t
);
1235 /* Make an indirect type which may be used as a placeholder for a type
1236 which is referenced before it is defined. */
1239 debug_make_indirect_type (handle
, slot
, tag
)
1244 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1245 struct debug_type
*t
;
1246 struct debug_indirect_type
*i
;
1248 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1250 return DEBUG_TYPE_NULL
;
1252 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1253 memset (i
, 0, sizeof *i
);
1263 /* Make a void type. There is only one of these. */
1266 debug_make_void_type (handle
)
1269 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1271 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1274 /* Make an integer type of a given size. The boolean argument is true
1275 if the integer is unsigned. */
1278 debug_make_int_type (handle
, size
, unsignedp
)
1281 bfd_boolean unsignedp
;
1283 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1284 struct debug_type
*t
;
1286 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1288 return DEBUG_TYPE_NULL
;
1290 t
->u
.kint
= unsignedp
;
1295 /* Make a floating point type of a given size. FIXME: On some
1296 platforms, like an Alpha, you probably need to be able to specify
1300 debug_make_float_type (handle
, size
)
1304 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1306 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1309 /* Make a boolean type of a given size. */
1312 debug_make_bool_type (handle
, size
)
1316 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1318 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1321 /* Make a complex type of a given size. */
1324 debug_make_complex_type (handle
, size
)
1328 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1330 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1333 /* Make a structure type. The second argument is true for a struct,
1334 false for a union. The third argument is the size of the struct.
1335 The fourth argument is a NULL terminated array of fields. */
1338 debug_make_struct_type (handle
, structp
, size
, fields
)
1340 bfd_boolean structp
;
1342 debug_field
*fields
;
1344 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1345 struct debug_type
*t
;
1346 struct debug_class_type
*c
;
1348 t
= debug_make_type (info
,
1349 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1352 return DEBUG_TYPE_NULL
;
1354 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1355 memset (c
, 0, sizeof *c
);
1364 /* Make an object type. The first three arguments after the handle
1365 are the same as for debug_make_struct_type. The next arguments are
1366 a NULL terminated array of base classes, a NULL terminated array of
1367 methods, the type of the object holding the virtual function table
1368 if it is not this object, and a boolean which is true if this
1369 object has its own virtual function table. */
1372 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1373 methods
, vptrbase
, ownvptr
)
1375 bfd_boolean structp
;
1377 debug_field
*fields
;
1378 debug_baseclass
*baseclasses
;
1379 debug_method
*methods
;
1380 debug_type vptrbase
;
1381 bfd_boolean ownvptr
;
1383 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1384 struct debug_type
*t
;
1385 struct debug_class_type
*c
;
1387 t
= debug_make_type (info
,
1388 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1391 return DEBUG_TYPE_NULL
;
1393 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1394 memset (c
, 0, sizeof *c
);
1397 c
->baseclasses
= baseclasses
;
1398 c
->methods
= methods
;
1402 c
->vptrbase
= vptrbase
;
1409 /* Make an enumeration type. The arguments are a null terminated
1410 array of strings, and an array of corresponding values. */
1413 debug_make_enum_type (handle
, names
, values
)
1416 bfd_signed_vma
*values
;
1418 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1419 struct debug_type
*t
;
1420 struct debug_enum_type
*e
;
1422 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1424 return DEBUG_TYPE_NULL
;
1426 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1427 memset (e
, 0, sizeof *e
);
1437 /* Make a pointer to a given type. */
1440 debug_make_pointer_type (handle
, type
)
1444 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1445 struct debug_type
*t
;
1448 return DEBUG_TYPE_NULL
;
1450 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1451 return type
->pointer
;
1453 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1455 return DEBUG_TYPE_NULL
;
1457 t
->u
.kpointer
= type
;
1464 /* Make a function returning a given type. FIXME: We should be able
1465 to record the parameter types. */
1468 debug_make_function_type (handle
, type
, arg_types
, varargs
)
1471 debug_type
*arg_types
;
1472 bfd_boolean varargs
;
1474 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1475 struct debug_type
*t
;
1476 struct debug_function_type
*f
;
1479 return DEBUG_TYPE_NULL
;
1481 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1483 return DEBUG_TYPE_NULL
;
1485 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1486 memset (f
, 0, sizeof *f
);
1488 f
->return_type
= type
;
1489 f
->arg_types
= arg_types
;
1490 f
->varargs
= varargs
;
1497 /* Make a reference to a given type. */
1500 debug_make_reference_type (handle
, type
)
1504 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1505 struct debug_type
*t
;
1508 return DEBUG_TYPE_NULL
;
1510 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1512 return DEBUG_TYPE_NULL
;
1514 t
->u
.kreference
= type
;
1519 /* Make a range of a given type from a lower to an upper bound. */
1522 debug_make_range_type (handle
, type
, lower
, upper
)
1525 bfd_signed_vma lower
;
1526 bfd_signed_vma upper
;
1528 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1529 struct debug_type
*t
;
1530 struct debug_range_type
*r
;
1533 return DEBUG_TYPE_NULL
;
1535 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1537 return DEBUG_TYPE_NULL
;
1539 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1540 memset (r
, 0, sizeof *r
);
1551 /* Make an array type. The second argument is the type of an element
1552 of the array. The third argument is the type of a range of the
1553 array. The fourth and fifth argument are the lower and upper
1554 bounds, respectively. The sixth argument is true if this array is
1555 actually a string, as in C. */
1558 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1561 debug_type element_type
;
1562 debug_type range_type
;
1563 bfd_signed_vma lower
;
1564 bfd_signed_vma upper
;
1565 bfd_boolean stringp
;
1567 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1568 struct debug_type
*t
;
1569 struct debug_array_type
*a
;
1571 if (element_type
== NULL
|| range_type
== NULL
)
1572 return DEBUG_TYPE_NULL
;
1574 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1576 return DEBUG_TYPE_NULL
;
1578 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1579 memset (a
, 0, sizeof *a
);
1581 a
->element_type
= element_type
;
1582 a
->range_type
= range_type
;
1585 a
->stringp
= stringp
;
1592 /* Make a set of a given type. For example, a Pascal set type. The
1593 boolean argument is true if this set is actually a bitstring, as in
1597 debug_make_set_type (handle
, type
, bitstringp
)
1600 bfd_boolean bitstringp
;
1602 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1603 struct debug_type
*t
;
1604 struct debug_set_type
*s
;
1607 return DEBUG_TYPE_NULL
;
1609 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1611 return DEBUG_TYPE_NULL
;
1613 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1614 memset (s
, 0, sizeof *s
);
1617 s
->bitstringp
= bitstringp
;
1624 /* Make a type for a pointer which is relative to an object. The
1625 second argument is the type of the object to which the pointer is
1626 relative. The third argument is the type that the pointer points
1630 debug_make_offset_type (handle
, base_type
, target_type
)
1632 debug_type base_type
;
1633 debug_type target_type
;
1635 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1636 struct debug_type
*t
;
1637 struct debug_offset_type
*o
;
1639 if (base_type
== NULL
|| target_type
== NULL
)
1640 return DEBUG_TYPE_NULL
;
1642 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1644 return DEBUG_TYPE_NULL
;
1646 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1647 memset (o
, 0, sizeof *o
);
1649 o
->base_type
= base_type
;
1650 o
->target_type
= target_type
;
1657 /* Make a type for a method function. The second argument is the
1658 return type, the third argument is the domain, and the fourth
1659 argument is a NULL terminated array of argument types. */
1662 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
, varargs
)
1664 debug_type return_type
;
1665 debug_type domain_type
;
1666 debug_type
*arg_types
;
1667 bfd_boolean varargs
;
1669 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1670 struct debug_type
*t
;
1671 struct debug_method_type
*m
;
1673 if (return_type
== NULL
)
1674 return DEBUG_TYPE_NULL
;
1676 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1678 return DEBUG_TYPE_NULL
;
1680 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1681 memset (m
, 0, sizeof *m
);
1683 m
->return_type
= return_type
;
1684 m
->domain_type
= domain_type
;
1685 m
->arg_types
= arg_types
;
1686 m
->varargs
= varargs
;
1693 /* Make a const qualified version of a given type. */
1696 debug_make_const_type (handle
, type
)
1700 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1701 struct debug_type
*t
;
1704 return DEBUG_TYPE_NULL
;
1706 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1708 return DEBUG_TYPE_NULL
;
1715 /* Make a volatile qualified version of a given type. */
1718 debug_make_volatile_type (handle
, type
)
1722 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1723 struct debug_type
*t
;
1726 return DEBUG_TYPE_NULL
;
1728 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1730 return DEBUG_TYPE_NULL
;
1732 t
->u
.kvolatile
= type
;
1737 /* Make an undefined tagged type. For example, a struct which has
1738 been mentioned, but not defined. */
1741 debug_make_undefined_tagged_type (handle
, name
, kind
)
1744 enum debug_type_kind kind
;
1746 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1747 struct debug_type
*t
;
1750 return DEBUG_TYPE_NULL
;
1754 case DEBUG_KIND_STRUCT
:
1755 case DEBUG_KIND_UNION
:
1756 case DEBUG_KIND_CLASS
:
1757 case DEBUG_KIND_UNION_CLASS
:
1758 case DEBUG_KIND_ENUM
:
1762 debug_error (_("debug_make_undefined_type: unsupported kind"));
1763 return DEBUG_TYPE_NULL
;
1766 t
= debug_make_type (info
, kind
, 0);
1768 return DEBUG_TYPE_NULL
;
1770 return debug_tag_type (handle
, name
, t
);
1773 /* Make a base class for an object. The second argument is the base
1774 class type. The third argument is the bit position of this base
1775 class in the object (always 0 unless doing multiple inheritance).
1776 The fourth argument is whether this is a virtual class. The fifth
1777 argument is the visibility of the base class. */
1780 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1781 PTR handle ATTRIBUTE_UNUSED
;
1784 bfd_boolean
virtual;
1785 enum debug_visibility visibility
;
1787 struct debug_baseclass
*b
;
1789 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1790 memset (b
, 0, sizeof *b
);
1794 b
->virtual = virtual;
1795 b
->visibility
= visibility
;
1800 /* Make a field for a struct. The second argument is the name. The
1801 third argument is the type of the field. The fourth argument is
1802 the bit position of the field. The fifth argument is the size of
1803 the field (it may be zero). The sixth argument is the visibility
1807 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1808 PTR handle ATTRIBUTE_UNUSED
;
1813 enum debug_visibility visibility
;
1815 struct debug_field
*f
;
1817 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1818 memset (f
, 0, sizeof *f
);
1822 f
->static_member
= FALSE
;
1823 f
->u
.f
.bitpos
= bitpos
;
1824 f
->u
.f
.bitsize
= bitsize
;
1825 f
->visibility
= visibility
;
1830 /* Make a static member of an object. The second argument is the
1831 name. The third argument is the type of the member. The fourth
1832 argument is the physical name of the member (i.e., the name as a
1833 global variable). The fifth argument is the visibility of the
1837 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1838 PTR handle ATTRIBUTE_UNUSED
;
1841 const char *physname
;
1842 enum debug_visibility visibility
;
1844 struct debug_field
*f
;
1846 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1847 memset (f
, 0, sizeof *f
);
1851 f
->static_member
= TRUE
;
1852 f
->u
.s
.physname
= physname
;
1853 f
->visibility
= visibility
;
1858 /* Make a method. The second argument is the name, and the third
1859 argument is a NULL terminated array of method variants. */
1862 debug_make_method (handle
, name
, variants
)
1863 PTR handle ATTRIBUTE_UNUSED
;
1865 debug_method_variant
*variants
;
1867 struct debug_method
*m
;
1869 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1870 memset (m
, 0, sizeof *m
);
1873 m
->variants
= variants
;
1878 /* Make a method argument. The second argument is the real name of
1879 the function. The third argument is the type of the function. The
1880 fourth argument is the visibility. The fifth argument is whether
1881 this is a const function. The sixth argument is whether this is a
1882 volatile function. The seventh argument is the offset in the
1883 virtual function table, if any. The eighth argument is the virtual
1884 function context. FIXME: Are the const and volatile arguments
1885 necessary? Could we just use debug_make_const_type? */
1887 debug_method_variant
1888 debug_make_method_variant (handle
, physname
, type
, visibility
, constp
,
1889 volatilep
, voffset
, context
)
1890 PTR handle ATTRIBUTE_UNUSED
;
1891 const char *physname
;
1893 enum debug_visibility visibility
;
1895 bfd_boolean volatilep
;
1899 struct debug_method_variant
*m
;
1901 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1902 memset (m
, 0, sizeof *m
);
1904 m
->physname
= physname
;
1906 m
->visibility
= visibility
;
1908 m
->volatilep
= volatilep
;
1909 m
->voffset
= voffset
;
1910 m
->context
= context
;
1915 /* Make a static method argument. The arguments are the same as for
1916 debug_make_method_variant, except that the last two are omitted
1917 since a static method can not also be virtual. */
1919 debug_method_variant
1920 debug_make_static_method_variant (handle
, physname
, type
, visibility
,
1922 PTR handle ATTRIBUTE_UNUSED
;
1923 const char *physname
;
1925 enum debug_visibility visibility
;
1927 bfd_boolean volatilep
;
1929 struct debug_method_variant
*m
;
1931 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1932 memset (m
, 0, sizeof *m
);
1934 m
->physname
= physname
;
1936 m
->visibility
= visibility
;
1938 m
->volatilep
= volatilep
;
1939 m
->voffset
= VOFFSET_STATIC_METHOD
;
1947 debug_name_type (handle
, name
, type
)
1952 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1953 struct debug_type
*t
;
1954 struct debug_named_type
*n
;
1955 struct debug_name
*nm
;
1957 if (name
== NULL
|| type
== NULL
)
1958 return DEBUG_TYPE_NULL
;
1960 if (info
->current_unit
== NULL
1961 || info
->current_file
== NULL
)
1963 debug_error (_("debug_name_type: no current file"));
1964 return DEBUG_TYPE_NULL
;
1967 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1969 return DEBUG_TYPE_NULL
;
1971 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1972 memset (n
, 0, sizeof *n
);
1978 /* We always add the name to the global namespace. This is probably
1979 wrong in some cases, but it seems to be right for stabs. FIXME. */
1981 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1982 DEBUG_OBJECT_TYPE
, DEBUG_LINKAGE_NONE
);
1984 return DEBUG_TYPE_NULL
;
1996 debug_tag_type (handle
, name
, type
)
2001 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2002 struct debug_type
*t
;
2003 struct debug_named_type
*n
;
2004 struct debug_name
*nm
;
2006 if (name
== NULL
|| type
== NULL
)
2007 return DEBUG_TYPE_NULL
;
2009 if (info
->current_file
== NULL
)
2011 debug_error (_("debug_tag_type: no current file"));
2012 return DEBUG_TYPE_NULL
;
2015 if (type
->kind
== DEBUG_KIND_TAGGED
)
2017 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
2019 debug_error (_("debug_tag_type: extra tag attempted"));
2020 return DEBUG_TYPE_NULL
;
2023 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
2025 return DEBUG_TYPE_NULL
;
2027 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
2028 memset (n
, 0, sizeof *n
);
2034 /* We keep a global namespace of tags for each compilation unit. I
2035 don't know if that is the right thing to do. */
2037 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
2038 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2040 return DEBUG_TYPE_NULL
;
2049 /* Record the size of a given type. */
2052 debug_record_type_size (handle
, type
, size
)
2053 PTR handle ATTRIBUTE_UNUSED
;
2057 if (type
->size
!= 0 && type
->size
!= size
)
2058 fprintf (stderr
, _("Warning: changing type size from %d to %d\n"),
2066 /* Find a named type. */
2069 debug_find_named_type (handle
, name
)
2073 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2074 struct debug_block
*b
;
2075 struct debug_file
*f
;
2077 /* We only search the current compilation unit. I don't know if
2078 this is right or not. */
2080 if (info
->current_unit
== NULL
)
2082 debug_error (_("debug_find_named_type: no current compilation unit"));
2083 return DEBUG_TYPE_NULL
;
2086 for (b
= info
->current_block
; b
!= NULL
; b
= b
->parent
)
2088 if (b
->locals
!= NULL
)
2090 struct debug_name
*n
;
2092 for (n
= b
->locals
->list
; n
!= NULL
; n
= n
->next
)
2094 if (n
->kind
== DEBUG_OBJECT_TYPE
2095 && n
->name
[0] == name
[0]
2096 && strcmp (n
->name
, name
) == 0)
2102 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
2104 if (f
->globals
!= NULL
)
2106 struct debug_name
*n
;
2108 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2110 if (n
->kind
== DEBUG_OBJECT_TYPE
2111 && n
->name
[0] == name
[0]
2112 && strcmp (n
->name
, name
) == 0)
2118 return DEBUG_TYPE_NULL
;
2121 /* Find a tagged type. */
2124 debug_find_tagged_type (handle
, name
, kind
)
2127 enum debug_type_kind kind
;
2129 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2130 struct debug_unit
*u
;
2132 /* We search the globals of all the compilation units. I don't know
2133 if this is correct or not. It would be easy to change. */
2135 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2137 struct debug_file
*f
;
2139 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2141 struct debug_name
*n
;
2143 if (f
->globals
!= NULL
)
2145 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2147 if (n
->kind
== DEBUG_OBJECT_TAG
2148 && (kind
== DEBUG_KIND_ILLEGAL
2149 || n
->u
.tag
->kind
== kind
)
2150 && n
->name
[0] == name
[0]
2151 && strcmp (n
->name
, name
) == 0)
2158 return DEBUG_TYPE_NULL
;
2161 /* Get a base type. We build a linked list on the stack to avoid
2162 crashing if the type is defined circularly. */
2164 static struct debug_type
*
2165 debug_get_real_type (handle
, type
, list
)
2168 struct debug_type_real_list
*list
;
2170 struct debug_type_real_list
*l
;
2171 struct debug_type_real_list rl
;
2178 case DEBUG_KIND_INDIRECT
:
2179 case DEBUG_KIND_NAMED
:
2180 case DEBUG_KIND_TAGGED
:
2184 for (l
= list
; l
!= NULL
; l
= l
->next
)
2186 if (l
->t
== type
|| l
== l
->next
)
2189 _("debug_get_real_type: circular debug information for %s\n"),
2190 debug_get_type_name (handle
, type
));
2200 /* The default case is just here to avoid warnings. */
2202 case DEBUG_KIND_INDIRECT
:
2203 if (*type
->u
.kindirect
->slot
!= NULL
)
2204 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
, &rl
);
2206 case DEBUG_KIND_NAMED
:
2207 case DEBUG_KIND_TAGGED
:
2208 return debug_get_real_type (handle
, type
->u
.knamed
->type
, &rl
);
2213 /* Get the kind of a type. */
2215 enum debug_type_kind
2216 debug_get_type_kind (handle
, type
)
2221 return DEBUG_KIND_ILLEGAL
;
2222 type
= debug_get_real_type (handle
, type
, NULL
);
2224 return DEBUG_KIND_ILLEGAL
;
2228 /* Get the name of a type. */
2231 debug_get_type_name (handle
, type
)
2235 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2237 if (*type
->u
.kindirect
->slot
!= NULL
)
2238 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2239 return type
->u
.kindirect
->tag
;
2241 if (type
->kind
== DEBUG_KIND_NAMED
2242 || type
->kind
== DEBUG_KIND_TAGGED
)
2243 return type
->u
.knamed
->name
->name
;
2247 /* Get the size of a type. */
2250 debug_get_type_size (handle
, type
)
2257 /* We don't call debug_get_real_type, because somebody might have
2258 called debug_record_type_size on a named or indirect type. */
2260 if (type
->size
!= 0)
2267 case DEBUG_KIND_INDIRECT
:
2268 if (*type
->u
.kindirect
->slot
!= NULL
)
2269 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2271 case DEBUG_KIND_NAMED
:
2272 case DEBUG_KIND_TAGGED
:
2273 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2278 /* Get the return type of a function or method type. */
2281 debug_get_return_type (handle
, type
)
2286 return DEBUG_TYPE_NULL
;
2288 type
= debug_get_real_type (handle
, type
, NULL
);
2290 return DEBUG_TYPE_NULL
;
2295 return DEBUG_TYPE_NULL
;
2296 case DEBUG_KIND_FUNCTION
:
2297 return type
->u
.kfunction
->return_type
;
2298 case DEBUG_KIND_METHOD
:
2299 return type
->u
.kmethod
->return_type
;
2304 /* Get the parameter types of a function or method type (except that
2305 we don't currently store the parameter types of a function). */
2308 debug_get_parameter_types (handle
, type
, pvarargs
)
2311 bfd_boolean
*pvarargs
;
2316 type
= debug_get_real_type (handle
, type
, NULL
);
2324 case DEBUG_KIND_FUNCTION
:
2325 *pvarargs
= type
->u
.kfunction
->varargs
;
2326 return type
->u
.kfunction
->arg_types
;
2327 case DEBUG_KIND_METHOD
:
2328 *pvarargs
= type
->u
.kmethod
->varargs
;
2329 return type
->u
.kmethod
->arg_types
;
2334 /* Get the target type of a type. */
2337 debug_get_target_type (handle
, type
)
2344 type
= debug_get_real_type (handle
, type
, NULL
);
2352 case DEBUG_KIND_POINTER
:
2353 return type
->u
.kpointer
;
2354 case DEBUG_KIND_REFERENCE
:
2355 return type
->u
.kreference
;
2356 case DEBUG_KIND_CONST
:
2357 return type
->u
.kconst
;
2358 case DEBUG_KIND_VOLATILE
:
2359 return type
->u
.kvolatile
;
2364 /* Get the NULL terminated array of fields for a struct, union, or
2368 debug_get_fields (handle
, type
)
2375 type
= debug_get_real_type (handle
, type
, NULL
);
2383 case DEBUG_KIND_STRUCT
:
2384 case DEBUG_KIND_UNION
:
2385 case DEBUG_KIND_CLASS
:
2386 case DEBUG_KIND_UNION_CLASS
:
2387 return type
->u
.kclass
->fields
;
2392 /* Get the type of a field. */
2395 debug_get_field_type (handle
, field
)
2396 PTR handle ATTRIBUTE_UNUSED
;
2404 /* Get the name of a field. */
2407 debug_get_field_name (handle
, field
)
2408 PTR handle ATTRIBUTE_UNUSED
;
2416 /* Get the bit position of a field. */
2419 debug_get_field_bitpos (handle
, field
)
2420 PTR handle ATTRIBUTE_UNUSED
;
2423 if (field
== NULL
|| field
->static_member
)
2424 return (bfd_vma
) -1;
2425 return field
->u
.f
.bitpos
;
2428 /* Get the bit size of a field. */
2431 debug_get_field_bitsize (handle
, field
)
2432 PTR handle ATTRIBUTE_UNUSED
;
2435 if (field
== NULL
|| field
->static_member
)
2436 return (bfd_vma
) -1;
2437 return field
->u
.f
.bitsize
;
2440 /* Get the visibility of a field. */
2442 enum debug_visibility
2443 debug_get_field_visibility (handle
, field
)
2444 PTR handle ATTRIBUTE_UNUSED
;
2448 return DEBUG_VISIBILITY_IGNORE
;
2449 return field
->visibility
;
2452 /* Get the physical name of a field. */
2455 debug_get_field_physname (handle
, field
)
2456 PTR handle ATTRIBUTE_UNUSED
;
2459 if (field
== NULL
|| ! field
->static_member
)
2461 return field
->u
.s
.physname
;
2464 /* Write out the debugging information. This is given a handle to
2465 debugging information, and a set of function pointers to call. */
2468 debug_write (handle
, fns
, fhandle
)
2470 const struct debug_write_fns
*fns
;
2473 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2474 struct debug_unit
*u
;
2476 /* We use a mark to tell whether we have already written out a
2477 particular name. We use an integer, so that we don't have to
2478 clear the mark fields if we happen to write out the same
2479 information more than once. */
2482 /* The base_id field holds an ID value which will never be used, so
2483 that we can tell whether we have assigned an ID during this call
2485 info
->base_id
= info
->class_id
;
2487 /* We keep a linked list of classes for which was have assigned ID's
2488 during this call to debug_write. */
2489 info
->id_list
= NULL
;
2491 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2493 struct debug_file
*f
;
2494 bfd_boolean first_file
;
2496 info
->current_write_lineno
= u
->linenos
;
2497 info
->current_write_lineno_index
= 0;
2499 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2503 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2505 struct debug_name
*n
;
2509 else if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2512 if (f
->globals
!= NULL
)
2513 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2514 if (! debug_write_name (info
, fns
, fhandle
, n
))
2518 /* Output any line number information which hasn't already been
2520 if (! debug_write_linenos (info
, fns
, fhandle
, (bfd_vma
) -1))
2527 /* Write out an element in a namespace. */
2530 debug_write_name (info
, fns
, fhandle
, n
)
2531 struct debug_handle
*info
;
2532 const struct debug_write_fns
*fns
;
2534 struct debug_name
*n
;
2538 case DEBUG_OBJECT_TYPE
:
2539 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2540 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2543 case DEBUG_OBJECT_TAG
:
2544 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2546 return (*fns
->tag
) (fhandle
, n
->name
);
2547 case DEBUG_OBJECT_VARIABLE
:
2548 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2549 (struct debug_name
*) NULL
))
2551 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2552 n
->u
.variable
->val
);
2553 case DEBUG_OBJECT_FUNCTION
:
2554 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2555 n
->linkage
, n
->u
.function
);
2556 case DEBUG_OBJECT_INT_CONSTANT
:
2557 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2558 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2559 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2560 case DEBUG_OBJECT_TYPED_CONSTANT
:
2561 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2562 (struct debug_name
*) NULL
))
2564 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2565 n
->u
.typed_constant
->val
);
2573 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2574 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2575 are about to call typedef or tag. If the type is anything else,
2576 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2577 points to this one. */
2580 debug_write_type (info
, fns
, fhandle
, type
, name
)
2581 struct debug_handle
*info
;
2582 const struct debug_write_fns
*fns
;
2584 struct debug_type
*type
;
2585 struct debug_name
*name
;
2589 const char *tag
= NULL
;
2591 /* If we have a name for this type, just output it. We only output
2592 typedef names after they have been defined. We output type tags
2593 whenever we are not actually defining them. */
2594 if ((type
->kind
== DEBUG_KIND_NAMED
2595 || type
->kind
== DEBUG_KIND_TAGGED
)
2596 && (type
->u
.knamed
->name
->mark
== info
->mark
2597 || (type
->kind
== DEBUG_KIND_TAGGED
2598 && type
->u
.knamed
->name
!= name
)))
2600 if (type
->kind
== DEBUG_KIND_NAMED
)
2601 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2604 struct debug_type
*real
;
2607 real
= debug_get_real_type ((PTR
) info
, type
, NULL
);
2609 return (*fns
->empty_type
) (fhandle
);
2611 if ((real
->kind
== DEBUG_KIND_STRUCT
2612 || real
->kind
== DEBUG_KIND_UNION
2613 || real
->kind
== DEBUG_KIND_CLASS
2614 || real
->kind
== DEBUG_KIND_UNION_CLASS
)
2615 && real
->u
.kclass
!= NULL
)
2617 if (real
->u
.kclass
->id
<= info
->base_id
)
2619 if (! debug_set_class_id (info
,
2620 type
->u
.knamed
->name
->name
,
2624 id
= real
->u
.kclass
->id
;
2627 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, id
,
2632 /* Mark the name after we have already looked for a known name, so
2633 that we don't just define a type in terms of itself. We need to
2634 mark the name here so that a struct containing a pointer to
2635 itself will work. */
2637 name
->mark
= info
->mark
;
2640 && type
->kind
!= DEBUG_KIND_NAMED
2641 && type
->kind
!= DEBUG_KIND_TAGGED
)
2643 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2649 case DEBUG_KIND_ILLEGAL
:
2650 debug_error (_("debug_write_type: illegal type encountered"));
2652 case DEBUG_KIND_INDIRECT
:
2653 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2654 return (*fns
->empty_type
) (fhandle
);
2655 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2657 case DEBUG_KIND_VOID
:
2658 return (*fns
->void_type
) (fhandle
);
2659 case DEBUG_KIND_INT
:
2660 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2661 case DEBUG_KIND_FLOAT
:
2662 return (*fns
->float_type
) (fhandle
, type
->size
);
2663 case DEBUG_KIND_COMPLEX
:
2664 return (*fns
->complex_type
) (fhandle
, type
->size
);
2665 case DEBUG_KIND_BOOL
:
2666 return (*fns
->bool_type
) (fhandle
, type
->size
);
2667 case DEBUG_KIND_STRUCT
:
2668 case DEBUG_KIND_UNION
:
2669 if (type
->u
.kclass
!= NULL
)
2671 if (type
->u
.kclass
->id
<= info
->base_id
)
2673 if (! debug_set_class_id (info
, tag
, type
))
2677 if (info
->mark
== type
->u
.kclass
->mark
)
2679 /* We are currently outputting this struct, or we have
2680 already output it. I don't know if this can happen,
2681 but it can happen for a class. */
2682 assert (type
->u
.kclass
->id
> info
->base_id
);
2683 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2686 type
->u
.kclass
->mark
= info
->mark
;
2689 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2690 (type
->u
.kclass
!= NULL
2691 ? type
->u
.kclass
->id
2693 type
->kind
== DEBUG_KIND_STRUCT
,
2696 if (type
->u
.kclass
!= NULL
2697 && type
->u
.kclass
->fields
!= NULL
)
2699 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2701 struct debug_field
*f
;
2703 f
= type
->u
.kclass
->fields
[i
];
2704 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2705 (struct debug_name
*) NULL
)
2706 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2707 f
->u
.f
.bitsize
, f
->visibility
))
2711 return (*fns
->end_struct_type
) (fhandle
);
2712 case DEBUG_KIND_CLASS
:
2713 case DEBUG_KIND_UNION_CLASS
:
2714 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2715 case DEBUG_KIND_ENUM
:
2716 if (type
->u
.kenum
== NULL
)
2717 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2718 (bfd_signed_vma
*) NULL
);
2719 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2720 type
->u
.kenum
->values
);
2721 case DEBUG_KIND_POINTER
:
2722 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2723 (struct debug_name
*) NULL
))
2725 return (*fns
->pointer_type
) (fhandle
);
2726 case DEBUG_KIND_FUNCTION
:
2727 if (! debug_write_type (info
, fns
, fhandle
,
2728 type
->u
.kfunction
->return_type
,
2729 (struct debug_name
*) NULL
))
2731 if (type
->u
.kfunction
->arg_types
== NULL
)
2735 for (is
= 0; type
->u
.kfunction
->arg_types
[is
] != NULL
; is
++)
2736 if (! debug_write_type (info
, fns
, fhandle
,
2737 type
->u
.kfunction
->arg_types
[is
],
2738 (struct debug_name
*) NULL
))
2741 return (*fns
->function_type
) (fhandle
, is
,
2742 type
->u
.kfunction
->varargs
);
2743 case DEBUG_KIND_REFERENCE
:
2744 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2745 (struct debug_name
*) NULL
))
2747 return (*fns
->reference_type
) (fhandle
);
2748 case DEBUG_KIND_RANGE
:
2749 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2750 (struct debug_name
*) NULL
))
2752 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2753 type
->u
.krange
->upper
);
2754 case DEBUG_KIND_ARRAY
:
2755 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2756 (struct debug_name
*) NULL
)
2757 || ! debug_write_type (info
, fns
, fhandle
,
2758 type
->u
.karray
->range_type
,
2759 (struct debug_name
*) NULL
))
2761 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2762 type
->u
.karray
->upper
,
2763 type
->u
.karray
->stringp
);
2764 case DEBUG_KIND_SET
:
2765 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2766 (struct debug_name
*) NULL
))
2768 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2769 case DEBUG_KIND_OFFSET
:
2770 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2771 (struct debug_name
*) NULL
)
2772 || ! debug_write_type (info
, fns
, fhandle
,
2773 type
->u
.koffset
->target_type
,
2774 (struct debug_name
*) NULL
))
2776 return (*fns
->offset_type
) (fhandle
);
2777 case DEBUG_KIND_METHOD
:
2778 if (! debug_write_type (info
, fns
, fhandle
,
2779 type
->u
.kmethod
->return_type
,
2780 (struct debug_name
*) NULL
))
2782 if (type
->u
.kmethod
->arg_types
== NULL
)
2786 for (is
= 0; type
->u
.kmethod
->arg_types
[is
] != NULL
; is
++)
2787 if (! debug_write_type (info
, fns
, fhandle
,
2788 type
->u
.kmethod
->arg_types
[is
],
2789 (struct debug_name
*) NULL
))
2792 if (type
->u
.kmethod
->domain_type
!= NULL
)
2794 if (! debug_write_type (info
, fns
, fhandle
,
2795 type
->u
.kmethod
->domain_type
,
2796 (struct debug_name
*) NULL
))
2799 return (*fns
->method_type
) (fhandle
,
2800 type
->u
.kmethod
->domain_type
!= NULL
,
2802 type
->u
.kmethod
->varargs
);
2803 case DEBUG_KIND_CONST
:
2804 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2805 (struct debug_name
*) NULL
))
2807 return (*fns
->const_type
) (fhandle
);
2808 case DEBUG_KIND_VOLATILE
:
2809 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2810 (struct debug_name
*) NULL
))
2812 return (*fns
->volatile_type
) (fhandle
);
2813 case DEBUG_KIND_NAMED
:
2814 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2815 (struct debug_name
*) NULL
);
2816 case DEBUG_KIND_TAGGED
:
2817 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2818 type
->u
.knamed
->name
);
2825 /* Write out a class type. */
2828 debug_write_class_type (info
, fns
, fhandle
, type
, tag
)
2829 struct debug_handle
*info
;
2830 const struct debug_write_fns
*fns
;
2832 struct debug_type
*type
;
2837 struct debug_type
*vptrbase
;
2839 if (type
->u
.kclass
== NULL
)
2846 if (type
->u
.kclass
->id
<= info
->base_id
)
2848 if (! debug_set_class_id (info
, tag
, type
))
2852 if (info
->mark
== type
->u
.kclass
->mark
)
2854 /* We are currently outputting this class, or we have
2855 already output it. This can happen when there are
2856 methods for an anonymous class. */
2857 assert (type
->u
.kclass
->id
> info
->base_id
);
2858 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2861 type
->u
.kclass
->mark
= info
->mark
;
2862 id
= type
->u
.kclass
->id
;
2864 vptrbase
= type
->u
.kclass
->vptrbase
;
2865 if (vptrbase
!= NULL
&& vptrbase
!= type
)
2867 if (! debug_write_type (info
, fns
, fhandle
, vptrbase
,
2868 (struct debug_name
*) NULL
))
2873 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2874 type
->kind
== DEBUG_KIND_CLASS
,
2880 if (type
->u
.kclass
!= NULL
)
2882 if (type
->u
.kclass
->fields
!= NULL
)
2884 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2886 struct debug_field
*f
;
2888 f
= type
->u
.kclass
->fields
[i
];
2889 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2890 (struct debug_name
*) NULL
))
2892 if (f
->static_member
)
2894 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2901 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2902 f
->u
.f
.bitsize
, f
->visibility
))
2908 if (type
->u
.kclass
->baseclasses
!= NULL
)
2910 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2912 struct debug_baseclass
*b
;
2914 b
= type
->u
.kclass
->baseclasses
[i
];
2915 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2916 (struct debug_name
*) NULL
))
2918 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2924 if (type
->u
.kclass
->methods
!= NULL
)
2926 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2928 struct debug_method
*m
;
2931 m
= type
->u
.kclass
->methods
[i
];
2932 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2934 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2936 struct debug_method_variant
*v
;
2939 if (v
->context
!= NULL
)
2941 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2942 (struct debug_name
*) NULL
))
2945 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2946 (struct debug_name
*) NULL
))
2948 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2950 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2955 v
->context
!= NULL
))
2960 if (! (*fns
->class_static_method_variant
) (fhandle
,
2968 if (! (*fns
->class_end_method
) (fhandle
))
2974 return (*fns
->end_class_type
) (fhandle
);
2977 /* Write out information for a function. */
2980 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2981 struct debug_handle
*info
;
2982 const struct debug_write_fns
*fns
;
2985 enum debug_object_linkage linkage
;
2986 struct debug_function
*function
;
2988 struct debug_parameter
*p
;
2989 struct debug_block
*b
;
2991 if (! debug_write_linenos (info
, fns
, fhandle
, function
->blocks
->start
))
2994 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2995 (struct debug_name
*) NULL
))
2998 if (! (*fns
->start_function
) (fhandle
, name
,
2999 linkage
== DEBUG_LINKAGE_GLOBAL
))
3002 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
3004 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
3005 (struct debug_name
*) NULL
)
3006 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
3010 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
3012 if (! debug_write_block (info
, fns
, fhandle
, b
))
3016 return (*fns
->end_function
) (fhandle
);
3019 /* Write out information for a block. */
3022 debug_write_block (info
, fns
, fhandle
, block
)
3023 struct debug_handle
*info
;
3024 const struct debug_write_fns
*fns
;
3026 struct debug_block
*block
;
3028 struct debug_name
*n
;
3029 struct debug_block
*b
;
3031 if (! debug_write_linenos (info
, fns
, fhandle
, block
->start
))
3034 /* I can't see any point to writing out a block with no local
3035 variables, so we don't bother, except for the top level block. */
3036 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
3038 if (! (*fns
->start_block
) (fhandle
, block
->start
))
3042 if (block
->locals
!= NULL
)
3044 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
3046 if (! debug_write_name (info
, fns
, fhandle
, n
))
3051 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
3053 if (! debug_write_block (info
, fns
, fhandle
, b
))
3057 if (! debug_write_linenos (info
, fns
, fhandle
, block
->end
))
3060 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
3062 if (! (*fns
->end_block
) (fhandle
, block
->end
))
3069 /* Write out line number information up to ADDRESS. */
3072 debug_write_linenos (info
, fns
, fhandle
, address
)
3073 struct debug_handle
*info
;
3074 const struct debug_write_fns
*fns
;
3078 while (info
->current_write_lineno
!= NULL
)
3080 struct debug_lineno
*l
;
3082 l
= info
->current_write_lineno
;
3084 while (info
->current_write_lineno_index
< DEBUG_LINENO_COUNT
)
3086 if (l
->linenos
[info
->current_write_lineno_index
]
3087 == (unsigned long) -1)
3090 if (l
->addrs
[info
->current_write_lineno_index
] >= address
)
3093 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
,
3094 l
->linenos
[info
->current_write_lineno_index
],
3095 l
->addrs
[info
->current_write_lineno_index
]))
3098 ++info
->current_write_lineno_index
;
3101 info
->current_write_lineno
= l
->next
;
3102 info
->current_write_lineno_index
= 0;
3108 /* Get the ID number for a class. If during the same call to
3109 debug_write we find a struct with the same definition with the same
3110 name, we use the same ID. This type of things happens because the
3111 same struct will be defined by multiple compilation units. */
3114 debug_set_class_id (info
, tag
, type
)
3115 struct debug_handle
*info
;
3117 struct debug_type
*type
;
3119 struct debug_class_type
*c
;
3120 struct debug_class_id
*l
;
3122 assert (type
->kind
== DEBUG_KIND_STRUCT
3123 || type
->kind
== DEBUG_KIND_UNION
3124 || type
->kind
== DEBUG_KIND_CLASS
3125 || type
->kind
== DEBUG_KIND_UNION_CLASS
);
3129 if (c
->id
> info
->base_id
)
3132 for (l
= info
->id_list
; l
!= NULL
; l
= l
->next
)
3134 if (l
->type
->kind
!= type
->kind
)
3145 || l
->tag
[0] != tag
[0]
3146 || strcmp (l
->tag
, tag
) != 0)
3150 if (debug_type_samep (info
, l
->type
, type
))
3152 c
->id
= l
->type
->u
.kclass
->id
;
3157 /* There are no identical types. Use a new ID, and add it to the
3160 c
->id
= info
->class_id
;
3162 l
= (struct debug_class_id
*) xmalloc (sizeof *l
);
3163 memset (l
, 0, sizeof *l
);
3168 l
->next
= info
->id_list
;
3174 /* See if two types are the same. At this point, we don't care about
3175 tags and the like. */
3178 debug_type_samep (info
, t1
, t2
)
3179 struct debug_handle
*info
;
3180 struct debug_type
*t1
;
3181 struct debug_type
*t2
;
3183 struct debug_type_compare_list
*l
;
3184 struct debug_type_compare_list top
;
3192 while (t1
->kind
== DEBUG_KIND_INDIRECT
)
3194 t1
= *t1
->u
.kindirect
->slot
;
3198 while (t2
->kind
== DEBUG_KIND_INDIRECT
)
3200 t2
= *t2
->u
.kindirect
->slot
;
3208 /* As a special case, permit a typedef to match a tag, since C++
3209 debugging output will sometimes add a typedef where C debugging
3211 if (t1
->kind
== DEBUG_KIND_NAMED
3212 && t2
->kind
== DEBUG_KIND_TAGGED
)
3213 return debug_type_samep (info
, t1
->u
.knamed
->type
, t2
);
3214 else if (t1
->kind
== DEBUG_KIND_TAGGED
3215 && t2
->kind
== DEBUG_KIND_NAMED
)
3216 return debug_type_samep (info
, t1
, t2
->u
.knamed
->type
);
3218 if (t1
->kind
!= t2
->kind
3219 || t1
->size
!= t2
->size
)
3222 /* Get rid of the trivial cases first. */
3227 case DEBUG_KIND_VOID
:
3228 case DEBUG_KIND_FLOAT
:
3229 case DEBUG_KIND_COMPLEX
:
3230 case DEBUG_KIND_BOOL
:
3232 case DEBUG_KIND_INT
:
3233 return t1
->u
.kint
== t2
->u
.kint
;
3236 /* We have to avoid an infinite recursion. We do this by keeping a
3237 list of types which we are comparing. We just keep the list on
3238 the stack. If we encounter a pair of types we are currently
3239 comparing, we just assume that they are equal. */
3240 for (l
= info
->compare_list
; l
!= NULL
; l
= l
->next
)
3242 if (l
->t1
== t1
&& l
->t2
== t2
)
3248 top
.next
= info
->compare_list
;
3249 info
->compare_list
= &top
;
3258 case DEBUG_KIND_STRUCT
:
3259 case DEBUG_KIND_UNION
:
3260 case DEBUG_KIND_CLASS
:
3261 case DEBUG_KIND_UNION_CLASS
:
3262 if (t1
->u
.kclass
== NULL
)
3263 ret
= t2
->u
.kclass
== NULL
;
3264 else if (t2
->u
.kclass
== NULL
)
3266 else if (t1
->u
.kclass
->id
> info
->base_id
3267 && t1
->u
.kclass
->id
== t2
->u
.kclass
->id
)
3270 ret
= debug_class_type_samep (info
, t1
, t2
);
3273 case DEBUG_KIND_ENUM
:
3274 if (t1
->u
.kenum
== NULL
)
3275 ret
= t2
->u
.kenum
== NULL
;
3276 else if (t2
->u
.kenum
== NULL
)
3280 const char **pn1
, **pn2
;
3281 bfd_signed_vma
*pv1
, *pv2
;
3283 pn1
= t1
->u
.kenum
->names
;
3284 pn2
= t2
->u
.kenum
->names
;
3285 pv1
= t1
->u
.kenum
->values
;
3286 pv2
= t2
->u
.kenum
->values
;
3287 while (*pn1
!= NULL
&& *pn2
!= NULL
)
3291 || strcmp (*pn1
, *pn2
) != 0)
3298 ret
= *pn1
== NULL
&& *pn2
== NULL
;
3302 case DEBUG_KIND_POINTER
:
3303 ret
= debug_type_samep (info
, t1
->u
.kpointer
, t2
->u
.kpointer
);
3306 case DEBUG_KIND_FUNCTION
:
3307 if (t1
->u
.kfunction
->varargs
!= t2
->u
.kfunction
->varargs
3308 || ! debug_type_samep (info
, t1
->u
.kfunction
->return_type
,
3309 t2
->u
.kfunction
->return_type
)
3310 || ((t1
->u
.kfunction
->arg_types
== NULL
)
3311 != (t2
->u
.kfunction
->arg_types
== NULL
)))
3313 else if (t1
->u
.kfunction
->arg_types
== NULL
)
3317 struct debug_type
**a1
, **a2
;
3319 a1
= t1
->u
.kfunction
->arg_types
;
3320 a2
= t2
->u
.kfunction
->arg_types
;
3321 while (*a1
!= NULL
&& *a2
!= NULL
)
3323 if (! debug_type_samep (info
, *a1
, *a2
))
3328 ret
= *a1
== NULL
&& *a2
== NULL
;
3332 case DEBUG_KIND_REFERENCE
:
3333 ret
= debug_type_samep (info
, t1
->u
.kreference
, t2
->u
.kreference
);
3336 case DEBUG_KIND_RANGE
:
3337 ret
= (t1
->u
.krange
->lower
== t2
->u
.krange
->lower
3338 && t1
->u
.krange
->upper
== t2
->u
.krange
->upper
3339 && debug_type_samep (info
, t1
->u
.krange
->type
,
3340 t2
->u
.krange
->type
));
3342 case DEBUG_KIND_ARRAY
:
3343 ret
= (t1
->u
.karray
->lower
== t2
->u
.karray
->lower
3344 && t1
->u
.karray
->upper
== t2
->u
.karray
->upper
3345 && t1
->u
.karray
->stringp
== t2
->u
.karray
->stringp
3346 && debug_type_samep (info
, t1
->u
.karray
->element_type
,
3347 t2
->u
.karray
->element_type
));
3350 case DEBUG_KIND_SET
:
3351 ret
= (t1
->u
.kset
->bitstringp
== t2
->u
.kset
->bitstringp
3352 && debug_type_samep (info
, t1
->u
.kset
->type
, t2
->u
.kset
->type
));
3355 case DEBUG_KIND_OFFSET
:
3356 ret
= (debug_type_samep (info
, t1
->u
.koffset
->base_type
,
3357 t2
->u
.koffset
->base_type
)
3358 && debug_type_samep (info
, t1
->u
.koffset
->target_type
,
3359 t2
->u
.koffset
->target_type
));
3362 case DEBUG_KIND_METHOD
:
3363 if (t1
->u
.kmethod
->varargs
!= t2
->u
.kmethod
->varargs
3364 || ! debug_type_samep (info
, t1
->u
.kmethod
->return_type
,
3365 t2
->u
.kmethod
->return_type
)
3366 || ! debug_type_samep (info
, t1
->u
.kmethod
->domain_type
,
3367 t2
->u
.kmethod
->domain_type
)
3368 || ((t1
->u
.kmethod
->arg_types
== NULL
)
3369 != (t2
->u
.kmethod
->arg_types
== NULL
)))
3371 else if (t1
->u
.kmethod
->arg_types
== NULL
)
3375 struct debug_type
**a1
, **a2
;
3377 a1
= t1
->u
.kmethod
->arg_types
;
3378 a2
= t2
->u
.kmethod
->arg_types
;
3379 while (*a1
!= NULL
&& *a2
!= NULL
)
3381 if (! debug_type_samep (info
, *a1
, *a2
))
3386 ret
= *a1
== NULL
&& *a2
== NULL
;
3390 case DEBUG_KIND_CONST
:
3391 ret
= debug_type_samep (info
, t1
->u
.kconst
, t2
->u
.kconst
);
3394 case DEBUG_KIND_VOLATILE
:
3395 ret
= debug_type_samep (info
, t1
->u
.kvolatile
, t2
->u
.kvolatile
);
3398 case DEBUG_KIND_NAMED
:
3399 case DEBUG_KIND_TAGGED
:
3400 ret
= (strcmp (t1
->u
.knamed
->name
->name
, t2
->u
.knamed
->name
->name
) == 0
3401 && debug_type_samep (info
, t1
->u
.knamed
->type
,
3402 t2
->u
.knamed
->type
));
3406 info
->compare_list
= top
.next
;
3411 /* See if two classes are the same. This is a subroutine of
3412 debug_type_samep. */
3415 debug_class_type_samep (info
, t1
, t2
)
3416 struct debug_handle
*info
;
3417 struct debug_type
*t1
;
3418 struct debug_type
*t2
;
3420 struct debug_class_type
*c1
, *c2
;
3425 if ((c1
->fields
== NULL
) != (c2
->fields
== NULL
)
3426 || (c1
->baseclasses
== NULL
) != (c2
->baseclasses
== NULL
)
3427 || (c1
->methods
== NULL
) != (c2
->methods
== NULL
)
3428 || (c1
->vptrbase
== NULL
) != (c2
->vptrbase
== NULL
))
3431 if (c1
->fields
!= NULL
)
3433 struct debug_field
**pf1
, **pf2
;
3435 for (pf1
= c1
->fields
, pf2
= c2
->fields
;
3436 *pf1
!= NULL
&& *pf2
!= NULL
;
3439 struct debug_field
*f1
, *f2
;
3443 if (f1
->name
[0] != f2
->name
[0]
3444 || f1
->visibility
!= f2
->visibility
3445 || f1
->static_member
!= f2
->static_member
)
3447 if (f1
->static_member
)
3449 if (strcmp (f1
->u
.s
.physname
, f2
->u
.s
.physname
) != 0)
3454 if (f1
->u
.f
.bitpos
!= f2
->u
.f
.bitpos
3455 || f1
->u
.f
.bitsize
!= f2
->u
.f
.bitsize
)
3458 /* We do the checks which require function calls last. We
3459 don't require that the types of fields have the same
3460 names, since that sometimes fails in the presence of
3461 typedefs and we really don't care. */
3462 if (strcmp (f1
->name
, f2
->name
) != 0
3463 || ! debug_type_samep (info
,
3464 debug_get_real_type ((PTR
) info
,
3466 debug_get_real_type ((PTR
) info
,
3470 if (*pf1
!= NULL
|| *pf2
!= NULL
)
3474 if (c1
->vptrbase
!= NULL
)
3476 if (! debug_type_samep (info
, c1
->vptrbase
, c2
->vptrbase
))
3480 if (c1
->baseclasses
!= NULL
)
3482 struct debug_baseclass
**pb1
, **pb2
;
3484 for (pb1
= c1
->baseclasses
, pb2
= c2
->baseclasses
;
3485 *pb1
!= NULL
&& *pb2
!= NULL
;
3488 struct debug_baseclass
*b1
, *b2
;
3492 if (b1
->bitpos
!= b2
->bitpos
3493 || b1
->virtual != b2
->virtual
3494 || b1
->visibility
!= b2
->visibility
3495 || ! debug_type_samep (info
, b1
->type
, b2
->type
))
3498 if (*pb1
!= NULL
|| *pb2
!= NULL
)
3502 if (c1
->methods
!= NULL
)
3504 struct debug_method
**pm1
, **pm2
;
3506 for (pm1
= c1
->methods
, pm2
= c2
->methods
;
3507 *pm1
!= NULL
&& *pm2
!= NULL
;
3510 struct debug_method
*m1
, *m2
;
3514 if (m1
->name
[0] != m2
->name
[0]
3515 || strcmp (m1
->name
, m2
->name
) != 0
3516 || (m1
->variants
== NULL
) != (m2
->variants
== NULL
))
3518 if (m1
->variants
== NULL
)
3520 struct debug_method_variant
**pv1
, **pv2
;
3522 for (pv1
= m1
->variants
, pv2
= m2
->variants
;
3523 *pv1
!= NULL
&& *pv2
!= NULL
;
3526 struct debug_method_variant
*v1
, *v2
;
3530 if (v1
->physname
[0] != v2
->physname
[0]
3531 || v1
->visibility
!= v2
->visibility
3532 || v1
->constp
!= v2
->constp
3533 || v1
->volatilep
!= v2
->volatilep
3534 || v1
->voffset
!= v2
->voffset
3535 || (v1
->context
== NULL
) != (v2
->context
== NULL
)
3536 || strcmp (v1
->physname
, v2
->physname
) != 0
3537 || ! debug_type_samep (info
, v1
->type
, v2
->type
))
3539 if (v1
->context
!= NULL
)
3541 if (! debug_type_samep (info
, v1
->context
,
3546 if (*pv1
!= NULL
|| *pv2
!= NULL
)
3550 if (*pm1
!= NULL
|| *pm2
!= NULL
)