1 /* debug.c -- Handle generic debugging information.
2 Copyright 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file implements a generic debugging format. We may eventually
23 have readers which convert different formats into this generic
24 format, and writers which write it out. The initial impetus for
25 this was writing a convertor from stabs to HP IEEE-695 debugging
33 #include "libiberty.h"
36 /* Global information we keep for debugging. A pointer to this
37 structure is the debugging handle passed to all the routines. */
41 /* A linked list of compilation units. */
42 struct debug_unit
*units
;
43 /* The current compilation unit. */
44 struct debug_unit
*current_unit
;
45 /* The current source file. */
46 struct debug_file
*current_file
;
47 /* The current function. */
48 struct debug_function
*current_function
;
49 /* The current block. */
50 struct debug_block
*current_block
;
51 /* The current line number information for the current unit. */
52 struct debug_lineno
*current_lineno
;
53 /* Mark. This is used by debug_write. */
55 /* A struct/class ID used by debug_write. */
56 unsigned int class_id
;
57 /* The base for class_id for this call to debug_write. */
59 /* The current line number in debug_write. */
60 struct debug_lineno
*current_write_lineno
;
61 unsigned int current_write_lineno_index
;
62 /* A list of classes which have assigned ID's during debug_write.
63 This is linked through the next_id field of debug_class_type. */
64 struct debug_class_id
*id_list
;
65 /* A list used to avoid recursion during debug_type_samep. */
66 struct debug_type_compare_list
*compare_list
;
69 /* Information we keep for a single compilation unit. */
73 /* The next compilation unit. */
74 struct debug_unit
*next
;
75 /* A list of files included in this compilation unit. The first
76 file is always the main one, and that is where the main file name
78 struct debug_file
*files
;
79 /* Line number information for this compilation unit. This is not
80 stored by function, because assembler code may have line number
81 information without function information. */
82 struct debug_lineno
*linenos
;
85 /* Information kept for a single source file. */
89 /* The next source file in this compilation unit. */
90 struct debug_file
*next
;
91 /* The name of the source file. */
93 /* Global functions, variables, types, etc. */
94 struct debug_namespace
*globals
;
102 enum debug_type_kind kind
;
103 /* Size of type (0 if not known). */
105 /* Type which is a pointer to this type. */
107 /* Tagged union with additional information about the type. */
110 /* DEBUG_KIND_INDIRECT. */
111 struct debug_indirect_type
*kindirect
;
112 /* DEBUG_KIND_INT. */
113 /* Whether the integer is unsigned. */
115 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
116 DEBUG_KIND_UNION_CLASS. */
117 struct debug_class_type
*kclass
;
118 /* DEBUG_KIND_ENUM. */
119 struct debug_enum_type
*kenum
;
120 /* DEBUG_KIND_POINTER. */
121 struct debug_type
*kpointer
;
122 /* DEBUG_KIND_FUNCTION. */
123 struct debug_function_type
*kfunction
;
124 /* DEBUG_KIND_REFERENCE. */
125 struct debug_type
*kreference
;
126 /* DEBUG_KIND_RANGE. */
127 struct debug_range_type
*krange
;
128 /* DEBUG_KIND_ARRAY. */
129 struct debug_array_type
*karray
;
130 /* DEBUG_KIND_SET. */
131 struct debug_set_type
*kset
;
132 /* DEBUG_KIND_OFFSET. */
133 struct debug_offset_type
*koffset
;
134 /* DEBUG_KIND_METHOD. */
135 struct debug_method_type
*kmethod
;
136 /* DEBUG_KIND_CONST. */
137 struct debug_type
*kconst
;
138 /* DEBUG_KIND_VOLATILE. */
139 struct debug_type
*kvolatile
;
140 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
141 struct debug_named_type
*knamed
;
145 /* Information kept for an indirect type. */
147 struct debug_indirect_type
149 /* Slot where the final type will appear. */
155 /* Information kept for a struct, union, or class. */
157 struct debug_class_type
159 /* NULL terminated array of fields. */
161 /* A mark field which indicates whether the struct has already been
164 /* This is used to uniquely identify unnamed structs when printing. */
166 /* The remaining fields are only used for DEBUG_KIND_CLASS and
167 DEBUG_KIND_UNION_CLASS. */
168 /* NULL terminated array of base classes. */
169 debug_baseclass
*baseclasses
;
170 /* NULL terminated array of methods. */
171 debug_method
*methods
;
172 /* The type of the class providing the virtual function table for
173 this class. This may point to the type itself. */
177 /* Information kept for an enum. */
179 struct debug_enum_type
181 /* NULL terminated array of names. */
183 /* Array of corresponding values. */
184 bfd_signed_vma
*values
;
187 /* Information kept for a function. FIXME: We should be able to
188 record the parameter types. */
190 struct debug_function_type
193 debug_type return_type
;
194 /* NULL terminated array of argument types. */
195 debug_type
*arg_types
;
196 /* Whether the function takes a variable number of arguments. */
200 /* Information kept for a range. */
202 struct debug_range_type
204 /* Range base type. */
207 bfd_signed_vma lower
;
209 bfd_signed_vma upper
;
212 /* Information kept for an array. */
214 struct debug_array_type
217 debug_type element_type
;
219 debug_type range_type
;
221 bfd_signed_vma lower
;
223 bfd_signed_vma upper
;
224 /* Whether this array is really a string. */
228 /* Information kept for a set. */
230 struct debug_set_type
234 /* Whether this set is really a bitstring. */
238 /* Information kept for an offset type (a based pointer). */
240 struct debug_offset_type
242 /* The type the pointer is an offset from. */
243 debug_type base_type
;
244 /* The type the pointer points to. */
245 debug_type target_type
;
248 /* Information kept for a method type. */
250 struct debug_method_type
252 /* The return type. */
253 debug_type return_type
;
254 /* The object type which this method is for. */
255 debug_type domain_type
;
256 /* A NULL terminated array of argument types. */
257 debug_type
*arg_types
;
258 /* Whether the method takes a variable number of arguments. */
262 /* Information kept for a named type. */
264 struct debug_named_type
267 struct debug_name
*name
;
272 /* A field in a struct or union. */
276 /* Name of the field. */
278 /* Type of the field. */
279 struct debug_type
*type
;
280 /* Visibility of the field. */
281 enum debug_visibility visibility
;
282 /* Whether this is a static member. */
283 boolean static_member
;
286 /* If static_member is false. */
289 /* Bit position of the field in the struct. */
291 /* Size of the field in bits. */
292 unsigned int bitsize
;
294 /* If static_member is true. */
297 const char *physname
;
302 /* A base class for an object. */
304 struct debug_baseclass
306 /* Type of the base class. */
307 struct debug_type
*type
;
308 /* Bit position of the base class in the object. */
310 /* Whether the base class is virtual. */
312 /* Visibility of the base class. */
313 enum debug_visibility visibility
;
316 /* A method of an object. */
320 /* The name of the method. */
322 /* A NULL terminated array of different types of variants. */
323 struct debug_method_variant
**variants
;
326 /* The variants of a method function of an object. These indicate
327 which method to run. */
329 struct debug_method_variant
331 /* The physical name of the function. */
332 const char *physname
;
333 /* The type of the function. */
334 struct debug_type
*type
;
335 /* The visibility of the function. */
336 enum debug_visibility visibility
;
337 /* Whether the function is const. */
339 /* Whether the function is volatile. */
341 /* The offset to the function in the virtual function table. */
343 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
344 #define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
345 /* Context of a virtual method function. */
346 struct debug_type
*context
;
349 /* A variable. This is the information we keep for a variable object.
350 This has no name; a name is associated with a variable in a
351 debug_name structure. */
353 struct debug_variable
355 /* Kind of variable. */
356 enum debug_var_kind kind
;
359 /* Value. The interpretation of the value depends upon kind. */
363 /* A function. This has no name; a name is associated with a function
364 in a debug_name structure. */
366 struct debug_function
369 debug_type return_type
;
370 /* Parameter information. */
371 struct debug_parameter
*parameters
;
372 /* Block information. The first structure on the list is the main
373 block of the function, and describes function local variables. */
374 struct debug_block
*blocks
;
377 /* A function parameter. */
379 struct debug_parameter
381 /* Next parameter. */
382 struct debug_parameter
*next
;
388 enum debug_parm_kind kind
;
389 /* Value (meaning depends upon kind). */
393 /* A typed constant. */
395 struct debug_typed_constant
399 /* Value. FIXME: We may eventually need to support non-integral
404 /* Information about a block within a function. */
408 /* Next block with the same parent. */
409 struct debug_block
*next
;
411 struct debug_block
*parent
;
412 /* List of child blocks. */
413 struct debug_block
*children
;
414 /* Start address of the block. */
416 /* End address of the block. */
418 /* Local variables. */
419 struct debug_namespace
*locals
;
422 /* Line number information we keep for a compilation unit. FIXME:
423 This structure is easy to create, but can be very space
428 /* More line number information for this block. */
429 struct debug_lineno
*next
;
431 struct debug_file
*file
;
432 /* Line numbers, terminated by a -1 or the end of the array. */
433 #define DEBUG_LINENO_COUNT 10
434 unsigned long linenos
[DEBUG_LINENO_COUNT
];
435 /* Addresses for the line numbers. */
436 bfd_vma addrs
[DEBUG_LINENO_COUNT
];
439 /* A namespace. This is a mapping from names to objects. FIXME: This
440 should be implemented as a hash table. */
442 struct debug_namespace
444 /* List of items in this namespace. */
445 struct debug_name
*list
;
446 /* Pointer to where the next item in this namespace should go. */
447 struct debug_name
**tail
;
450 /* Kinds of objects that appear in a namespace. */
452 enum debug_object_kind
456 /* A tagged type (really a different sort of namespace). */
459 DEBUG_OBJECT_VARIABLE
,
461 DEBUG_OBJECT_FUNCTION
,
462 /* An integer constant. */
463 DEBUG_OBJECT_INT_CONSTANT
,
464 /* A floating point constant. */
465 DEBUG_OBJECT_FLOAT_CONSTANT
,
466 /* A typed constant. */
467 DEBUG_OBJECT_TYPED_CONSTANT
470 /* Linkage of an object that appears in a namespace. */
472 enum debug_object_linkage
474 /* Local variable. */
475 DEBUG_LINKAGE_AUTOMATIC
,
476 /* Static--either file static or function static, depending upon the
478 DEBUG_LINKAGE_STATIC
,
480 DEBUG_LINKAGE_GLOBAL
,
485 /* A name in a namespace. */
489 /* Next name in this namespace. */
490 struct debug_name
*next
;
493 /* Mark. This is used by debug_write. */
495 /* Kind of object. */
496 enum debug_object_kind kind
;
497 /* Linkage of object. */
498 enum debug_object_linkage linkage
;
499 /* Tagged union with additional information about the object. */
502 /* DEBUG_OBJECT_TYPE. */
503 struct debug_type
*type
;
504 /* DEBUG_OBJECT_TAG. */
505 struct debug_type
*tag
;
506 /* DEBUG_OBJECT_VARIABLE. */
507 struct debug_variable
*variable
;
508 /* DEBUG_OBJECT_FUNCTION. */
509 struct debug_function
*function
;
510 /* DEBUG_OBJECT_INT_CONSTANT. */
511 bfd_vma int_constant
;
512 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
513 double float_constant
;
514 /* DEBUG_OBJECT_TYPED_CONSTANT. */
515 struct debug_typed_constant
*typed_constant
;
519 /* During debug_write, a linked list of these structures is used to
520 keep track of ID numbers that have been assigned to classes. */
522 struct debug_class_id
524 /* Next ID number. */
525 struct debug_class_id
*next
;
526 /* The type with the ID. */
527 struct debug_type
*type
;
528 /* The tag; NULL if no tag. */
532 /* During debug_type_samep, a linked list of these structures is kept
533 on the stack to avoid infinite recursion. */
535 struct debug_type_compare_list
537 /* Next type on list. */
538 struct debug_type_compare_list
*next
;
539 /* The types we are comparing. */
540 struct debug_type
*t1
;
541 struct debug_type
*t2
;
544 /* 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
PARAMS ((const char *));
558 static struct debug_name
*debug_add_to_namespace
559 PARAMS ((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 PARAMS ((struct debug_handle
*, const char *, enum debug_object_kind
,
563 enum debug_object_linkage
));
564 static struct debug_type
*debug_make_type
565 PARAMS ((struct debug_handle
*, enum debug_type_kind
, unsigned int));
566 static struct debug_type
*debug_get_real_type
567 PARAMS ((PTR
, debug_type
, struct debug_type_real_list
*));
568 static boolean debug_write_name
569 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
570 struct debug_name
*));
571 static boolean debug_write_type
572 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
573 struct debug_type
*, struct debug_name
*));
574 static boolean debug_write_class_type
575 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
576 struct debug_type
*, const char *));
577 static boolean debug_write_function
578 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
579 const char *, enum debug_object_linkage
, struct debug_function
*));
580 static boolean debug_write_block
581 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
582 struct debug_block
*));
583 static boolean debug_write_linenos
584 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
586 static boolean debug_set_class_id
587 PARAMS ((struct debug_handle
*, const char *, struct debug_type
*));
588 static boolean debug_type_samep
589 PARAMS ((struct debug_handle
*, struct debug_type
*, struct debug_type
*));
590 static boolean debug_class_type_samep
591 PARAMS ((struct debug_handle
*, struct debug_type
*, struct debug_type
*));
593 /* Issue an error message. */
596 debug_error (message
)
599 fprintf (stderr
, "%s\n", message
);
602 /* Add an object to a namespace. */
604 static struct debug_name
*
605 debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
)
606 struct debug_handle
*info ATTRIBUTE_UNUSED
;
607 struct debug_namespace
**nsp
;
609 enum debug_object_kind kind
;
610 enum debug_object_linkage linkage
;
612 struct debug_name
*n
;
613 struct debug_namespace
*ns
;
615 n
= (struct debug_name
*) xmalloc (sizeof *n
);
616 memset (n
, 0, sizeof *n
);
620 n
->linkage
= linkage
;
625 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
626 memset (ns
, 0, sizeof *ns
);
628 ns
->tail
= &ns
->list
;
639 /* Add an object to the current namespace. */
641 static struct debug_name
*
642 debug_add_to_current_namespace (info
, name
, kind
, linkage
)
643 struct debug_handle
*info
;
645 enum debug_object_kind kind
;
646 enum debug_object_linkage linkage
;
648 struct debug_namespace
**nsp
;
650 if (info
->current_unit
== NULL
651 || info
->current_file
== NULL
)
653 debug_error (_("debug_add_to_current_namespace: no current file"));
657 if (info
->current_block
!= NULL
)
658 nsp
= &info
->current_block
->locals
;
660 nsp
= &info
->current_file
->globals
;
662 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
665 /* Return a handle for debugging information. */
670 struct debug_handle
*ret
;
672 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
673 memset (ret
, 0, sizeof *ret
);
677 /* Set the source filename. This implicitly starts a new compilation
681 debug_set_filename (handle
, name
)
685 struct debug_handle
*info
= (struct debug_handle
*) handle
;
686 struct debug_file
*nfile
;
687 struct debug_unit
*nunit
;
692 nfile
= (struct debug_file
*) xmalloc (sizeof *nfile
);
693 memset (nfile
, 0, sizeof *nfile
);
695 nfile
->filename
= name
;
697 nunit
= (struct debug_unit
*) xmalloc (sizeof *nunit
);
698 memset (nunit
, 0, sizeof *nunit
);
700 nunit
->files
= nfile
;
701 info
->current_file
= nfile
;
703 if (info
->current_unit
!= NULL
)
704 info
->current_unit
->next
= nunit
;
707 assert (info
->units
== NULL
);
711 info
->current_unit
= nunit
;
713 info
->current_function
= NULL
;
714 info
->current_block
= NULL
;
715 info
->current_lineno
= NULL
;
720 /* Change source files to the given file name. This is used for
721 include files in a single compilation unit. */
724 debug_start_source (handle
, name
)
728 struct debug_handle
*info
= (struct debug_handle
*) handle
;
729 struct debug_file
*f
, **pf
;
734 if (info
->current_unit
== NULL
)
736 debug_error (_("debug_start_source: no debug_set_filename call"));
740 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
742 if (f
->filename
[0] == name
[0]
743 && f
->filename
[1] == name
[1]
744 && strcmp (f
->filename
, name
) == 0)
746 info
->current_file
= f
;
751 f
= (struct debug_file
*) xmalloc (sizeof *f
);
752 memset (f
, 0, sizeof *f
);
756 for (pf
= &info
->current_file
->next
;
762 info
->current_file
= f
;
767 /* Record a function definition. This implicitly starts a function
768 block. The debug_type argument is the type of the return value.
769 The boolean indicates whether the function is globally visible.
770 The bfd_vma is the address of the start of the function. Currently
771 the parameter types are specified by calls to
772 debug_record_parameter. FIXME: There is no way to specify nested
776 debug_record_function (handle
, name
, return_type
, global
, addr
)
779 debug_type return_type
;
783 struct debug_handle
*info
= (struct debug_handle
*) handle
;
784 struct debug_function
*f
;
785 struct debug_block
*b
;
786 struct debug_name
*n
;
790 if (return_type
== NULL
)
793 if (info
->current_unit
== NULL
)
795 debug_error (_("debug_record_function: no debug_set_filename call"));
799 f
= (struct debug_function
*) xmalloc (sizeof *f
);
800 memset (f
, 0, sizeof *f
);
802 f
->return_type
= return_type
;
804 b
= (struct debug_block
*) xmalloc (sizeof *b
);
805 memset (b
, 0, sizeof *b
);
808 b
->end
= (bfd_vma
) -1;
812 info
->current_function
= f
;
813 info
->current_block
= b
;
815 /* FIXME: If we could handle nested functions, this would be the
816 place: we would want to use a different namespace. */
817 n
= debug_add_to_namespace (info
,
818 &info
->current_file
->globals
,
820 DEBUG_OBJECT_FUNCTION
,
822 ? DEBUG_LINKAGE_GLOBAL
823 : DEBUG_LINKAGE_STATIC
));
832 /* Record a parameter for the current function. */
835 debug_record_parameter (handle
, name
, type
, kind
, val
)
839 enum debug_parm_kind kind
;
842 struct debug_handle
*info
= (struct debug_handle
*) handle
;
843 struct debug_parameter
*p
, **pp
;
845 if (name
== NULL
|| type
== NULL
)
848 if (info
->current_unit
== NULL
849 || info
->current_function
== NULL
)
851 debug_error (_("debug_record_parameter: no current function"));
855 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
856 memset (p
, 0, sizeof *p
);
863 for (pp
= &info
->current_function
->parameters
;
872 /* End a function. FIXME: This should handle function nesting. */
875 debug_end_function (handle
, addr
)
879 struct debug_handle
*info
= (struct debug_handle
*) handle
;
881 if (info
->current_unit
== NULL
882 || info
->current_block
== NULL
883 || info
->current_function
== NULL
)
885 debug_error (_("debug_end_function: no current function"));
889 if (info
->current_block
->parent
!= NULL
)
891 debug_error (_("debug_end_function: some blocks were not closed"));
895 info
->current_block
->end
= addr
;
897 info
->current_function
= NULL
;
898 info
->current_block
= NULL
;
903 /* Start a block in a function. All local information will be
904 recorded in this block, until the matching call to debug_end_block.
905 debug_start_block and debug_end_block may be nested. The bfd_vma
906 argument is the address at which this block starts. */
909 debug_start_block (handle
, addr
)
913 struct debug_handle
*info
= (struct debug_handle
*) handle
;
914 struct debug_block
*b
, **pb
;
916 /* We must always have a current block: debug_record_function sets
918 if (info
->current_unit
== NULL
919 || info
->current_block
== NULL
)
921 debug_error (_("debug_start_block: no current block"));
925 b
= (struct debug_block
*) xmalloc (sizeof *b
);
926 memset (b
, 0, sizeof *b
);
928 b
->parent
= info
->current_block
;
930 b
->end
= (bfd_vma
) -1;
932 /* This new block is a child of the current block. */
933 for (pb
= &info
->current_block
->children
;
939 info
->current_block
= b
;
944 /* Finish a block in a function. This matches the call to
945 debug_start_block. The argument is the address at which this block
949 debug_end_block (handle
, addr
)
953 struct debug_handle
*info
= (struct debug_handle
*) handle
;
954 struct debug_block
*parent
;
956 if (info
->current_unit
== NULL
957 || info
->current_block
== NULL
)
959 debug_error (_("debug_end_block: no current block"));
963 parent
= info
->current_block
->parent
;
966 debug_error (_("debug_end_block: attempt to close top level block"));
970 info
->current_block
->end
= addr
;
972 info
->current_block
= parent
;
977 /* Associate a line number in the current source file and function
978 with a given address. */
981 debug_record_line (handle
, lineno
, addr
)
983 unsigned long lineno
;
986 struct debug_handle
*info
= (struct debug_handle
*) handle
;
987 struct debug_lineno
*l
;
990 if (info
->current_unit
== NULL
)
992 debug_error (_("debug_record_line: no current unit"));
996 l
= info
->current_lineno
;
997 if (l
!= NULL
&& l
->file
== info
->current_file
)
999 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
1001 if (l
->linenos
[i
] == (unsigned long) -1)
1003 l
->linenos
[i
] = lineno
;
1010 /* If we get here, then either 1) there is no current_lineno
1011 structure, which means this is the first line number in this
1012 compilation unit, 2) the current_lineno structure is for a
1013 different file, or 3) the current_lineno structure is full.
1014 Regardless, we want to allocate a new debug_lineno structure, put
1015 it in the right place, and make it the new current_lineno
1018 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
1019 memset (l
, 0, sizeof *l
);
1021 l
->file
= info
->current_file
;
1022 l
->linenos
[0] = lineno
;
1024 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
1025 l
->linenos
[i
] = (unsigned long) -1;
1027 if (info
->current_lineno
!= NULL
)
1028 info
->current_lineno
->next
= l
;
1030 info
->current_unit
->linenos
= l
;
1032 info
->current_lineno
= l
;
1037 /* Start a named common block. This is a block of variables that may
1041 debug_start_common_block (handle
, name
)
1042 PTR handle ATTRIBUTE_UNUSED
;
1043 const char *name ATTRIBUTE_UNUSED
;
1046 debug_error (_("debug_start_common_block: not implemented"));
1050 /* End a named common block. */
1053 debug_end_common_block (handle
, name
)
1054 PTR handle ATTRIBUTE_UNUSED
;
1055 const char *name ATTRIBUTE_UNUSED
;
1058 debug_error (_("debug_end_common_block: not implemented"));
1062 /* Record a named integer constant. */
1065 debug_record_int_const (handle
, name
, val
)
1070 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1071 struct debug_name
*n
;
1076 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1077 DEBUG_LINKAGE_NONE
);
1081 n
->u
.int_constant
= val
;
1086 /* Record a named floating point constant. */
1089 debug_record_float_const (handle
, name
, val
)
1094 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1095 struct debug_name
*n
;
1100 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1101 DEBUG_LINKAGE_NONE
);
1105 n
->u
.float_constant
= val
;
1110 /* Record a typed constant with an integral value. */
1113 debug_record_typed_const (handle
, name
, type
, val
)
1119 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1120 struct debug_name
*n
;
1121 struct debug_typed_constant
*tc
;
1123 if (name
== NULL
|| type
== NULL
)
1126 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1127 DEBUG_LINKAGE_NONE
);
1131 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1132 memset (tc
, 0, sizeof *tc
);
1137 n
->u
.typed_constant
= tc
;
1142 /* Record a label. */
1145 debug_record_label (handle
, name
, type
, addr
)
1146 PTR handle ATTRIBUTE_UNUSED
;
1147 const char *name ATTRIBUTE_UNUSED
;
1148 debug_type type ATTRIBUTE_UNUSED
;
1149 bfd_vma addr ATTRIBUTE_UNUSED
;
1152 debug_error (_("debug_record_label not implemented"));
1156 /* Record a variable. */
1159 debug_record_variable (handle
, name
, type
, kind
, val
)
1163 enum debug_var_kind kind
;
1166 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1167 struct debug_namespace
**nsp
;
1168 enum debug_object_linkage linkage
;
1169 struct debug_name
*n
;
1170 struct debug_variable
*v
;
1172 if (name
== NULL
|| type
== NULL
)
1175 if (info
->current_unit
== NULL
1176 || info
->current_file
== NULL
)
1178 debug_error (_("debug_record_variable: no current file"));
1182 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1184 nsp
= &info
->current_file
->globals
;
1185 if (kind
== DEBUG_GLOBAL
)
1186 linkage
= DEBUG_LINKAGE_GLOBAL
;
1188 linkage
= DEBUG_LINKAGE_STATIC
;
1192 if (info
->current_block
== NULL
)
1194 debug_error (_("debug_record_variable: no current block"));
1197 nsp
= &info
->current_block
->locals
;
1198 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1201 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1205 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1206 memset (v
, 0, sizeof *v
);
1217 /* Make a type with a given kind and size. */
1220 static struct debug_type
*
1221 debug_make_type (info
, kind
, size
)
1222 struct debug_handle
*info ATTRIBUTE_UNUSED
;
1223 enum debug_type_kind kind
;
1226 struct debug_type
*t
;
1228 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1229 memset (t
, 0, sizeof *t
);
1237 /* Make an indirect type which may be used as a placeholder for a type
1238 which is referenced before it is defined. */
1241 debug_make_indirect_type (handle
, slot
, tag
)
1246 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1247 struct debug_type
*t
;
1248 struct debug_indirect_type
*i
;
1250 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1252 return DEBUG_TYPE_NULL
;
1254 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1255 memset (i
, 0, sizeof *i
);
1265 /* Make a void type. There is only one of these. */
1268 debug_make_void_type (handle
)
1271 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1273 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1276 /* Make an integer type of a given size. The boolean argument is true
1277 if the integer is unsigned. */
1280 debug_make_int_type (handle
, size
, unsignedp
)
1285 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1286 struct debug_type
*t
;
1288 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1290 return DEBUG_TYPE_NULL
;
1292 t
->u
.kint
= unsignedp
;
1297 /* Make a floating point type of a given size. FIXME: On some
1298 platforms, like an Alpha, you probably need to be able to specify
1302 debug_make_float_type (handle
, size
)
1306 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1308 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1311 /* Make a boolean type of a given size. */
1314 debug_make_bool_type (handle
, size
)
1318 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1320 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1323 /* Make a complex type of a given size. */
1326 debug_make_complex_type (handle
, size
)
1330 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1332 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1335 /* Make a structure type. The second argument is true for a struct,
1336 false for a union. The third argument is the size of the struct.
1337 The fourth argument is a NULL terminated array of fields. */
1340 debug_make_struct_type (handle
, structp
, size
, fields
)
1344 debug_field
*fields
;
1346 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1347 struct debug_type
*t
;
1348 struct debug_class_type
*c
;
1350 t
= debug_make_type (info
,
1351 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1354 return DEBUG_TYPE_NULL
;
1356 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1357 memset (c
, 0, sizeof *c
);
1366 /* Make an object type. The first three arguments after the handle
1367 are the same as for debug_make_struct_type. The next arguments are
1368 a NULL terminated array of base classes, a NULL terminated array of
1369 methods, the type of the object holding the virtual function table
1370 if it is not this object, and a boolean which is true if this
1371 object has its own virtual function table. */
1374 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1375 methods
, vptrbase
, ownvptr
)
1379 debug_field
*fields
;
1380 debug_baseclass
*baseclasses
;
1381 debug_method
*methods
;
1382 debug_type vptrbase
;
1385 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1386 struct debug_type
*t
;
1387 struct debug_class_type
*c
;
1389 t
= debug_make_type (info
,
1390 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1393 return DEBUG_TYPE_NULL
;
1395 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1396 memset (c
, 0, sizeof *c
);
1399 c
->baseclasses
= baseclasses
;
1400 c
->methods
= methods
;
1404 c
->vptrbase
= vptrbase
;
1411 /* Make an enumeration type. The arguments are a null terminated
1412 array of strings, and an array of corresponding values. */
1415 debug_make_enum_type (handle
, names
, values
)
1418 bfd_signed_vma
*values
;
1420 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1421 struct debug_type
*t
;
1422 struct debug_enum_type
*e
;
1424 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1426 return DEBUG_TYPE_NULL
;
1428 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1429 memset (e
, 0, sizeof *e
);
1439 /* Make a pointer to a given type. */
1442 debug_make_pointer_type (handle
, type
)
1446 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1447 struct debug_type
*t
;
1450 return DEBUG_TYPE_NULL
;
1452 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1453 return type
->pointer
;
1455 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1457 return DEBUG_TYPE_NULL
;
1459 t
->u
.kpointer
= type
;
1466 /* Make a function returning a given type. FIXME: We should be able
1467 to record the parameter types. */
1470 debug_make_function_type (handle
, type
, arg_types
, varargs
)
1473 debug_type
*arg_types
;
1476 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1477 struct debug_type
*t
;
1478 struct debug_function_type
*f
;
1481 return DEBUG_TYPE_NULL
;
1483 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1485 return DEBUG_TYPE_NULL
;
1487 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1488 memset (f
, 0, sizeof *f
);
1490 f
->return_type
= type
;
1491 f
->arg_types
= arg_types
;
1492 f
->varargs
= varargs
;
1499 /* Make a reference to a given type. */
1502 debug_make_reference_type (handle
, type
)
1506 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1507 struct debug_type
*t
;
1510 return DEBUG_TYPE_NULL
;
1512 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1514 return DEBUG_TYPE_NULL
;
1516 t
->u
.kreference
= type
;
1521 /* Make a range of a given type from a lower to an upper bound. */
1524 debug_make_range_type (handle
, type
, lower
, upper
)
1527 bfd_signed_vma lower
;
1528 bfd_signed_vma upper
;
1530 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1531 struct debug_type
*t
;
1532 struct debug_range_type
*r
;
1535 return DEBUG_TYPE_NULL
;
1537 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1539 return DEBUG_TYPE_NULL
;
1541 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1542 memset (r
, 0, sizeof *r
);
1553 /* Make an array type. The second argument is the type of an element
1554 of the array. The third argument is the type of a range of the
1555 array. The fourth and fifth argument are the lower and upper
1556 bounds, respectively. The sixth argument is true if this array is
1557 actually a string, as in C. */
1560 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1563 debug_type element_type
;
1564 debug_type range_type
;
1565 bfd_signed_vma lower
;
1566 bfd_signed_vma upper
;
1569 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1570 struct debug_type
*t
;
1571 struct debug_array_type
*a
;
1573 if (element_type
== NULL
|| range_type
== NULL
)
1574 return DEBUG_TYPE_NULL
;
1576 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1578 return DEBUG_TYPE_NULL
;
1580 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1581 memset (a
, 0, sizeof *a
);
1583 a
->element_type
= element_type
;
1584 a
->range_type
= range_type
;
1587 a
->stringp
= stringp
;
1594 /* Make a set of a given type. For example, a Pascal set type. The
1595 boolean argument is true if this set is actually a bitstring, as in
1599 debug_make_set_type (handle
, type
, bitstringp
)
1604 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1605 struct debug_type
*t
;
1606 struct debug_set_type
*s
;
1609 return DEBUG_TYPE_NULL
;
1611 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1613 return DEBUG_TYPE_NULL
;
1615 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1616 memset (s
, 0, sizeof *s
);
1619 s
->bitstringp
= bitstringp
;
1626 /* Make a type for a pointer which is relative to an object. The
1627 second argument is the type of the object to which the pointer is
1628 relative. The third argument is the type that the pointer points
1632 debug_make_offset_type (handle
, base_type
, target_type
)
1634 debug_type base_type
;
1635 debug_type target_type
;
1637 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1638 struct debug_type
*t
;
1639 struct debug_offset_type
*o
;
1641 if (base_type
== NULL
|| target_type
== NULL
)
1642 return DEBUG_TYPE_NULL
;
1644 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1646 return DEBUG_TYPE_NULL
;
1648 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1649 memset (o
, 0, sizeof *o
);
1651 o
->base_type
= base_type
;
1652 o
->target_type
= target_type
;
1659 /* Make a type for a method function. The second argument is the
1660 return type, the third argument is the domain, and the fourth
1661 argument is a NULL terminated array of argument types. */
1664 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
, varargs
)
1666 debug_type return_type
;
1667 debug_type domain_type
;
1668 debug_type
*arg_types
;
1671 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1672 struct debug_type
*t
;
1673 struct debug_method_type
*m
;
1675 if (return_type
== NULL
)
1676 return DEBUG_TYPE_NULL
;
1678 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1680 return DEBUG_TYPE_NULL
;
1682 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1683 memset (m
, 0, sizeof *m
);
1685 m
->return_type
= return_type
;
1686 m
->domain_type
= domain_type
;
1687 m
->arg_types
= arg_types
;
1688 m
->varargs
= varargs
;
1695 /* Make a const qualified version of a given type. */
1698 debug_make_const_type (handle
, type
)
1702 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1703 struct debug_type
*t
;
1706 return DEBUG_TYPE_NULL
;
1708 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1710 return DEBUG_TYPE_NULL
;
1717 /* Make a volatile qualified version of a given type. */
1720 debug_make_volatile_type (handle
, type
)
1724 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1725 struct debug_type
*t
;
1728 return DEBUG_TYPE_NULL
;
1730 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1732 return DEBUG_TYPE_NULL
;
1734 t
->u
.kvolatile
= type
;
1739 /* Make an undefined tagged type. For example, a struct which has
1740 been mentioned, but not defined. */
1743 debug_make_undefined_tagged_type (handle
, name
, kind
)
1746 enum debug_type_kind kind
;
1748 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1749 struct debug_type
*t
;
1752 return DEBUG_TYPE_NULL
;
1756 case DEBUG_KIND_STRUCT
:
1757 case DEBUG_KIND_UNION
:
1758 case DEBUG_KIND_CLASS
:
1759 case DEBUG_KIND_UNION_CLASS
:
1760 case DEBUG_KIND_ENUM
:
1764 debug_error (_("debug_make_undefined_type: unsupported kind"));
1765 return DEBUG_TYPE_NULL
;
1768 t
= debug_make_type (info
, kind
, 0);
1770 return DEBUG_TYPE_NULL
;
1772 return debug_tag_type (handle
, name
, t
);
1775 /* Make a base class for an object. The second argument is the base
1776 class type. The third argument is the bit position of this base
1777 class in the object (always 0 unless doing multiple inheritance).
1778 The fourth argument is whether this is a virtual class. The fifth
1779 argument is the visibility of the base class. */
1783 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1784 PTR handle ATTRIBUTE_UNUSED
;
1788 enum debug_visibility visibility
;
1790 struct debug_baseclass
*b
;
1792 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1793 memset (b
, 0, sizeof *b
);
1797 b
->virtual = virtual;
1798 b
->visibility
= visibility
;
1803 /* Make a field for a struct. The second argument is the name. The
1804 third argument is the type of the field. The fourth argument is
1805 the bit position of the field. The fifth argument is the size of
1806 the field (it may be zero). The sixth argument is the visibility
1811 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1812 PTR handle ATTRIBUTE_UNUSED
;
1817 enum debug_visibility visibility
;
1819 struct debug_field
*f
;
1821 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1822 memset (f
, 0, sizeof *f
);
1826 f
->static_member
= false;
1827 f
->u
.f
.bitpos
= bitpos
;
1828 f
->u
.f
.bitsize
= bitsize
;
1829 f
->visibility
= visibility
;
1834 /* Make a static member of an object. The second argument is the
1835 name. The third argument is the type of the member. The fourth
1836 argument is the physical name of the member (i.e., the name as a
1837 global variable). The fifth argument is the visibility of the
1842 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1843 PTR handle ATTRIBUTE_UNUSED
;
1846 const char *physname
;
1847 enum debug_visibility visibility
;
1849 struct debug_field
*f
;
1851 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1852 memset (f
, 0, sizeof *f
);
1856 f
->static_member
= true;
1857 f
->u
.s
.physname
= physname
;
1858 f
->visibility
= visibility
;
1863 /* Make a method. The second argument is the name, and the third
1864 argument is a NULL terminated array of method variants. */
1868 debug_make_method (handle
, name
, variants
)
1869 PTR handle ATTRIBUTE_UNUSED
;
1871 debug_method_variant
*variants
;
1873 struct debug_method
*m
;
1875 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1876 memset (m
, 0, sizeof *m
);
1879 m
->variants
= variants
;
1884 /* Make a method argument. The second argument is the real name of
1885 the function. The third argument is the type of the function. The
1886 fourth argument is the visibility. The fifth argument is whether
1887 this is a const function. The sixth argument is whether this is a
1888 volatile function. The seventh argument is the offset in the
1889 virtual function table, if any. The eighth argument is the virtual
1890 function context. FIXME: Are the const and volatile arguments
1891 necessary? Could we just use debug_make_const_type? */
1894 debug_method_variant
1895 debug_make_method_variant (handle
, physname
, type
, visibility
, constp
,
1896 volatilep
, voffset
, context
)
1897 PTR handle ATTRIBUTE_UNUSED
;
1898 const char *physname
;
1900 enum debug_visibility visibility
;
1906 struct debug_method_variant
*m
;
1908 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1909 memset (m
, 0, sizeof *m
);
1911 m
->physname
= physname
;
1913 m
->visibility
= visibility
;
1915 m
->volatilep
= volatilep
;
1916 m
->voffset
= voffset
;
1917 m
->context
= context
;
1922 /* Make a static method argument. The arguments are the same as for
1923 debug_make_method_variant, except that the last two are omitted
1924 since a static method can not also be virtual. */
1926 debug_method_variant
1927 debug_make_static_method_variant (handle
, physname
, type
, visibility
,
1929 PTR handle ATTRIBUTE_UNUSED
;
1930 const char *physname
;
1932 enum debug_visibility visibility
;
1936 struct debug_method_variant
*m
;
1938 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1939 memset (m
, 0, sizeof *m
);
1941 m
->physname
= physname
;
1943 m
->visibility
= visibility
;
1945 m
->volatilep
= volatilep
;
1946 m
->voffset
= VOFFSET_STATIC_METHOD
;
1954 debug_name_type (handle
, name
, type
)
1959 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1960 struct debug_type
*t
;
1961 struct debug_named_type
*n
;
1962 struct debug_name
*nm
;
1964 if (name
== NULL
|| type
== NULL
)
1965 return DEBUG_TYPE_NULL
;
1967 if (info
->current_unit
== NULL
1968 || info
->current_file
== NULL
)
1970 debug_error (_("debug_name_type: no current file"));
1971 return DEBUG_TYPE_NULL
;
1974 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1976 return DEBUG_TYPE_NULL
;
1978 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1979 memset (n
, 0, sizeof *n
);
1985 /* We always add the name to the global namespace. This is probably
1986 wrong in some cases, but it seems to be right for stabs. FIXME. */
1988 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1989 DEBUG_OBJECT_TYPE
, DEBUG_LINKAGE_NONE
);
1991 return DEBUG_TYPE_NULL
;
2003 debug_tag_type (handle
, name
, type
)
2008 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2009 struct debug_type
*t
;
2010 struct debug_named_type
*n
;
2011 struct debug_name
*nm
;
2013 if (name
== NULL
|| type
== NULL
)
2014 return DEBUG_TYPE_NULL
;
2016 if (info
->current_file
== NULL
)
2018 debug_error (_("debug_tag_type: no current file"));
2019 return DEBUG_TYPE_NULL
;
2022 if (type
->kind
== DEBUG_KIND_TAGGED
)
2024 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
2026 debug_error (_("debug_tag_type: extra tag attempted"));
2027 return DEBUG_TYPE_NULL
;
2030 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
2032 return DEBUG_TYPE_NULL
;
2034 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
2035 memset (n
, 0, sizeof *n
);
2041 /* We keep a global namespace of tags for each compilation unit. I
2042 don't know if that is the right thing to do. */
2044 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
2045 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2047 return DEBUG_TYPE_NULL
;
2056 /* Record the size of a given type. */
2060 debug_record_type_size (handle
, type
, size
)
2061 PTR handle ATTRIBUTE_UNUSED
;
2065 if (type
->size
!= 0 && type
->size
!= size
)
2066 fprintf (stderr
, _("Warning: changing type size from %d to %d\n"),
2074 /* Find a named type. */
2077 debug_find_named_type (handle
, name
)
2081 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2082 struct debug_block
*b
;
2083 struct debug_file
*f
;
2085 /* We only search the current compilation unit. I don't know if
2086 this is right or not. */
2088 if (info
->current_unit
== NULL
)
2090 debug_error (_("debug_find_named_type: no current compilation unit"));
2091 return DEBUG_TYPE_NULL
;
2094 for (b
= info
->current_block
; b
!= NULL
; b
= b
->parent
)
2096 if (b
->locals
!= NULL
)
2098 struct debug_name
*n
;
2100 for (n
= b
->locals
->list
; n
!= NULL
; n
= n
->next
)
2102 if (n
->kind
== DEBUG_OBJECT_TYPE
2103 && n
->name
[0] == name
[0]
2104 && strcmp (n
->name
, name
) == 0)
2110 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
2112 if (f
->globals
!= NULL
)
2114 struct debug_name
*n
;
2116 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2118 if (n
->kind
== DEBUG_OBJECT_TYPE
2119 && n
->name
[0] == name
[0]
2120 && strcmp (n
->name
, name
) == 0)
2126 return DEBUG_TYPE_NULL
;
2129 /* Find a tagged type. */
2132 debug_find_tagged_type (handle
, name
, kind
)
2135 enum debug_type_kind kind
;
2137 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2138 struct debug_unit
*u
;
2140 /* We search the globals of all the compilation units. I don't know
2141 if this is correct or not. It would be easy to change. */
2143 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2145 struct debug_file
*f
;
2147 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2149 struct debug_name
*n
;
2151 if (f
->globals
!= NULL
)
2153 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2155 if (n
->kind
== DEBUG_OBJECT_TAG
2156 && (kind
== DEBUG_KIND_ILLEGAL
2157 || n
->u
.tag
->kind
== kind
)
2158 && n
->name
[0] == name
[0]
2159 && strcmp (n
->name
, name
) == 0)
2166 return DEBUG_TYPE_NULL
;
2169 /* Get a base type. We build a linked list on the stack to avoid
2170 crashing if the type is defined circularly. */
2172 static struct debug_type
*
2173 debug_get_real_type (handle
, type
, list
)
2176 struct debug_type_real_list
*list
;
2178 struct debug_type_real_list
*l
;
2179 struct debug_type_real_list rl
;
2186 case DEBUG_KIND_INDIRECT
:
2187 case DEBUG_KIND_NAMED
:
2188 case DEBUG_KIND_TAGGED
:
2192 for (l
= list
; l
!= NULL
; l
= l
->next
)
2197 _("debug_get_real_type: circular debug information for %s\n"),
2198 debug_get_type_name (handle
, type
));
2208 /* The default case is just here to avoid warnings. */
2210 case DEBUG_KIND_INDIRECT
:
2211 if (*type
->u
.kindirect
->slot
!= NULL
)
2212 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
, &rl
);
2214 case DEBUG_KIND_NAMED
:
2215 case DEBUG_KIND_TAGGED
:
2216 return debug_get_real_type (handle
, type
->u
.knamed
->type
, &rl
);
2221 /* Get the kind of a type. */
2223 enum debug_type_kind
2224 debug_get_type_kind (handle
, type
)
2229 return DEBUG_KIND_ILLEGAL
;
2230 type
= debug_get_real_type (handle
, type
, NULL
);
2232 return DEBUG_KIND_ILLEGAL
;
2236 /* Get the name of a type. */
2239 debug_get_type_name (handle
, type
)
2243 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2245 if (*type
->u
.kindirect
->slot
!= NULL
)
2246 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2247 return type
->u
.kindirect
->tag
;
2249 if (type
->kind
== DEBUG_KIND_NAMED
2250 || type
->kind
== DEBUG_KIND_TAGGED
)
2251 return type
->u
.knamed
->name
->name
;
2255 /* Get the size of a type. */
2258 debug_get_type_size (handle
, type
)
2265 /* We don't call debug_get_real_type, because somebody might have
2266 called debug_record_type_size on a named or indirect type. */
2268 if (type
->size
!= 0)
2275 case DEBUG_KIND_INDIRECT
:
2276 if (*type
->u
.kindirect
->slot
!= NULL
)
2277 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2279 case DEBUG_KIND_NAMED
:
2280 case DEBUG_KIND_TAGGED
:
2281 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2286 /* Get the return type of a function or method type. */
2289 debug_get_return_type (handle
, type
)
2294 return DEBUG_TYPE_NULL
;
2295 type
= debug_get_real_type (handle
, type
, NULL
);
2297 return DEBUG_TYPE_NULL
;
2301 return DEBUG_TYPE_NULL
;
2302 case DEBUG_KIND_FUNCTION
:
2303 return type
->u
.kfunction
->return_type
;
2304 case DEBUG_KIND_METHOD
:
2305 return type
->u
.kmethod
->return_type
;
2310 /* Get the parameter types of a function or method type (except that
2311 we don't currently store the parameter types of a function). */
2314 debug_get_parameter_types (handle
, type
, pvarargs
)
2321 type
= debug_get_real_type (handle
, type
, NULL
);
2328 case DEBUG_KIND_FUNCTION
:
2329 *pvarargs
= type
->u
.kfunction
->varargs
;
2330 return type
->u
.kfunction
->arg_types
;
2331 case DEBUG_KIND_METHOD
:
2332 *pvarargs
= type
->u
.kmethod
->varargs
;
2333 return type
->u
.kmethod
->arg_types
;
2338 /* Get the target type of a type. */
2341 debug_get_target_type (handle
, type
)
2347 type
= debug_get_real_type (handle
, type
, NULL
);
2354 case DEBUG_KIND_POINTER
:
2355 return type
->u
.kpointer
;
2356 case DEBUG_KIND_REFERENCE
:
2357 return type
->u
.kreference
;
2358 case DEBUG_KIND_CONST
:
2359 return type
->u
.kconst
;
2360 case DEBUG_KIND_VOLATILE
:
2361 return type
->u
.kvolatile
;
2366 /* Get the NULL terminated array of fields for a struct, union, or
2370 debug_get_fields (handle
, type
)
2376 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. */
2396 debug_get_field_type (handle
, field
)
2397 PTR handle ATTRIBUTE_UNUSED
;
2405 /* Get the name of a field. */
2409 debug_get_field_name (handle
, field
)
2410 PTR handle ATTRIBUTE_UNUSED
;
2418 /* Get the bit position of a field. */
2422 debug_get_field_bitpos (handle
, field
)
2423 PTR handle ATTRIBUTE_UNUSED
;
2426 if (field
== NULL
|| field
->static_member
)
2427 return (bfd_vma
) -1;
2428 return field
->u
.f
.bitpos
;
2431 /* Get the bit size of a field. */
2435 debug_get_field_bitsize (handle
, field
)
2436 PTR handle ATTRIBUTE_UNUSED
;
2439 if (field
== NULL
|| field
->static_member
)
2440 return (bfd_vma
) -1;
2441 return field
->u
.f
.bitsize
;
2444 /* Get the visibility of a field. */
2447 enum debug_visibility
2448 debug_get_field_visibility (handle
, field
)
2449 PTR handle ATTRIBUTE_UNUSED
;
2453 return DEBUG_VISIBILITY_IGNORE
;
2454 return field
->visibility
;
2457 /* Get the physical name of a field. */
2460 debug_get_field_physname (handle
, field
)
2461 PTR handle ATTRIBUTE_UNUSED
;
2464 if (field
== NULL
|| ! field
->static_member
)
2466 return field
->u
.s
.physname
;
2469 /* Write out the debugging information. This is given a handle to
2470 debugging information, and a set of function pointers to call. */
2473 debug_write (handle
, fns
, fhandle
)
2475 const struct debug_write_fns
*fns
;
2478 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2479 struct debug_unit
*u
;
2481 /* We use a mark to tell whether we have already written out a
2482 particular name. We use an integer, so that we don't have to
2483 clear the mark fields if we happen to write out the same
2484 information more than once. */
2487 /* The base_id field holds an ID value which will never be used, so
2488 that we can tell whether we have assigned an ID during this call
2490 info
->base_id
= info
->class_id
;
2492 /* We keep a linked list of classes for which was have assigned ID's
2493 during this call to debug_write. */
2494 info
->id_list
= NULL
;
2496 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2498 struct debug_file
*f
;
2501 info
->current_write_lineno
= u
->linenos
;
2502 info
->current_write_lineno_index
= 0;
2504 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2508 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2510 struct debug_name
*n
;
2516 if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2520 if (f
->globals
!= NULL
)
2522 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2524 if (! debug_write_name (info
, fns
, fhandle
, n
))
2530 /* Output any line number information which hasn't already been
2532 if (! debug_write_linenos (info
, fns
, fhandle
, (bfd_vma
) -1))
2539 /* Write out an element in a namespace. */
2542 debug_write_name (info
, fns
, fhandle
, n
)
2543 struct debug_handle
*info
;
2544 const struct debug_write_fns
*fns
;
2546 struct debug_name
*n
;
2550 case DEBUG_OBJECT_TYPE
:
2551 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2552 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2555 case DEBUG_OBJECT_TAG
:
2556 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2558 return (*fns
->tag
) (fhandle
, n
->name
);
2559 case DEBUG_OBJECT_VARIABLE
:
2560 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2561 (struct debug_name
*) NULL
))
2563 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2564 n
->u
.variable
->val
);
2565 case DEBUG_OBJECT_FUNCTION
:
2566 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2567 n
->linkage
, n
->u
.function
);
2568 case DEBUG_OBJECT_INT_CONSTANT
:
2569 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2570 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2571 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2572 case DEBUG_OBJECT_TYPED_CONSTANT
:
2573 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2574 (struct debug_name
*) NULL
))
2576 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2577 n
->u
.typed_constant
->val
);
2585 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2586 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2587 are about to call typedef or tag. If the type is anything else,
2588 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2589 points to this one. */
2592 debug_write_type (info
, fns
, fhandle
, type
, name
)
2593 struct debug_handle
*info
;
2594 const struct debug_write_fns
*fns
;
2596 struct debug_type
*type
;
2597 struct debug_name
*name
;
2601 const char *tag
= NULL
;
2603 /* If we have a name for this type, just output it. We only output
2604 typedef names after they have been defined. We output type tags
2605 whenever we are not actually defining them. */
2606 if ((type
->kind
== DEBUG_KIND_NAMED
2607 || type
->kind
== DEBUG_KIND_TAGGED
)
2608 && (type
->u
.knamed
->name
->mark
== info
->mark
2609 || (type
->kind
== DEBUG_KIND_TAGGED
2610 && type
->u
.knamed
->name
!= name
)))
2612 if (type
->kind
== DEBUG_KIND_NAMED
)
2613 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2616 struct debug_type
*real
;
2619 real
= debug_get_real_type ((PTR
) info
, type
, NULL
);
2621 return (*fns
->empty_type
) (fhandle
);
2623 if ((real
->kind
== DEBUG_KIND_STRUCT
2624 || real
->kind
== DEBUG_KIND_UNION
2625 || real
->kind
== DEBUG_KIND_CLASS
2626 || real
->kind
== DEBUG_KIND_UNION_CLASS
)
2627 && real
->u
.kclass
!= NULL
)
2629 if (real
->u
.kclass
->id
<= info
->base_id
)
2631 if (! debug_set_class_id (info
,
2632 type
->u
.knamed
->name
->name
,
2636 id
= real
->u
.kclass
->id
;
2639 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, id
,
2644 /* Mark the name after we have already looked for a known name, so
2645 that we don't just define a type in terms of itself. We need to
2646 mark the name here so that a struct containing a pointer to
2647 itself will work. */
2649 name
->mark
= info
->mark
;
2652 && type
->kind
!= DEBUG_KIND_NAMED
2653 && type
->kind
!= DEBUG_KIND_TAGGED
)
2655 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2661 case DEBUG_KIND_ILLEGAL
:
2662 debug_error (_("debug_write_type: illegal type encountered"));
2664 case DEBUG_KIND_INDIRECT
:
2665 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2666 return (*fns
->empty_type
) (fhandle
);
2667 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2669 case DEBUG_KIND_VOID
:
2670 return (*fns
->void_type
) (fhandle
);
2671 case DEBUG_KIND_INT
:
2672 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2673 case DEBUG_KIND_FLOAT
:
2674 return (*fns
->float_type
) (fhandle
, type
->size
);
2675 case DEBUG_KIND_COMPLEX
:
2676 return (*fns
->complex_type
) (fhandle
, type
->size
);
2677 case DEBUG_KIND_BOOL
:
2678 return (*fns
->bool_type
) (fhandle
, type
->size
);
2679 case DEBUG_KIND_STRUCT
:
2680 case DEBUG_KIND_UNION
:
2681 if (type
->u
.kclass
!= NULL
)
2683 if (type
->u
.kclass
->id
<= info
->base_id
)
2685 if (! debug_set_class_id (info
, tag
, type
))
2689 if (info
->mark
== type
->u
.kclass
->mark
)
2691 /* We are currently outputting this struct, or we have
2692 already output it. I don't know if this can happen,
2693 but it can happen for a class. */
2694 assert (type
->u
.kclass
->id
> info
->base_id
);
2695 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2698 type
->u
.kclass
->mark
= info
->mark
;
2701 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2702 (type
->u
.kclass
!= NULL
2703 ? type
->u
.kclass
->id
2705 type
->kind
== DEBUG_KIND_STRUCT
,
2708 if (type
->u
.kclass
!= NULL
2709 && type
->u
.kclass
->fields
!= NULL
)
2711 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2713 struct debug_field
*f
;
2715 f
= type
->u
.kclass
->fields
[i
];
2716 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2717 (struct debug_name
*) NULL
)
2718 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2719 f
->u
.f
.bitsize
, f
->visibility
))
2723 return (*fns
->end_struct_type
) (fhandle
);
2724 case DEBUG_KIND_CLASS
:
2725 case DEBUG_KIND_UNION_CLASS
:
2726 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2727 case DEBUG_KIND_ENUM
:
2728 if (type
->u
.kenum
== NULL
)
2729 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2730 (bfd_signed_vma
*) NULL
);
2731 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2732 type
->u
.kenum
->values
);
2733 case DEBUG_KIND_POINTER
:
2734 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2735 (struct debug_name
*) NULL
))
2737 return (*fns
->pointer_type
) (fhandle
);
2738 case DEBUG_KIND_FUNCTION
:
2739 if (! debug_write_type (info
, fns
, fhandle
,
2740 type
->u
.kfunction
->return_type
,
2741 (struct debug_name
*) NULL
))
2743 if (type
->u
.kfunction
->arg_types
== NULL
)
2747 for (is
= 0; type
->u
.kfunction
->arg_types
[is
] != NULL
; is
++)
2748 if (! debug_write_type (info
, fns
, fhandle
,
2749 type
->u
.kfunction
->arg_types
[is
],
2750 (struct debug_name
*) NULL
))
2753 return (*fns
->function_type
) (fhandle
, is
,
2754 type
->u
.kfunction
->varargs
);
2755 case DEBUG_KIND_REFERENCE
:
2756 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2757 (struct debug_name
*) NULL
))
2759 return (*fns
->reference_type
) (fhandle
);
2760 case DEBUG_KIND_RANGE
:
2761 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2762 (struct debug_name
*) NULL
))
2764 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2765 type
->u
.krange
->upper
);
2766 case DEBUG_KIND_ARRAY
:
2767 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2768 (struct debug_name
*) NULL
)
2769 || ! debug_write_type (info
, fns
, fhandle
,
2770 type
->u
.karray
->range_type
,
2771 (struct debug_name
*) NULL
))
2773 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2774 type
->u
.karray
->upper
,
2775 type
->u
.karray
->stringp
);
2776 case DEBUG_KIND_SET
:
2777 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2778 (struct debug_name
*) NULL
))
2780 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2781 case DEBUG_KIND_OFFSET
:
2782 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2783 (struct debug_name
*) NULL
)
2784 || ! debug_write_type (info
, fns
, fhandle
,
2785 type
->u
.koffset
->target_type
,
2786 (struct debug_name
*) NULL
))
2788 return (*fns
->offset_type
) (fhandle
);
2789 case DEBUG_KIND_METHOD
:
2790 if (! debug_write_type (info
, fns
, fhandle
,
2791 type
->u
.kmethod
->return_type
,
2792 (struct debug_name
*) NULL
))
2794 if (type
->u
.kmethod
->arg_types
== NULL
)
2798 for (is
= 0; type
->u
.kmethod
->arg_types
[is
] != NULL
; is
++)
2799 if (! debug_write_type (info
, fns
, fhandle
,
2800 type
->u
.kmethod
->arg_types
[is
],
2801 (struct debug_name
*) NULL
))
2804 if (type
->u
.kmethod
->domain_type
!= NULL
)
2806 if (! debug_write_type (info
, fns
, fhandle
,
2807 type
->u
.kmethod
->domain_type
,
2808 (struct debug_name
*) NULL
))
2811 return (*fns
->method_type
) (fhandle
,
2812 type
->u
.kmethod
->domain_type
!= NULL
,
2814 type
->u
.kmethod
->varargs
);
2815 case DEBUG_KIND_CONST
:
2816 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2817 (struct debug_name
*) NULL
))
2819 return (*fns
->const_type
) (fhandle
);
2820 case DEBUG_KIND_VOLATILE
:
2821 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2822 (struct debug_name
*) NULL
))
2824 return (*fns
->volatile_type
) (fhandle
);
2825 case DEBUG_KIND_NAMED
:
2826 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2827 (struct debug_name
*) NULL
);
2828 case DEBUG_KIND_TAGGED
:
2829 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2830 type
->u
.knamed
->name
);
2837 /* Write out a class type. */
2840 debug_write_class_type (info
, fns
, fhandle
, type
, tag
)
2841 struct debug_handle
*info
;
2842 const struct debug_write_fns
*fns
;
2844 struct debug_type
*type
;
2849 struct debug_type
*vptrbase
;
2851 if (type
->u
.kclass
== NULL
)
2858 if (type
->u
.kclass
->id
<= info
->base_id
)
2860 if (! debug_set_class_id (info
, tag
, type
))
2864 if (info
->mark
== type
->u
.kclass
->mark
)
2866 /* We are currently outputting this class, or we have
2867 already output it. This can happen when there are
2868 methods for an anonymous class. */
2869 assert (type
->u
.kclass
->id
> info
->base_id
);
2870 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2873 type
->u
.kclass
->mark
= info
->mark
;
2874 id
= type
->u
.kclass
->id
;
2876 vptrbase
= type
->u
.kclass
->vptrbase
;
2877 if (vptrbase
!= NULL
&& vptrbase
!= type
)
2879 if (! debug_write_type (info
, fns
, fhandle
, vptrbase
,
2880 (struct debug_name
*) NULL
))
2885 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2886 type
->kind
== DEBUG_KIND_CLASS
,
2892 if (type
->u
.kclass
!= NULL
)
2894 if (type
->u
.kclass
->fields
!= NULL
)
2896 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2898 struct debug_field
*f
;
2900 f
= type
->u
.kclass
->fields
[i
];
2901 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2902 (struct debug_name
*) NULL
))
2904 if (f
->static_member
)
2906 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2913 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2914 f
->u
.f
.bitsize
, f
->visibility
))
2920 if (type
->u
.kclass
->baseclasses
!= NULL
)
2922 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2924 struct debug_baseclass
*b
;
2926 b
= type
->u
.kclass
->baseclasses
[i
];
2927 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2928 (struct debug_name
*) NULL
))
2930 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2936 if (type
->u
.kclass
->methods
!= NULL
)
2938 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2940 struct debug_method
*m
;
2943 m
= type
->u
.kclass
->methods
[i
];
2944 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2946 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2948 struct debug_method_variant
*v
;
2951 if (v
->context
!= NULL
)
2953 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2954 (struct debug_name
*) NULL
))
2957 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2958 (struct debug_name
*) NULL
))
2960 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2962 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2967 v
->context
!= NULL
))
2972 if (! (*fns
->class_static_method_variant
) (fhandle
,
2980 if (! (*fns
->class_end_method
) (fhandle
))
2986 return (*fns
->end_class_type
) (fhandle
);
2989 /* Write out information for a function. */
2992 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2993 struct debug_handle
*info
;
2994 const struct debug_write_fns
*fns
;
2997 enum debug_object_linkage linkage
;
2998 struct debug_function
*function
;
3000 struct debug_parameter
*p
;
3001 struct debug_block
*b
;
3003 if (! debug_write_linenos (info
, fns
, fhandle
, function
->blocks
->start
))
3006 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
3007 (struct debug_name
*) NULL
))
3010 if (! (*fns
->start_function
) (fhandle
, name
,
3011 linkage
== DEBUG_LINKAGE_GLOBAL
))
3014 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
3016 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
3017 (struct debug_name
*) NULL
)
3018 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
3022 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
3024 if (! debug_write_block (info
, fns
, fhandle
, b
))
3028 return (*fns
->end_function
) (fhandle
);
3031 /* Write out information for a block. */
3034 debug_write_block (info
, fns
, fhandle
, block
)
3035 struct debug_handle
*info
;
3036 const struct debug_write_fns
*fns
;
3038 struct debug_block
*block
;
3040 struct debug_name
*n
;
3041 struct debug_block
*b
;
3043 if (! debug_write_linenos (info
, fns
, fhandle
, block
->start
))
3046 /* I can't see any point to writing out a block with no local
3047 variables, so we don't bother, except for the top level block. */
3048 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
3050 if (! (*fns
->start_block
) (fhandle
, block
->start
))
3054 if (block
->locals
!= NULL
)
3056 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
3058 if (! debug_write_name (info
, fns
, fhandle
, n
))
3063 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
3065 if (! debug_write_block (info
, fns
, fhandle
, b
))
3069 if (! debug_write_linenos (info
, fns
, fhandle
, block
->end
))
3072 if (block
->locals
!= NULL
|| block
->parent
== NULL
)
3074 if (! (*fns
->end_block
) (fhandle
, block
->end
))
3081 /* Write out line number information up to ADDRESS. */
3084 debug_write_linenos (info
, fns
, fhandle
, address
)
3085 struct debug_handle
*info
;
3086 const struct debug_write_fns
*fns
;
3090 while (info
->current_write_lineno
!= NULL
)
3092 struct debug_lineno
*l
;
3094 l
= info
->current_write_lineno
;
3096 while (info
->current_write_lineno_index
< DEBUG_LINENO_COUNT
)
3098 if (l
->linenos
[info
->current_write_lineno_index
]
3099 == (unsigned long) -1)
3102 if (l
->addrs
[info
->current_write_lineno_index
] >= address
)
3105 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
,
3106 l
->linenos
[info
->current_write_lineno_index
],
3107 l
->addrs
[info
->current_write_lineno_index
]))
3110 ++info
->current_write_lineno_index
;
3113 info
->current_write_lineno
= l
->next
;
3114 info
->current_write_lineno_index
= 0;
3120 /* Get the ID number for a class. If during the same call to
3121 debug_write we find a struct with the same definition with the same
3122 name, we use the same ID. This type of things happens because the
3123 same struct will be defined by multiple compilation units. */
3126 debug_set_class_id (info
, tag
, type
)
3127 struct debug_handle
*info
;
3129 struct debug_type
*type
;
3131 struct debug_class_type
*c
;
3132 struct debug_class_id
*l
;
3134 assert (type
->kind
== DEBUG_KIND_STRUCT
3135 || type
->kind
== DEBUG_KIND_UNION
3136 || type
->kind
== DEBUG_KIND_CLASS
3137 || type
->kind
== DEBUG_KIND_UNION_CLASS
);
3141 if (c
->id
> info
->base_id
)
3144 for (l
= info
->id_list
; l
!= NULL
; l
= l
->next
)
3146 if (l
->type
->kind
!= type
->kind
)
3157 || l
->tag
[0] != tag
[0]
3158 || strcmp (l
->tag
, tag
) != 0)
3162 if (debug_type_samep (info
, l
->type
, type
))
3164 c
->id
= l
->type
->u
.kclass
->id
;
3169 /* There are no identical types. Use a new ID, and add it to the
3172 c
->id
= info
->class_id
;
3174 l
= (struct debug_class_id
*) xmalloc (sizeof *l
);
3175 memset (l
, 0, sizeof *l
);
3180 l
->next
= info
->id_list
;
3186 /* See if two types are the same. At this point, we don't care about
3187 tags and the like. */
3190 debug_type_samep (info
, t1
, t2
)
3191 struct debug_handle
*info
;
3192 struct debug_type
*t1
;
3193 struct debug_type
*t2
;
3195 struct debug_type_compare_list
*l
;
3196 struct debug_type_compare_list top
;
3204 while (t1
->kind
== DEBUG_KIND_INDIRECT
)
3206 t1
= *t1
->u
.kindirect
->slot
;
3210 while (t2
->kind
== DEBUG_KIND_INDIRECT
)
3212 t2
= *t2
->u
.kindirect
->slot
;
3220 /* As a special case, permit a typedef to match a tag, since C++
3221 debugging output will sometimes add a typedef where C debugging
3223 if (t1
->kind
== DEBUG_KIND_NAMED
3224 && t2
->kind
== DEBUG_KIND_TAGGED
)
3225 return debug_type_samep (info
, t1
->u
.knamed
->type
, t2
);
3226 else if (t1
->kind
== DEBUG_KIND_TAGGED
3227 && t2
->kind
== DEBUG_KIND_NAMED
)
3228 return debug_type_samep (info
, t1
, t2
->u
.knamed
->type
);
3230 if (t1
->kind
!= t2
->kind
3231 || t1
->size
!= t2
->size
)
3234 /* Get rid of the trivial cases first. */
3239 case DEBUG_KIND_VOID
:
3240 case DEBUG_KIND_FLOAT
:
3241 case DEBUG_KIND_COMPLEX
:
3242 case DEBUG_KIND_BOOL
:
3244 case DEBUG_KIND_INT
:
3245 return t1
->u
.kint
== t2
->u
.kint
;
3248 /* We have to avoid an infinite recursion. We do this by keeping a
3249 list of types which we are comparing. We just keep the list on
3250 the stack. If we encounter a pair of types we are currently
3251 comparing, we just assume that they are equal. */
3252 for (l
= info
->compare_list
; l
!= NULL
; l
= l
->next
)
3254 if (l
->t1
== t1
&& l
->t2
== t2
)
3260 top
.next
= info
->compare_list
;
3261 info
->compare_list
= &top
;
3270 case DEBUG_KIND_STRUCT
:
3271 case DEBUG_KIND_UNION
:
3272 case DEBUG_KIND_CLASS
:
3273 case DEBUG_KIND_UNION_CLASS
:
3274 if (t1
->u
.kclass
== NULL
)
3275 ret
= t2
->u
.kclass
== NULL
;
3276 else if (t2
->u
.kclass
== NULL
)
3278 else if (t1
->u
.kclass
->id
> info
->base_id
3279 && t1
->u
.kclass
->id
== t2
->u
.kclass
->id
)
3282 ret
= debug_class_type_samep (info
, t1
, t2
);
3285 case DEBUG_KIND_ENUM
:
3286 if (t1
->u
.kenum
== NULL
)
3287 ret
= t2
->u
.kenum
== NULL
;
3288 else if (t2
->u
.kenum
== NULL
)
3292 const char **pn1
, **pn2
;
3293 bfd_signed_vma
*pv1
, *pv2
;
3295 pn1
= t1
->u
.kenum
->names
;
3296 pn2
= t2
->u
.kenum
->names
;
3297 pv1
= t1
->u
.kenum
->values
;
3298 pv2
= t2
->u
.kenum
->values
;
3299 while (*pn1
!= NULL
&& *pn2
!= NULL
)
3303 || strcmp (*pn1
, *pn2
) != 0)
3310 ret
= *pn1
== NULL
&& *pn2
== NULL
;
3314 case DEBUG_KIND_POINTER
:
3315 ret
= debug_type_samep (info
, t1
->u
.kpointer
, t2
->u
.kpointer
);
3318 case DEBUG_KIND_FUNCTION
:
3319 if (t1
->u
.kfunction
->varargs
!= t2
->u
.kfunction
->varargs
3320 || ! debug_type_samep (info
, t1
->u
.kfunction
->return_type
,
3321 t2
->u
.kfunction
->return_type
)
3322 || ((t1
->u
.kfunction
->arg_types
== NULL
)
3323 != (t2
->u
.kfunction
->arg_types
== NULL
)))
3325 else if (t1
->u
.kfunction
->arg_types
== NULL
)
3329 struct debug_type
**a1
, **a2
;
3331 a1
= t1
->u
.kfunction
->arg_types
;
3332 a2
= t2
->u
.kfunction
->arg_types
;
3333 while (*a1
!= NULL
&& *a2
!= NULL
)
3335 if (! debug_type_samep (info
, *a1
, *a2
))
3340 ret
= *a1
== NULL
&& *a2
== NULL
;
3344 case DEBUG_KIND_REFERENCE
:
3345 ret
= debug_type_samep (info
, t1
->u
.kreference
, t2
->u
.kreference
);
3348 case DEBUG_KIND_RANGE
:
3349 ret
= (t1
->u
.krange
->lower
== t2
->u
.krange
->lower
3350 && t1
->u
.krange
->upper
== t2
->u
.krange
->upper
3351 && debug_type_samep (info
, t1
->u
.krange
->type
,
3352 t2
->u
.krange
->type
));
3354 case DEBUG_KIND_ARRAY
:
3355 ret
= (t1
->u
.karray
->lower
== t2
->u
.karray
->lower
3356 && t1
->u
.karray
->upper
== t2
->u
.karray
->upper
3357 && t1
->u
.karray
->stringp
== t2
->u
.karray
->stringp
3358 && debug_type_samep (info
, t1
->u
.karray
->element_type
,
3359 t2
->u
.karray
->element_type
));
3362 case DEBUG_KIND_SET
:
3363 ret
= (t1
->u
.kset
->bitstringp
== t2
->u
.kset
->bitstringp
3364 && debug_type_samep (info
, t1
->u
.kset
->type
, t2
->u
.kset
->type
));
3367 case DEBUG_KIND_OFFSET
:
3368 ret
= (debug_type_samep (info
, t1
->u
.koffset
->base_type
,
3369 t2
->u
.koffset
->base_type
)
3370 && debug_type_samep (info
, t1
->u
.koffset
->target_type
,
3371 t2
->u
.koffset
->target_type
));
3374 case DEBUG_KIND_METHOD
:
3375 if (t1
->u
.kmethod
->varargs
!= t2
->u
.kmethod
->varargs
3376 || ! debug_type_samep (info
, t1
->u
.kmethod
->return_type
,
3377 t2
->u
.kmethod
->return_type
)
3378 || ! debug_type_samep (info
, t1
->u
.kmethod
->domain_type
,
3379 t2
->u
.kmethod
->domain_type
)
3380 || ((t1
->u
.kmethod
->arg_types
== NULL
)
3381 != (t2
->u
.kmethod
->arg_types
== NULL
)))
3383 else if (t1
->u
.kmethod
->arg_types
== NULL
)
3387 struct debug_type
**a1
, **a2
;
3389 a1
= t1
->u
.kmethod
->arg_types
;
3390 a2
= t2
->u
.kmethod
->arg_types
;
3391 while (*a1
!= NULL
&& *a2
!= NULL
)
3393 if (! debug_type_samep (info
, *a1
, *a2
))
3398 ret
= *a1
== NULL
&& *a2
== NULL
;
3402 case DEBUG_KIND_CONST
:
3403 ret
= debug_type_samep (info
, t1
->u
.kconst
, t2
->u
.kconst
);
3406 case DEBUG_KIND_VOLATILE
:
3407 ret
= debug_type_samep (info
, t1
->u
.kvolatile
, t2
->u
.kvolatile
);
3410 case DEBUG_KIND_NAMED
:
3411 case DEBUG_KIND_TAGGED
:
3412 ret
= (strcmp (t1
->u
.knamed
->name
->name
, t2
->u
.knamed
->name
->name
) == 0
3413 && debug_type_samep (info
, t1
->u
.knamed
->type
,
3414 t2
->u
.knamed
->type
));
3418 info
->compare_list
= top
.next
;
3423 /* See if two classes are the same. This is a subroutine of
3424 debug_type_samep. */
3427 debug_class_type_samep (info
, t1
, t2
)
3428 struct debug_handle
*info
;
3429 struct debug_type
*t1
;
3430 struct debug_type
*t2
;
3432 struct debug_class_type
*c1
, *c2
;
3437 if ((c1
->fields
== NULL
) != (c2
->fields
== NULL
)
3438 || (c1
->baseclasses
== NULL
) != (c2
->baseclasses
== NULL
)
3439 || (c1
->methods
== NULL
) != (c2
->methods
== NULL
)
3440 || (c1
->vptrbase
== NULL
) != (c2
->vptrbase
== NULL
))
3443 if (c1
->fields
!= NULL
)
3445 struct debug_field
**pf1
, **pf2
;
3447 for (pf1
= c1
->fields
, pf2
= c2
->fields
;
3448 *pf1
!= NULL
&& *pf2
!= NULL
;
3451 struct debug_field
*f1
, *f2
;
3455 if (f1
->name
[0] != f2
->name
[0]
3456 || f1
->visibility
!= f2
->visibility
3457 || f1
->static_member
!= f2
->static_member
)
3459 if (f1
->static_member
)
3461 if (strcmp (f1
->u
.s
.physname
, f2
->u
.s
.physname
) != 0)
3466 if (f1
->u
.f
.bitpos
!= f2
->u
.f
.bitpos
3467 || f1
->u
.f
.bitsize
!= f2
->u
.f
.bitsize
)
3470 /* We do the checks which require function calls last. We
3471 don't require that the types of fields have the same
3472 names, since that sometimes fails in the presence of
3473 typedefs and we really don't care. */
3474 if (strcmp (f1
->name
, f2
->name
) != 0
3475 || ! debug_type_samep (info
,
3476 debug_get_real_type ((PTR
) info
,
3478 debug_get_real_type ((PTR
) info
,
3482 if (*pf1
!= NULL
|| *pf2
!= NULL
)
3486 if (c1
->vptrbase
!= NULL
)
3488 if (! debug_type_samep (info
, c1
->vptrbase
, c2
->vptrbase
))
3492 if (c1
->baseclasses
!= NULL
)
3494 struct debug_baseclass
**pb1
, **pb2
;
3496 for (pb1
= c1
->baseclasses
, pb2
= c2
->baseclasses
;
3497 *pb1
!= NULL
&& *pb2
!= NULL
;
3500 struct debug_baseclass
*b1
, *b2
;
3504 if (b1
->bitpos
!= b2
->bitpos
3505 || b1
->virtual != b2
->virtual
3506 || b1
->visibility
!= b2
->visibility
3507 || ! debug_type_samep (info
, b1
->type
, b2
->type
))
3510 if (*pb1
!= NULL
|| *pb2
!= NULL
)
3514 if (c1
->methods
!= NULL
)
3516 struct debug_method
**pm1
, **pm2
;
3518 for (pm1
= c1
->methods
, pm2
= c2
->methods
;
3519 *pm1
!= NULL
&& *pm2
!= NULL
;
3522 struct debug_method
*m1
, *m2
;
3526 if (m1
->name
[0] != m2
->name
[0]
3527 || strcmp (m1
->name
, m2
->name
) != 0
3528 || (m1
->variants
== NULL
) != (m2
->variants
== NULL
))
3530 if (m1
->variants
== NULL
)
3532 struct debug_method_variant
**pv1
, **pv2
;
3534 for (pv1
= m1
->variants
, pv2
= m2
->variants
;
3535 *pv1
!= NULL
&& *pv2
!= NULL
;
3538 struct debug_method_variant
*v1
, *v2
;
3542 if (v1
->physname
[0] != v2
->physname
[0]
3543 || v1
->visibility
!= v2
->visibility
3544 || v1
->constp
!= v2
->constp
3545 || v1
->volatilep
!= v2
->volatilep
3546 || v1
->voffset
!= v2
->voffset
3547 || (v1
->context
== NULL
) != (v2
->context
== NULL
)
3548 || strcmp (v1
->physname
, v2
->physname
) != 0
3549 || ! debug_type_samep (info
, v1
->type
, v2
->type
))
3551 if (v1
->context
!= NULL
)
3553 if (! debug_type_samep (info
, v1
->context
,
3558 if (*pv1
!= NULL
|| *pv2
!= NULL
)
3562 if (*pm1
!= NULL
|| *pm2
!= NULL
)