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;
1709 t = debug_make_type (info, kind, 0);
1711 return DEBUG_TYPE_NULL;
1713 return debug_tag_type (handle, name, t);
1716 /* Make a base class for an object. The second argument is the base
1717 class type. The third argument is the bit position of this base
1718 class in the object (always 0 unless doing multiple inheritance).
1719 The fourth argument is whether this is a virtual class. The fifth
1720 argument is the visibility of the base class. */
1724 debug_make_baseclass (handle, type, bitpos, virtual, visibility)
1729 enum debug_visibility visibility;
1731 struct debug_baseclass *b;
1733 b = (struct debug_baseclass *) xmalloc (sizeof *b);
1734 memset (b, 0, sizeof *b);
1738 b->virtual = virtual;
1739 b->visibility = visibility;
1744 /* Make a field for a struct. The second argument is the name. The
1745 third argument is the type of the field. The fourth argument is
1746 the bit position of the field. The fifth argument is the size of
1747 the field (it may be zero). The sixth argument is the visibility
1752 debug_make_field (handle, name, type, bitpos, bitsize, visibility)
1758 enum debug_visibility visibility;
1760 struct debug_field *f;
1762 f = (struct debug_field *) xmalloc (sizeof *f);
1763 memset (f, 0, sizeof *f);
1767 f->static_member = false;
1768 f->u.f.bitpos = bitpos;
1769 f->u.f.bitsize = bitsize;
1770 f->visibility = visibility;
1775 /* Make a static member of an object. The second argument is the
1776 name. The third argument is the type of the member. The fourth
1777 argument is the physical name of the member (i.e., the name as a
1778 global variable). The fifth argument is the visibility of the
1783 debug_make_static_member (handle, name, type, physname, visibility)
1787 const char *physname;
1788 enum debug_visibility visibility;
1790 struct debug_field *f;
1792 f = (struct debug_field *) xmalloc (sizeof *f);
1793 memset (f, 0, sizeof *f);
1797 f->static_member = true;
1798 f->u.s.physname = physname;
1799 f->visibility = visibility;
1804 /* Make a method. The second argument is the name, and the third
1805 argument is a NULL terminated array of method variants. */
1809 debug_make_method (handle, name, variants)
1812 debug_method_variant *variants;
1814 struct debug_method *m;
1816 m = (struct debug_method *) xmalloc (sizeof *m);
1817 memset (m, 0, sizeof *m);
1820 m->variants = variants;
1825 /* Make a method argument. The second argument is the real name of
1826 the function. The third argument is the type of the function. The
1827 fourth argument is the visibility. The fifth argument is whether
1828 this is a const function. The sixth argument is whether this is a
1829 volatile function. The seventh argument is the offset in the
1830 virtual function table, if any. The eighth argument is the virtual
1831 function context. FIXME: Are the const and volatile arguments
1832 necessary? Could we just use debug_make_const_type? */
1835 debug_method_variant
1836 debug_make_method_variant (handle, argtypes, type, visibility, constp,
1837 volatilep, voffset, context)
1839 const char *argtypes;
1841 enum debug_visibility visibility;
1847 struct debug_method_variant *m;
1849 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1850 memset (m, 0, sizeof *m);
1852 m->argtypes = argtypes;
1854 m->visibility = visibility;
1856 m->volatilep = volatilep;
1857 m->voffset = voffset;
1858 m->context = context;
1863 /* Make a static method argument. The arguments are the same as for
1864 debug_make_method_variant, except that the last two are omitted
1865 since a static method can not also be virtual. */
1867 debug_method_variant
1868 debug_make_static_method_variant (handle, argtypes, type, visibility,
1871 const char *argtypes;
1873 enum debug_visibility visibility;
1877 struct debug_method_variant *m;
1879 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1880 memset (m, 0, sizeof *m);
1882 m->argtypes = argtypes;
1884 m->visibility = visibility;
1886 m->volatilep = volatilep;
1887 m->voffset = VOFFSET_STATIC_METHOD;
1895 debug_name_type (handle, name, type)
1900 struct debug_handle *info = (struct debug_handle *) handle;
1901 struct debug_type *t;
1902 struct debug_named_type *n;
1903 struct debug_name *nm;
1905 if (name == NULL || type == NULL)
1906 return DEBUG_TYPE_NULL;
1908 t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1910 return DEBUG_TYPE_NULL;
1912 n = (struct debug_named_type *) xmalloc (sizeof *n);
1913 memset (n, 0, sizeof *n);
1919 /* We also need to add the name to the current namespace. */
1921 nm = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPE,
1922 DEBUG_LINKAGE_NONE);
1936 debug_tag_type (handle, name, type)
1941 struct debug_handle *info = (struct debug_handle *) handle;
1942 struct debug_type *t;
1943 struct debug_named_type *n;
1944 struct debug_name *nm;
1946 if (name == NULL || type == NULL)
1947 return DEBUG_TYPE_NULL;
1949 if (info->current_file == NULL)
1951 debug_error ("debug_tag_type: no current file");
1952 return DEBUG_TYPE_NULL;
1955 if (type->kind == DEBUG_KIND_TAGGED)
1957 if (strcmp (type->u.knamed->name->name, name) == 0)
1959 debug_error ("debug_tag_type: extra tag attempted");
1960 return DEBUG_TYPE_NULL;
1963 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
1965 return DEBUG_TYPE_NULL;
1967 n = (struct debug_named_type *) xmalloc (sizeof *n);
1968 memset (n, 0, sizeof *n);
1974 /* We keep a global namespace of tags for each compilation unit. I
1975 don't know if that is the right thing to do. */
1977 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1978 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
1989 /* Record the size of a given type. */
1993 debug_record_type_size (handle, type, size)
1998 if (type->size != 0 && type->size != size)
1999 fprintf (stderr, "Warning: changing type size from %d to %d\n",
2007 /* Find a tagged type. */
2010 debug_find_tagged_type (handle, name, kind)
2013 enum debug_type_kind kind;
2015 struct debug_handle *info = (struct debug_handle *) handle;
2016 struct debug_unit *u;
2018 /* We search the globals of all the compilation units. I don't know
2019 if this is correct or not. It would be easy to change. */
2021 for (u = info->units; u != NULL; u = u->next)
2023 struct debug_file *f;
2025 for (f = u->files; f != NULL; f = f->next)
2027 struct debug_name *n;
2029 if (f->globals != NULL)
2031 for (n = f->globals->list; n != NULL; n = n->next)
2033 if (n->kind == DEBUG_OBJECT_TAG
2034 && (kind == DEBUG_KIND_VOID
2035 || n->u.tag->kind == kind)
2036 && n->name[0] == name[0]
2037 && strcmp (n->name, name) == 0)
2044 return DEBUG_TYPE_NULL;
2047 /* Get the name of a type. */
2051 debug_get_type_name (handle, type)
2055 if (type->kind == DEBUG_KIND_INDIRECT)
2057 if (*type->u.kindirect->slot != NULL)
2058 return debug_get_type_name (handle, *type->u.kindirect->slot);
2059 return type->u.kindirect->tag;
2061 if (type->kind == DEBUG_KIND_NAMED
2062 || type->kind == DEBUG_KIND_TAGGED)
2063 return type->u.knamed->name->name;
2067 /* Write out the debugging information. This is given a handle to
2068 debugging information, and a set of function pointers to call. */
2071 debug_write (handle, fns, fhandle)
2073 const struct debug_write_fns *fns;
2076 struct debug_handle *info = (struct debug_handle *) handle;
2077 struct debug_unit *u;
2079 /* We use a mark to tell whether we have already written out a
2080 particular name. We use an integer, so that we don't have to
2081 clear the mark fields if we happen to write out the same
2082 information more than once. */
2085 for (u = info->units; u != NULL; u = u->next)
2087 struct debug_file *f;
2089 struct debug_lineno *l;
2091 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2095 for (f = u->files; f != NULL; f = f->next)
2097 struct debug_name *n;
2103 if (! (*fns->start_source) (fhandle, f->filename))
2107 if (f->globals != NULL)
2109 for (n = f->globals->list; n != NULL; n = n->next)
2111 if (! debug_write_name (info, fns, fhandle, n))
2117 for (l = u->linenos; l != NULL; l = l->next)
2121 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
2123 if (l->linenos[i] == (unsigned long) -1)
2125 if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
2135 /* Write out an element in a namespace. */
2138 debug_write_name (info, fns, fhandle, n)
2139 struct debug_handle *info;
2140 const struct debug_write_fns *fns;
2142 struct debug_name *n;
2144 /* The class_mark field is used to prevent recursively outputting a
2150 case DEBUG_OBJECT_TYPE:
2151 if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2152 || ! (*fns->typdef) (fhandle, n->name))
2155 case DEBUG_OBJECT_TAG:
2156 if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2158 return (*fns->tag) (fhandle, n->name);
2159 case DEBUG_OBJECT_VARIABLE:
2160 if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2161 (struct debug_name *) NULL))
2163 return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2164 n->u.variable->val);
2165 case DEBUG_OBJECT_FUNCTION:
2166 return debug_write_function (info, fns, fhandle, n->name,
2167 n->linkage, n->u.function);
2168 case DEBUG_OBJECT_INT_CONSTANT:
2169 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2170 case DEBUG_OBJECT_FLOAT_CONSTANT:
2171 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2172 case DEBUG_OBJECT_TYPED_CONSTANT:
2173 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2174 (struct debug_name *) NULL))
2176 return (*fns->typed_constant) (fhandle, n->name,
2177 n->u.typed_constant->val);
2185 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2186 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2187 are about to call typedef or tag. If the type is anything else,
2188 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2189 points to this one. */
2192 debug_write_type (info, fns, fhandle, type, name)
2193 struct debug_handle *info;
2194 const struct debug_write_fns *fns;
2196 struct debug_type *type;
2197 struct debug_name *name;
2202 /* If we have a name for this type, just output it. We only output
2203 typedef names after they have been defined. We output type tags
2204 whenever we are not actually defining them. */
2205 if ((type->kind == DEBUG_KIND_NAMED
2206 || type->kind == DEBUG_KIND_TAGGED)
2207 && (type->u.knamed->name->mark == info->mark
2208 || (type->kind == DEBUG_KIND_TAGGED
2209 && type->u.knamed->name != name)))
2211 if (type->kind == DEBUG_KIND_NAMED)
2212 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2214 return (*fns->tag_type) (fhandle, type->u.knamed->name->name,
2215 type->u.knamed->type->kind);
2218 /* Mark the name after we have already looked for a known name, so
2219 that we don't just define a type in terms of itself. We need to
2220 mark the name here so that a struct containing a pointer to
2221 itself will work. */
2223 name->mark = info->mark;
2227 && type->kind != DEBUG_KIND_NAMED
2228 && type->kind != DEBUG_KIND_TAGGED)
2230 assert (name->kind == DEBUG_OBJECT_TAG);
2236 case DEBUG_KIND_INDIRECT:
2237 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2238 return (*fns->empty_type) (fhandle);
2239 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2240 (struct debug_name *) NULL);
2241 case DEBUG_KIND_VOID:
2242 return (*fns->void_type) (fhandle);
2243 case DEBUG_KIND_INT:
2244 return (*fns->int_type) (fhandle, type->size, type->u.kint);
2245 case DEBUG_KIND_FLOAT:
2246 return (*fns->float_type) (fhandle, type->size);
2247 case DEBUG_KIND_COMPLEX:
2248 return (*fns->complex_type) (fhandle, type->size);
2249 case DEBUG_KIND_BOOL:
2250 return (*fns->bool_type) (fhandle, type->size);
2251 case DEBUG_KIND_STRUCT:
2252 case DEBUG_KIND_UNION:
2253 if (info->class_mark == type->u.kclass->mark)
2255 /* We are currently outputting this struct. I don't know if
2256 this can happen, but it can happen for a class. */
2257 return (*fns->tag_type) (fhandle, "?defining?", type->kind);
2259 type->u.kclass->mark = info->class_mark;
2261 if (! (*fns->start_struct_type) (fhandle, tag,
2262 type->kind == DEBUG_KIND_STRUCT,
2265 if (type->u.kclass->fields != NULL)
2267 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2269 struct debug_field *f;
2271 f = type->u.kclass->fields[i];
2272 if (! debug_write_type (info, fns, fhandle, f->type,
2273 (struct debug_name *) NULL)
2274 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2275 f->u.f.bitsize, f->visibility))
2279 return (*fns->end_struct_type) (fhandle);
2280 case DEBUG_KIND_CLASS:
2281 case DEBUG_KIND_UNION_CLASS:
2282 return debug_write_class_type (info, fns, fhandle, type, tag);
2283 case DEBUG_KIND_ENUM:
2284 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2285 type->u.kenum->values);
2286 case DEBUG_KIND_POINTER:
2287 if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2288 (struct debug_name *) NULL))
2290 return (*fns->pointer_type) (fhandle);
2291 case DEBUG_KIND_FUNCTION:
2292 if (! debug_write_type (info, fns, fhandle,
2293 type->u.kfunction->return_type,
2294 (struct debug_name *) NULL))
2296 return (*fns->function_type) (fhandle);
2297 case DEBUG_KIND_REFERENCE:
2298 if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2299 (struct debug_name *) NULL))
2301 return (*fns->reference_type) (fhandle);
2302 case DEBUG_KIND_RANGE:
2303 if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2304 (struct debug_name *) NULL))
2306 return (*fns->range_type) (fhandle, type->u.krange->lower,
2307 type->u.krange->upper);
2308 case DEBUG_KIND_ARRAY:
2309 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2310 (struct debug_name *) NULL)
2311 || ! debug_write_type (info, fns, fhandle,
2312 type->u.karray->range_type,
2313 (struct debug_name *) NULL))
2315 return (*fns->array_type) (fhandle, type->u.karray->lower,
2316 type->u.karray->upper,
2317 type->u.karray->stringp);
2318 case DEBUG_KIND_SET:
2319 if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2320 (struct debug_name *) NULL))
2322 return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2323 case DEBUG_KIND_OFFSET:
2324 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2325 (struct debug_name *) NULL)
2326 || ! debug_write_type (info, fns, fhandle,
2327 type->u.koffset->target_type,
2328 (struct debug_name *) NULL))
2330 return (*fns->offset_type) (fhandle);
2331 case DEBUG_KIND_METHOD:
2332 if (! debug_write_type (info, fns, fhandle,
2333 type->u.kmethod->return_type,
2334 (struct debug_name *) NULL))
2336 if (type->u.kmethod->arg_types == NULL)
2340 for (i = 0; type->u.kmethod->arg_types[i] != NULL; i++)
2342 if (! debug_write_type (info, fns, fhandle,
2343 type->u.kmethod->arg_types[i],
2344 (struct debug_name *) NULL))
2348 if (type->u.kmethod->domain_type != NULL)
2350 if (! debug_write_type (info, fns, fhandle,
2351 type->u.kmethod->domain_type,
2352 (struct debug_name *) NULL))
2355 return (*fns->method_type) (fhandle,
2356 type->u.kmethod->domain_type != NULL,
2358 case DEBUG_KIND_CONST:
2359 if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2360 (struct debug_name *) NULL))
2362 return (*fns->const_type) (fhandle);
2363 case DEBUG_KIND_VOLATILE:
2364 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2365 (struct debug_name *) NULL))
2367 return (*fns->volatile_type) (fhandle);
2368 case DEBUG_KIND_NAMED:
2369 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2370 (struct debug_name *) NULL);
2371 case DEBUG_KIND_TAGGED:
2372 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2373 type->u.knamed->name);
2380 /* Write out a class type. */
2383 debug_write_class_type (info, fns, fhandle, type, tag)
2384 struct debug_handle *info;
2385 const struct debug_write_fns *fns;
2387 struct debug_type *type;
2392 if (info->class_mark == type->u.kclass->mark)
2394 /* We are currently outputting this class. This can happen when
2395 there are methods for an anonymous class. */
2396 return (*fns->tag_type) (fhandle, "?defining?", type->kind);
2398 type->u.kclass->mark = info->class_mark;
2400 if (type->u.kclass->vptrbase != NULL
2401 && type->u.kclass->vptrbase != type)
2403 if (! debug_write_type (info, fns, fhandle, type->u.kclass->vptrbase,
2404 (struct debug_name *) NULL))
2408 if (! (*fns->start_class_type) (fhandle, tag,
2409 type->kind == DEBUG_KIND_CLASS,
2411 type->u.kclass->vptrbase != NULL,
2412 type->u.kclass->vptrbase == type))
2414 if (type->u.kclass->fields != NULL)
2416 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2418 struct debug_field *f;
2420 f = type->u.kclass->fields[i];
2421 if (! debug_write_type (info, fns, fhandle, f->type,
2422 (struct debug_name *) NULL))
2424 if (f->static_member)
2426 if (! (*fns->class_static_member) (fhandle, f->name,
2433 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2434 f->u.f.bitsize, f->visibility))
2440 if (type->u.kclass->baseclasses != NULL)
2442 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2444 struct debug_baseclass *b;
2446 b = type->u.kclass->baseclasses[i];
2447 if (! debug_write_type (info, fns, fhandle, b->type,
2448 (struct debug_name *) NULL))
2450 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
2456 if (type->u.kclass->methods != NULL)
2458 for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2460 struct debug_method *m;
2463 m = type->u.kclass->methods[i];
2464 if (! (*fns->class_start_method) (fhandle, m->name))
2466 for (j = 0; m->variants[j] != NULL; j++)
2468 struct debug_method_variant *v;
2471 if (v->context != NULL)
2473 if (! debug_write_type (info, fns, fhandle, v->context,
2474 (struct debug_name *) NULL))
2477 if (! debug_write_type (info, fns, fhandle, v->type,
2478 (struct debug_name *) NULL))
2480 if (v->voffset != VOFFSET_STATIC_METHOD)
2482 if (! (*fns->class_method_variant) (fhandle, v->argtypes,
2484 v->constp, v->volatilep,
2486 v->context != NULL))
2491 if (! (*fns->class_static_method_variant) (fhandle,
2499 if (! (*fns->class_end_method) (fhandle))
2504 return (*fns->end_class_type) (fhandle);
2507 /* Write out information for a function. */
2510 debug_write_function (info, fns, fhandle, name, linkage, function)
2511 struct debug_handle *info;
2512 const struct debug_write_fns *fns;
2515 enum debug_object_linkage linkage;
2516 struct debug_function *function;
2518 struct debug_parameter *p;
2519 struct debug_block *b;
2521 if (! debug_write_type (info, fns, fhandle, function->return_type,
2522 (struct debug_name *) NULL))
2525 if (! (*fns->start_function) (fhandle, name,
2526 linkage == DEBUG_LINKAGE_GLOBAL))
2529 for (p = function->parameters; p != NULL; p = p->next)
2531 if (! debug_write_type (info, fns, fhandle, p->type,
2532 (struct debug_name *) NULL)
2533 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2537 for (b = function->blocks; b != NULL; b = b->next)
2539 if (! debug_write_block (info, fns, fhandle, b))
2543 return (*fns->end_function) (fhandle);
2546 /* Write out information for a block. */
2549 debug_write_block (info, fns, fhandle, block)
2550 struct debug_handle *info;
2551 const struct debug_write_fns *fns;
2553 struct debug_block *block;
2555 struct debug_name *n;
2556 struct debug_block *b;
2558 if (! (*fns->start_block) (fhandle, block->start))
2561 if (block->locals != NULL)
2563 for (n = block->locals->list; n != NULL; n = n->next)
2565 if (! debug_write_name (info, fns, fhandle, n))
2570 for (b = block->children; b != NULL; b = b->next)
2572 if (! debug_write_block (info, fns, fhandle, b))
2576 return (*fns->end_block) (fhandle, block->end);