1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995, 1996 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 /* Another mark used by debug_write. */
56 unsigned int class_mark
;
57 /* A struct/class ID used by debug_write. */
58 unsigned int class_id
;
59 /* The base for class_id for this call to debug_write. */
63 /* Information we keep for a single compilation unit. */
67 /* The next compilation unit. */
68 struct debug_unit
*next
;
69 /* A list of files included in this compilation unit. The first
70 file is always the main one, and that is where the main file name
72 struct debug_file
*files
;
73 /* Line number information for this compilation unit. This is not
74 stored by function, because assembler code may have line number
75 information without function information. */
76 struct debug_lineno
*linenos
;
79 /* Information kept for a single source file. */
83 /* The next source file in this compilation unit. */
84 struct debug_file
*next
;
85 /* The name of the source file. */
87 /* Global functions, variables, types, etc. */
88 struct debug_namespace
*globals
;
96 enum debug_type_kind kind
;
97 /* Size of type (0 if not known). */
99 /* Type which is a pointer to this type. */
101 /* Tagged union with additional information about the type. */
104 /* DEBUG_KIND_INDIRECT. */
105 struct debug_indirect_type
*kindirect
;
106 /* DEBUG_KIND_INT. */
107 /* Whether the integer is unsigned. */
109 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
110 DEBUG_KIND_UNION_CLASS. */
111 struct debug_class_type
*kclass
;
112 /* DEBUG_KIND_ENUM. */
113 struct debug_enum_type
*kenum
;
114 /* DEBUG_KIND_POINTER. */
115 struct debug_type
*kpointer
;
116 /* DEBUG_KIND_FUNCTION. */
117 struct debug_function_type
*kfunction
;
118 /* DEBUG_KIND_REFERENCE. */
119 struct debug_type
*kreference
;
120 /* DEBUG_KIND_RANGE. */
121 struct debug_range_type
*krange
;
122 /* DEBUG_KIND_ARRAY. */
123 struct debug_array_type
*karray
;
124 /* DEBUG_KIND_SET. */
125 struct debug_set_type
*kset
;
126 /* DEBUG_KIND_OFFSET. */
127 struct debug_offset_type
*koffset
;
128 /* DEBUG_KIND_METHOD. */
129 struct debug_method_type
*kmethod
;
130 /* DEBUG_KIND_CONST. */
131 struct debug_type
*kconst
;
132 /* DEBUG_KIND_VOLATILE. */
133 struct debug_type
*kvolatile
;
134 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
135 struct debug_named_type
*knamed
;
139 /* Information kept for an indirect type. */
141 struct debug_indirect_type
143 /* Slot where the final type will appear. */
149 /* Information kept for a struct, union, or class. */
151 struct debug_class_type
153 /* NULL terminated array of fields. */
155 /* A mark field used to avoid recursively printing out structs. */
157 /* This is used to uniquely identify unnamed structs when printing. */
159 /* The remaining fields are only used for DEBUG_KIND_CLASS and
160 DEBUG_KIND_UNION_CLASS. */
161 /* NULL terminated array of base classes. */
162 debug_baseclass
*baseclasses
;
163 /* NULL terminated array of methods. */
164 debug_method
*methods
;
165 /* The type of the class providing the virtual function table for
166 this class. This may point to the type itself. */
170 /* Information kept for an enum. */
172 struct debug_enum_type
174 /* NULL terminated array of names. */
176 /* Array of corresponding values. */
177 bfd_signed_vma
*values
;
180 /* Information kept for a function. FIXME: We should be able to
181 record the parameter types. */
183 struct debug_function_type
186 debug_type return_type
;
187 /* NULL terminated array of argument types. */
188 debug_type
*arg_types
;
189 /* Whether the function takes a variable number of arguments. */
193 /* Information kept for a range. */
195 struct debug_range_type
197 /* Range base type. */
200 bfd_signed_vma lower
;
202 bfd_signed_vma upper
;
205 /* Information kept for an array. */
207 struct debug_array_type
210 debug_type element_type
;
212 debug_type range_type
;
214 bfd_signed_vma lower
;
216 bfd_signed_vma upper
;
217 /* Whether this array is really a string. */
221 /* Information kept for a set. */
223 struct debug_set_type
227 /* Whether this set is really a bitstring. */
231 /* Information kept for an offset type (a based pointer). */
233 struct debug_offset_type
235 /* The type the pointer is an offset from. */
236 debug_type base_type
;
237 /* The type the pointer points to. */
238 debug_type target_type
;
241 /* Information kept for a method type. */
243 struct debug_method_type
245 /* The return type. */
246 debug_type return_type
;
247 /* The object type which this method is for. */
248 debug_type domain_type
;
249 /* A NULL terminated array of argument types. */
250 debug_type
*arg_types
;
251 /* Whether the method takes a variable number of arguments. */
255 /* Information kept for a named type. */
257 struct debug_named_type
260 struct debug_name
*name
;
265 /* A field in a struct or union. */
269 /* Name of the field. */
271 /* Type of the field. */
272 struct debug_type
*type
;
273 /* Visibility of the field. */
274 enum debug_visibility visibility
;
275 /* Whether this is a static member. */
276 boolean static_member
;
279 /* If static_member is false. */
282 /* Bit position of the field in the struct. */
284 /* Size of the field in bits. */
285 unsigned int bitsize
;
287 /* If static_member is true. */
290 const char *physname
;
295 /* A base class for an object. */
297 struct debug_baseclass
299 /* Type of the base class. */
300 struct debug_type
*type
;
301 /* Bit position of the base class in the object. */
303 /* Whether the base class is virtual. */
305 /* Visibility of the base class. */
306 enum debug_visibility visibility
;
309 /* A method of an object. */
313 /* The name of the method. */
315 /* A NULL terminated array of different types of variants. */
316 struct debug_method_variant
**variants
;
319 /* The variants of a method function of an object. These indicate
320 which method to run. */
322 struct debug_method_variant
324 /* The physical name of the function. */
325 const char *physname
;
326 /* The type of the function. */
327 struct debug_type
*type
;
328 /* The visibility of the function. */
329 enum debug_visibility visibility
;
330 /* Whether the function is const. */
332 /* Whether the function is volatile. */
334 /* The offset to the function in the virtual function table. */
336 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
337 #define VOFFSET_STATIC_METHOD (1)
338 /* Context of a virtual method function. */
339 struct debug_type
*context
;
342 /* A variable. This is the information we keep for a variable object.
343 This has no name; a name is associated with a variable in a
344 debug_name structure. */
346 struct debug_variable
348 /* Kind of variable. */
349 enum debug_var_kind kind
;
352 /* Value. The interpretation of the value depends upon kind. */
356 /* A function. This has no name; a name is associated with a function
357 in a debug_name structure. */
359 struct debug_function
362 debug_type return_type
;
363 /* Parameter information. */
364 struct debug_parameter
*parameters
;
365 /* Block information. The first structure on the list is the main
366 block of the function, and describes function local variables. */
367 struct debug_block
*blocks
;
370 /* A function parameter. */
372 struct debug_parameter
374 /* Next parameter. */
375 struct debug_parameter
*next
;
381 enum debug_parm_kind kind
;
382 /* Value (meaning depends upon kind). */
386 /* A typed constant. */
388 struct debug_typed_constant
392 /* Value. FIXME: We may eventually need to support non-integral
397 /* Information about a block within a function. */
401 /* Next block with the same parent. */
402 struct debug_block
*next
;
404 struct debug_block
*parent
;
405 /* List of child blocks. */
406 struct debug_block
*children
;
407 /* Start address of the block. */
409 /* End address of the block. */
411 /* Local variables. */
412 struct debug_namespace
*locals
;
415 /* Line number information we keep for a compilation unit. FIXME:
416 This structure is easy to create, but can be very space
421 /* More line number information for this block. */
422 struct debug_lineno
*next
;
424 struct debug_file
*file
;
425 /* Line numbers, terminated by a -1 or the end of the array. */
426 #define DEBUG_LINENO_COUNT 10
427 unsigned long linenos
[DEBUG_LINENO_COUNT
];
428 /* Addresses for the line numbers. */
429 bfd_vma addrs
[DEBUG_LINENO_COUNT
];
432 /* A namespace. This is a mapping from names to objects. FIXME: This
433 should be implemented as a hash table. */
435 struct debug_namespace
437 /* List of items in this namespace. */
438 struct debug_name
*list
;
439 /* Pointer to where the next item in this namespace should go. */
440 struct debug_name
**tail
;
443 /* Kinds of objects that appear in a namespace. */
445 enum debug_object_kind
449 /* A tagged type (really a different sort of namespace). */
452 DEBUG_OBJECT_VARIABLE
,
454 DEBUG_OBJECT_FUNCTION
,
455 /* An integer constant. */
456 DEBUG_OBJECT_INT_CONSTANT
,
457 /* A floating point constant. */
458 DEBUG_OBJECT_FLOAT_CONSTANT
,
459 /* A typed constant. */
460 DEBUG_OBJECT_TYPED_CONSTANT
463 /* Linkage of an object that appears in a namespace. */
465 enum debug_object_linkage
467 /* Local variable. */
468 DEBUG_LINKAGE_AUTOMATIC
,
469 /* Static--either file static or function static, depending upon the
471 DEBUG_LINKAGE_STATIC
,
473 DEBUG_LINKAGE_GLOBAL
,
478 /* A name in a namespace. */
482 /* Next name in this namespace. */
483 struct debug_name
*next
;
486 /* Mark. This is used by debug_write. */
488 /* Kind of object. */
489 enum debug_object_kind kind
;
490 /* Linkage of object. */
491 enum debug_object_linkage linkage
;
492 /* Tagged union with additional information about the object. */
495 /* DEBUG_OBJECT_TYPE. */
496 struct debug_type
*type
;
497 /* DEBUG_OBJECT_TAG. */
498 struct debug_type
*tag
;
499 /* DEBUG_OBJECT_VARIABLE. */
500 struct debug_variable
*variable
;
501 /* DEBUG_OBJECT_FUNCTION. */
502 struct debug_function
*function
;
503 /* DEBUG_OBJECT_INT_CONSTANT. */
504 bfd_vma int_constant
;
505 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
506 double float_constant
;
507 /* DEBUG_OBJECT_TYPED_CONSTANT. */
508 struct debug_typed_constant
*typed_constant
;
512 /* Local functions. */
514 static void debug_error
PARAMS ((const char *));
515 static struct debug_name
*debug_add_to_namespace
516 PARAMS ((struct debug_handle
*, struct debug_namespace
**, const char *,
517 enum debug_object_kind
, enum debug_object_linkage
));
518 static struct debug_name
*debug_add_to_current_namespace
519 PARAMS ((struct debug_handle
*, const char *, enum debug_object_kind
,
520 enum debug_object_linkage
));
521 static struct debug_type
*debug_make_type
522 PARAMS ((struct debug_handle
*, enum debug_type_kind
, unsigned int));
523 static struct debug_type
*debug_get_real_type
PARAMS ((PTR
, debug_type
));
524 static boolean debug_write_name
525 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
526 struct debug_name
*));
527 static boolean debug_write_type
528 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
529 struct debug_type
*, struct debug_name
*));
530 static boolean debug_write_class_type
531 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
532 struct debug_type
*, const char *));
533 static boolean debug_write_function
534 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
535 const char *, enum debug_object_linkage
, struct debug_function
*));
536 static boolean debug_write_block
537 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
538 struct debug_block
*));
540 /* Issue an error message. */
543 debug_error (message
)
546 fprintf (stderr
, "%s\n", message
);
549 /* Add an object to a namespace. */
551 static struct debug_name
*
552 debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
)
553 struct debug_handle
*info
;
554 struct debug_namespace
**nsp
;
556 enum debug_object_kind kind
;
557 enum debug_object_linkage linkage
;
559 struct debug_name
*n
;
560 struct debug_namespace
*ns
;
562 n
= (struct debug_name
*) xmalloc (sizeof *n
);
563 memset (n
, 0, sizeof *n
);
567 n
->linkage
= linkage
;
572 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
573 memset (ns
, 0, sizeof *ns
);
575 ns
->tail
= &ns
->list
;
586 /* Add an object to the current namespace. */
588 static struct debug_name
*
589 debug_add_to_current_namespace (info
, name
, kind
, linkage
)
590 struct debug_handle
*info
;
592 enum debug_object_kind kind
;
593 enum debug_object_linkage linkage
;
595 struct debug_namespace
**nsp
;
597 if (info
->current_unit
== NULL
598 || info
->current_file
== NULL
)
600 debug_error ("debug_add_to_current_namespace: no current file");
604 if (info
->current_block
!= NULL
)
605 nsp
= &info
->current_block
->locals
;
607 nsp
= &info
->current_file
->globals
;
609 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
612 /* Return a handle for debugging information. */
617 struct debug_handle
*ret
;
619 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
620 memset (ret
, 0, sizeof *ret
);
624 /* Set the source filename. This implicitly starts a new compilation
628 debug_set_filename (handle
, name
)
632 struct debug_handle
*info
= (struct debug_handle
*) handle
;
633 struct debug_file
*nfile
;
634 struct debug_unit
*nunit
;
639 nfile
= (struct debug_file
*) xmalloc (sizeof *nfile
);
640 memset (nfile
, 0, sizeof *nfile
);
642 nfile
->filename
= name
;
644 nunit
= (struct debug_unit
*) xmalloc (sizeof *nunit
);
645 memset (nunit
, 0, sizeof *nunit
);
647 nunit
->files
= nfile
;
648 info
->current_file
= nfile
;
650 if (info
->current_unit
!= NULL
)
651 info
->current_unit
->next
= nunit
;
654 assert (info
->units
== NULL
);
658 info
->current_unit
= nunit
;
660 info
->current_function
= NULL
;
661 info
->current_block
= NULL
;
662 info
->current_lineno
= NULL
;
667 /* Append a string to the source filename. */
670 debug_append_filename (handle
, string
)
674 struct debug_handle
*info
= (struct debug_handle
*) handle
;
680 if (info
->current_unit
== NULL
)
682 debug_error ("debug_append_filename: no current file");
686 n
= (char *) xmalloc (strlen (info
->current_unit
->files
->filename
)
689 sprintf (n
, "%s%s", info
->current_unit
->files
->filename
, string
);
690 info
->current_unit
->files
->filename
= n
;
695 /* Change source files to the given file name. This is used for
696 include files in a single compilation unit. */
699 debug_start_source (handle
, name
)
703 struct debug_handle
*info
= (struct debug_handle
*) handle
;
704 struct debug_file
*f
, **pf
;
709 if (info
->current_unit
== NULL
)
711 debug_error ("debug_start_source: no debug_set_filename call");
715 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
717 if (f
->filename
[0] == name
[0]
718 && f
->filename
[1] == name
[1]
719 && strcmp (f
->filename
, name
) == 0)
721 info
->current_file
= f
;
726 f
= (struct debug_file
*) xmalloc (sizeof *f
);
727 memset (f
, 0, sizeof *f
);
731 for (pf
= &info
->current_file
->next
;
737 info
->current_file
= f
;
742 /* Record a function definition. This implicitly starts a function
743 block. The debug_type argument is the type of the return value.
744 The boolean indicates whether the function is globally visible.
745 The bfd_vma is the address of the start of the function. Currently
746 the parameter types are specified by calls to
747 debug_record_parameter. FIXME: There is no way to specify nested
748 functions. FIXME: I don't think there is any way to record where a
752 debug_record_function (handle
, name
, return_type
, global
, addr
)
755 debug_type return_type
;
759 struct debug_handle
*info
= (struct debug_handle
*) handle
;
760 struct debug_function
*f
;
761 struct debug_block
*b
;
762 struct debug_name
*n
;
766 if (return_type
== NULL
)
769 if (info
->current_unit
== NULL
)
771 debug_error ("debug_record_function: no debug_set_filename call");
775 f
= (struct debug_function
*) xmalloc (sizeof *f
);
776 memset (f
, 0, sizeof *f
);
778 f
->return_type
= return_type
;
780 b
= (struct debug_block
*) xmalloc (sizeof *b
);
781 memset (b
, 0, sizeof *b
);
784 b
->end
= (bfd_vma
) -1;
788 info
->current_function
= f
;
789 info
->current_block
= b
;
791 /* FIXME: If we could handle nested functions, this would be the
792 place: we would want to use a different namespace. */
793 n
= debug_add_to_namespace (info
,
794 &info
->current_file
->globals
,
796 DEBUG_OBJECT_FUNCTION
,
798 ? DEBUG_LINKAGE_GLOBAL
799 : DEBUG_LINKAGE_STATIC
));
808 /* Record a parameter for the current function. */
811 debug_record_parameter (handle
, name
, type
, kind
, val
)
815 enum debug_parm_kind kind
;
818 struct debug_handle
*info
= (struct debug_handle
*) handle
;
819 struct debug_parameter
*p
, **pp
;
821 if (name
== NULL
|| type
== NULL
)
824 if (info
->current_unit
== NULL
825 || info
->current_function
== NULL
)
827 debug_error ("debug_record_parameter: no current function");
831 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
832 memset (p
, 0, sizeof *p
);
839 for (pp
= &info
->current_function
->parameters
;
848 /* End a function. FIXME: This should handle function nesting. */
851 debug_end_function (handle
, addr
)
855 struct debug_handle
*info
= (struct debug_handle
*) handle
;
857 if (info
->current_unit
== NULL
858 || info
->current_block
== NULL
859 || info
->current_function
== NULL
)
861 debug_error ("debug_end_function: no current function");
865 if (info
->current_block
->parent
!= NULL
)
867 debug_error ("debug_end_function: some blocks were not closed");
871 info
->current_block
->end
= addr
;
873 info
->current_function
= NULL
;
874 info
->current_block
= NULL
;
879 /* Start a block in a function. All local information will be
880 recorded in this block, until the matching call to debug_end_block.
881 debug_start_block and debug_end_block may be nested. The bfd_vma
882 argument is the address at which this block starts. */
885 debug_start_block (handle
, addr
)
889 struct debug_handle
*info
= (struct debug_handle
*) handle
;
890 struct debug_block
*b
, **pb
;
892 /* We must always have a current block: debug_record_function sets
894 if (info
->current_unit
== NULL
895 || info
->current_block
== NULL
)
897 debug_error ("debug_start_block: no current block");
901 b
= (struct debug_block
*) xmalloc (sizeof *b
);
902 memset (b
, 0, sizeof *b
);
904 b
->parent
= info
->current_block
;
906 b
->end
= (bfd_vma
) -1;
908 /* This new block is a child of the current block. */
909 for (pb
= &info
->current_block
->children
;
915 info
->current_block
= b
;
920 /* Finish a block in a function. This matches the call to
921 debug_start_block. The argument is the address at which this block
925 debug_end_block (handle
, addr
)
929 struct debug_handle
*info
= (struct debug_handle
*) handle
;
930 struct debug_block
*parent
;
932 if (info
->current_unit
== NULL
933 || info
->current_block
== NULL
)
935 debug_error ("debug_end_block: no current block");
939 parent
= info
->current_block
->parent
;
942 debug_error ("debug_end_block: attempt to close top level block");
946 info
->current_block
->end
= addr
;
948 info
->current_block
= parent
;
953 /* Associate a line number in the current source file and function
954 with a given address. */
957 debug_record_line (handle
, lineno
, addr
)
959 unsigned long lineno
;
962 struct debug_handle
*info
= (struct debug_handle
*) handle
;
963 struct debug_lineno
*l
;
966 if (info
->current_unit
== NULL
)
968 debug_error ("debug_record_line: no current unit");
972 l
= info
->current_lineno
;
973 if (l
!= NULL
&& l
->file
== info
->current_file
)
975 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
977 if (l
->linenos
[i
] == (unsigned long) -1)
979 l
->linenos
[i
] = lineno
;
986 /* If we get here, then either 1) there is no current_lineno
987 structure, which means this is the first line number in this
988 compilation unit, 2) the current_lineno structure is for a
989 different file, or 3) the current_lineno structure is full.
990 Regardless, we want to allocate a new debug_lineno structure, put
991 it in the right place, and make it the new current_lineno
994 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
995 memset (l
, 0, sizeof *l
);
997 l
->file
= info
->current_file
;
998 l
->linenos
[0] = lineno
;
1000 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
1001 l
->linenos
[i
] = (unsigned long) -1;
1003 if (info
->current_lineno
!= NULL
)
1004 info
->current_lineno
->next
= l
;
1006 info
->current_unit
->linenos
= l
;
1008 info
->current_lineno
= l
;
1013 /* Start a named common block. This is a block of variables that may
1017 debug_start_common_block (handle
, name
)
1022 debug_error ("debug_start_common_block: not implemented");
1026 /* End a named common block. */
1029 debug_end_common_block (handle
, name
)
1034 debug_error ("debug_end_common_block: not implemented");
1038 /* Record a named integer constant. */
1041 debug_record_int_const (handle
, name
, val
)
1046 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1047 struct debug_name
*n
;
1052 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1053 DEBUG_LINKAGE_NONE
);
1057 n
->u
.int_constant
= val
;
1062 /* Record a named floating point constant. */
1065 debug_record_float_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_FLOAT_CONSTANT
,
1077 DEBUG_LINKAGE_NONE
);
1081 n
->u
.float_constant
= val
;
1086 /* Record a typed constant with an integral value. */
1089 debug_record_typed_const (handle
, name
, type
, val
)
1095 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1096 struct debug_name
*n
;
1097 struct debug_typed_constant
*tc
;
1099 if (name
== NULL
|| type
== NULL
)
1102 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1103 DEBUG_LINKAGE_NONE
);
1107 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1108 memset (tc
, 0, sizeof *tc
);
1113 n
->u
.typed_constant
= tc
;
1118 /* Record a label. */
1121 debug_record_label (handle
, name
, type
, addr
)
1128 debug_error ("debug_record_label not implemented");
1132 /* Record a variable. */
1135 debug_record_variable (handle
, name
, type
, kind
, val
)
1139 enum debug_var_kind kind
;
1142 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1143 struct debug_namespace
**nsp
;
1144 enum debug_object_linkage linkage
;
1145 struct debug_name
*n
;
1146 struct debug_variable
*v
;
1148 if (name
== NULL
|| type
== NULL
)
1151 if (info
->current_unit
== NULL
1152 || info
->current_file
== NULL
)
1154 debug_error ("debug_record_variable: no current file");
1158 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1160 nsp
= &info
->current_file
->globals
;
1161 if (kind
== DEBUG_GLOBAL
)
1162 linkage
= DEBUG_LINKAGE_GLOBAL
;
1164 linkage
= DEBUG_LINKAGE_STATIC
;
1168 if (info
->current_block
== NULL
)
1170 debug_error ("debug_record_variable: no current block");
1173 nsp
= &info
->current_block
->locals
;
1174 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1177 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1181 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1182 memset (v
, 0, sizeof *v
);
1193 /* Make a type with a given kind and size. */
1196 static struct debug_type
*
1197 debug_make_type (info
, kind
, size
)
1198 struct debug_handle
*info
;
1199 enum debug_type_kind kind
;
1202 struct debug_type
*t
;
1204 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1205 memset (t
, 0, sizeof *t
);
1213 /* Make an indirect type which may be used as a placeholder for a type
1214 which is referenced before it is defined. */
1217 debug_make_indirect_type (handle
, slot
, tag
)
1222 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1223 struct debug_type
*t
;
1224 struct debug_indirect_type
*i
;
1226 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1228 return DEBUG_TYPE_NULL
;
1230 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1231 memset (i
, 0, sizeof *i
);
1241 /* Make a void type. There is only one of these. */
1244 debug_make_void_type (handle
)
1247 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1249 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1252 /* Make an integer type of a given size. The boolean argument is true
1253 if the integer is unsigned. */
1256 debug_make_int_type (handle
, size
, unsignedp
)
1261 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1262 struct debug_type
*t
;
1264 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1266 return DEBUG_TYPE_NULL
;
1268 t
->u
.kint
= unsignedp
;
1273 /* Make a floating point type of a given size. FIXME: On some
1274 platforms, like an Alpha, you probably need to be able to specify
1278 debug_make_float_type (handle
, size
)
1282 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1284 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1287 /* Make a boolean type of a given size. */
1290 debug_make_bool_type (handle
, size
)
1294 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1296 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1299 /* Make a complex type of a given size. */
1302 debug_make_complex_type (handle
, size
)
1306 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1308 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1311 /* Make a structure type. The second argument is true for a struct,
1312 false for a union. The third argument is the size of the struct.
1313 The fourth argument is a NULL terminated array of fields. */
1316 debug_make_struct_type (handle
, structp
, size
, fields
)
1320 debug_field
*fields
;
1322 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1323 struct debug_type
*t
;
1324 struct debug_class_type
*c
;
1326 t
= debug_make_type (info
,
1327 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1330 return DEBUG_TYPE_NULL
;
1332 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1333 memset (c
, 0, sizeof *c
);
1342 /* Make an object type. The first three arguments after the handle
1343 are the same as for debug_make_struct_type. The next arguments are
1344 a NULL terminated array of base classes, a NULL terminated array of
1345 methods, the type of the object holding the virtual function table
1346 if it is not this object, and a boolean which is true if this
1347 object has its own virtual function table. */
1350 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1351 methods
, vptrbase
, ownvptr
)
1355 debug_field
*fields
;
1356 debug_baseclass
*baseclasses
;
1357 debug_method
*methods
;
1358 debug_type vptrbase
;
1361 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1362 struct debug_type
*t
;
1363 struct debug_class_type
*c
;
1365 t
= debug_make_type (info
,
1366 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1369 return DEBUG_TYPE_NULL
;
1371 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1372 memset (c
, 0, sizeof *c
);
1375 c
->baseclasses
= baseclasses
;
1376 c
->methods
= methods
;
1380 c
->vptrbase
= vptrbase
;
1387 /* Make an enumeration type. The arguments are a null terminated
1388 array of strings, and an array of corresponding values. */
1391 debug_make_enum_type (handle
, names
, values
)
1394 bfd_signed_vma
*values
;
1396 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1397 struct debug_type
*t
;
1398 struct debug_enum_type
*e
;
1400 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1402 return DEBUG_TYPE_NULL
;
1404 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1405 memset (e
, 0, sizeof *e
);
1415 /* Make a pointer to a given type. */
1418 debug_make_pointer_type (handle
, type
)
1422 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1423 struct debug_type
*t
;
1426 return DEBUG_TYPE_NULL
;
1428 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1429 return type
->pointer
;
1431 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1433 return DEBUG_TYPE_NULL
;
1435 t
->u
.kpointer
= type
;
1442 /* Make a function returning a given type. FIXME: We should be able
1443 to record the parameter types. */
1446 debug_make_function_type (handle
, type
, arg_types
, varargs
)
1449 debug_type
*arg_types
;
1452 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1453 struct debug_type
*t
;
1454 struct debug_function_type
*f
;
1457 return DEBUG_TYPE_NULL
;
1459 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1461 return DEBUG_TYPE_NULL
;
1463 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1464 memset (f
, 0, sizeof *f
);
1466 f
->return_type
= type
;
1467 f
->arg_types
= arg_types
;
1468 f
->varargs
= varargs
;
1475 /* Make a reference to a given type. */
1478 debug_make_reference_type (handle
, type
)
1482 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1483 struct debug_type
*t
;
1486 return DEBUG_TYPE_NULL
;
1488 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1490 return DEBUG_TYPE_NULL
;
1492 t
->u
.kreference
= type
;
1497 /* Make a range of a given type from a lower to an upper bound. */
1500 debug_make_range_type (handle
, type
, lower
, upper
)
1503 bfd_signed_vma lower
;
1504 bfd_signed_vma upper
;
1506 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1507 struct debug_type
*t
;
1508 struct debug_range_type
*r
;
1511 return DEBUG_TYPE_NULL
;
1513 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1515 return DEBUG_TYPE_NULL
;
1517 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1518 memset (r
, 0, sizeof *r
);
1529 /* Make an array type. The second argument is the type of an element
1530 of the array. The third argument is the type of a range of the
1531 array. The fourth and fifth argument are the lower and upper
1532 bounds, respectively. The sixth argument is true if this array is
1533 actually a string, as in C. */
1536 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1539 debug_type element_type
;
1540 debug_type range_type
;
1541 bfd_signed_vma lower
;
1542 bfd_signed_vma upper
;
1545 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1546 struct debug_type
*t
;
1547 struct debug_array_type
*a
;
1549 if (element_type
== NULL
|| range_type
== NULL
)
1550 return DEBUG_TYPE_NULL
;
1552 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1554 return DEBUG_TYPE_NULL
;
1556 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1557 memset (a
, 0, sizeof *a
);
1559 a
->element_type
= element_type
;
1560 a
->range_type
= range_type
;
1563 a
->stringp
= stringp
;
1570 /* Make a set of a given type. For example, a Pascal set type. The
1571 boolean argument is true if this set is actually a bitstring, as in
1575 debug_make_set_type (handle
, type
, bitstringp
)
1580 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1581 struct debug_type
*t
;
1582 struct debug_set_type
*s
;
1585 return DEBUG_TYPE_NULL
;
1587 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1589 return DEBUG_TYPE_NULL
;
1591 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1592 memset (s
, 0, sizeof *s
);
1595 s
->bitstringp
= bitstringp
;
1602 /* Make a type for a pointer which is relative to an object. The
1603 second argument is the type of the object to which the pointer is
1604 relative. The third argument is the type that the pointer points
1608 debug_make_offset_type (handle
, base_type
, target_type
)
1610 debug_type base_type
;
1611 debug_type target_type
;
1613 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1614 struct debug_type
*t
;
1615 struct debug_offset_type
*o
;
1617 if (base_type
== NULL
|| target_type
== NULL
)
1618 return DEBUG_TYPE_NULL
;
1620 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1622 return DEBUG_TYPE_NULL
;
1624 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1625 memset (o
, 0, sizeof *o
);
1627 o
->base_type
= base_type
;
1628 o
->target_type
= target_type
;
1635 /* Make a type for a method function. The second argument is the
1636 return type, the third argument is the domain, and the fourth
1637 argument is a NULL terminated array of argument types. */
1640 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
, varargs
)
1642 debug_type return_type
;
1643 debug_type domain_type
;
1644 debug_type
*arg_types
;
1647 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1648 struct debug_type
*t
;
1649 struct debug_method_type
*m
;
1651 if (return_type
== NULL
)
1652 return DEBUG_TYPE_NULL
;
1654 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1656 return DEBUG_TYPE_NULL
;
1658 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1659 memset (m
, 0, sizeof *m
);
1661 m
->return_type
= return_type
;
1662 m
->domain_type
= domain_type
;
1663 m
->arg_types
= arg_types
;
1664 m
->varargs
= varargs
;
1671 /* Make a const qualified version of a given type. */
1674 debug_make_const_type (handle
, type
)
1678 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1679 struct debug_type
*t
;
1682 return DEBUG_TYPE_NULL
;
1684 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1686 return DEBUG_TYPE_NULL
;
1693 /* Make a volatile qualified version of a given type. */
1696 debug_make_volatile_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_VOLATILE
, 0);
1708 return DEBUG_TYPE_NULL
;
1710 t
->u
.kvolatile
= type
;
1715 /* Make an undefined tagged type. For example, a struct which has
1716 been mentioned, but not defined. */
1719 debug_make_undefined_tagged_type (handle
, name
, kind
)
1722 enum debug_type_kind kind
;
1724 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1725 struct debug_type
*t
;
1728 return DEBUG_TYPE_NULL
;
1732 case DEBUG_KIND_STRUCT
:
1733 case DEBUG_KIND_UNION
:
1734 case DEBUG_KIND_CLASS
:
1735 case DEBUG_KIND_UNION_CLASS
:
1736 case DEBUG_KIND_ENUM
:
1740 debug_error ("debug_make_undefined_type: unsupported kind");
1741 return DEBUG_TYPE_NULL
;
1744 t
= debug_make_type (info
, kind
, 0);
1746 return DEBUG_TYPE_NULL
;
1748 return debug_tag_type (handle
, name
, t
);
1751 /* Make a base class for an object. The second argument is the base
1752 class type. The third argument is the bit position of this base
1753 class in the object (always 0 unless doing multiple inheritance).
1754 The fourth argument is whether this is a virtual class. The fifth
1755 argument is the visibility of the base class. */
1759 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1764 enum debug_visibility visibility
;
1766 struct debug_baseclass
*b
;
1768 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1769 memset (b
, 0, sizeof *b
);
1773 b
->virtual = virtual;
1774 b
->visibility
= visibility
;
1779 /* Make a field for a struct. The second argument is the name. The
1780 third argument is the type of the field. The fourth argument is
1781 the bit position of the field. The fifth argument is the size of
1782 the field (it may be zero). The sixth argument is the visibility
1787 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1793 enum debug_visibility visibility
;
1795 struct debug_field
*f
;
1797 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1798 memset (f
, 0, sizeof *f
);
1802 f
->static_member
= false;
1803 f
->u
.f
.bitpos
= bitpos
;
1804 f
->u
.f
.bitsize
= bitsize
;
1805 f
->visibility
= visibility
;
1810 /* Make a static member of an object. The second argument is the
1811 name. The third argument is the type of the member. The fourth
1812 argument is the physical name of the member (i.e., the name as a
1813 global variable). The fifth argument is the visibility of the
1818 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1822 const char *physname
;
1823 enum debug_visibility visibility
;
1825 struct debug_field
*f
;
1827 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1828 memset (f
, 0, sizeof *f
);
1832 f
->static_member
= true;
1833 f
->u
.s
.physname
= physname
;
1834 f
->visibility
= visibility
;
1839 /* Make a method. The second argument is the name, and the third
1840 argument is a NULL terminated array of method variants. */
1844 debug_make_method (handle
, name
, variants
)
1847 debug_method_variant
*variants
;
1849 struct debug_method
*m
;
1851 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1852 memset (m
, 0, sizeof *m
);
1855 m
->variants
= variants
;
1860 /* Make a method argument. The second argument is the real name of
1861 the function. The third argument is the type of the function. The
1862 fourth argument is the visibility. The fifth argument is whether
1863 this is a const function. The sixth argument is whether this is a
1864 volatile function. The seventh argument is the offset in the
1865 virtual function table, if any. The eighth argument is the virtual
1866 function context. FIXME: Are the const and volatile arguments
1867 necessary? Could we just use debug_make_const_type? */
1870 debug_method_variant
1871 debug_make_method_variant (handle
, physname
, type
, visibility
, constp
,
1872 volatilep
, voffset
, context
)
1874 const char *physname
;
1876 enum debug_visibility visibility
;
1882 struct debug_method_variant
*m
;
1884 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1885 memset (m
, 0, sizeof *m
);
1887 m
->physname
= physname
;
1889 m
->visibility
= visibility
;
1891 m
->volatilep
= volatilep
;
1892 m
->voffset
= voffset
;
1893 m
->context
= context
;
1898 /* Make a static method argument. The arguments are the same as for
1899 debug_make_method_variant, except that the last two are omitted
1900 since a static method can not also be virtual. */
1902 debug_method_variant
1903 debug_make_static_method_variant (handle
, physname
, type
, visibility
,
1906 const char *physname
;
1908 enum debug_visibility visibility
;
1912 struct debug_method_variant
*m
;
1914 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1915 memset (m
, 0, sizeof *m
);
1917 m
->physname
= physname
;
1919 m
->visibility
= visibility
;
1921 m
->volatilep
= volatilep
;
1922 m
->voffset
= VOFFSET_STATIC_METHOD
;
1930 debug_name_type (handle
, name
, type
)
1935 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1936 struct debug_type
*t
;
1937 struct debug_named_type
*n
;
1938 struct debug_name
*nm
;
1940 if (name
== NULL
|| type
== NULL
)
1941 return DEBUG_TYPE_NULL
;
1943 if (info
->current_unit
== NULL
1944 || info
->current_file
== NULL
)
1946 debug_error ("debug_record_variable: no current file");
1950 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1952 return DEBUG_TYPE_NULL
;
1954 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1955 memset (n
, 0, sizeof *n
);
1961 /* We always add the name to the global namespace. This is probably
1962 wrong in some cases, but it seems to be right for stabs. FIXME. */
1964 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1965 DEBUG_OBJECT_TYPE
, DEBUG_LINKAGE_NONE
);
1979 debug_tag_type (handle
, name
, type
)
1984 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1985 struct debug_type
*t
;
1986 struct debug_named_type
*n
;
1987 struct debug_name
*nm
;
1989 if (name
== NULL
|| type
== NULL
)
1990 return DEBUG_TYPE_NULL
;
1992 if (info
->current_file
== NULL
)
1994 debug_error ("debug_tag_type: no current file");
1995 return DEBUG_TYPE_NULL
;
1998 if (type
->kind
== DEBUG_KIND_TAGGED
)
2000 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
2002 debug_error ("debug_tag_type: extra tag attempted");
2003 return DEBUG_TYPE_NULL
;
2006 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
2008 return DEBUG_TYPE_NULL
;
2010 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
2011 memset (n
, 0, sizeof *n
);
2017 /* We keep a global namespace of tags for each compilation unit. I
2018 don't know if that is the right thing to do. */
2020 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
2021 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2032 /* Record the size of a given type. */
2036 debug_record_type_size (handle
, type
, size
)
2041 if (type
->size
!= 0 && type
->size
!= size
)
2042 fprintf (stderr
, "Warning: changing type size from %d to %d\n",
2050 /* Find a named type. */
2053 debug_find_named_type (handle
, name
)
2057 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2058 struct debug_block
*b
;
2059 struct debug_file
*f
;
2061 /* We only search the current compilation unit. I don't know if
2062 this is right or not. */
2064 if (info
->current_unit
== NULL
)
2066 debug_error ("debug_find_named_type: no current compilation unit");
2067 return DEBUG_TYPE_NULL
;
2070 for (b
= info
->current_block
; b
!= NULL
; b
= b
->parent
)
2072 if (b
->locals
!= NULL
)
2074 struct debug_name
*n
;
2076 for (n
= b
->locals
->list
; n
!= NULL
; n
= n
->next
)
2078 if (n
->kind
== DEBUG_OBJECT_TYPE
2079 && n
->name
[0] == name
[0]
2080 && strcmp (n
->name
, name
) == 0)
2086 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
2088 if (f
->globals
!= NULL
)
2090 struct debug_name
*n
;
2092 for (n
= f
->globals
->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 return DEBUG_TYPE_NULL
;
2105 /* Find a tagged type. */
2108 debug_find_tagged_type (handle
, name
, kind
)
2111 enum debug_type_kind kind
;
2113 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2114 struct debug_unit
*u
;
2116 /* We search the globals of all the compilation units. I don't know
2117 if this is correct or not. It would be easy to change. */
2119 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2121 struct debug_file
*f
;
2123 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2125 struct debug_name
*n
;
2127 if (f
->globals
!= NULL
)
2129 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2131 if (n
->kind
== DEBUG_OBJECT_TAG
2132 && (kind
== DEBUG_KIND_ILLEGAL
2133 || n
->u
.tag
->kind
== kind
)
2134 && n
->name
[0] == name
[0]
2135 && strcmp (n
->name
, name
) == 0)
2142 return DEBUG_TYPE_NULL
;
2145 /* Get a base type. */
2147 static struct debug_type
*
2148 debug_get_real_type (handle
, type
)
2156 case DEBUG_KIND_INDIRECT
:
2157 if (*type
->u
.kindirect
->slot
!= NULL
)
2158 return debug_get_real_type (handle
, *type
->u
.kindirect
->slot
);
2160 case DEBUG_KIND_NAMED
:
2161 case DEBUG_KIND_TAGGED
:
2162 return debug_get_real_type (handle
, type
->u
.knamed
->type
);
2167 /* Get the kind of a type. */
2169 enum debug_type_kind
2170 debug_get_type_kind (handle
, type
)
2175 return DEBUG_KIND_ILLEGAL
;
2176 type
= debug_get_real_type (handle
, type
);
2180 /* Get the name of a type. */
2183 debug_get_type_name (handle
, type
)
2187 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2189 if (*type
->u
.kindirect
->slot
!= NULL
)
2190 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2191 return type
->u
.kindirect
->tag
;
2193 if (type
->kind
== DEBUG_KIND_NAMED
2194 || type
->kind
== DEBUG_KIND_TAGGED
)
2195 return type
->u
.knamed
->name
->name
;
2199 /* Get the size of a type. */
2202 debug_get_type_size (handle
, type
)
2209 /* We don't call debug_get_real_type, because somebody might have
2210 called debug_record_type_size on a named or indirect type. */
2212 if (type
->size
!= 0)
2219 case DEBUG_KIND_INDIRECT
:
2220 if (*type
->u
.kindirect
->slot
!= NULL
)
2221 return debug_get_type_size (handle
, *type
->u
.kindirect
->slot
);
2223 case DEBUG_KIND_NAMED
:
2224 case DEBUG_KIND_TAGGED
:
2225 return debug_get_type_size (handle
, type
->u
.knamed
->type
);
2230 /* Get the return type of a function or method type. */
2233 debug_get_return_type (handle
, type
)
2238 return DEBUG_TYPE_NULL
;
2239 type
= debug_get_real_type (handle
, type
);
2243 return DEBUG_TYPE_NULL
;
2244 case DEBUG_KIND_FUNCTION
:
2245 return type
->u
.kfunction
->return_type
;
2246 case DEBUG_KIND_METHOD
:
2247 return type
->u
.kmethod
->return_type
;
2252 /* Get the parameter types of a function or method type (except that
2253 we don't currently store the parameter types of a function). */
2256 debug_get_parameter_types (handle
, type
, pvarargs
)
2263 type
= debug_get_real_type (handle
, type
);
2268 case DEBUG_KIND_METHOD
:
2269 *pvarargs
= type
->u
.kmethod
->varargs
;
2270 return type
->u
.kmethod
->arg_types
;
2275 /* Get the target type of a type. */
2278 debug_get_target_type (handle
, type
)
2284 type
= debug_get_real_type (handle
, type
);
2289 case DEBUG_KIND_POINTER
:
2290 return type
->u
.kpointer
;
2291 case DEBUG_KIND_REFERENCE
:
2292 return type
->u
.kreference
;
2293 case DEBUG_KIND_CONST
:
2294 return type
->u
.kconst
;
2295 case DEBUG_KIND_VOLATILE
:
2296 return type
->u
.kvolatile
;
2301 /* Get the NULL terminated array of fields for a struct, union, or
2305 debug_get_fields (handle
, type
)
2311 type
= debug_get_real_type (handle
, type
);
2316 case DEBUG_KIND_STRUCT
:
2317 case DEBUG_KIND_UNION
:
2318 case DEBUG_KIND_CLASS
:
2319 case DEBUG_KIND_UNION_CLASS
:
2320 return type
->u
.kclass
->fields
;
2325 /* Get the type of a field. */
2329 debug_get_field_type (handle
, field
)
2338 /* Get the name of a field. */
2342 debug_get_field_name (handle
, field
)
2351 /* Get the bit position of a field. */
2355 debug_get_field_bitpos (handle
, field
)
2359 if (field
== NULL
|| field
->static_member
)
2360 return (bfd_vma
) -1;
2361 return field
->u
.f
.bitpos
;
2364 /* Get the bit size of a field. */
2368 debug_get_field_bitsize (handle
, field
)
2372 if (field
== NULL
|| field
->static_member
)
2373 return (bfd_vma
) -1;
2374 return field
->u
.f
.bitsize
;
2377 /* Get the visibility of a field. */
2380 enum debug_visibility
2381 debug_get_field_visibility (handle
, field
)
2386 return DEBUG_VISIBILITY_IGNORE
;
2387 return field
->visibility
;
2390 /* Get the physical name of a field. */
2393 debug_get_field_physname (handle
, field
)
2397 if (field
== NULL
|| ! field
->static_member
)
2399 return field
->u
.s
.physname
;
2402 /* Write out the debugging information. This is given a handle to
2403 debugging information, and a set of function pointers to call. */
2406 debug_write (handle
, fns
, fhandle
)
2408 const struct debug_write_fns
*fns
;
2411 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2412 struct debug_unit
*u
;
2414 /* We use a mark to tell whether we have already written out a
2415 particular name. We use an integer, so that we don't have to
2416 clear the mark fields if we happen to write out the same
2417 information more than once. */
2420 /* The base_id field holds an ID value which will never be used, so
2421 that we can tell whether we have assigned an ID during this call
2423 info
->base_id
= info
->class_id
;
2425 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2427 struct debug_file
*f
;
2429 struct debug_lineno
*l
;
2431 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2435 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2437 struct debug_name
*n
;
2443 if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2447 if (f
->globals
!= NULL
)
2449 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2451 if (! debug_write_name (info
, fns
, fhandle
, n
))
2457 for (l
= u
->linenos
; l
!= NULL
; l
= l
->next
)
2461 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
2463 if (l
->linenos
[i
] == (unsigned long) -1)
2465 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
, l
->linenos
[i
],
2475 /* Write out an element in a namespace. */
2478 debug_write_name (info
, fns
, fhandle
, n
)
2479 struct debug_handle
*info
;
2480 const struct debug_write_fns
*fns
;
2482 struct debug_name
*n
;
2484 /* The class_mark field is used to prevent recursively outputting a
2490 case DEBUG_OBJECT_TYPE
:
2491 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2492 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2495 case DEBUG_OBJECT_TAG
:
2496 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2498 return (*fns
->tag
) (fhandle
, n
->name
);
2499 case DEBUG_OBJECT_VARIABLE
:
2500 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2501 (struct debug_name
*) NULL
))
2503 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2504 n
->u
.variable
->val
);
2505 case DEBUG_OBJECT_FUNCTION
:
2506 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2507 n
->linkage
, n
->u
.function
);
2508 case DEBUG_OBJECT_INT_CONSTANT
:
2509 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2510 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2511 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2512 case DEBUG_OBJECT_TYPED_CONSTANT
:
2513 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2514 (struct debug_name
*) NULL
))
2516 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2517 n
->u
.typed_constant
->val
);
2525 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2526 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2527 are about to call typedef or tag. If the type is anything else,
2528 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2529 points to this one. */
2532 debug_write_type (info
, fns
, fhandle
, type
, name
)
2533 struct debug_handle
*info
;
2534 const struct debug_write_fns
*fns
;
2536 struct debug_type
*type
;
2537 struct debug_name
*name
;
2543 /* If we have a name for this type, just output it. We only output
2544 typedef names after they have been defined. We output type tags
2545 whenever we are not actually defining them. */
2546 if ((type
->kind
== DEBUG_KIND_NAMED
2547 || type
->kind
== DEBUG_KIND_TAGGED
)
2548 && (type
->u
.knamed
->name
->mark
== info
->mark
2549 || (type
->kind
== DEBUG_KIND_TAGGED
2550 && type
->u
.knamed
->name
!= name
)))
2552 if (type
->kind
== DEBUG_KIND_NAMED
)
2553 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2556 struct debug_type
*real
;
2558 real
= debug_get_real_type ((PTR
) info
, type
);
2559 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
, 0,
2564 /* Mark the name after we have already looked for a known name, so
2565 that we don't just define a type in terms of itself. We need to
2566 mark the name here so that a struct containing a pointer to
2567 itself will work. */
2569 name
->mark
= info
->mark
;
2573 && type
->kind
!= DEBUG_KIND_NAMED
2574 && type
->kind
!= DEBUG_KIND_TAGGED
)
2576 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2582 case DEBUG_KIND_ILLEGAL
:
2583 debug_error ("debug_write_type: illegal type encountered");
2585 case DEBUG_KIND_INDIRECT
:
2586 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2587 return (*fns
->empty_type
) (fhandle
);
2588 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2590 case DEBUG_KIND_VOID
:
2591 return (*fns
->void_type
) (fhandle
);
2592 case DEBUG_KIND_INT
:
2593 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2594 case DEBUG_KIND_FLOAT
:
2595 return (*fns
->float_type
) (fhandle
, type
->size
);
2596 case DEBUG_KIND_COMPLEX
:
2597 return (*fns
->complex_type
) (fhandle
, type
->size
);
2598 case DEBUG_KIND_BOOL
:
2599 return (*fns
->bool_type
) (fhandle
, type
->size
);
2600 case DEBUG_KIND_STRUCT
:
2601 case DEBUG_KIND_UNION
:
2602 if (type
->u
.kclass
!= NULL
)
2604 if (info
->class_mark
== type
->u
.kclass
->mark
2605 || type
->u
.kclass
->id
> info
->base_id
)
2607 /* We are currently outputting this struct, or we have
2608 already output it. I don't know if this can happen,
2609 but it can happen for a class. */
2610 assert (type
->u
.kclass
->id
> info
->base_id
);
2611 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2614 type
->u
.kclass
->mark
= info
->class_mark
;
2616 type
->u
.kclass
->id
= info
->class_id
;
2619 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2620 (type
->u
.kclass
!= NULL
2621 ? type
->u
.kclass
->id
2623 type
->kind
== DEBUG_KIND_STRUCT
,
2626 if (type
->u
.kclass
!= NULL
2627 && type
->u
.kclass
->fields
!= NULL
)
2629 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2631 struct debug_field
*f
;
2633 f
= type
->u
.kclass
->fields
[i
];
2634 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2635 (struct debug_name
*) NULL
)
2636 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2637 f
->u
.f
.bitsize
, f
->visibility
))
2641 return (*fns
->end_struct_type
) (fhandle
);
2642 case DEBUG_KIND_CLASS
:
2643 case DEBUG_KIND_UNION_CLASS
:
2644 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2645 case DEBUG_KIND_ENUM
:
2646 if (type
->u
.kenum
== NULL
)
2647 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2648 (bfd_signed_vma
*) NULL
);
2649 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2650 type
->u
.kenum
->values
);
2651 case DEBUG_KIND_POINTER
:
2652 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2653 (struct debug_name
*) NULL
))
2655 return (*fns
->pointer_type
) (fhandle
);
2656 case DEBUG_KIND_FUNCTION
:
2657 if (type
->u
.kfunction
->arg_types
== NULL
)
2661 for (is
= 0; type
->u
.kfunction
->arg_types
[is
] != NULL
; is
++)
2662 if (! debug_write_type (info
, fns
, fhandle
,
2663 type
->u
.kfunction
->arg_types
[is
],
2664 (struct debug_name
*) NULL
))
2667 if (! debug_write_type (info
, fns
, fhandle
,
2668 type
->u
.kfunction
->return_type
,
2669 (struct debug_name
*) NULL
))
2671 return (*fns
->function_type
) (fhandle
, is
,
2672 type
->u
.kfunction
->varargs
);
2673 case DEBUG_KIND_REFERENCE
:
2674 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2675 (struct debug_name
*) NULL
))
2677 return (*fns
->reference_type
) (fhandle
);
2678 case DEBUG_KIND_RANGE
:
2679 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2680 (struct debug_name
*) NULL
))
2682 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2683 type
->u
.krange
->upper
);
2684 case DEBUG_KIND_ARRAY
:
2685 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2686 (struct debug_name
*) NULL
)
2687 || ! debug_write_type (info
, fns
, fhandle
,
2688 type
->u
.karray
->range_type
,
2689 (struct debug_name
*) NULL
))
2691 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2692 type
->u
.karray
->upper
,
2693 type
->u
.karray
->stringp
);
2694 case DEBUG_KIND_SET
:
2695 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2696 (struct debug_name
*) NULL
))
2698 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2699 case DEBUG_KIND_OFFSET
:
2700 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2701 (struct debug_name
*) NULL
)
2702 || ! debug_write_type (info
, fns
, fhandle
,
2703 type
->u
.koffset
->target_type
,
2704 (struct debug_name
*) NULL
))
2706 return (*fns
->offset_type
) (fhandle
);
2707 case DEBUG_KIND_METHOD
:
2708 if (! debug_write_type (info
, fns
, fhandle
,
2709 type
->u
.kmethod
->return_type
,
2710 (struct debug_name
*) NULL
))
2712 if (type
->u
.kmethod
->arg_types
== NULL
)
2716 for (is
= 0; type
->u
.kmethod
->arg_types
[is
] != NULL
; is
++)
2717 if (! debug_write_type (info
, fns
, fhandle
,
2718 type
->u
.kmethod
->arg_types
[is
],
2719 (struct debug_name
*) NULL
))
2722 if (type
->u
.kmethod
->domain_type
!= NULL
)
2724 if (! debug_write_type (info
, fns
, fhandle
,
2725 type
->u
.kmethod
->domain_type
,
2726 (struct debug_name
*) NULL
))
2729 return (*fns
->method_type
) (fhandle
,
2730 type
->u
.kmethod
->domain_type
!= NULL
,
2732 type
->u
.kmethod
->varargs
);
2733 case DEBUG_KIND_CONST
:
2734 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2735 (struct debug_name
*) NULL
))
2737 return (*fns
->const_type
) (fhandle
);
2738 case DEBUG_KIND_VOLATILE
:
2739 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2740 (struct debug_name
*) NULL
))
2742 return (*fns
->volatile_type
) (fhandle
);
2743 case DEBUG_KIND_NAMED
:
2744 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2745 (struct debug_name
*) NULL
);
2746 case DEBUG_KIND_TAGGED
:
2747 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2748 type
->u
.knamed
->name
);
2755 /* Write out a class type. */
2758 debug_write_class_type (info
, fns
, fhandle
, type
, tag
)
2759 struct debug_handle
*info
;
2760 const struct debug_write_fns
*fns
;
2762 struct debug_type
*type
;
2767 struct debug_type
*vptrbase
;
2769 if (type
->u
.kclass
== NULL
)
2776 if (info
->class_mark
== type
->u
.kclass
->mark
2777 || type
->u
.kclass
->id
> info
->base_id
)
2779 /* We are currently outputting this class, or we have
2780 already output it. This can happen when there are
2781 methods for an anonymous class. */
2782 assert (type
->u
.kclass
->id
> info
->base_id
);
2783 return (*fns
->tag_type
) (fhandle
, tag
, type
->u
.kclass
->id
,
2786 type
->u
.kclass
->mark
= info
->class_mark
;
2788 id
= info
->class_id
;
2789 type
->u
.kclass
->id
= id
;
2791 vptrbase
= type
->u
.kclass
->vptrbase
;
2792 if (vptrbase
!= NULL
&& vptrbase
!= type
)
2794 if (! debug_write_type (info
, fns
, fhandle
, vptrbase
,
2795 (struct debug_name
*) NULL
))
2800 if (! (*fns
->start_class_type
) (fhandle
, tag
, id
,
2801 type
->kind
== DEBUG_KIND_CLASS
,
2807 if (type
->u
.kclass
!= NULL
)
2809 if (type
->u
.kclass
->fields
!= NULL
)
2811 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2813 struct debug_field
*f
;
2815 f
= type
->u
.kclass
->fields
[i
];
2816 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2817 (struct debug_name
*) NULL
))
2819 if (f
->static_member
)
2821 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2828 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2829 f
->u
.f
.bitsize
, f
->visibility
))
2835 if (type
->u
.kclass
->baseclasses
!= NULL
)
2837 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2839 struct debug_baseclass
*b
;
2841 b
= type
->u
.kclass
->baseclasses
[i
];
2842 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2843 (struct debug_name
*) NULL
))
2845 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2851 if (type
->u
.kclass
->methods
!= NULL
)
2853 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2855 struct debug_method
*m
;
2858 m
= type
->u
.kclass
->methods
[i
];
2859 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2861 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2863 struct debug_method_variant
*v
;
2866 if (v
->context
!= NULL
)
2868 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2869 (struct debug_name
*) NULL
))
2872 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2873 (struct debug_name
*) NULL
))
2875 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2877 if (! (*fns
->class_method_variant
) (fhandle
, v
->physname
,
2882 v
->context
!= NULL
))
2887 if (! (*fns
->class_static_method_variant
) (fhandle
,
2895 if (! (*fns
->class_end_method
) (fhandle
))
2901 return (*fns
->end_class_type
) (fhandle
);
2904 /* Write out information for a function. */
2907 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2908 struct debug_handle
*info
;
2909 const struct debug_write_fns
*fns
;
2912 enum debug_object_linkage linkage
;
2913 struct debug_function
*function
;
2915 struct debug_parameter
*p
;
2916 struct debug_block
*b
;
2918 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2919 (struct debug_name
*) NULL
))
2922 if (! (*fns
->start_function
) (fhandle
, name
,
2923 linkage
== DEBUG_LINKAGE_GLOBAL
))
2926 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
2928 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
2929 (struct debug_name
*) NULL
)
2930 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
2934 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2936 if (! debug_write_block (info
, fns
, fhandle
, b
))
2940 return (*fns
->end_function
) (fhandle
);
2943 /* Write out information for a block. */
2946 debug_write_block (info
, fns
, fhandle
, block
)
2947 struct debug_handle
*info
;
2948 const struct debug_write_fns
*fns
;
2950 struct debug_block
*block
;
2952 struct debug_name
*n
;
2953 struct debug_block
*b
;
2955 if (! (*fns
->start_block
) (fhandle
, block
->start
))
2958 if (block
->locals
!= NULL
)
2960 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
2962 if (! debug_write_name (info
, fns
, fhandle
, n
))
2967 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
2969 if (! debug_write_block (info
, fns
, fhandle
, b
))
2973 return (*fns
->end_block
) (fhandle
, block
->end
);