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
;
59 /* Information we keep for a single compilation unit. */
63 /* The next compilation unit. */
64 struct debug_unit
*next
;
65 /* A list of files included in this compilation unit. The first
66 file is always the main one, and that is where the main file name
68 struct debug_file
*files
;
69 /* Line number information for this compilation unit. This is not
70 stored by function, because assembler code may have line number
71 information without function information. */
72 struct debug_lineno
*linenos
;
75 /* Information kept for a single source file. */
79 /* The next source file in this compilation unit. */
80 struct debug_file
*next
;
81 /* The name of the source file. */
83 /* Global functions, variables, types, etc. */
84 struct debug_namespace
*globals
;
92 enum debug_type_kind kind
;
93 /* Size of type (0 if not known). */
95 /* Type which is a pointer to this type. */
97 /* Tagged union with additional information about the type. */
100 /* DEBUG_KIND_INDIRECT. */
101 struct debug_indirect_type
*kindirect
;
102 /* DEBUG_KIND_INT. */
103 /* Whether the integer is unsigned. */
105 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
106 DEBUG_KIND_UNION_CLASS. */
107 struct debug_class_type
*kclass
;
108 /* DEBUG_KIND_ENUM. */
109 struct debug_enum_type
*kenum
;
110 /* DEBUG_KIND_POINTER. */
111 struct debug_type
*kpointer
;
112 /* DEBUG_KIND_FUNCTION. */
113 struct debug_function_type
*kfunction
;
114 /* DEBUG_KIND_REFERENCE. */
115 struct debug_type
*kreference
;
116 /* DEBUG_KIND_RANGE. */
117 struct debug_range_type
*krange
;
118 /* DEBUG_KIND_ARRAY. */
119 struct debug_array_type
*karray
;
120 /* DEBUG_KIND_SET. */
121 struct debug_set_type
*kset
;
122 /* DEBUG_KIND_OFFSET. */
123 struct debug_offset_type
*koffset
;
124 /* DEBUG_KIND_METHOD. */
125 struct debug_method_type
*kmethod
;
126 /* DEBUG_KIND_CONST. */
127 struct debug_type
*kconst
;
128 /* DEBUG_KIND_VOLATILE. */
129 struct debug_type
*kvolatile
;
130 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
131 struct debug_named_type
*knamed
;
135 /* Information kept for an indirect type. */
137 struct debug_indirect_type
139 /* Slot where the final type will appear. */
145 /* Information kept for a struct, union, or class. */
147 struct debug_class_type
149 /* NULL terminated array of fields. */
151 /* A mark field used to avoid recursively printing out structs. */
153 /* The remaining fields are only used for DEBUG_KIND_CLASS and
154 DEBUG_KIND_UNION_CLASS. */
155 /* NULL terminated array of base classes. */
156 debug_baseclass
*baseclasses
;
157 /* NULL terminated array of methods. */
158 debug_method
*methods
;
159 /* The type of the class providing the virtual function table for
160 this class. This may point to the type itself. */
164 /* Information kept for an enum. */
166 struct debug_enum_type
168 /* NULL terminated array of names. */
170 /* Array of corresponding values. */
171 bfd_signed_vma
*values
;
174 /* Information kept for a function. FIXME: We should be able to
175 record the parameter types. */
177 struct debug_function_type
180 debug_type return_type
;
183 /* Information kept for a range. */
185 struct debug_range_type
187 /* Range base type. */
190 bfd_signed_vma lower
;
192 bfd_signed_vma upper
;
195 /* Information kept for an array. */
197 struct debug_array_type
200 debug_type element_type
;
202 debug_type range_type
;
204 bfd_signed_vma lower
;
206 bfd_signed_vma upper
;
207 /* Whether this array is really a string. */
211 /* Information kept for a set. */
213 struct debug_set_type
217 /* Whether this set is really a bitstring. */
221 /* Information kept for an offset type (a based pointer). */
223 struct debug_offset_type
225 /* The type the pointer is an offset from. */
226 debug_type base_type
;
227 /* The type the pointer points to. */
228 debug_type target_type
;
231 /* Information kept for a method type. */
233 struct debug_method_type
235 /* The return type. */
236 debug_type return_type
;
237 /* The object type which this method is for. */
238 debug_type domain_type
;
239 /* A NULL terminated array of argument types. */
240 debug_type
*arg_types
;
243 /* Information kept for a named type. */
245 struct debug_named_type
248 struct debug_name
*name
;
253 /* A field in a struct or union. */
257 /* Name of the field. */
259 /* Type of the field. */
260 struct debug_type
*type
;
261 /* Visibility of the field. */
262 enum debug_visibility visibility
;
263 /* Whether this is a static member. */
264 boolean static_member
;
267 /* If static_member is false. */
270 /* Bit position of the field in the struct. */
272 /* Size of the field in bits. */
273 unsigned int bitsize
;
275 /* If static_member is true. */
278 const char *physname
;
283 /* A base class for an object. */
285 struct debug_baseclass
287 /* Type of the base class. */
288 struct debug_type
*type
;
289 /* Bit position of the base class in the object. */
291 /* Whether the base class is virtual. */
293 /* Visibility of the base class. */
294 enum debug_visibility visibility
;
297 /* A method of an object. */
301 /* The name of the method. */
303 /* A NULL terminated array of different types of variants. */
304 struct debug_method_variant
**variants
;
307 /* The variants of a method function of an object. These indicate
308 which method to run. */
310 struct debug_method_variant
312 /* The argument types of the function. */
313 const char *argtypes
;
314 /* The type of the function. */
315 struct debug_type
*type
;
316 /* The visibility of the function. */
317 enum debug_visibility visibility
;
318 /* Whether the function is const. */
320 /* Whether the function is volatile. */
322 /* The offset to the function in the virtual function table. */
324 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
325 #define VOFFSET_STATIC_METHOD (1)
326 /* Context of a virtual method function. */
327 struct debug_type
*context
;
330 /* A variable. This is the information we keep for a variable object.
331 This has no name; a name is associated with a variable in a
332 debug_name structure. */
334 struct debug_variable
336 /* Kind of variable. */
337 enum debug_var_kind kind
;
340 /* Value. The interpretation of the value depends upon kind. */
344 /* A function. This has no name; a name is associated with a function
345 in a debug_name structure. */
347 struct debug_function
350 debug_type return_type
;
351 /* Parameter information. */
352 struct debug_parameter
*parameters
;
353 /* Block information. The first structure on the list is the main
354 block of the function, and describes function local variables. */
355 struct debug_block
*blocks
;
358 /* A function parameter. */
360 struct debug_parameter
362 /* Next parameter. */
363 struct debug_parameter
*next
;
369 enum debug_parm_kind kind
;
370 /* Value (meaning depends upon kind). */
374 /* A typed constant. */
376 struct debug_typed_constant
380 /* Value. FIXME: We may eventually need to support non-integral
385 /* Information about a block within a function. */
389 /* Next block with the same parent. */
390 struct debug_block
*next
;
392 struct debug_block
*parent
;
393 /* List of child blocks. */
394 struct debug_block
*children
;
395 /* Start address of the block. */
397 /* End address of the block. */
399 /* Local variables. */
400 struct debug_namespace
*locals
;
403 /* Line number information we keep for a compilation unit. FIXME:
404 This structure is easy to create, but can be very space
409 /* More line number information for this block. */
410 struct debug_lineno
*next
;
412 struct debug_file
*file
;
413 /* Line numbers, terminated by a -1 or the end of the array. */
414 #define DEBUG_LINENO_COUNT 10
415 unsigned long linenos
[DEBUG_LINENO_COUNT
];
416 /* Addresses for the line numbers. */
417 bfd_vma addrs
[DEBUG_LINENO_COUNT
];
420 /* A namespace. This is a mapping from names to objects. FIXME: This
421 should be implemented as a hash table. */
423 struct debug_namespace
425 /* List of items in this namespace. */
426 struct debug_name
*list
;
427 /* Pointer to where the next item in this namespace should go. */
428 struct debug_name
**tail
;
431 /* Kinds of objects that appear in a namespace. */
433 enum debug_object_kind
437 /* A tagged type (really a different sort of namespace). */
440 DEBUG_OBJECT_VARIABLE
,
442 DEBUG_OBJECT_FUNCTION
,
443 /* An integer constant. */
444 DEBUG_OBJECT_INT_CONSTANT
,
445 /* A floating point constant. */
446 DEBUG_OBJECT_FLOAT_CONSTANT
,
447 /* A typed constant. */
448 DEBUG_OBJECT_TYPED_CONSTANT
451 /* Linkage of an object that appears in a namespace. */
453 enum debug_object_linkage
455 /* Local variable. */
456 DEBUG_LINKAGE_AUTOMATIC
,
457 /* Static--either file static or function static, depending upon the
459 DEBUG_LINKAGE_STATIC
,
461 DEBUG_LINKAGE_GLOBAL
,
466 /* A name in a namespace. */
470 /* Next name in this namespace. */
471 struct debug_name
*next
;
474 /* Mark. This is used by debug_write. */
476 /* Kind of object. */
477 enum debug_object_kind kind
;
478 /* Linkage of object. */
479 enum debug_object_linkage linkage
;
480 /* Tagged union with additional information about the object. */
483 /* DEBUG_OBJECT_TYPE. */
484 struct debug_type
*type
;
485 /* DEBUG_OBJECT_TAG. */
486 struct debug_type
*tag
;
487 /* DEBUG_OBJECT_VARIABLE. */
488 struct debug_variable
*variable
;
489 /* DEBUG_OBJECT_FUNCTION. */
490 struct debug_function
*function
;
491 /* DEBUG_OBJECT_INT_CONSTANT. */
492 bfd_vma int_constant
;
493 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
494 double float_constant
;
495 /* DEBUG_OBJECT_TYPED_CONSTANT. */
496 struct debug_typed_constant
*typed_constant
;
500 static void debug_error
PARAMS ((const char *));
501 static struct debug_name
*debug_add_to_namespace
502 PARAMS ((struct debug_handle
*, struct debug_namespace
**, const char *,
503 enum debug_object_kind
, enum debug_object_linkage
));
504 static struct debug_name
*debug_add_to_current_namespace
505 PARAMS ((struct debug_handle
*, const char *, enum debug_object_kind
,
506 enum debug_object_linkage
));
507 static struct debug_type
*debug_make_type
508 PARAMS ((struct debug_handle
*, enum debug_type_kind
, unsigned int));
509 static boolean debug_write_name
510 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
511 struct debug_name
*));
512 static boolean debug_write_type
513 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
514 struct debug_type
*, struct debug_name
*));
515 static boolean debug_write_class_type
516 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
517 struct debug_type
*, const char *));
518 static boolean debug_write_function
519 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
520 const char *, enum debug_object_linkage
, struct debug_function
*));
521 static boolean debug_write_block
522 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
523 struct debug_block
*));
525 /* Issue an error message. */
528 debug_error (message
)
531 fprintf (stderr
, "%s\n", message
);
534 /* Add an object to a namespace. */
536 static struct debug_name
*
537 debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
)
538 struct debug_handle
*info
;
539 struct debug_namespace
**nsp
;
541 enum debug_object_kind kind
;
542 enum debug_object_linkage linkage
;
544 struct debug_name
*n
;
545 struct debug_namespace
*ns
;
547 n
= (struct debug_name
*) xmalloc (sizeof *n
);
548 memset (n
, 0, sizeof *n
);
552 n
->linkage
= linkage
;
557 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
558 memset (ns
, 0, sizeof *ns
);
560 ns
->tail
= &ns
->list
;
571 /* Add an object to the current namespace. */
573 static struct debug_name
*
574 debug_add_to_current_namespace (info
, name
, kind
, linkage
)
575 struct debug_handle
*info
;
577 enum debug_object_kind kind
;
578 enum debug_object_linkage linkage
;
580 struct debug_namespace
**nsp
;
582 if (info
->current_unit
== NULL
583 || info
->current_file
== NULL
)
585 debug_error ("debug_add_to_current_namespace: no current file");
589 if (info
->current_block
!= NULL
)
590 nsp
= &info
->current_block
->locals
;
592 nsp
= &info
->current_file
->globals
;
594 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
597 /* Return a handle for debugging information. */
602 struct debug_handle
*ret
;
604 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
605 memset (ret
, 0, sizeof *ret
);
609 /* Set the source filename. This implicitly starts a new compilation
613 debug_set_filename (handle
, name
)
617 struct debug_handle
*info
= (struct debug_handle
*) handle
;
618 struct debug_file
*nfile
;
619 struct debug_unit
*nunit
;
624 nfile
= (struct debug_file
*) xmalloc (sizeof *nfile
);
625 memset (nfile
, 0, sizeof *nfile
);
627 nfile
->filename
= name
;
629 nunit
= (struct debug_unit
*) xmalloc (sizeof *nunit
);
630 memset (nunit
, 0, sizeof *nunit
);
632 nunit
->files
= nfile
;
633 info
->current_file
= nfile
;
635 if (info
->current_unit
!= NULL
)
636 info
->current_unit
->next
= nunit
;
639 assert (info
->units
== NULL
);
643 info
->current_unit
= nunit
;
645 info
->current_function
= NULL
;
646 info
->current_block
= NULL
;
647 info
->current_lineno
= NULL
;
652 /* Append a string to the source filename. */
655 debug_append_filename (handle
, string
)
659 struct debug_handle
*info
= (struct debug_handle
*) handle
;
665 if (info
->current_unit
== NULL
)
667 debug_error ("debug_append_filename: no current file");
671 n
= (char *) xmalloc (strlen (info
->current_unit
->files
->filename
)
674 sprintf (n
, "%s%s", info
->current_unit
->files
->filename
, string
);
675 info
->current_unit
->files
->filename
= n
;
680 /* Change source files to the given file name. This is used for
681 include files in a single compilation unit. */
684 debug_start_source (handle
, name
)
688 struct debug_handle
*info
= (struct debug_handle
*) handle
;
689 struct debug_file
*f
, **pf
;
694 if (info
->current_unit
== NULL
)
696 debug_error ("debug_start_source: no debug_set_filename call");
700 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
702 if (f
->filename
[0] == name
[0]
703 && f
->filename
[1] == name
[1]
704 && strcmp (f
->filename
, name
) == 0)
706 info
->current_file
= f
;
711 f
= (struct debug_file
*) xmalloc (sizeof *f
);
712 memset (f
, 0, sizeof *f
);
716 for (pf
= &info
->current_file
->next
;
722 info
->current_file
= f
;
727 /* Record a function definition. This implicitly starts a function
728 block. The debug_type argument is the type of the return value.
729 The boolean indicates whether the function is globally visible.
730 The bfd_vma is the address of the start of the function. Currently
731 the parameter types are specified by calls to
732 debug_record_parameter. FIXME: There is no way to specify nested
733 functions. FIXME: I don't think there is any way to record where a
737 debug_record_function (handle
, name
, return_type
, global
, addr
)
740 debug_type return_type
;
744 struct debug_handle
*info
= (struct debug_handle
*) handle
;
745 struct debug_function
*f
;
746 struct debug_block
*b
;
747 struct debug_name
*n
;
751 if (return_type
== NULL
)
754 if (info
->current_unit
== NULL
)
756 debug_error ("debug_record_function: no debug_set_filename call");
760 f
= (struct debug_function
*) xmalloc (sizeof *f
);
761 memset (f
, 0, sizeof *f
);
763 f
->return_type
= return_type
;
765 b
= (struct debug_block
*) xmalloc (sizeof *b
);
766 memset (b
, 0, sizeof *b
);
769 b
->end
= (bfd_vma
) -1;
773 info
->current_function
= f
;
774 info
->current_block
= b
;
776 /* FIXME: If we could handle nested functions, this would be the
777 place: we would want to use a different namespace. */
778 n
= debug_add_to_namespace (info
,
779 &info
->current_file
->globals
,
781 DEBUG_OBJECT_FUNCTION
,
783 ? DEBUG_LINKAGE_GLOBAL
784 : DEBUG_LINKAGE_STATIC
));
793 /* Record a parameter for the current function. */
796 debug_record_parameter (handle
, name
, type
, kind
, val
)
800 enum debug_parm_kind kind
;
803 struct debug_handle
*info
= (struct debug_handle
*) handle
;
804 struct debug_parameter
*p
, **pp
;
806 if (name
== NULL
|| type
== NULL
)
809 if (info
->current_unit
== NULL
810 || info
->current_function
== NULL
)
812 debug_error ("debug_record_parameter: no current function");
816 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
817 memset (p
, 0, sizeof *p
);
824 for (pp
= &info
->current_function
->parameters
;
833 /* End a function. FIXME: This should handle function nesting. */
836 debug_end_function (handle
, addr
)
840 struct debug_handle
*info
= (struct debug_handle
*) handle
;
842 if (info
->current_unit
== NULL
843 || info
->current_block
== NULL
844 || info
->current_function
== NULL
)
846 debug_error ("debug_end_function: no current function");
850 if (info
->current_block
->parent
!= NULL
)
852 debug_error ("debug_end_function: some blocks were not closed");
856 info
->current_block
->end
= addr
;
858 info
->current_function
= NULL
;
859 info
->current_block
= NULL
;
864 /* Start a block in a function. All local information will be
865 recorded in this block, until the matching call to debug_end_block.
866 debug_start_block and debug_end_block may be nested. The bfd_vma
867 argument is the address at which this block starts. */
870 debug_start_block (handle
, addr
)
874 struct debug_handle
*info
= (struct debug_handle
*) handle
;
875 struct debug_block
*b
, **pb
;
877 /* We must always have a current block: debug_record_function sets
879 if (info
->current_unit
== NULL
880 || info
->current_block
== NULL
)
882 debug_error ("debug_start_block: no current block");
886 b
= (struct debug_block
*) xmalloc (sizeof *b
);
887 memset (b
, 0, sizeof *b
);
889 b
->parent
= info
->current_block
;
891 b
->end
= (bfd_vma
) -1;
893 /* This new block is a child of the current block. */
894 for (pb
= &info
->current_block
->children
;
900 info
->current_block
= b
;
905 /* Finish a block in a function. This matches the call to
906 debug_start_block. The argument is the address at which this block
910 debug_end_block (handle
, addr
)
914 struct debug_handle
*info
= (struct debug_handle
*) handle
;
915 struct debug_block
*parent
;
917 if (info
->current_unit
== NULL
918 || info
->current_block
== NULL
)
920 debug_error ("debug_end_block: no current block");
924 parent
= info
->current_block
->parent
;
927 debug_error ("debug_end_block: attempt to close top level block");
931 info
->current_block
->end
= addr
;
933 info
->current_block
= parent
;
938 /* Associate a line number in the current source file and function
939 with a given address. */
942 debug_record_line (handle
, lineno
, addr
)
944 unsigned long lineno
;
947 struct debug_handle
*info
= (struct debug_handle
*) handle
;
948 struct debug_lineno
*l
;
951 if (info
->current_unit
== NULL
)
953 debug_error ("debug_record_line: no current unit");
957 l
= info
->current_lineno
;
958 if (l
!= NULL
&& l
->file
== info
->current_file
)
960 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
962 if (l
->linenos
[i
] == (unsigned long) -1)
964 l
->linenos
[i
] = lineno
;
971 /* If we get here, then either 1) there is no current_lineno
972 structure, which means this is the first line number in this
973 compilation unit, 2) the current_lineno structure is for a
974 different file, or 3) the current_lineno structure is full.
975 Regardless, we want to allocate a new debug_lineno structure, put
976 it in the right place, and make it the new current_lineno
979 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
980 memset (l
, 0, sizeof *l
);
982 l
->file
= info
->current_file
;
983 l
->linenos
[0] = lineno
;
985 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
986 l
->linenos
[i
] = (unsigned long) -1;
988 if (info
->current_lineno
!= NULL
)
989 info
->current_lineno
->next
= l
;
991 info
->current_unit
->linenos
= l
;
993 info
->current_lineno
= l
;
998 /* Start a named common block. This is a block of variables that may
1002 debug_start_common_block (handle
, name
)
1007 debug_error ("debug_start_common_block: not implemented");
1011 /* End a named common block. */
1014 debug_end_common_block (handle
, name
)
1019 debug_error ("debug_end_common_block: not implemented");
1023 /* Record a named integer constant. */
1026 debug_record_int_const (handle
, name
, val
)
1031 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1032 struct debug_name
*n
;
1037 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1038 DEBUG_LINKAGE_NONE
);
1042 n
->u
.int_constant
= val
;
1047 /* Record a named floating point constant. */
1050 debug_record_float_const (handle
, name
, val
)
1055 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1056 struct debug_name
*n
;
1061 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1062 DEBUG_LINKAGE_NONE
);
1066 n
->u
.float_constant
= val
;
1071 /* Record a typed constant with an integral value. */
1074 debug_record_typed_const (handle
, name
, type
, val
)
1080 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1081 struct debug_name
*n
;
1082 struct debug_typed_constant
*tc
;
1084 if (name
== NULL
|| type
== NULL
)
1087 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1088 DEBUG_LINKAGE_NONE
);
1092 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1093 memset (tc
, 0, sizeof *tc
);
1098 n
->u
.typed_constant
= tc
;
1103 /* Record a label. */
1106 debug_record_label (handle
, name
, type
, addr
)
1113 debug_error ("debug_record_label not implemented");
1117 /* Record a variable. */
1120 debug_record_variable (handle
, name
, type
, kind
, val
)
1124 enum debug_var_kind kind
;
1127 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1128 struct debug_namespace
**nsp
;
1129 enum debug_object_linkage linkage
;
1130 struct debug_name
*n
;
1131 struct debug_variable
*v
;
1133 if (name
== NULL
|| type
== NULL
)
1136 if (info
->current_unit
== NULL
1137 || info
->current_file
== NULL
)
1139 debug_error ("debug_record_variable: no current file");
1143 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1145 nsp
= &info
->current_file
->globals
;
1146 if (kind
== DEBUG_GLOBAL
)
1147 linkage
= DEBUG_LINKAGE_GLOBAL
;
1149 linkage
= DEBUG_LINKAGE_STATIC
;
1153 if (info
->current_block
== NULL
)
1155 debug_error ("debug_record_variable: no current block");
1158 nsp
= &info
->current_block
->locals
;
1159 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1162 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1166 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1167 memset (v
, 0, sizeof *v
);
1178 /* Make a type with a given kind and size. */
1181 static struct debug_type
*
1182 debug_make_type (info
, kind
, size
)
1183 struct debug_handle
*info
;
1184 enum debug_type_kind kind
;
1187 struct debug_type
*t
;
1189 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1190 memset (t
, 0, sizeof *t
);
1198 /* Make an indirect type which may be used as a placeholder for a type
1199 which is referenced before it is defined. */
1202 debug_make_indirect_type (handle
, slot
, tag
)
1207 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1208 struct debug_type
*t
;
1209 struct debug_indirect_type
*i
;
1211 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1213 return DEBUG_TYPE_NULL
;
1215 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1216 memset (i
, 0, sizeof *i
);
1226 /* Make a void type. There is only one of these. */
1229 debug_make_void_type (handle
)
1232 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1234 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1237 /* Make an integer type of a given size. The boolean argument is true
1238 if the integer is unsigned. */
1241 debug_make_int_type (handle
, size
, unsignedp
)
1246 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1247 struct debug_type
*t
;
1249 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1251 return DEBUG_TYPE_NULL
;
1253 t
->u
.kint
= unsignedp
;
1258 /* Make a floating point type of a given size. FIXME: On some
1259 platforms, like an Alpha, you probably need to be able to specify
1263 debug_make_float_type (handle
, size
)
1267 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1269 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1272 /* Make a boolean type of a given size. */
1275 debug_make_bool_type (handle
, size
)
1279 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1281 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1284 /* Make a complex type of a given size. */
1287 debug_make_complex_type (handle
, size
)
1291 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1293 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1296 /* Make a structure type. The second argument is true for a struct,
1297 false for a union. The third argument is the size of the struct.
1298 The fourth argument is a NULL terminated array of fields. */
1301 debug_make_struct_type (handle
, structp
, size
, fields
)
1305 debug_field
*fields
;
1307 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1308 struct debug_type
*t
;
1309 struct debug_class_type
*c
;
1311 t
= debug_make_type (info
,
1312 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1315 return DEBUG_TYPE_NULL
;
1317 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1318 memset (c
, 0, sizeof *c
);
1327 /* Make an object type. The first three arguments after the handle
1328 are the same as for debug_make_struct_type. The next arguments are
1329 a NULL terminated array of base classes, a NULL terminated array of
1330 methods, the type of the object holding the virtual function table
1331 if it is not this object, and a boolean which is true if this
1332 object has its own virtual function table. */
1335 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1336 methods
, vptrbase
, ownvptr
)
1340 debug_field
*fields
;
1341 debug_baseclass
*baseclasses
;
1342 debug_method
*methods
;
1343 debug_type vptrbase
;
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_CLASS
: DEBUG_KIND_UNION_CLASS
,
1354 return DEBUG_TYPE_NULL
;
1356 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1357 memset (c
, 0, sizeof *c
);
1360 c
->baseclasses
= baseclasses
;
1361 c
->methods
= methods
;
1365 c
->vptrbase
= vptrbase
;
1372 /* Make an enumeration type. The arguments are a null terminated
1373 array of strings, and an array of corresponding values. */
1376 debug_make_enum_type (handle
, names
, values
)
1379 bfd_signed_vma
*values
;
1381 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1382 struct debug_type
*t
;
1383 struct debug_enum_type
*e
;
1385 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1387 return DEBUG_TYPE_NULL
;
1389 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1390 memset (e
, 0, sizeof *e
);
1400 /* Make a pointer to a given type. */
1403 debug_make_pointer_type (handle
, type
)
1407 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1408 struct debug_type
*t
;
1411 return DEBUG_TYPE_NULL
;
1413 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1414 return type
->pointer
;
1416 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1418 return DEBUG_TYPE_NULL
;
1420 t
->u
.kpointer
= type
;
1427 /* Make a function returning a given type. FIXME: We should be able
1428 to record the parameter types. */
1431 debug_make_function_type (handle
, type
)
1435 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1436 struct debug_type
*t
;
1437 struct debug_function_type
*f
;
1440 return DEBUG_TYPE_NULL
;
1442 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1444 return DEBUG_TYPE_NULL
;
1446 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1447 memset (f
, 0, sizeof *f
);
1449 f
->return_type
= type
;
1456 /* Make a reference to a given type. */
1459 debug_make_reference_type (handle
, type
)
1463 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1464 struct debug_type
*t
;
1467 return DEBUG_TYPE_NULL
;
1469 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1471 return DEBUG_TYPE_NULL
;
1473 t
->u
.kreference
= type
;
1478 /* Make a range of a given type from a lower to an upper bound. */
1481 debug_make_range_type (handle
, type
, lower
, upper
)
1484 bfd_signed_vma lower
;
1485 bfd_signed_vma upper
;
1487 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1488 struct debug_type
*t
;
1489 struct debug_range_type
*r
;
1492 return DEBUG_TYPE_NULL
;
1494 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1496 return DEBUG_TYPE_NULL
;
1498 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1499 memset (r
, 0, sizeof *r
);
1510 /* Make an array type. The second argument is the type of an element
1511 of the array. The third argument is the type of a range of the
1512 array. The fourth and fifth argument are the lower and upper
1513 bounds, respectively. The sixth argument is true if this array is
1514 actually a string, as in C. */
1517 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1520 debug_type element_type
;
1521 debug_type range_type
;
1522 bfd_signed_vma lower
;
1523 bfd_signed_vma upper
;
1526 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1527 struct debug_type
*t
;
1528 struct debug_array_type
*a
;
1530 if (element_type
== NULL
|| range_type
== NULL
)
1531 return DEBUG_TYPE_NULL
;
1533 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1535 return DEBUG_TYPE_NULL
;
1537 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1538 memset (a
, 0, sizeof *a
);
1540 a
->element_type
= element_type
;
1541 a
->range_type
= range_type
;
1544 a
->stringp
= stringp
;
1551 /* Make a set of a given type. For example, a Pascal set type. The
1552 boolean argument is true if this set is actually a bitstring, as in
1556 debug_make_set_type (handle
, type
, bitstringp
)
1561 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1562 struct debug_type
*t
;
1563 struct debug_set_type
*s
;
1566 return DEBUG_TYPE_NULL
;
1568 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1570 return DEBUG_TYPE_NULL
;
1572 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1573 memset (s
, 0, sizeof *s
);
1576 s
->bitstringp
= bitstringp
;
1583 /* Make a type for a pointer which is relative to an object. The
1584 second argument is the type of the object to which the pointer is
1585 relative. The third argument is the type that the pointer points
1589 debug_make_offset_type (handle
, base_type
, target_type
)
1591 debug_type base_type
;
1592 debug_type target_type
;
1594 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1595 struct debug_type
*t
;
1596 struct debug_offset_type
*o
;
1598 if (base_type
== NULL
|| target_type
== NULL
)
1599 return DEBUG_TYPE_NULL
;
1601 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1603 return DEBUG_TYPE_NULL
;
1605 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1606 memset (o
, 0, sizeof *o
);
1608 o
->base_type
= base_type
;
1609 o
->target_type
= target_type
;
1616 /* Make a type for a method function. The second argument is the
1617 return type, the third argument is the domain, and the fourth
1618 argument is a NULL terminated array of argument types. */
1621 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
)
1623 debug_type return_type
;
1624 debug_type domain_type
;
1625 debug_type
*arg_types
;
1627 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1628 struct debug_type
*t
;
1629 struct debug_method_type
*m
;
1631 if (return_type
== NULL
)
1632 return DEBUG_TYPE_NULL
;
1634 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1636 return DEBUG_TYPE_NULL
;
1638 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1639 memset (m
, 0, sizeof *m
);
1641 m
->return_type
= return_type
;
1642 m
->domain_type
= domain_type
;
1643 m
->arg_types
= arg_types
;
1650 /* Make a const qualified version of a given type. */
1653 debug_make_const_type (handle
, type
)
1657 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1658 struct debug_type
*t
;
1661 return DEBUG_TYPE_NULL
;
1663 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1665 return DEBUG_TYPE_NULL
;
1672 /* Make a volatile qualified version of a given type. */
1675 debug_make_volatile_type (handle
, type
)
1679 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1680 struct debug_type
*t
;
1683 return DEBUG_TYPE_NULL
;
1685 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1687 return DEBUG_TYPE_NULL
;
1689 t
->u
.kvolatile
= type
;
1694 /* Make an undefined tagged type. For example, a struct which has
1695 been mentioned, but not defined. */
1698 debug_make_undefined_tagged_type (handle
, name
, kind
)
1701 enum debug_type_kind kind
;
1703 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1704 struct debug_type
*t
;
1707 return DEBUG_TYPE_NULL
;
1711 case DEBUG_KIND_STRUCT
:
1712 case DEBUG_KIND_UNION
:
1713 case DEBUG_KIND_CLASS
:
1714 case DEBUG_KIND_UNION_CLASS
:
1715 case DEBUG_KIND_ENUM
:
1719 debug_error ("debug_make_undefined_type: unsupported kind");
1720 return DEBUG_TYPE_NULL
;
1723 t
= debug_make_type (info
, kind
, 0);
1725 return DEBUG_TYPE_NULL
;
1727 return debug_tag_type (handle
, name
, t
);
1730 /* Make a base class for an object. The second argument is the base
1731 class type. The third argument is the bit position of this base
1732 class in the object (always 0 unless doing multiple inheritance).
1733 The fourth argument is whether this is a virtual class. The fifth
1734 argument is the visibility of the base class. */
1738 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1743 enum debug_visibility visibility
;
1745 struct debug_baseclass
*b
;
1747 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1748 memset (b
, 0, sizeof *b
);
1752 b
->virtual = virtual;
1753 b
->visibility
= visibility
;
1758 /* Make a field for a struct. The second argument is the name. The
1759 third argument is the type of the field. The fourth argument is
1760 the bit position of the field. The fifth argument is the size of
1761 the field (it may be zero). The sixth argument is the visibility
1766 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1772 enum debug_visibility visibility
;
1774 struct debug_field
*f
;
1776 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1777 memset (f
, 0, sizeof *f
);
1781 f
->static_member
= false;
1782 f
->u
.f
.bitpos
= bitpos
;
1783 f
->u
.f
.bitsize
= bitsize
;
1784 f
->visibility
= visibility
;
1789 /* Make a static member of an object. The second argument is the
1790 name. The third argument is the type of the member. The fourth
1791 argument is the physical name of the member (i.e., the name as a
1792 global variable). The fifth argument is the visibility of the
1797 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1801 const char *physname
;
1802 enum debug_visibility visibility
;
1804 struct debug_field
*f
;
1806 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1807 memset (f
, 0, sizeof *f
);
1811 f
->static_member
= true;
1812 f
->u
.s
.physname
= physname
;
1813 f
->visibility
= visibility
;
1818 /* Make a method. The second argument is the name, and the third
1819 argument is a NULL terminated array of method variants. */
1823 debug_make_method (handle
, name
, variants
)
1826 debug_method_variant
*variants
;
1828 struct debug_method
*m
;
1830 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1831 memset (m
, 0, sizeof *m
);
1834 m
->variants
= variants
;
1839 /* Make a method argument. The second argument is the real name of
1840 the function. The third argument is the type of the function. The
1841 fourth argument is the visibility. The fifth argument is whether
1842 this is a const function. The sixth argument is whether this is a
1843 volatile function. The seventh argument is the offset in the
1844 virtual function table, if any. The eighth argument is the virtual
1845 function context. FIXME: Are the const and volatile arguments
1846 necessary? Could we just use debug_make_const_type? */
1849 debug_method_variant
1850 debug_make_method_variant (handle
, argtypes
, type
, visibility
, constp
,
1851 volatilep
, voffset
, context
)
1853 const char *argtypes
;
1855 enum debug_visibility visibility
;
1861 struct debug_method_variant
*m
;
1863 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1864 memset (m
, 0, sizeof *m
);
1866 m
->argtypes
= argtypes
;
1868 m
->visibility
= visibility
;
1870 m
->volatilep
= volatilep
;
1871 m
->voffset
= voffset
;
1872 m
->context
= context
;
1877 /* Make a static method argument. The arguments are the same as for
1878 debug_make_method_variant, except that the last two are omitted
1879 since a static method can not also be virtual. */
1881 debug_method_variant
1882 debug_make_static_method_variant (handle
, argtypes
, type
, visibility
,
1885 const char *argtypes
;
1887 enum debug_visibility visibility
;
1891 struct debug_method_variant
*m
;
1893 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1894 memset (m
, 0, sizeof *m
);
1896 m
->argtypes
= argtypes
;
1898 m
->visibility
= visibility
;
1900 m
->volatilep
= volatilep
;
1901 m
->voffset
= VOFFSET_STATIC_METHOD
;
1909 debug_name_type (handle
, name
, type
)
1914 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1915 struct debug_type
*t
;
1916 struct debug_named_type
*n
;
1917 struct debug_name
*nm
;
1919 if (name
== NULL
|| type
== NULL
)
1920 return DEBUG_TYPE_NULL
;
1922 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1924 return DEBUG_TYPE_NULL
;
1926 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1927 memset (n
, 0, sizeof *n
);
1933 /* We also need to add the name to the current namespace. */
1935 nm
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPE
,
1936 DEBUG_LINKAGE_NONE
);
1950 debug_tag_type (handle
, name
, type
)
1955 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1956 struct debug_type
*t
;
1957 struct debug_named_type
*n
;
1958 struct debug_name
*nm
;
1960 if (name
== NULL
|| type
== NULL
)
1961 return DEBUG_TYPE_NULL
;
1963 if (info
->current_file
== NULL
)
1965 debug_error ("debug_tag_type: no current file");
1966 return DEBUG_TYPE_NULL
;
1969 if (type
->kind
== DEBUG_KIND_TAGGED
)
1971 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
1973 debug_error ("debug_tag_type: extra tag attempted");
1974 return DEBUG_TYPE_NULL
;
1977 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
1979 return DEBUG_TYPE_NULL
;
1981 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1982 memset (n
, 0, sizeof *n
);
1988 /* We keep a global namespace of tags for each compilation unit. I
1989 don't know if that is the right thing to do. */
1991 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1992 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2003 /* Record the size of a given type. */
2007 debug_record_type_size (handle
, type
, size
)
2012 if (type
->size
!= 0 && type
->size
!= size
)
2013 fprintf (stderr
, "Warning: changing type size from %d to %d\n",
2021 /* Find a tagged type. */
2024 debug_find_tagged_type (handle
, name
, kind
)
2027 enum debug_type_kind kind
;
2029 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2030 struct debug_unit
*u
;
2032 /* We search the globals of all the compilation units. I don't know
2033 if this is correct or not. It would be easy to change. */
2035 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2037 struct debug_file
*f
;
2039 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2041 struct debug_name
*n
;
2043 if (f
->globals
!= NULL
)
2045 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2047 if (n
->kind
== DEBUG_OBJECT_TAG
2048 && (kind
== DEBUG_KIND_VOID
2049 || n
->u
.tag
->kind
== kind
)
2050 && n
->name
[0] == name
[0]
2051 && strcmp (n
->name
, name
) == 0)
2058 return DEBUG_TYPE_NULL
;
2061 /* Get the name of a type. */
2065 debug_get_type_name (handle
, type
)
2069 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2071 if (*type
->u
.kindirect
->slot
!= NULL
)
2072 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2073 return type
->u
.kindirect
->tag
;
2075 if (type
->kind
== DEBUG_KIND_NAMED
2076 || type
->kind
== DEBUG_KIND_TAGGED
)
2077 return type
->u
.knamed
->name
->name
;
2081 /* Write out the debugging information. This is given a handle to
2082 debugging information, and a set of function pointers to call. */
2085 debug_write (handle
, fns
, fhandle
)
2087 const struct debug_write_fns
*fns
;
2090 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2091 struct debug_unit
*u
;
2093 /* We use a mark to tell whether we have already written out a
2094 particular name. We use an integer, so that we don't have to
2095 clear the mark fields if we happen to write out the same
2096 information more than once. */
2099 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2101 struct debug_file
*f
;
2103 struct debug_lineno
*l
;
2105 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2109 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2111 struct debug_name
*n
;
2117 if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2121 if (f
->globals
!= NULL
)
2123 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2125 if (! debug_write_name (info
, fns
, fhandle
, n
))
2131 for (l
= u
->linenos
; l
!= NULL
; l
= l
->next
)
2135 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
2137 if (l
->linenos
[i
] == (unsigned long) -1)
2139 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
, l
->linenos
[i
],
2149 /* Write out an element in a namespace. */
2152 debug_write_name (info
, fns
, fhandle
, n
)
2153 struct debug_handle
*info
;
2154 const struct debug_write_fns
*fns
;
2156 struct debug_name
*n
;
2158 /* The class_mark field is used to prevent recursively outputting a
2164 case DEBUG_OBJECT_TYPE
:
2165 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2166 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2169 case DEBUG_OBJECT_TAG
:
2170 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2172 return (*fns
->tag
) (fhandle
, n
->name
);
2173 case DEBUG_OBJECT_VARIABLE
:
2174 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2175 (struct debug_name
*) NULL
))
2177 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2178 n
->u
.variable
->val
);
2179 case DEBUG_OBJECT_FUNCTION
:
2180 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2181 n
->linkage
, n
->u
.function
);
2182 case DEBUG_OBJECT_INT_CONSTANT
:
2183 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2184 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2185 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2186 case DEBUG_OBJECT_TYPED_CONSTANT
:
2187 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2188 (struct debug_name
*) NULL
))
2190 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2191 n
->u
.typed_constant
->val
);
2199 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2200 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2201 are about to call typedef or tag. If the type is anything else,
2202 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2203 points to this one. */
2206 debug_write_type (info
, fns
, fhandle
, type
, name
)
2207 struct debug_handle
*info
;
2208 const struct debug_write_fns
*fns
;
2210 struct debug_type
*type
;
2211 struct debug_name
*name
;
2216 /* If we have a name for this type, just output it. We only output
2217 typedef names after they have been defined. We output type tags
2218 whenever we are not actually defining them. */
2219 if ((type
->kind
== DEBUG_KIND_NAMED
2220 || type
->kind
== DEBUG_KIND_TAGGED
)
2221 && (type
->u
.knamed
->name
->mark
== info
->mark
2222 || (type
->kind
== DEBUG_KIND_TAGGED
2223 && type
->u
.knamed
->name
!= name
)))
2225 if (type
->kind
== DEBUG_KIND_NAMED
)
2226 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2228 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
,
2229 type
->u
.knamed
->type
->kind
);
2232 /* Mark the name after we have already looked for a known name, so
2233 that we don't just define a type in terms of itself. We need to
2234 mark the name here so that a struct containing a pointer to
2235 itself will work. */
2237 name
->mark
= info
->mark
;
2241 && type
->kind
!= DEBUG_KIND_NAMED
2242 && type
->kind
!= DEBUG_KIND_TAGGED
)
2244 assert (name
->kind
== DEBUG_OBJECT_TAG
);
2250 case DEBUG_KIND_INDIRECT
:
2251 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2252 return (*fns
->empty_type
) (fhandle
);
2253 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2254 (struct debug_name
*) NULL
);
2255 case DEBUG_KIND_VOID
:
2256 return (*fns
->void_type
) (fhandle
);
2257 case DEBUG_KIND_INT
:
2258 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2259 case DEBUG_KIND_FLOAT
:
2260 return (*fns
->float_type
) (fhandle
, type
->size
);
2261 case DEBUG_KIND_COMPLEX
:
2262 return (*fns
->complex_type
) (fhandle
, type
->size
);
2263 case DEBUG_KIND_BOOL
:
2264 return (*fns
->bool_type
) (fhandle
, type
->size
);
2265 case DEBUG_KIND_STRUCT
:
2266 case DEBUG_KIND_UNION
:
2267 if (type
->u
.kclass
!= NULL
)
2269 if (info
->class_mark
== type
->u
.kclass
->mark
)
2271 /* We are currently outputting this struct. I don't
2272 know if this can happen, but it can happen for a
2274 return (*fns
->tag_type
) (fhandle
, "?defining?", type
->kind
);
2276 type
->u
.kclass
->mark
= info
->class_mark
;
2279 if (! (*fns
->start_struct_type
) (fhandle
, tag
,
2280 type
->kind
== DEBUG_KIND_STRUCT
,
2283 if (type
->u
.kclass
!= NULL
2284 && type
->u
.kclass
->fields
!= NULL
)
2286 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2288 struct debug_field
*f
;
2290 f
= type
->u
.kclass
->fields
[i
];
2291 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2292 (struct debug_name
*) NULL
)
2293 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2294 f
->u
.f
.bitsize
, f
->visibility
))
2298 return (*fns
->end_struct_type
) (fhandle
);
2299 case DEBUG_KIND_CLASS
:
2300 case DEBUG_KIND_UNION_CLASS
:
2301 return debug_write_class_type (info
, fns
, fhandle
, type
, tag
);
2302 case DEBUG_KIND_ENUM
:
2303 if (type
->u
.kenum
== NULL
)
2304 return (*fns
->enum_type
) (fhandle
, tag
, (const char **) NULL
,
2305 (bfd_signed_vma
*) NULL
);
2306 return (*fns
->enum_type
) (fhandle
, tag
, type
->u
.kenum
->names
,
2307 type
->u
.kenum
->values
);
2308 case DEBUG_KIND_POINTER
:
2309 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2310 (struct debug_name
*) NULL
))
2312 return (*fns
->pointer_type
) (fhandle
);
2313 case DEBUG_KIND_FUNCTION
:
2314 if (! debug_write_type (info
, fns
, fhandle
,
2315 type
->u
.kfunction
->return_type
,
2316 (struct debug_name
*) NULL
))
2318 return (*fns
->function_type
) (fhandle
);
2319 case DEBUG_KIND_REFERENCE
:
2320 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2321 (struct debug_name
*) NULL
))
2323 return (*fns
->reference_type
) (fhandle
);
2324 case DEBUG_KIND_RANGE
:
2325 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2326 (struct debug_name
*) NULL
))
2328 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2329 type
->u
.krange
->upper
);
2330 case DEBUG_KIND_ARRAY
:
2331 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2332 (struct debug_name
*) NULL
)
2333 || ! debug_write_type (info
, fns
, fhandle
,
2334 type
->u
.karray
->range_type
,
2335 (struct debug_name
*) NULL
))
2337 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2338 type
->u
.karray
->upper
,
2339 type
->u
.karray
->stringp
);
2340 case DEBUG_KIND_SET
:
2341 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2342 (struct debug_name
*) NULL
))
2344 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2345 case DEBUG_KIND_OFFSET
:
2346 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2347 (struct debug_name
*) NULL
)
2348 || ! debug_write_type (info
, fns
, fhandle
,
2349 type
->u
.koffset
->target_type
,
2350 (struct debug_name
*) NULL
))
2352 return (*fns
->offset_type
) (fhandle
);
2353 case DEBUG_KIND_METHOD
:
2354 if (! debug_write_type (info
, fns
, fhandle
,
2355 type
->u
.kmethod
->return_type
,
2356 (struct debug_name
*) NULL
))
2358 if (type
->u
.kmethod
->arg_types
== NULL
)
2362 for (i
= 0; type
->u
.kmethod
->arg_types
[i
] != NULL
; i
++)
2364 if (! debug_write_type (info
, fns
, fhandle
,
2365 type
->u
.kmethod
->arg_types
[i
],
2366 (struct debug_name
*) NULL
))
2370 if (type
->u
.kmethod
->domain_type
!= NULL
)
2372 if (! debug_write_type (info
, fns
, fhandle
,
2373 type
->u
.kmethod
->domain_type
,
2374 (struct debug_name
*) NULL
))
2377 return (*fns
->method_type
) (fhandle
,
2378 type
->u
.kmethod
->domain_type
!= NULL
,
2380 case DEBUG_KIND_CONST
:
2381 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2382 (struct debug_name
*) NULL
))
2384 return (*fns
->const_type
) (fhandle
);
2385 case DEBUG_KIND_VOLATILE
:
2386 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2387 (struct debug_name
*) NULL
))
2389 return (*fns
->volatile_type
) (fhandle
);
2390 case DEBUG_KIND_NAMED
:
2391 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2392 (struct debug_name
*) NULL
);
2393 case DEBUG_KIND_TAGGED
:
2394 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2395 type
->u
.knamed
->name
);
2402 /* Write out a class type. */
2405 debug_write_class_type (info
, fns
, fhandle
, type
, tag
)
2406 struct debug_handle
*info
;
2407 const struct debug_write_fns
*fns
;
2409 struct debug_type
*type
;
2414 if (type
->u
.kclass
!= NULL
)
2416 if (info
->class_mark
== type
->u
.kclass
->mark
)
2418 /* We are currently outputting this class. This can happen
2419 when there are methods for an anonymous class. */
2420 return (*fns
->tag_type
) (fhandle
, "?defining?", type
->kind
);
2422 type
->u
.kclass
->mark
= info
->class_mark
;
2424 if (type
->u
.kclass
->vptrbase
!= NULL
2425 && type
->u
.kclass
->vptrbase
!= type
)
2427 if (! debug_write_type (info
, fns
, fhandle
,
2428 type
->u
.kclass
->vptrbase
,
2429 (struct debug_name
*) NULL
))
2434 if (! (*fns
->start_class_type
) (fhandle
, tag
,
2435 type
->kind
== DEBUG_KIND_CLASS
,
2437 type
->u
.kclass
->vptrbase
!= NULL
,
2438 type
->u
.kclass
->vptrbase
== type
))
2441 if (type
->u
.kclass
!= NULL
)
2443 if (type
->u
.kclass
->fields
!= NULL
)
2445 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2447 struct debug_field
*f
;
2449 f
= type
->u
.kclass
->fields
[i
];
2450 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2451 (struct debug_name
*) NULL
))
2453 if (f
->static_member
)
2455 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2462 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2463 f
->u
.f
.bitsize
, f
->visibility
))
2469 if (type
->u
.kclass
->baseclasses
!= NULL
)
2471 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2473 struct debug_baseclass
*b
;
2475 b
= type
->u
.kclass
->baseclasses
[i
];
2476 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2477 (struct debug_name
*) NULL
))
2479 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2485 if (type
->u
.kclass
->methods
!= NULL
)
2487 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2489 struct debug_method
*m
;
2492 m
= type
->u
.kclass
->methods
[i
];
2493 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2495 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2497 struct debug_method_variant
*v
;
2500 if (v
->context
!= NULL
)
2502 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2503 (struct debug_name
*) NULL
))
2506 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2507 (struct debug_name
*) NULL
))
2509 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2511 if (! (*fns
->class_method_variant
) (fhandle
, v
->argtypes
,
2516 v
->context
!= NULL
))
2521 if (! (*fns
->class_static_method_variant
) (fhandle
,
2529 if (! (*fns
->class_end_method
) (fhandle
))
2535 return (*fns
->end_class_type
) (fhandle
);
2538 /* Write out information for a function. */
2541 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2542 struct debug_handle
*info
;
2543 const struct debug_write_fns
*fns
;
2546 enum debug_object_linkage linkage
;
2547 struct debug_function
*function
;
2549 struct debug_parameter
*p
;
2550 struct debug_block
*b
;
2552 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2553 (struct debug_name
*) NULL
))
2556 if (! (*fns
->start_function
) (fhandle
, name
,
2557 linkage
== DEBUG_LINKAGE_GLOBAL
))
2560 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
2562 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
2563 (struct debug_name
*) NULL
)
2564 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
2568 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2570 if (! debug_write_block (info
, fns
, fhandle
, b
))
2574 return (*fns
->end_function
) (fhandle
);
2577 /* Write out information for a block. */
2580 debug_write_block (info
, fns
, fhandle
, block
)
2581 struct debug_handle
*info
;
2582 const struct debug_write_fns
*fns
;
2584 struct debug_block
*block
;
2586 struct debug_name
*n
;
2587 struct debug_block
*b
;
2589 if (! (*fns
->start_block
) (fhandle
, block
->start
))
2592 if (block
->locals
!= NULL
)
2594 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
2596 if (! debug_write_name (info
, fns
, fhandle
, n
))
2601 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
2603 if (! debug_write_block (info
, fns
, fhandle
, b
))
2607 return (*fns
->end_block
) (fhandle
, block
->end
);