1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995 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 block. */
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
;
71 /* Information kept for a single source file. */
75 /* The next source file in this compilation unit. */
76 struct debug_file
*next
;
77 /* The name of the source file. */
79 /* Global functions, variables, types, etc. */
80 struct debug_namespace
*globals
;
88 enum debug_type_kind kind
;
89 /* Size of type (0 if not known). */
91 /* Type which is a pointer to this type. */
93 /* Tagged union with additional information about the type. */
96 /* DEBUG_KIND_INDIRECT. */
97 struct debug_indirect_type
*kindirect
;
99 /* Whether the integer is unsigned. */
101 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
102 DEBUG_KIND_UNION_CLASS. */
103 struct debug_class_type
*kclass
;
104 /* DEBUG_KIND_ENUM. */
105 struct debug_enum_type
*kenum
;
106 /* DEBUG_KIND_POINTER. */
107 struct debug_type
*kpointer
;
108 /* DEBUG_KIND_FUNCTION. */
109 struct debug_function_type
*kfunction
;
110 /* DEBUG_KIND_REFERENCE. */
111 struct debug_type
*kreference
;
112 /* DEBUG_KIND_RANGE. */
113 struct debug_range_type
*krange
;
114 /* DEBUG_KIND_ARRAY. */
115 struct debug_array_type
*karray
;
116 /* DEBUG_KIND_SET. */
117 struct debug_set_type
*kset
;
118 /* DEBUG_KIND_OFFSET. */
119 struct debug_offset_type
*koffset
;
120 /* DEBUG_KIND_METHOD. */
121 struct debug_method_type
*kmethod
;
122 /* DEBUG_KIND_CONST. */
123 struct debug_type
*kconst
;
124 /* DEBUG_KIND_VOLATILE. */
125 struct debug_type
*kvolatile
;
126 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
127 struct debug_named_type
*knamed
;
131 /* Information kept for an indirect type. */
133 struct debug_indirect_type
135 /* Slot where the final type will appear. */
141 /* Information kept for a struct, union, or class. */
143 struct debug_class_type
145 /* NULL terminated array of fields. */
147 /* A mark field used to avoid recursively printing out structs. */
149 /* The remaining fields are only used for DEBUG_KIND_CLASS and
150 DEBUG_KIND_UNION_CLASS. */
151 /* NULL terminated array of base classes. */
152 debug_baseclass
*baseclasses
;
153 /* NULL terminated array of methods. */
154 debug_method
*methods
;
155 /* The type of the class providing the virtual function table for
156 this class. This may point to the type itself. */
160 /* Information kept for an enum. */
162 struct debug_enum_type
164 /* NULL terminated array of names. */
166 /* Array of corresponding values. */
167 bfd_signed_vma
*values
;
170 /* Information kept for a function. FIXME: We should be able to
171 record the parameter types. */
173 struct debug_function_type
176 debug_type return_type
;
179 /* Information kept for a range. */
181 struct debug_range_type
183 /* Range base type. */
186 bfd_signed_vma lower
;
188 bfd_signed_vma upper
;
191 /* Information kept for an array. */
193 struct debug_array_type
196 debug_type element_type
;
198 debug_type range_type
;
200 bfd_signed_vma lower
;
202 bfd_signed_vma upper
;
203 /* Whether this array is really a string. */
207 /* Information kept for a set. */
209 struct debug_set_type
213 /* Whether this set is really a bitstring. */
217 /* Information kept for an offset type (a based pointer). */
219 struct debug_offset_type
221 /* The type the pointer is an offset from. */
222 debug_type base_type
;
223 /* The type the pointer points to. */
224 debug_type target_type
;
227 /* Information kept for a method type. */
229 struct debug_method_type
231 /* The return type. */
232 debug_type return_type
;
233 /* The object type which this method is for. */
234 debug_type domain_type
;
235 /* A NULL terminated array of argument types. */
236 debug_type
*arg_types
;
239 /* Information kept for a named type. */
241 struct debug_named_type
244 struct debug_name
*name
;
249 /* A field in a struct or union. */
253 /* Name of the field. */
255 /* Type of the field. */
256 struct debug_type
*type
;
257 /* Visibility of the field. */
258 enum debug_visibility visibility
;
259 /* Whether this is a static member. */
260 boolean static_member
;
263 /* If static_member is false. */
266 /* Bit position of the field in the struct. */
268 /* Size of the field in bits. */
269 unsigned int bitsize
;
271 /* If static_member is true. */
274 const char *physname
;
279 /* A base class for an object. */
281 struct debug_baseclass
283 /* Type of the base class. */
284 struct debug_type
*type
;
285 /* Bit position of the base class in the object. */
287 /* Whether the base class is virtual. */
289 /* Visibility of the base class. */
290 enum debug_visibility visibility
;
293 /* A method of an object. */
297 /* The name of the method. */
299 /* A NULL terminated array of different types of variants. */
300 struct debug_method_variant
**variants
;
303 /* The variants of a method function of an object. These indicate
304 which method to run. */
306 struct debug_method_variant
308 /* The argument types of the function. */
309 const char *argtypes
;
310 /* The type of the function. */
311 struct debug_type
*type
;
312 /* The visibility of the function. */
313 enum debug_visibility visibility
;
314 /* Whether the function is const. */
316 /* Whether the function is volatile. */
318 /* The offset to the function in the virtual function table. */
320 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
321 #define VOFFSET_STATIC_METHOD (1)
322 /* Context of a virtual method function. */
323 struct debug_type
*context
;
326 /* A variable. This is the information we keep for a variable object.
327 This has no name; a name is associated with a variable in a
328 debug_name structure. */
330 struct debug_variable
332 /* Kind of variable. */
333 enum debug_var_kind kind
;
336 /* Value. The interpretation of the value depends upon kind. */
340 /* A function. This has no name; a name is associated with a function
341 in a debug_name structure. */
343 struct debug_function
346 debug_type return_type
;
347 /* Parameter information. */
348 struct debug_parameter
*parameters
;
349 /* Block information. The first structure on the list is the main
350 block of the function, and describes function local variables. */
351 struct debug_block
*blocks
;
354 /* A function parameter. */
356 struct debug_parameter
358 /* Next parameter. */
359 struct debug_parameter
*next
;
365 enum debug_parm_kind kind
;
366 /* Value (meaning depends upon kind). */
370 /* A typed constant. */
372 struct debug_typed_constant
376 /* Value. FIXME: We may eventually need to support non-integral
381 /* Information about a block within a function. */
385 /* Next block with the same parent. */
386 struct debug_block
*next
;
388 struct debug_block
*parent
;
389 /* List of child blocks. */
390 struct debug_block
*children
;
391 /* Start address of the block. */
393 /* End address of the block. */
395 /* Local variables. */
396 struct debug_namespace
*locals
;
397 /* Line number information. */
398 struct debug_lineno
*linenos
;
401 /* Line number information we keep for a function. FIXME: This
402 structure is easy to create, but can be very space inefficient. */
406 /* More line number information for this block. */
407 struct debug_lineno
*next
;
409 struct debug_file
*file
;
410 /* Line numbers, terminated by a -1 or the end of the array. */
411 #define DEBUG_LINENO_COUNT 10
412 unsigned long linenos
[DEBUG_LINENO_COUNT
];
413 /* Addresses for the line numbers. */
414 bfd_vma addrs
[DEBUG_LINENO_COUNT
];
417 /* A namespace. This is a mapping from names to objects. FIXME: This
418 should be implemented as a hash table. */
420 struct debug_namespace
422 /* List of items in this namespace. */
423 struct debug_name
*list
;
424 /* Pointer to where the next item in this namespace should go. */
425 struct debug_name
**tail
;
428 /* Kinds of objects that appear in a namespace. */
430 enum debug_object_kind
434 /* A tagged type (really a different sort of namespace). */
437 DEBUG_OBJECT_VARIABLE
,
439 DEBUG_OBJECT_FUNCTION
,
440 /* An integer constant. */
441 DEBUG_OBJECT_INT_CONSTANT
,
442 /* A floating point constant. */
443 DEBUG_OBJECT_FLOAT_CONSTANT
,
444 /* A typed constant. */
445 DEBUG_OBJECT_TYPED_CONSTANT
448 /* Linkage of an object that appears in a namespace. */
450 enum debug_object_linkage
452 /* Local variable. */
453 DEBUG_LINKAGE_AUTOMATIC
,
454 /* Static--either file static or function static, depending upon the
456 DEBUG_LINKAGE_STATIC
,
458 DEBUG_LINKAGE_GLOBAL
,
463 /* A name in a namespace. */
467 /* Next name in this namespace. */
468 struct debug_name
*next
;
471 /* Mark. This is used by debug_write. */
473 /* Kind of object. */
474 enum debug_object_kind kind
;
475 /* Linkage of object. */
476 enum debug_object_linkage linkage
;
477 /* Tagged union with additional information about the object. */
480 /* DEBUG_OBJECT_TYPE. */
481 struct debug_type
*type
;
482 /* DEBUG_OBJECT_TAG. */
483 struct debug_type
*tag
;
484 /* DEBUG_OBJECT_VARIABLE. */
485 struct debug_variable
*variable
;
486 /* DEBUG_OBJECT_FUNCTION. */
487 struct debug_function
*function
;
488 /* DEBUG_OBJECT_INT_CONSTANT. */
489 bfd_vma int_constant
;
490 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
491 double float_constant
;
492 /* DEBUG_OBJECT_TYPED_CONSTANT. */
493 struct debug_typed_constant
*typed_constant
;
497 static void debug_error
PARAMS ((const char *));
498 static struct debug_name
*debug_add_to_namespace
499 PARAMS ((struct debug_handle
*, struct debug_namespace
**, const char *,
500 enum debug_object_kind
, enum debug_object_linkage
));
501 static struct debug_name
*debug_add_to_current_namespace
502 PARAMS ((struct debug_handle
*, const char *, enum debug_object_kind
,
503 enum debug_object_linkage
));
504 static struct debug_type
*debug_make_type
505 PARAMS ((struct debug_handle
*, enum debug_type_kind
, unsigned int));
506 static boolean debug_write_name
507 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
508 struct debug_name
*));
509 static boolean debug_write_type
510 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
511 struct debug_type
*, struct debug_name
*));
512 static boolean debug_write_class_type
513 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
514 struct debug_type
*));
515 static boolean debug_write_function
516 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
517 const char *, enum debug_object_linkage
, struct debug_function
*));
518 static boolean debug_write_block
519 PARAMS ((struct debug_handle
*, const struct debug_write_fns
*, PTR
,
520 struct debug_block
*));
522 /* Issue an error message. */
525 debug_error (message
)
528 fprintf (stderr
, "%s\n", message
);
531 /* Add an object to a namespace. */
533 static struct debug_name
*
534 debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
)
535 struct debug_handle
*info
;
536 struct debug_namespace
**nsp
;
538 enum debug_object_kind kind
;
539 enum debug_object_linkage linkage
;
541 struct debug_name
*n
;
542 struct debug_namespace
*ns
;
544 n
= (struct debug_name
*) xmalloc (sizeof *n
);
545 memset (n
, 0, sizeof *n
);
549 n
->linkage
= linkage
;
554 ns
= (struct debug_namespace
*) xmalloc (sizeof *ns
);
555 memset (ns
, 0, sizeof *ns
);
557 ns
->tail
= &ns
->list
;
568 /* Add an object to the current namespace. */
570 static struct debug_name
*
571 debug_add_to_current_namespace (info
, name
, kind
, linkage
)
572 struct debug_handle
*info
;
574 enum debug_object_kind kind
;
575 enum debug_object_linkage linkage
;
577 struct debug_namespace
**nsp
;
579 if (info
->current_unit
== NULL
580 || info
->current_file
== NULL
)
582 debug_error ("debug_add_to_current_namespace: no current file");
586 if (info
->current_block
!= NULL
)
587 nsp
= &info
->current_block
->locals
;
589 nsp
= &info
->current_file
->globals
;
591 return debug_add_to_namespace (info
, nsp
, name
, kind
, linkage
);
594 /* Return a handle for debugging information. */
599 struct debug_handle
*ret
;
601 ret
= (struct debug_handle
*) xmalloc (sizeof *ret
);
602 memset (ret
, 0, sizeof *ret
);
606 /* Set the source filename. This implicitly starts a new compilation
610 debug_set_filename (handle
, name
)
614 struct debug_handle
*info
= (struct debug_handle
*) handle
;
615 struct debug_file
*nfile
;
616 struct debug_unit
*nunit
;
621 nfile
= (struct debug_file
*) xmalloc (sizeof *nfile
);
622 memset (nfile
, 0, sizeof *nfile
);
624 nfile
->filename
= name
;
626 nunit
= (struct debug_unit
*) xmalloc (sizeof *nunit
);
627 memset (nunit
, 0, sizeof *nunit
);
629 nunit
->files
= nfile
;
630 info
->current_file
= nfile
;
632 if (info
->current_unit
!= NULL
)
633 info
->current_unit
->next
= nunit
;
636 assert (info
->units
== NULL
);
640 info
->current_unit
= nunit
;
642 info
->current_function
= NULL
;
643 info
->current_block
= NULL
;
644 info
->current_lineno
= NULL
;
649 /* Append a string to the source filename. */
652 debug_append_filename (handle
, string
)
656 struct debug_handle
*info
= (struct debug_handle
*) handle
;
662 if (info
->current_unit
== NULL
)
664 debug_error ("debug_append_filename: no current file");
668 n
= (char *) xmalloc (strlen (info
->current_unit
->files
->filename
)
671 sprintf (n
, "%s%s", info
->current_unit
->files
->filename
, string
);
672 info
->current_unit
->files
->filename
= n
;
677 /* Change source files to the given file name. This is used for
678 include files in a single compilation unit. */
681 debug_start_source (handle
, name
)
685 struct debug_handle
*info
= (struct debug_handle
*) handle
;
686 struct debug_file
*f
, **pf
;
691 if (info
->current_unit
== NULL
)
693 debug_error ("debug_start_source: no debug_set_filename call");
697 for (f
= info
->current_unit
->files
; f
!= NULL
; f
= f
->next
)
699 if (f
->filename
[0] == name
[0]
700 && f
->filename
[1] == name
[1]
701 && strcmp (f
->filename
, name
) == 0)
703 info
->current_file
= f
;
708 f
= (struct debug_file
*) xmalloc (sizeof *f
);
709 memset (f
, 0, sizeof *f
);
713 for (pf
= &info
->current_file
->next
;
719 info
->current_file
= f
;
724 /* Record a function definition. This implicitly starts a function
725 block. The debug_type argument is the type of the return value.
726 The boolean indicates whether the function is globally visible.
727 The bfd_vma is the address of the start of the function. Currently
728 the parameter types are specified by calls to
729 debug_record_parameter. FIXME: There is no way to specify nested
730 functions. FIXME: I don't think there is any way to record where a
734 debug_record_function (handle
, name
, return_type
, global
, addr
)
737 debug_type return_type
;
741 struct debug_handle
*info
= (struct debug_handle
*) handle
;
742 struct debug_function
*f
;
743 struct debug_block
*b
;
744 struct debug_name
*n
;
748 if (return_type
== NULL
)
751 if (info
->current_unit
== NULL
)
753 debug_error ("debug_record_function: no debug_set_filename call");
757 f
= (struct debug_function
*) xmalloc (sizeof *f
);
758 memset (f
, 0, sizeof *f
);
760 f
->return_type
= return_type
;
762 b
= (struct debug_block
*) xmalloc (sizeof *b
);
763 memset (b
, 0, sizeof *b
);
766 b
->end
= (bfd_vma
) -1;
770 info
->current_function
= f
;
771 info
->current_block
= b
;
772 info
->current_lineno
= NULL
;
774 /* FIXME: If we could handle nested functions, this would be the
775 place: we would want to use a different namespace. */
776 n
= debug_add_to_namespace (info
,
777 &info
->current_file
->globals
,
779 DEBUG_OBJECT_FUNCTION
,
781 ? DEBUG_LINKAGE_GLOBAL
782 : DEBUG_LINKAGE_STATIC
));
791 /* Record a parameter for the current function. */
794 debug_record_parameter (handle
, name
, type
, kind
, val
)
798 enum debug_parm_kind kind
;
801 struct debug_handle
*info
= (struct debug_handle
*) handle
;
802 struct debug_parameter
*p
, **pp
;
804 if (name
== NULL
|| type
== NULL
)
807 if (info
->current_unit
== NULL
808 || info
->current_function
== NULL
)
810 debug_error ("debug_record_parameter: no current function");
814 p
= (struct debug_parameter
*) xmalloc (sizeof *p
);
815 memset (p
, 0, sizeof *p
);
822 for (pp
= &info
->current_function
->parameters
;
831 /* End a function. FIXME: This should handle function nesting. */
834 debug_end_function (handle
, addr
)
838 struct debug_handle
*info
= (struct debug_handle
*) handle
;
840 if (info
->current_unit
== NULL
841 || info
->current_block
== NULL
842 || info
->current_function
== NULL
)
844 debug_error ("debug_end_function: no current function");
848 if (info
->current_block
->parent
!= NULL
)
850 debug_error ("debug_end_function: some blocks were not closed");
854 info
->current_block
->end
= addr
;
856 info
->current_function
= NULL
;
857 info
->current_block
= NULL
;
858 info
->current_lineno
= NULL
;
863 /* Start a block in a function. All local information will be
864 recorded in this block, until the matching call to debug_end_block.
865 debug_start_block and debug_end_block may be nested. The bfd_vma
866 argument is the address at which this block starts. */
869 debug_start_block (handle
, addr
)
873 struct debug_handle
*info
= (struct debug_handle
*) handle
;
874 struct debug_block
*b
, **pb
;
876 /* We must always have a current block: debug_record_function sets
878 if (info
->current_unit
== NULL
879 || info
->current_block
== NULL
)
881 debug_error ("debug_start_block: no current block");
885 b
= (struct debug_block
*) xmalloc (sizeof *b
);
886 memset (b
, 0, sizeof *b
);
888 b
->parent
= info
->current_block
;
890 b
->end
= (bfd_vma
) -1;
892 /* This new block is a child of the current block. */
893 for (pb
= &info
->current_block
->children
;
899 info
->current_block
= b
;
900 info
->current_lineno
= NULL
;
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
;
934 info
->current_lineno
= NULL
;
939 /* Associate a line number in the current source file and function
940 with a given address. */
943 debug_record_line (handle
, lineno
, addr
)
945 unsigned long lineno
;
948 struct debug_handle
*info
= (struct debug_handle
*) handle
;
949 struct debug_lineno
*l
;
952 if (info
->current_unit
== NULL
953 || info
->current_block
== NULL
)
955 debug_error ("debug_record_line: no current block");
959 l
= info
->current_lineno
;
960 if (l
!= NULL
&& l
->file
== info
->current_file
)
962 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
964 if (l
->linenos
[i
] == (unsigned long) -1)
966 l
->linenos
[i
] = lineno
;
973 /* If we get here, then either 1) there is no current_lineno
974 structure, which means this is the first line number since we got
975 to this block, 2) the current_lineno structure is for a different
976 file, or 3) the current_lineno structure is full. Regardless, we
977 want to allocate a new debug_lineno structure, put it in the
978 right place, and make it the new current_lineno structure. */
980 l
= (struct debug_lineno
*) xmalloc (sizeof *l
);
981 memset (l
, 0, sizeof *l
);
983 l
->file
= info
->current_file
;
984 l
->linenos
[0] = lineno
;
986 for (i
= 1; i
< DEBUG_LINENO_COUNT
; i
++)
987 l
->linenos
[i
] = (unsigned long) -1;
989 if (info
->current_lineno
!= NULL
)
990 info
->current_lineno
->next
= l
;
993 struct debug_lineno
**pl
;
995 /* We may be back in this block after dealing with child blocks,
996 which means we may have some line number information for this
997 block even though current_lineno was NULL. */
998 for (pl
= &info
->current_block
->linenos
;
1005 info
->current_lineno
= l
;
1010 /* Start a named common block. This is a block of variables that may
1014 debug_start_common_block (handle
, name
)
1019 debug_error ("debug_start_common_block: not implemented");
1023 /* End a named common block. */
1026 debug_end_common_block (handle
, name
)
1031 debug_error ("debug_end_common_block: not implemented");
1035 /* Record a named integer constant. */
1038 debug_record_int_const (handle
, name
, val
)
1043 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1044 struct debug_name
*n
;
1049 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_INT_CONSTANT
,
1050 DEBUG_LINKAGE_NONE
);
1054 n
->u
.int_constant
= val
;
1059 /* Record a named floating point constant. */
1062 debug_record_float_const (handle
, name
, val
)
1067 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1068 struct debug_name
*n
;
1073 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_FLOAT_CONSTANT
,
1074 DEBUG_LINKAGE_NONE
);
1078 n
->u
.float_constant
= val
;
1083 /* Record a typed constant with an integral value. */
1086 debug_record_typed_const (handle
, name
, type
, val
)
1092 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1093 struct debug_name
*n
;
1094 struct debug_typed_constant
*tc
;
1096 if (name
== NULL
|| type
== NULL
)
1099 n
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPED_CONSTANT
,
1100 DEBUG_LINKAGE_NONE
);
1104 tc
= (struct debug_typed_constant
*) xmalloc (sizeof *tc
);
1105 memset (tc
, 0, sizeof *tc
);
1110 n
->u
.typed_constant
= tc
;
1115 /* Record a label. */
1118 debug_record_label (handle
, name
, type
, addr
)
1125 debug_error ("debug_record_label not implemented");
1129 /* Record a variable. */
1132 debug_record_variable (handle
, name
, type
, kind
, val
)
1136 enum debug_var_kind kind
;
1139 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1140 struct debug_namespace
**nsp
;
1141 enum debug_object_linkage linkage
;
1142 struct debug_name
*n
;
1143 struct debug_variable
*v
;
1145 if (name
== NULL
|| type
== NULL
)
1148 if (info
->current_unit
== NULL
1149 || info
->current_file
== NULL
)
1151 debug_error ("debug_record_variable: no current file");
1155 if (kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
1157 nsp
= &info
->current_file
->globals
;
1158 if (kind
== DEBUG_GLOBAL
)
1159 linkage
= DEBUG_LINKAGE_GLOBAL
;
1161 linkage
= DEBUG_LINKAGE_STATIC
;
1165 if (info
->current_block
== NULL
)
1167 debug_error ("debug_record_variable: no current block");
1170 nsp
= &info
->current_block
->locals
;
1171 linkage
= DEBUG_LINKAGE_AUTOMATIC
;
1174 n
= debug_add_to_namespace (info
, nsp
, name
, DEBUG_OBJECT_VARIABLE
, linkage
);
1178 v
= (struct debug_variable
*) xmalloc (sizeof *v
);
1179 memset (v
, 0, sizeof *v
);
1190 /* Make a type with a given kind and size. */
1193 static struct debug_type
*
1194 debug_make_type (info
, kind
, size
)
1195 struct debug_handle
*info
;
1196 enum debug_type_kind kind
;
1199 struct debug_type
*t
;
1201 t
= (struct debug_type
*) xmalloc (sizeof *t
);
1202 memset (t
, 0, sizeof *t
);
1210 /* Make an indirect type which may be used as a placeholder for a type
1211 which is referenced before it is defined. */
1214 debug_make_indirect_type (handle
, slot
, tag
)
1219 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1220 struct debug_type
*t
;
1221 struct debug_indirect_type
*i
;
1223 t
= debug_make_type (info
, DEBUG_KIND_INDIRECT
, 0);
1225 return DEBUG_TYPE_NULL
;
1227 i
= (struct debug_indirect_type
*) xmalloc (sizeof *i
);
1228 memset (i
, 0, sizeof *i
);
1238 /* Make a void type. There is only one of these. */
1241 debug_make_void_type (handle
)
1244 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1246 return debug_make_type (info
, DEBUG_KIND_VOID
, 0);
1249 /* Make an integer type of a given size. The boolean argument is true
1250 if the integer is unsigned. */
1253 debug_make_int_type (handle
, size
, unsignedp
)
1258 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1259 struct debug_type
*t
;
1261 t
= debug_make_type (info
, DEBUG_KIND_INT
, size
);
1263 return DEBUG_TYPE_NULL
;
1265 t
->u
.kint
= unsignedp
;
1270 /* Make a floating point type of a given size. FIXME: On some
1271 platforms, like an Alpha, you probably need to be able to specify
1275 debug_make_float_type (handle
, size
)
1279 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1281 return debug_make_type (info
, DEBUG_KIND_FLOAT
, size
);
1284 /* Make a boolean type of a given size. */
1287 debug_make_bool_type (handle
, size
)
1291 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1293 return debug_make_type (info
, DEBUG_KIND_BOOL
, size
);
1296 /* Make a complex type of a given size. */
1299 debug_make_complex_type (handle
, size
)
1303 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1305 return debug_make_type (info
, DEBUG_KIND_COMPLEX
, size
);
1308 /* Make a structure type. The second argument is true for a struct,
1309 false for a union. The third argument is the size of the struct.
1310 The fourth argument is a NULL terminated array of fields. */
1313 debug_make_struct_type (handle
, structp
, size
, fields
)
1317 debug_field
*fields
;
1319 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1320 struct debug_type
*t
;
1321 struct debug_class_type
*c
;
1323 t
= debug_make_type (info
,
1324 structp
? DEBUG_KIND_STRUCT
: DEBUG_KIND_UNION
,
1327 return DEBUG_TYPE_NULL
;
1329 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1330 memset (c
, 0, sizeof *c
);
1339 /* Make an object type. The first three arguments after the handle
1340 are the same as for debug_make_struct_type. The next arguments are
1341 a NULL terminated array of base classes, a NULL terminated array of
1342 methods, the type of the object holding the virtual function table
1343 if it is not this object, and a boolean which is true if this
1344 object has its own virtual function table. */
1347 debug_make_object_type (handle
, structp
, size
, fields
, baseclasses
,
1348 methods
, vptrbase
, ownvptr
)
1352 debug_field
*fields
;
1353 debug_baseclass
*baseclasses
;
1354 debug_method
*methods
;
1355 debug_type vptrbase
;
1358 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1359 struct debug_type
*t
;
1360 struct debug_class_type
*c
;
1362 t
= debug_make_type (info
,
1363 structp
? DEBUG_KIND_CLASS
: DEBUG_KIND_UNION_CLASS
,
1366 return DEBUG_TYPE_NULL
;
1368 c
= (struct debug_class_type
*) xmalloc (sizeof *c
);
1369 memset (c
, 0, sizeof *c
);
1372 c
->baseclasses
= baseclasses
;
1373 c
->methods
= methods
;
1377 c
->vptrbase
= vptrbase
;
1384 /* Make an enumeration type. The arguments are a null terminated
1385 array of strings, and an array of corresponding values. */
1388 debug_make_enum_type (handle
, names
, values
)
1391 bfd_signed_vma
*values
;
1393 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1394 struct debug_type
*t
;
1395 struct debug_enum_type
*e
;
1397 t
= debug_make_type (info
, DEBUG_KIND_ENUM
, 0);
1399 return DEBUG_TYPE_NULL
;
1401 e
= (struct debug_enum_type
*) xmalloc (sizeof *e
);
1402 memset (e
, 0, sizeof *e
);
1412 /* Make a pointer to a given type. */
1415 debug_make_pointer_type (handle
, type
)
1419 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1420 struct debug_type
*t
;
1423 return DEBUG_TYPE_NULL
;
1425 if (type
->pointer
!= DEBUG_TYPE_NULL
)
1426 return type
->pointer
;
1428 t
= debug_make_type (info
, DEBUG_KIND_POINTER
, 0);
1430 return DEBUG_TYPE_NULL
;
1432 t
->u
.kpointer
= type
;
1439 /* Make a function returning a given type. FIXME: We should be able
1440 to record the parameter types. */
1443 debug_make_function_type (handle
, type
)
1447 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1448 struct debug_type
*t
;
1449 struct debug_function_type
*f
;
1452 return DEBUG_TYPE_NULL
;
1454 t
= debug_make_type (info
, DEBUG_KIND_FUNCTION
, 0);
1456 return DEBUG_TYPE_NULL
;
1458 f
= (struct debug_function_type
*) xmalloc (sizeof *f
);
1459 memset (f
, 0, sizeof *f
);
1461 f
->return_type
= type
;
1468 /* Make a reference to a given type. */
1471 debug_make_reference_type (handle
, type
)
1475 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1476 struct debug_type
*t
;
1479 return DEBUG_TYPE_NULL
;
1481 t
= debug_make_type (info
, DEBUG_KIND_REFERENCE
, 0);
1483 return DEBUG_TYPE_NULL
;
1485 t
->u
.kreference
= type
;
1490 /* Make a range of a given type from a lower to an upper bound. */
1493 debug_make_range_type (handle
, type
, lower
, upper
)
1496 bfd_signed_vma lower
;
1497 bfd_signed_vma upper
;
1499 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1500 struct debug_type
*t
;
1501 struct debug_range_type
*r
;
1504 return DEBUG_TYPE_NULL
;
1506 t
= debug_make_type (info
, DEBUG_KIND_RANGE
, 0);
1508 return DEBUG_TYPE_NULL
;
1510 r
= (struct debug_range_type
*) xmalloc (sizeof *r
);
1511 memset (r
, 0, sizeof *r
);
1522 /* Make an array type. The second argument is the type of an element
1523 of the array. The third argument is the type of a range of the
1524 array. The fourth and fifth argument are the lower and upper
1525 bounds, respectively. The sixth argument is true if this array is
1526 actually a string, as in C. */
1529 debug_make_array_type (handle
, element_type
, range_type
, lower
, upper
,
1532 debug_type element_type
;
1533 debug_type range_type
;
1534 bfd_signed_vma lower
;
1535 bfd_signed_vma upper
;
1538 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1539 struct debug_type
*t
;
1540 struct debug_array_type
*a
;
1542 if (element_type
== NULL
|| range_type
== NULL
)
1543 return DEBUG_TYPE_NULL
;
1545 t
= debug_make_type (info
, DEBUG_KIND_ARRAY
, 0);
1547 return DEBUG_TYPE_NULL
;
1549 a
= (struct debug_array_type
*) xmalloc (sizeof *a
);
1550 memset (a
, 0, sizeof *a
);
1552 a
->element_type
= element_type
;
1553 a
->range_type
= range_type
;
1556 a
->stringp
= stringp
;
1563 /* Make a set of a given type. For example, a Pascal set type. The
1564 boolean argument is true if this set is actually a bitstring, as in
1568 debug_make_set_type (handle
, type
, bitstringp
)
1573 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1574 struct debug_type
*t
;
1575 struct debug_set_type
*s
;
1578 return DEBUG_TYPE_NULL
;
1580 t
= debug_make_type (info
, DEBUG_KIND_SET
, 0);
1582 return DEBUG_TYPE_NULL
;
1584 s
= (struct debug_set_type
*) xmalloc (sizeof *s
);
1585 memset (s
, 0, sizeof *s
);
1588 s
->bitstringp
= bitstringp
;
1595 /* Make a type for a pointer which is relative to an object. The
1596 second argument is the type of the object to which the pointer is
1597 relative. The third argument is the type that the pointer points
1601 debug_make_offset_type (handle
, base_type
, target_type
)
1603 debug_type base_type
;
1604 debug_type target_type
;
1606 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1607 struct debug_type
*t
;
1608 struct debug_offset_type
*o
;
1610 if (base_type
== NULL
|| target_type
== NULL
)
1611 return DEBUG_TYPE_NULL
;
1613 t
= debug_make_type (info
, DEBUG_KIND_OFFSET
, 0);
1615 return DEBUG_TYPE_NULL
;
1617 o
= (struct debug_offset_type
*) xmalloc (sizeof *o
);
1618 memset (o
, 0, sizeof *o
);
1620 o
->base_type
= base_type
;
1621 o
->target_type
= target_type
;
1628 /* Make a type for a method function. The second argument is the
1629 return type, the third argument is the domain, and the fourth
1630 argument is a NULL terminated array of argument types. */
1633 debug_make_method_type (handle
, return_type
, domain_type
, arg_types
)
1635 debug_type return_type
;
1636 debug_type domain_type
;
1637 debug_type
*arg_types
;
1639 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1640 struct debug_type
*t
;
1641 struct debug_method_type
*m
;
1643 if (return_type
== NULL
)
1644 return DEBUG_TYPE_NULL
;
1646 t
= debug_make_type (info
, DEBUG_KIND_METHOD
, 0);
1648 return DEBUG_TYPE_NULL
;
1650 m
= (struct debug_method_type
*) xmalloc (sizeof *m
);
1651 memset (m
, 0, sizeof *m
);
1653 m
->return_type
= return_type
;
1654 m
->domain_type
= domain_type
;
1655 m
->arg_types
= arg_types
;
1662 /* Make a const qualified version of a given type. */
1665 debug_make_const_type (handle
, type
)
1669 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1670 struct debug_type
*t
;
1673 return DEBUG_TYPE_NULL
;
1675 t
= debug_make_type (info
, DEBUG_KIND_CONST
, 0);
1677 return DEBUG_TYPE_NULL
;
1684 /* Make a volatile qualified version of a given type. */
1687 debug_make_volatile_type (handle
, type
)
1691 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1692 struct debug_type
*t
;
1695 return DEBUG_TYPE_NULL
;
1697 t
= debug_make_type (info
, DEBUG_KIND_VOLATILE
, 0);
1699 return DEBUG_TYPE_NULL
;
1701 t
->u
.kvolatile
= type
;
1706 /* Make an undefined tagged type. For example, a struct which has
1707 been mentioned, but not defined. */
1710 debug_make_undefined_tagged_type (handle
, name
, kind
)
1713 enum debug_type_kind kind
;
1715 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1716 struct debug_type
*t
;
1719 return DEBUG_TYPE_NULL
;
1721 t
= debug_make_type (info
, kind
, 0);
1723 return DEBUG_TYPE_NULL
;
1725 return debug_tag_type (handle
, name
, t
);
1728 /* Make a base class for an object. The second argument is the base
1729 class type. The third argument is the bit position of this base
1730 class in the object (always 0 unless doing multiple inheritance).
1731 The fourth argument is whether this is a virtual class. The fifth
1732 argument is the visibility of the base class. */
1736 debug_make_baseclass (handle
, type
, bitpos
, virtual, visibility
)
1741 enum debug_visibility visibility
;
1743 struct debug_baseclass
*b
;
1745 b
= (struct debug_baseclass
*) xmalloc (sizeof *b
);
1746 memset (b
, 0, sizeof *b
);
1750 b
->virtual = virtual;
1751 b
->visibility
= visibility
;
1756 /* Make a field for a struct. The second argument is the name. The
1757 third argument is the type of the field. The fourth argument is
1758 the bit position of the field. The fifth argument is the size of
1759 the field (it may be zero). The sixth argument is the visibility
1764 debug_make_field (handle
, name
, type
, bitpos
, bitsize
, visibility
)
1770 enum debug_visibility visibility
;
1772 struct debug_field
*f
;
1774 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1775 memset (f
, 0, sizeof *f
);
1779 f
->static_member
= false;
1780 f
->u
.f
.bitpos
= bitpos
;
1781 f
->u
.f
.bitsize
= bitsize
;
1782 f
->visibility
= visibility
;
1787 /* Make a static member of an object. The second argument is the
1788 name. The third argument is the type of the member. The fourth
1789 argument is the physical name of the member (i.e., the name as a
1790 global variable). The fifth argument is the visibility of the
1795 debug_make_static_member (handle
, name
, type
, physname
, visibility
)
1799 const char *physname
;
1800 enum debug_visibility visibility
;
1802 struct debug_field
*f
;
1804 f
= (struct debug_field
*) xmalloc (sizeof *f
);
1805 memset (f
, 0, sizeof *f
);
1809 f
->static_member
= true;
1810 f
->u
.s
.physname
= physname
;
1811 f
->visibility
= visibility
;
1816 /* Make a method. The second argument is the name, and the third
1817 argument is a NULL terminated array of method variants. */
1821 debug_make_method (handle
, name
, variants
)
1824 debug_method_variant
*variants
;
1826 struct debug_method
*m
;
1828 m
= (struct debug_method
*) xmalloc (sizeof *m
);
1829 memset (m
, 0, sizeof *m
);
1832 m
->variants
= variants
;
1837 /* Make a method argument. The second argument is the real name of
1838 the function. The third argument is the type of the function. The
1839 fourth argument is the visibility. The fifth argument is whether
1840 this is a const function. The sixth argument is whether this is a
1841 volatile function. The seventh argument is the offset in the
1842 virtual function table, if any. The eighth argument is the virtual
1843 function context. FIXME: Are the const and volatile arguments
1844 necessary? Could we just use debug_make_const_type? */
1847 debug_method_variant
1848 debug_make_method_variant (handle
, argtypes
, type
, visibility
, constp
,
1849 volatilep
, voffset
, context
)
1851 const char *argtypes
;
1853 enum debug_visibility visibility
;
1859 struct debug_method_variant
*m
;
1861 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1862 memset (m
, 0, sizeof *m
);
1864 m
->argtypes
= argtypes
;
1866 m
->visibility
= visibility
;
1868 m
->volatilep
= volatilep
;
1869 m
->voffset
= voffset
;
1870 m
->context
= context
;
1875 /* Make a static method argument. The arguments are the same as for
1876 debug_make_method_variant, except that the last two are omitted
1877 since a static method can not also be virtual. */
1879 debug_method_variant
1880 debug_make_static_method_variant (handle
, argtypes
, type
, visibility
,
1883 const char *argtypes
;
1885 enum debug_visibility visibility
;
1889 struct debug_method_variant
*m
;
1891 m
= (struct debug_method_variant
*) xmalloc (sizeof *m
);
1892 memset (m
, 0, sizeof *m
);
1894 m
->argtypes
= argtypes
;
1896 m
->visibility
= visibility
;
1898 m
->volatilep
= volatilep
;
1899 m
->voffset
= VOFFSET_STATIC_METHOD
;
1907 debug_name_type (handle
, name
, type
)
1912 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1913 struct debug_type
*t
;
1914 struct debug_named_type
*n
;
1915 struct debug_name
*nm
;
1917 if (name
== NULL
|| type
== NULL
)
1918 return DEBUG_TYPE_NULL
;
1920 t
= debug_make_type (info
, DEBUG_KIND_NAMED
, 0);
1922 return DEBUG_TYPE_NULL
;
1924 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1925 memset (n
, 0, sizeof *n
);
1931 /* We also need to add the name to the current namespace. */
1933 nm
= debug_add_to_current_namespace (info
, name
, DEBUG_OBJECT_TYPE
,
1934 DEBUG_LINKAGE_NONE
);
1948 debug_tag_type (handle
, name
, type
)
1953 struct debug_handle
*info
= (struct debug_handle
*) handle
;
1954 struct debug_type
*t
;
1955 struct debug_named_type
*n
;
1956 struct debug_name
*nm
;
1958 if (name
== NULL
|| type
== NULL
)
1959 return DEBUG_TYPE_NULL
;
1961 if (info
->current_file
== NULL
)
1963 debug_error ("debug_tag_type: no current file");
1964 return DEBUG_TYPE_NULL
;
1967 if (type
->kind
== DEBUG_KIND_TAGGED
)
1969 if (strcmp (type
->u
.knamed
->name
->name
, name
) == 0)
1971 debug_error ("debug_tag_type: extra tag attempted");
1972 return DEBUG_TYPE_NULL
;
1975 t
= debug_make_type (info
, DEBUG_KIND_TAGGED
, 0);
1977 return DEBUG_TYPE_NULL
;
1979 n
= (struct debug_named_type
*) xmalloc (sizeof *n
);
1980 memset (n
, 0, sizeof *n
);
1986 /* We keep a global namespace of tags for each compilation unit. I
1987 don't know if that is the right thing to do. */
1989 nm
= debug_add_to_namespace (info
, &info
->current_file
->globals
, name
,
1990 DEBUG_OBJECT_TAG
, DEBUG_LINKAGE_NONE
);
2001 /* Record the size of a given type. */
2005 debug_record_type_size (handle
, type
, size
)
2010 if (type
->size
!= 0 && type
->size
!= size
)
2011 fprintf (stderr
, "Warning: changing type size from %d to %d\n",
2019 /* Find a tagged type. */
2022 debug_find_tagged_type (handle
, name
, kind
)
2025 enum debug_type_kind kind
;
2027 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2028 struct debug_unit
*u
;
2030 /* We search the globals of all the compilation units. I don't know
2031 if this is correct or not. It would be easy to change. */
2033 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2035 struct debug_file
*f
;
2037 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2039 struct debug_name
*n
;
2041 if (f
->globals
!= NULL
)
2043 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2045 if (n
->kind
== DEBUG_OBJECT_TAG
2046 && (kind
== DEBUG_KIND_VOID
2047 || n
->u
.tag
->kind
== kind
)
2048 && n
->name
[0] == name
[0]
2049 && strcmp (n
->name
, name
) == 0)
2056 return DEBUG_TYPE_NULL
;
2059 /* Get the name of a type. */
2063 debug_get_type_name (handle
, type
)
2067 if (type
->kind
== DEBUG_KIND_INDIRECT
)
2069 if (*type
->u
.kindirect
->slot
!= NULL
)
2070 return debug_get_type_name (handle
, *type
->u
.kindirect
->slot
);
2071 return type
->u
.kindirect
->tag
;
2073 if (type
->kind
== DEBUG_KIND_NAMED
2074 || type
->kind
== DEBUG_KIND_TAGGED
)
2075 return type
->u
.knamed
->name
->name
;
2079 /* Write out the debugging information. This is given a handle to
2080 debugging information, and a set of function pointers to call. */
2083 debug_write (handle
, fns
, fhandle
)
2085 const struct debug_write_fns
*fns
;
2088 struct debug_handle
*info
= (struct debug_handle
*) handle
;
2089 struct debug_unit
*u
;
2091 /* We use a mark to tell whether we have already written out a
2092 particular name. We use an integer, so that we don't have to
2093 clear the mark fields if we happen to write out the same
2094 information more than once. */
2097 for (u
= info
->units
; u
!= NULL
; u
= u
->next
)
2099 struct debug_file
*f
;
2102 if (! (*fns
->start_compilation_unit
) (fhandle
, u
->files
->filename
))
2106 for (f
= u
->files
; f
!= NULL
; f
= f
->next
)
2108 struct debug_name
*n
;
2114 if (! (*fns
->start_source
) (fhandle
, f
->filename
))
2118 if (f
->globals
!= NULL
)
2120 for (n
= f
->globals
->list
; n
!= NULL
; n
= n
->next
)
2122 if (! debug_write_name (info
, fns
, fhandle
, n
))
2132 /* Write out an element in a namespace. */
2135 debug_write_name (info
, fns
, fhandle
, n
)
2136 struct debug_handle
*info
;
2137 const struct debug_write_fns
*fns
;
2139 struct debug_name
*n
;
2141 /* The class_mark field is used to prevent recursively outputting a
2147 case DEBUG_OBJECT_TYPE
:
2148 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.type
, n
)
2149 || ! (*fns
->typdef
) (fhandle
, n
->name
))
2152 case DEBUG_OBJECT_TAG
:
2153 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.tag
, n
))
2155 return (*fns
->tag
) (fhandle
, n
->name
);
2156 case DEBUG_OBJECT_VARIABLE
:
2157 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.variable
->type
,
2158 (struct debug_name
*) NULL
))
2160 return (*fns
->variable
) (fhandle
, n
->name
, n
->u
.variable
->kind
,
2161 n
->u
.variable
->val
);
2162 case DEBUG_OBJECT_FUNCTION
:
2163 return debug_write_function (info
, fns
, fhandle
, n
->name
,
2164 n
->linkage
, n
->u
.function
);
2165 case DEBUG_OBJECT_INT_CONSTANT
:
2166 return (*fns
->int_constant
) (fhandle
, n
->name
, n
->u
.int_constant
);
2167 case DEBUG_OBJECT_FLOAT_CONSTANT
:
2168 return (*fns
->float_constant
) (fhandle
, n
->name
, n
->u
.float_constant
);
2169 case DEBUG_OBJECT_TYPED_CONSTANT
:
2170 if (! debug_write_type (info
, fns
, fhandle
, n
->u
.typed_constant
->type
,
2171 (struct debug_name
*) NULL
))
2173 return (*fns
->typed_constant
) (fhandle
, n
->name
,
2174 n
->u
.typed_constant
->val
);
2182 /* Write out a type. */
2185 debug_write_type (info
, fns
, fhandle
, type
, name
)
2186 struct debug_handle
*info
;
2187 const struct debug_write_fns
*fns
;
2189 struct debug_type
*type
;
2190 struct debug_name
*name
;
2194 /* If we have a name for this type, just output it. We only output
2195 typedef names after they have been defined. We output type tags
2196 whenever we are not actually defining them. */
2197 if ((type
->kind
== DEBUG_KIND_NAMED
2198 || type
->kind
== DEBUG_KIND_TAGGED
)
2199 && (type
->u
.knamed
->name
->mark
== info
->mark
2200 || (type
->kind
== DEBUG_KIND_TAGGED
2201 && type
->u
.knamed
->name
!= name
)))
2203 if (type
->kind
== DEBUG_KIND_NAMED
)
2204 return (*fns
->typedef_type
) (fhandle
, type
->u
.knamed
->name
->name
);
2206 return (*fns
->tag_type
) (fhandle
, type
->u
.knamed
->name
->name
,
2207 type
->u
.knamed
->type
->kind
);
2210 /* Mark the name after we have already looked for a known name, so
2211 that we don't just define a type in terms of itself. We need to
2212 mark the name here so that a struct containing a pointer to
2213 itself will work. */
2215 name
->mark
= info
->mark
;
2219 case DEBUG_KIND_INDIRECT
:
2220 if (*type
->u
.kindirect
->slot
== DEBUG_TYPE_NULL
)
2221 return (*fns
->empty_type
) (fhandle
);
2222 return debug_write_type (info
, fns
, fhandle
, *type
->u
.kindirect
->slot
,
2223 (struct debug_name
*) NULL
);
2224 case DEBUG_KIND_VOID
:
2225 return (*fns
->void_type
) (fhandle
);
2226 case DEBUG_KIND_INT
:
2227 return (*fns
->int_type
) (fhandle
, type
->size
, type
->u
.kint
);
2228 case DEBUG_KIND_FLOAT
:
2229 return (*fns
->float_type
) (fhandle
, type
->size
);
2230 case DEBUG_KIND_COMPLEX
:
2231 return (*fns
->complex_type
) (fhandle
, type
->size
);
2232 case DEBUG_KIND_BOOL
:
2233 return (*fns
->bool_type
) (fhandle
, type
->size
);
2234 case DEBUG_KIND_STRUCT
:
2235 case DEBUG_KIND_UNION
:
2236 if (info
->class_mark
== type
->u
.kclass
->mark
)
2238 /* We are currently outputting this struct. I don't know if
2239 this can happen, but it can happen for a class. */
2240 return (*fns
->tag_type
) (fhandle
, "?defining?", type
->kind
);
2242 type
->u
.kclass
->mark
= info
->class_mark
;
2244 if (! (*fns
->start_struct_type
) (fhandle
,
2245 type
->kind
== DEBUG_KIND_STRUCT
,
2248 if (type
->u
.kclass
->fields
!= NULL
)
2250 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2252 struct debug_field
*f
;
2254 f
= type
->u
.kclass
->fields
[i
];
2255 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2256 (struct debug_name
*) NULL
)
2257 || ! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2258 f
->u
.f
.bitsize
, f
->visibility
))
2262 return (*fns
->end_struct_type
) (fhandle
);
2263 case DEBUG_KIND_CLASS
:
2264 case DEBUG_KIND_UNION_CLASS
:
2265 return debug_write_class_type (info
, fns
, fhandle
, type
);
2266 case DEBUG_KIND_ENUM
:
2267 return (*fns
->enum_type
) (fhandle
, type
->u
.kenum
->names
,
2268 type
->u
.kenum
->values
);
2269 case DEBUG_KIND_POINTER
:
2270 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kpointer
,
2271 (struct debug_name
*) NULL
))
2273 return (*fns
->pointer_type
) (fhandle
);
2274 case DEBUG_KIND_FUNCTION
:
2275 if (! debug_write_type (info
, fns
, fhandle
,
2276 type
->u
.kfunction
->return_type
,
2277 (struct debug_name
*) NULL
))
2279 return (*fns
->function_type
) (fhandle
);
2280 case DEBUG_KIND_REFERENCE
:
2281 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kreference
,
2282 (struct debug_name
*) NULL
))
2284 return (*fns
->reference_type
) (fhandle
);
2285 case DEBUG_KIND_RANGE
:
2286 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.krange
->type
,
2287 (struct debug_name
*) NULL
))
2289 return (*fns
->range_type
) (fhandle
, type
->u
.krange
->lower
,
2290 type
->u
.krange
->upper
);
2291 case DEBUG_KIND_ARRAY
:
2292 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.karray
->element_type
,
2293 (struct debug_name
*) NULL
)
2294 || ! debug_write_type (info
, fns
, fhandle
,
2295 type
->u
.karray
->range_type
,
2296 (struct debug_name
*) NULL
))
2298 return (*fns
->array_type
) (fhandle
, type
->u
.karray
->lower
,
2299 type
->u
.karray
->upper
,
2300 type
->u
.karray
->stringp
);
2301 case DEBUG_KIND_SET
:
2302 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kset
->type
,
2303 (struct debug_name
*) NULL
))
2305 return (*fns
->set_type
) (fhandle
, type
->u
.kset
->bitstringp
);
2306 case DEBUG_KIND_OFFSET
:
2307 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.koffset
->base_type
,
2308 (struct debug_name
*) NULL
)
2309 || ! debug_write_type (info
, fns
, fhandle
,
2310 type
->u
.koffset
->target_type
,
2311 (struct debug_name
*) NULL
))
2313 return (*fns
->offset_type
) (fhandle
);
2314 case DEBUG_KIND_METHOD
:
2315 if (! debug_write_type (info
, fns
, fhandle
,
2316 type
->u
.kmethod
->return_type
,
2317 (struct debug_name
*) NULL
))
2319 if (type
->u
.kmethod
->arg_types
== NULL
)
2323 for (i
= 0; type
->u
.kmethod
->arg_types
[i
] != NULL
; i
++)
2325 if (! debug_write_type (info
, fns
, fhandle
,
2326 type
->u
.kmethod
->arg_types
[i
],
2327 (struct debug_name
*) NULL
))
2331 if (type
->u
.kmethod
->domain_type
!= NULL
)
2333 if (! debug_write_type (info
, fns
, fhandle
,
2334 type
->u
.kmethod
->domain_type
,
2335 (struct debug_name
*) NULL
))
2338 return (*fns
->method_type
) (fhandle
,
2339 type
->u
.kmethod
->domain_type
!= NULL
,
2341 case DEBUG_KIND_CONST
:
2342 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kconst
,
2343 (struct debug_name
*) NULL
))
2345 return (*fns
->const_type
) (fhandle
);
2346 case DEBUG_KIND_VOLATILE
:
2347 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kvolatile
,
2348 (struct debug_name
*) NULL
))
2350 return (*fns
->volatile_type
) (fhandle
);
2351 case DEBUG_KIND_NAMED
:
2352 case DEBUG_KIND_TAGGED
:
2353 return debug_write_type (info
, fns
, fhandle
, type
->u
.knamed
->type
,
2354 (struct debug_name
*) NULL
);
2361 /* Write out a class type. */
2364 debug_write_class_type (info
, fns
, fhandle
, type
)
2365 struct debug_handle
*info
;
2366 const struct debug_write_fns
*fns
;
2368 struct debug_type
*type
;
2372 if (info
->class_mark
== type
->u
.kclass
->mark
)
2374 /* We are currently outputting this class. This can happen when
2375 there are methods for an anonymous class. */
2376 return (*fns
->tag_type
) (fhandle
, "?defining?", type
->kind
);
2378 type
->u
.kclass
->mark
= info
->class_mark
;
2380 if (type
->u
.kclass
->vptrbase
!= NULL
2381 && type
->u
.kclass
->vptrbase
!= type
)
2383 if (! debug_write_type (info
, fns
, fhandle
, type
->u
.kclass
->vptrbase
,
2384 (struct debug_name
*) NULL
))
2388 if (! (*fns
->start_class_type
) (fhandle
,
2389 type
->kind
== DEBUG_KIND_CLASS
,
2391 type
->u
.kclass
->vptrbase
!= NULL
,
2392 type
->u
.kclass
->vptrbase
== type
))
2394 if (type
->u
.kclass
->fields
!= NULL
)
2396 for (i
= 0; type
->u
.kclass
->fields
[i
] != NULL
; i
++)
2398 struct debug_field
*f
;
2400 f
= type
->u
.kclass
->fields
[i
];
2401 if (! debug_write_type (info
, fns
, fhandle
, f
->type
,
2402 (struct debug_name
*) NULL
))
2404 if (f
->static_member
)
2406 if (! (*fns
->class_static_member
) (fhandle
, f
->name
,
2413 if (! (*fns
->struct_field
) (fhandle
, f
->name
, f
->u
.f
.bitpos
,
2414 f
->u
.f
.bitsize
, f
->visibility
))
2420 if (type
->u
.kclass
->baseclasses
!= NULL
)
2422 for (i
= 0; type
->u
.kclass
->baseclasses
[i
] != NULL
; i
++)
2424 struct debug_baseclass
*b
;
2426 b
= type
->u
.kclass
->baseclasses
[i
];
2427 if (! debug_write_type (info
, fns
, fhandle
, b
->type
,
2428 (struct debug_name
*) NULL
))
2430 if (! (*fns
->class_baseclass
) (fhandle
, b
->bitpos
, b
->virtual,
2436 if (type
->u
.kclass
->methods
!= NULL
)
2438 for (i
= 0; type
->u
.kclass
->methods
[i
] != NULL
; i
++)
2440 struct debug_method
*m
;
2443 m
= type
->u
.kclass
->methods
[i
];
2444 if (! (*fns
->class_start_method
) (fhandle
, m
->name
))
2446 for (j
= 0; m
->variants
[j
] != NULL
; j
++)
2448 struct debug_method_variant
*v
;
2451 if (v
->context
!= NULL
)
2453 if (! debug_write_type (info
, fns
, fhandle
, v
->context
,
2454 (struct debug_name
*) NULL
))
2457 if (! debug_write_type (info
, fns
, fhandle
, v
->type
,
2458 (struct debug_name
*) NULL
))
2460 if (v
->voffset
!= VOFFSET_STATIC_METHOD
)
2462 if (! (*fns
->class_method_variant
) (fhandle
, v
->argtypes
,
2464 v
->constp
, v
->volatilep
,
2466 v
->context
!= NULL
))
2471 if (! (*fns
->class_static_method_variant
) (fhandle
,
2479 if (! (*fns
->class_end_method
) (fhandle
))
2484 return (*fns
->end_class_type
) (fhandle
);
2487 /* Write out information for a function. */
2490 debug_write_function (info
, fns
, fhandle
, name
, linkage
, function
)
2491 struct debug_handle
*info
;
2492 const struct debug_write_fns
*fns
;
2495 enum debug_object_linkage linkage
;
2496 struct debug_function
*function
;
2498 struct debug_parameter
*p
;
2499 struct debug_block
*b
;
2501 if (! debug_write_type (info
, fns
, fhandle
, function
->return_type
,
2502 (struct debug_name
*) NULL
))
2505 if (! (*fns
->start_function
) (fhandle
, name
,
2506 linkage
== DEBUG_LINKAGE_GLOBAL
))
2509 for (p
= function
->parameters
; p
!= NULL
; p
= p
->next
)
2511 if (! debug_write_type (info
, fns
, fhandle
, p
->type
,
2512 (struct debug_name
*) NULL
)
2513 || ! (*fns
->function_parameter
) (fhandle
, p
->name
, p
->kind
, p
->val
))
2517 for (b
= function
->blocks
; b
!= NULL
; b
= b
->next
)
2519 if (! debug_write_block (info
, fns
, fhandle
, b
))
2523 return (*fns
->end_function
) (fhandle
);
2526 /* Write out information for a block. */
2529 debug_write_block (info
, fns
, fhandle
, block
)
2530 struct debug_handle
*info
;
2531 const struct debug_write_fns
*fns
;
2533 struct debug_block
*block
;
2535 struct debug_name
*n
;
2536 struct debug_lineno
*l
;
2537 struct debug_block
*b
;
2539 if (! (*fns
->start_block
) (fhandle
, block
->start
))
2542 if (block
->locals
!= NULL
)
2544 for (n
= block
->locals
->list
; n
!= NULL
; n
= n
->next
)
2546 if (! debug_write_name (info
, fns
, fhandle
, n
))
2551 for (l
= block
->linenos
; l
!= NULL
; l
= l
->next
)
2555 for (i
= 0; i
< DEBUG_LINENO_COUNT
; i
++)
2557 if (l
->linenos
[i
] == (unsigned long) -1)
2559 if (! (*fns
->lineno
) (fhandle
, l
->file
->filename
, l
->linenos
[i
],
2565 for (b
= block
->children
; b
!= NULL
; b
= b
->next
)
2567 if (! debug_write_block (info
, fns
, fhandle
, b
))
2571 return (*fns
->end_block
) (fhandle
, block
->end
);