1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file implements a generic debugging format. We may eventually
23 have readers which convert different formats into this generic
24 format, and writers which write it out. The initial impetus for
25 this was writing a convertor from stabs to HP IEEE-695 debugging
33 #include "libiberty.h"
36 /* Global information we keep for debugging. A pointer to this
37 structure is the debugging handle passed to all the routines. */
41 /* A linked list of compilation units. */
42 struct debug_unit *units;
43 /* The current compilation unit. */
44 struct debug_unit *current_unit;
45 /* The current source file. */
46 struct debug_file *current_file;
47 /* The current function. */
48 struct debug_function *current_function;
49 /* The current block. */
50 struct debug_block *current_block;
51 /* The current line number information for the current unit. */
52 struct debug_lineno *current_lineno;
53 /* Mark. This is used by debug_write. */
55 /* Another mark used by debug_write. */
56 unsigned int class_mark;
57 /* A struct/class ID used by debug_write. */
58 unsigned int class_id;
59 /* The base for class_id for this call to debug_write. */
63 /* Information we keep for a single compilation unit. */
67 /* The next compilation unit. */
68 struct debug_unit *next;
69 /* A list of files included in this compilation unit. The first
70 file is always the main one, and that is where the main file name
72 struct debug_file *files;
73 /* Line number information for this compilation unit. This is not
74 stored by function, because assembler code may have line number
75 information without function information. */
76 struct debug_lineno *linenos;
79 /* Information kept for a single source file. */
83 /* The next source file in this compilation unit. */
84 struct debug_file *next;
85 /* The name of the source file. */
87 /* Global functions, variables, types, etc. */
88 struct debug_namespace *globals;
96 enum debug_type_kind kind;
97 /* Size of type (0 if not known). */
99 /* Type which is a pointer to this type. */
101 /* Tagged union with additional information about the type. */
104 /* DEBUG_KIND_INDIRECT. */
105 struct debug_indirect_type *kindirect;
106 /* DEBUG_KIND_INT. */
107 /* Whether the integer is unsigned. */
109 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
110 DEBUG_KIND_UNION_CLASS. */
111 struct debug_class_type *kclass;
112 /* DEBUG_KIND_ENUM. */
113 struct debug_enum_type *kenum;
114 /* DEBUG_KIND_POINTER. */
115 struct debug_type *kpointer;
116 /* DEBUG_KIND_FUNCTION. */
117 struct debug_function_type *kfunction;
118 /* DEBUG_KIND_REFERENCE. */
119 struct debug_type *kreference;
120 /* DEBUG_KIND_RANGE. */
121 struct debug_range_type *krange;
122 /* DEBUG_KIND_ARRAY. */
123 struct debug_array_type *karray;
124 /* DEBUG_KIND_SET. */
125 struct debug_set_type *kset;
126 /* DEBUG_KIND_OFFSET. */
127 struct debug_offset_type *koffset;
128 /* DEBUG_KIND_METHOD. */
129 struct debug_method_type *kmethod;
130 /* DEBUG_KIND_CONST. */
131 struct debug_type *kconst;
132 /* DEBUG_KIND_VOLATILE. */
133 struct debug_type *kvolatile;
134 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
135 struct debug_named_type *knamed;
139 /* Information kept for an indirect type. */
141 struct debug_indirect_type
143 /* Slot where the final type will appear. */
149 /* Information kept for a struct, union, or class. */
151 struct debug_class_type
153 /* NULL terminated array of fields. */
155 /* A mark field used to avoid recursively printing out structs. */
157 /* This is used to uniquely identify unnamed structs when printing. */
159 /* The remaining fields are only used for DEBUG_KIND_CLASS and
160 DEBUG_KIND_UNION_CLASS. */
161 /* NULL terminated array of base classes. */
162 debug_baseclass *baseclasses;
163 /* NULL terminated array of methods. */
164 debug_method *methods;
165 /* The type of the class providing the virtual function table for
166 this class. This may point to the type itself. */
170 /* Information kept for an enum. */
172 struct debug_enum_type
174 /* NULL terminated array of names. */
176 /* Array of corresponding values. */
177 bfd_signed_vma *values;
180 /* Information kept for a function. FIXME: We should be able to
181 record the parameter types. */
183 struct debug_function_type
186 debug_type return_type;
189 /* Information kept for a range. */
191 struct debug_range_type
193 /* Range base type. */
196 bfd_signed_vma lower;
198 bfd_signed_vma upper;
201 /* Information kept for an array. */
203 struct debug_array_type
206 debug_type element_type;
208 debug_type range_type;
210 bfd_signed_vma lower;
212 bfd_signed_vma upper;
213 /* Whether this array is really a string. */
217 /* Information kept for a set. */
219 struct debug_set_type
223 /* Whether this set is really a bitstring. */
227 /* Information kept for an offset type (a based pointer). */
229 struct debug_offset_type
231 /* The type the pointer is an offset from. */
232 debug_type base_type;
233 /* The type the pointer points to. */
234 debug_type target_type;
237 /* Information kept for a method type. */
239 struct debug_method_type
241 /* The return type. */
242 debug_type return_type;
243 /* The object type which this method is for. */
244 debug_type domain_type;
245 /* A NULL terminated array of argument types. */
246 debug_type *arg_types;
249 /* Information kept for a named type. */
251 struct debug_named_type
254 struct debug_name *name;
259 /* A field in a struct or union. */
263 /* Name of the field. */
265 /* Type of the field. */
266 struct debug_type *type;
267 /* Visibility of the field. */
268 enum debug_visibility visibility;
269 /* Whether this is a static member. */
270 boolean static_member;
273 /* If static_member is false. */
276 /* Bit position of the field in the struct. */
278 /* Size of the field in bits. */
279 unsigned int bitsize;
281 /* If static_member is true. */
284 const char *physname;
289 /* A base class for an object. */
291 struct debug_baseclass
293 /* Type of the base class. */
294 struct debug_type *type;
295 /* Bit position of the base class in the object. */
297 /* Whether the base class is virtual. */
299 /* Visibility of the base class. */
300 enum debug_visibility visibility;
303 /* A method of an object. */
307 /* The name of the method. */
309 /* A NULL terminated array of different types of variants. */
310 struct debug_method_variant **variants;
313 /* The variants of a method function of an object. These indicate
314 which method to run. */
316 struct debug_method_variant
318 /* The physical name of the function. */
319 const char *physname;
320 /* The type of the function. */
321 struct debug_type *type;
322 /* The visibility of the function. */
323 enum debug_visibility visibility;
324 /* Whether the function is const. */
326 /* Whether the function is volatile. */
328 /* The offset to the function in the virtual function table. */
330 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
331 #define VOFFSET_STATIC_METHOD (1)
332 /* Context of a virtual method function. */
333 struct debug_type *context;
336 /* A variable. This is the information we keep for a variable object.
337 This has no name; a name is associated with a variable in a
338 debug_name structure. */
340 struct debug_variable
342 /* Kind of variable. */
343 enum debug_var_kind kind;
346 /* Value. The interpretation of the value depends upon kind. */
350 /* A function. This has no name; a name is associated with a function
351 in a debug_name structure. */
353 struct debug_function
356 debug_type return_type;
357 /* Parameter information. */
358 struct debug_parameter *parameters;
359 /* Block information. The first structure on the list is the main
360 block of the function, and describes function local variables. */
361 struct debug_block *blocks;
364 /* A function parameter. */
366 struct debug_parameter
368 /* Next parameter. */
369 struct debug_parameter *next;
375 enum debug_parm_kind kind;
376 /* Value (meaning depends upon kind). */
380 /* A typed constant. */
382 struct debug_typed_constant
386 /* Value. FIXME: We may eventually need to support non-integral
391 /* Information about a block within a function. */
395 /* Next block with the same parent. */
396 struct debug_block *next;
398 struct debug_block *parent;
399 /* List of child blocks. */
400 struct debug_block *children;
401 /* Start address of the block. */
403 /* End address of the block. */
405 /* Local variables. */
406 struct debug_namespace *locals;
409 /* Line number information we keep for a compilation unit. FIXME:
410 This structure is easy to create, but can be very space
415 /* More line number information for this block. */
416 struct debug_lineno *next;
418 struct debug_file *file;
419 /* Line numbers, terminated by a -1 or the end of the array. */
420 #define DEBUG_LINENO_COUNT 10
421 unsigned long linenos[DEBUG_LINENO_COUNT];
422 /* Addresses for the line numbers. */
423 bfd_vma addrs[DEBUG_LINENO_COUNT];
426 /* A namespace. This is a mapping from names to objects. FIXME: This
427 should be implemented as a hash table. */
429 struct debug_namespace
431 /* List of items in this namespace. */
432 struct debug_name *list;
433 /* Pointer to where the next item in this namespace should go. */
434 struct debug_name **tail;
437 /* Kinds of objects that appear in a namespace. */
439 enum debug_object_kind
443 /* A tagged type (really a different sort of namespace). */
446 DEBUG_OBJECT_VARIABLE,
448 DEBUG_OBJECT_FUNCTION,
449 /* An integer constant. */
450 DEBUG_OBJECT_INT_CONSTANT,
451 /* A floating point constant. */
452 DEBUG_OBJECT_FLOAT_CONSTANT,
453 /* A typed constant. */
454 DEBUG_OBJECT_TYPED_CONSTANT
457 /* Linkage of an object that appears in a namespace. */
459 enum debug_object_linkage
461 /* Local variable. */
462 DEBUG_LINKAGE_AUTOMATIC,
463 /* Static--either file static or function static, depending upon the
465 DEBUG_LINKAGE_STATIC,
467 DEBUG_LINKAGE_GLOBAL,
472 /* A name in a namespace. */
476 /* Next name in this namespace. */
477 struct debug_name *next;
480 /* Mark. This is used by debug_write. */
482 /* Kind of object. */
483 enum debug_object_kind kind;
484 /* Linkage of object. */
485 enum debug_object_linkage linkage;
486 /* Tagged union with additional information about the object. */
489 /* DEBUG_OBJECT_TYPE. */
490 struct debug_type *type;
491 /* DEBUG_OBJECT_TAG. */
492 struct debug_type *tag;
493 /* DEBUG_OBJECT_VARIABLE. */
494 struct debug_variable *variable;
495 /* DEBUG_OBJECT_FUNCTION. */
496 struct debug_function *function;
497 /* DEBUG_OBJECT_INT_CONSTANT. */
498 bfd_vma int_constant;
499 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
500 double float_constant;
501 /* DEBUG_OBJECT_TYPED_CONSTANT. */
502 struct debug_typed_constant *typed_constant;
506 /* This variable is an ellipsis type. The contents are not used; its
507 address is returned by debug_make_ellipsis_type, and anything which
508 needs to know whether it is dealing with an ellipsis compares
511 static const struct debug_type debug_ellipsis_type;
513 #define ELLIPSIS_P(t) ((t) == &debug_ellipsis_type)
515 /* Local functions. */
517 static void debug_error PARAMS ((const char *));
518 static struct debug_name *debug_add_to_namespace
519 PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
520 enum debug_object_kind, enum debug_object_linkage));
521 static struct debug_name *debug_add_to_current_namespace
522 PARAMS ((struct debug_handle *, const char *, enum debug_object_kind,
523 enum debug_object_linkage));
524 static struct debug_type *debug_make_type
525 PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
526 static struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type));
527 static boolean debug_write_name
528 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
529 struct debug_name *));
530 static boolean debug_write_type
531 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
532 struct debug_type *, struct debug_name *));
533 static boolean debug_write_class_type
534 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
535 struct debug_type *, const char *));
536 static boolean debug_write_function
537 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
538 const char *, enum debug_object_linkage, struct debug_function *));
539 static boolean debug_write_block
540 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
541 struct debug_block *));
543 /* Issue an error message. */
546 debug_error (message)
549 fprintf (stderr, "%s\n", message);
552 /* Add an object to a namespace. */
554 static struct debug_name *
555 debug_add_to_namespace (info, nsp, name, kind, linkage)
556 struct debug_handle *info;
557 struct debug_namespace **nsp;
559 enum debug_object_kind kind;
560 enum debug_object_linkage linkage;
562 struct debug_name *n;
563 struct debug_namespace *ns;
565 n = (struct debug_name *) xmalloc (sizeof *n);
566 memset (n, 0, sizeof *n);
570 n->linkage = linkage;
575 ns = (struct debug_namespace *) xmalloc (sizeof *ns);
576 memset (ns, 0, sizeof *ns);
578 ns->tail = &ns->list;
589 /* Add an object to the current namespace. */
591 static struct debug_name *
592 debug_add_to_current_namespace (info, name, kind, linkage)
593 struct debug_handle *info;
595 enum debug_object_kind kind;
596 enum debug_object_linkage linkage;
598 struct debug_namespace **nsp;
600 if (info->current_unit == NULL
601 || info->current_file == NULL)
603 debug_error ("debug_add_to_current_namespace: no current file");
607 if (info->current_block != NULL)
608 nsp = &info->current_block->locals;
610 nsp = &info->current_file->globals;
612 return debug_add_to_namespace (info, nsp, name, kind, linkage);
615 /* Return a handle for debugging information. */
620 struct debug_handle *ret;
622 ret = (struct debug_handle *) xmalloc (sizeof *ret);
623 memset (ret, 0, sizeof *ret);
627 /* Set the source filename. This implicitly starts a new compilation
631 debug_set_filename (handle, name)
635 struct debug_handle *info = (struct debug_handle *) handle;
636 struct debug_file *nfile;
637 struct debug_unit *nunit;
642 nfile = (struct debug_file *) xmalloc (sizeof *nfile);
643 memset (nfile, 0, sizeof *nfile);
645 nfile->filename = name;
647 nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
648 memset (nunit, 0, sizeof *nunit);
650 nunit->files = nfile;
651 info->current_file = nfile;
653 if (info->current_unit != NULL)
654 info->current_unit->next = nunit;
657 assert (info->units == NULL);
661 info->current_unit = nunit;
663 info->current_function = NULL;
664 info->current_block = NULL;
665 info->current_lineno = NULL;
670 /* Append a string to the source filename. */
673 debug_append_filename (handle, string)
677 struct debug_handle *info = (struct debug_handle *) handle;
683 if (info->current_unit == NULL)
685 debug_error ("debug_append_filename: no current file");
689 n = (char *) xmalloc (strlen (info->current_unit->files->filename)
692 sprintf (n, "%s%s", info->current_unit->files->filename, string);
693 info->current_unit->files->filename = n;
698 /* Change source files to the given file name. This is used for
699 include files in a single compilation unit. */
702 debug_start_source (handle, name)
706 struct debug_handle *info = (struct debug_handle *) handle;
707 struct debug_file *f, **pf;
712 if (info->current_unit == NULL)
714 debug_error ("debug_start_source: no debug_set_filename call");
718 for (f = info->current_unit->files; f != NULL; f = f->next)
720 if (f->filename[0] == name[0]
721 && f->filename[1] == name[1]
722 && strcmp (f->filename, name) == 0)
724 info->current_file = f;
729 f = (struct debug_file *) xmalloc (sizeof *f);
730 memset (f, 0, sizeof *f);
734 for (pf = &info->current_file->next;
740 info->current_file = f;
745 /* Record a function definition. This implicitly starts a function
746 block. The debug_type argument is the type of the return value.
747 The boolean indicates whether the function is globally visible.
748 The bfd_vma is the address of the start of the function. Currently
749 the parameter types are specified by calls to
750 debug_record_parameter. FIXME: There is no way to specify nested
751 functions. FIXME: I don't think there is any way to record where a
755 debug_record_function (handle, name, return_type, global, addr)
758 debug_type return_type;
762 struct debug_handle *info = (struct debug_handle *) handle;
763 struct debug_function *f;
764 struct debug_block *b;
765 struct debug_name *n;
769 if (return_type == NULL)
772 if (info->current_unit == NULL)
774 debug_error ("debug_record_function: no debug_set_filename call");
778 f = (struct debug_function *) xmalloc (sizeof *f);
779 memset (f, 0, sizeof *f);
781 f->return_type = return_type;
783 b = (struct debug_block *) xmalloc (sizeof *b);
784 memset (b, 0, sizeof *b);
787 b->end = (bfd_vma) -1;
791 info->current_function = f;
792 info->current_block = b;
794 /* FIXME: If we could handle nested functions, this would be the
795 place: we would want to use a different namespace. */
796 n = debug_add_to_namespace (info,
797 &info->current_file->globals,
799 DEBUG_OBJECT_FUNCTION,
801 ? DEBUG_LINKAGE_GLOBAL
802 : DEBUG_LINKAGE_STATIC));
811 /* Record a parameter for the current function. */
814 debug_record_parameter (handle, name, type, kind, val)
818 enum debug_parm_kind kind;
821 struct debug_handle *info = (struct debug_handle *) handle;
822 struct debug_parameter *p, **pp;
824 if (name == NULL || type == NULL)
827 if (info->current_unit == NULL
828 || info->current_function == NULL)
830 debug_error ("debug_record_parameter: no current function");
834 p = (struct debug_parameter *) xmalloc (sizeof *p);
835 memset (p, 0, sizeof *p);
842 for (pp = &info->current_function->parameters;
851 /* End a function. FIXME: This should handle function nesting. */
854 debug_end_function (handle, addr)
858 struct debug_handle *info = (struct debug_handle *) handle;
860 if (info->current_unit == NULL
861 || info->current_block == NULL
862 || info->current_function == NULL)
864 debug_error ("debug_end_function: no current function");
868 if (info->current_block->parent != NULL)
870 debug_error ("debug_end_function: some blocks were not closed");
874 info->current_block->end = addr;
876 info->current_function = NULL;
877 info->current_block = NULL;
882 /* Start a block in a function. All local information will be
883 recorded in this block, until the matching call to debug_end_block.
884 debug_start_block and debug_end_block may be nested. The bfd_vma
885 argument is the address at which this block starts. */
888 debug_start_block (handle, addr)
892 struct debug_handle *info = (struct debug_handle *) handle;
893 struct debug_block *b, **pb;
895 /* We must always have a current block: debug_record_function sets
897 if (info->current_unit == NULL
898 || info->current_block == NULL)
900 debug_error ("debug_start_block: no current block");
904 b = (struct debug_block *) xmalloc (sizeof *b);
905 memset (b, 0, sizeof *b);
907 b->parent = info->current_block;
909 b->end = (bfd_vma) -1;
911 /* This new block is a child of the current block. */
912 for (pb = &info->current_block->children;
918 info->current_block = b;
923 /* Finish a block in a function. This matches the call to
924 debug_start_block. The argument is the address at which this block
928 debug_end_block (handle, addr)
932 struct debug_handle *info = (struct debug_handle *) handle;
933 struct debug_block *parent;
935 if (info->current_unit == NULL
936 || info->current_block == NULL)
938 debug_error ("debug_end_block: no current block");
942 parent = info->current_block->parent;
945 debug_error ("debug_end_block: attempt to close top level block");
949 info->current_block->end = addr;
951 info->current_block = parent;
956 /* Associate a line number in the current source file and function
957 with a given address. */
960 debug_record_line (handle, lineno, addr)
962 unsigned long lineno;
965 struct debug_handle *info = (struct debug_handle *) handle;
966 struct debug_lineno *l;
969 if (info->current_unit == NULL)
971 debug_error ("debug_record_line: no current unit");
975 l = info->current_lineno;
976 if (l != NULL && l->file == info->current_file)
978 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
980 if (l->linenos[i] == (unsigned long) -1)
982 l->linenos[i] = lineno;
989 /* If we get here, then either 1) there is no current_lineno
990 structure, which means this is the first line number in this
991 compilation unit, 2) the current_lineno structure is for a
992 different file, or 3) the current_lineno structure is full.
993 Regardless, we want to allocate a new debug_lineno structure, put
994 it in the right place, and make it the new current_lineno
997 l = (struct debug_lineno *) xmalloc (sizeof *l);
998 memset (l, 0, sizeof *l);
1000 l->file = info->current_file;
1001 l->linenos[0] = lineno;
1003 for (i = 1; i < DEBUG_LINENO_COUNT; i++)
1004 l->linenos[i] = (unsigned long) -1;
1006 if (info->current_lineno != NULL)
1007 info->current_lineno->next = l;
1009 info->current_unit->linenos = l;
1011 info->current_lineno = l;
1016 /* Start a named common block. This is a block of variables that may
1020 debug_start_common_block (handle, name)
1025 debug_error ("debug_start_common_block: not implemented");
1029 /* End a named common block. */
1032 debug_end_common_block (handle, name)
1037 debug_error ("debug_end_common_block: not implemented");
1041 /* Record a named integer constant. */
1044 debug_record_int_const (handle, name, val)
1049 struct debug_handle *info = (struct debug_handle *) handle;
1050 struct debug_name *n;
1055 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
1056 DEBUG_LINKAGE_NONE);
1060 n->u.int_constant = val;
1065 /* Record a named floating point constant. */
1068 debug_record_float_const (handle, name, val)
1073 struct debug_handle *info = (struct debug_handle *) handle;
1074 struct debug_name *n;
1079 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
1080 DEBUG_LINKAGE_NONE);
1084 n->u.float_constant = val;
1089 /* Record a typed constant with an integral value. */
1092 debug_record_typed_const (handle, name, type, val)
1098 struct debug_handle *info = (struct debug_handle *) handle;
1099 struct debug_name *n;
1100 struct debug_typed_constant *tc;
1102 if (name == NULL || type == NULL)
1105 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
1106 DEBUG_LINKAGE_NONE);
1110 tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
1111 memset (tc, 0, sizeof *tc);
1116 n->u.typed_constant = tc;
1121 /* Record a label. */
1124 debug_record_label (handle, name, type, addr)
1131 debug_error ("debug_record_label not implemented");
1135 /* Record a variable. */
1138 debug_record_variable (handle, name, type, kind, val)
1142 enum debug_var_kind kind;
1145 struct debug_handle *info = (struct debug_handle *) handle;
1146 struct debug_namespace **nsp;
1147 enum debug_object_linkage linkage;
1148 struct debug_name *n;
1149 struct debug_variable *v;
1151 if (name == NULL || type == NULL)
1154 if (info->current_unit == NULL
1155 || info->current_file == NULL)
1157 debug_error ("debug_record_variable: no current file");
1161 if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
1163 nsp = &info->current_file->globals;
1164 if (kind == DEBUG_GLOBAL)
1165 linkage = DEBUG_LINKAGE_GLOBAL;
1167 linkage = DEBUG_LINKAGE_STATIC;
1171 if (info->current_block == NULL)
1173 debug_error ("debug_record_variable: no current block");
1176 nsp = &info->current_block->locals;
1177 linkage = DEBUG_LINKAGE_AUTOMATIC;
1180 n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
1184 v = (struct debug_variable *) xmalloc (sizeof *v);
1185 memset (v, 0, sizeof *v);
1196 /* Make a type with a given kind and size. */
1199 static struct debug_type *
1200 debug_make_type (info, kind, size)
1201 struct debug_handle *info;
1202 enum debug_type_kind kind;
1205 struct debug_type *t;
1207 t = (struct debug_type *) xmalloc (sizeof *t);
1208 memset (t, 0, sizeof *t);
1216 /* Make an indirect type which may be used as a placeholder for a type
1217 which is referenced before it is defined. */
1220 debug_make_indirect_type (handle, slot, tag)
1225 struct debug_handle *info = (struct debug_handle *) handle;
1226 struct debug_type *t;
1227 struct debug_indirect_type *i;
1229 t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
1231 return DEBUG_TYPE_NULL;
1233 i = (struct debug_indirect_type *) xmalloc (sizeof *i);
1234 memset (i, 0, sizeof *i);
1244 /* Make an ellipsis type. This is not a type at all, but is a marker
1245 suitable for appearing in the list of argument types passed to
1246 debug_make_method_type. It should be used to indicate a method
1247 which takes a variable number of arguments. */
1250 debug_make_ellipsis_type (handle)
1253 return (debug_type) &debug_ellipsis_type;
1256 /* Make a void type. There is only one of these. */
1259 debug_make_void_type (handle)
1262 struct debug_handle *info = (struct debug_handle *) handle;
1264 return debug_make_type (info, DEBUG_KIND_VOID, 0);
1267 /* Make an integer type of a given size. The boolean argument is true
1268 if the integer is unsigned. */
1271 debug_make_int_type (handle, size, unsignedp)
1276 struct debug_handle *info = (struct debug_handle *) handle;
1277 struct debug_type *t;
1279 t = debug_make_type (info, DEBUG_KIND_INT, size);
1281 return DEBUG_TYPE_NULL;
1283 t->u.kint = unsignedp;
1288 /* Make a floating point type of a given size. FIXME: On some
1289 platforms, like an Alpha, you probably need to be able to specify
1293 debug_make_float_type (handle, size)
1297 struct debug_handle *info = (struct debug_handle *) handle;
1299 return debug_make_type (info, DEBUG_KIND_FLOAT, size);
1302 /* Make a boolean type of a given size. */
1305 debug_make_bool_type (handle, size)
1309 struct debug_handle *info = (struct debug_handle *) handle;
1311 return debug_make_type (info, DEBUG_KIND_BOOL, size);
1314 /* Make a complex type of a given size. */
1317 debug_make_complex_type (handle, size)
1321 struct debug_handle *info = (struct debug_handle *) handle;
1323 return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
1326 /* Make a structure type. The second argument is true for a struct,
1327 false for a union. The third argument is the size of the struct.
1328 The fourth argument is a NULL terminated array of fields. */
1331 debug_make_struct_type (handle, structp, size, fields)
1335 debug_field *fields;
1337 struct debug_handle *info = (struct debug_handle *) handle;
1338 struct debug_type *t;
1339 struct debug_class_type *c;
1341 t = debug_make_type (info,
1342 structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
1345 return DEBUG_TYPE_NULL;
1347 c = (struct debug_class_type *) xmalloc (sizeof *c);
1348 memset (c, 0, sizeof *c);
1357 /* Make an object type. The first three arguments after the handle
1358 are the same as for debug_make_struct_type. The next arguments are
1359 a NULL terminated array of base classes, a NULL terminated array of
1360 methods, the type of the object holding the virtual function table
1361 if it is not this object, and a boolean which is true if this
1362 object has its own virtual function table. */
1365 debug_make_object_type (handle, structp, size, fields, baseclasses,
1366 methods, vptrbase, ownvptr)
1370 debug_field *fields;
1371 debug_baseclass *baseclasses;
1372 debug_method *methods;
1373 debug_type vptrbase;
1376 struct debug_handle *info = (struct debug_handle *) handle;
1377 struct debug_type *t;
1378 struct debug_class_type *c;
1380 t = debug_make_type (info,
1381 structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
1384 return DEBUG_TYPE_NULL;
1386 c = (struct debug_class_type *) xmalloc (sizeof *c);
1387 memset (c, 0, sizeof *c);
1390 c->baseclasses = baseclasses;
1391 c->methods = methods;
1395 c->vptrbase = vptrbase;
1402 /* Make an enumeration type. The arguments are a null terminated
1403 array of strings, and an array of corresponding values. */
1406 debug_make_enum_type (handle, names, values)
1409 bfd_signed_vma *values;
1411 struct debug_handle *info = (struct debug_handle *) handle;
1412 struct debug_type *t;
1413 struct debug_enum_type *e;
1415 t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
1417 return DEBUG_TYPE_NULL;
1419 e = (struct debug_enum_type *) xmalloc (sizeof *e);
1420 memset (e, 0, sizeof *e);
1430 /* Make a pointer to a given type. */
1433 debug_make_pointer_type (handle, type)
1437 struct debug_handle *info = (struct debug_handle *) handle;
1438 struct debug_type *t;
1441 return DEBUG_TYPE_NULL;
1443 if (type->pointer != DEBUG_TYPE_NULL)
1444 return type->pointer;
1446 t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
1448 return DEBUG_TYPE_NULL;
1450 t->u.kpointer = type;
1457 /* Make a function returning a given type. FIXME: We should be able
1458 to record the parameter types. */
1461 debug_make_function_type (handle, type)
1465 struct debug_handle *info = (struct debug_handle *) handle;
1466 struct debug_type *t;
1467 struct debug_function_type *f;
1470 return DEBUG_TYPE_NULL;
1472 t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
1474 return DEBUG_TYPE_NULL;
1476 f = (struct debug_function_type *) xmalloc (sizeof *f);
1477 memset (f, 0, sizeof *f);
1479 f->return_type = type;
1486 /* Make a reference to a given type. */
1489 debug_make_reference_type (handle, type)
1493 struct debug_handle *info = (struct debug_handle *) handle;
1494 struct debug_type *t;
1497 return DEBUG_TYPE_NULL;
1499 t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
1501 return DEBUG_TYPE_NULL;
1503 t->u.kreference = type;
1508 /* Make a range of a given type from a lower to an upper bound. */
1511 debug_make_range_type (handle, type, lower, upper)
1514 bfd_signed_vma lower;
1515 bfd_signed_vma upper;
1517 struct debug_handle *info = (struct debug_handle *) handle;
1518 struct debug_type *t;
1519 struct debug_range_type *r;
1522 return DEBUG_TYPE_NULL;
1524 t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
1526 return DEBUG_TYPE_NULL;
1528 r = (struct debug_range_type *) xmalloc (sizeof *r);
1529 memset (r, 0, sizeof *r);
1540 /* Make an array type. The second argument is the type of an element
1541 of the array. The third argument is the type of a range of the
1542 array. The fourth and fifth argument are the lower and upper
1543 bounds, respectively. The sixth argument is true if this array is
1544 actually a string, as in C. */
1547 debug_make_array_type (handle, element_type, range_type, lower, upper,
1550 debug_type element_type;
1551 debug_type range_type;
1552 bfd_signed_vma lower;
1553 bfd_signed_vma upper;
1556 struct debug_handle *info = (struct debug_handle *) handle;
1557 struct debug_type *t;
1558 struct debug_array_type *a;
1560 if (element_type == NULL || range_type == NULL)
1561 return DEBUG_TYPE_NULL;
1563 t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
1565 return DEBUG_TYPE_NULL;
1567 a = (struct debug_array_type *) xmalloc (sizeof *a);
1568 memset (a, 0, sizeof *a);
1570 a->element_type = element_type;
1571 a->range_type = range_type;
1574 a->stringp = stringp;
1581 /* Make a set of a given type. For example, a Pascal set type. The
1582 boolean argument is true if this set is actually a bitstring, as in
1586 debug_make_set_type (handle, type, bitstringp)
1591 struct debug_handle *info = (struct debug_handle *) handle;
1592 struct debug_type *t;
1593 struct debug_set_type *s;
1596 return DEBUG_TYPE_NULL;
1598 t = debug_make_type (info, DEBUG_KIND_SET, 0);
1600 return DEBUG_TYPE_NULL;
1602 s = (struct debug_set_type *) xmalloc (sizeof *s);
1603 memset (s, 0, sizeof *s);
1606 s->bitstringp = bitstringp;
1613 /* Make a type for a pointer which is relative to an object. The
1614 second argument is the type of the object to which the pointer is
1615 relative. The third argument is the type that the pointer points
1619 debug_make_offset_type (handle, base_type, target_type)
1621 debug_type base_type;
1622 debug_type target_type;
1624 struct debug_handle *info = (struct debug_handle *) handle;
1625 struct debug_type *t;
1626 struct debug_offset_type *o;
1628 if (base_type == NULL || target_type == NULL)
1629 return DEBUG_TYPE_NULL;
1631 t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
1633 return DEBUG_TYPE_NULL;
1635 o = (struct debug_offset_type *) xmalloc (sizeof *o);
1636 memset (o, 0, sizeof *o);
1638 o->base_type = base_type;
1639 o->target_type = target_type;
1646 /* Make a type for a method function. The second argument is the
1647 return type, the third argument is the domain, and the fourth
1648 argument is a NULL terminated array of argument types. */
1651 debug_make_method_type (handle, return_type, domain_type, arg_types)
1653 debug_type return_type;
1654 debug_type domain_type;
1655 debug_type *arg_types;
1657 struct debug_handle *info = (struct debug_handle *) handle;
1658 struct debug_type *t;
1659 struct debug_method_type *m;
1661 if (return_type == NULL)
1662 return DEBUG_TYPE_NULL;
1664 t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
1666 return DEBUG_TYPE_NULL;
1668 m = (struct debug_method_type *) xmalloc (sizeof *m);
1669 memset (m, 0, sizeof *m);
1671 m->return_type = return_type;
1672 m->domain_type = domain_type;
1673 m->arg_types = arg_types;
1680 /* Make a const qualified version of a given type. */
1683 debug_make_const_type (handle, type)
1687 struct debug_handle *info = (struct debug_handle *) handle;
1688 struct debug_type *t;
1691 return DEBUG_TYPE_NULL;
1693 t = debug_make_type (info, DEBUG_KIND_CONST, 0);
1695 return DEBUG_TYPE_NULL;
1702 /* Make a volatile qualified version of a given type. */
1705 debug_make_volatile_type (handle, type)
1709 struct debug_handle *info = (struct debug_handle *) handle;
1710 struct debug_type *t;
1713 return DEBUG_TYPE_NULL;
1715 t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
1717 return DEBUG_TYPE_NULL;
1719 t->u.kvolatile = type;
1724 /* Make an undefined tagged type. For example, a struct which has
1725 been mentioned, but not defined. */
1728 debug_make_undefined_tagged_type (handle, name, kind)
1731 enum debug_type_kind kind;
1733 struct debug_handle *info = (struct debug_handle *) handle;
1734 struct debug_type *t;
1737 return DEBUG_TYPE_NULL;
1741 case DEBUG_KIND_STRUCT:
1742 case DEBUG_KIND_UNION:
1743 case DEBUG_KIND_CLASS:
1744 case DEBUG_KIND_UNION_CLASS:
1745 case DEBUG_KIND_ENUM:
1749 debug_error ("debug_make_undefined_type: unsupported kind");
1750 return DEBUG_TYPE_NULL;
1753 t = debug_make_type (info, kind, 0);
1755 return DEBUG_TYPE_NULL;
1757 return debug_tag_type (handle, name, t);
1760 /* Make a base class for an object. The second argument is the base
1761 class type. The third argument is the bit position of this base
1762 class in the object (always 0 unless doing multiple inheritance).
1763 The fourth argument is whether this is a virtual class. The fifth
1764 argument is the visibility of the base class. */
1768 debug_make_baseclass (handle, type, bitpos, virtual, visibility)
1773 enum debug_visibility visibility;
1775 struct debug_baseclass *b;
1777 b = (struct debug_baseclass *) xmalloc (sizeof *b);
1778 memset (b, 0, sizeof *b);
1782 b->virtual = virtual;
1783 b->visibility = visibility;
1788 /* Make a field for a struct. The second argument is the name. The
1789 third argument is the type of the field. The fourth argument is
1790 the bit position of the field. The fifth argument is the size of
1791 the field (it may be zero). The sixth argument is the visibility
1796 debug_make_field (handle, name, type, bitpos, bitsize, visibility)
1802 enum debug_visibility visibility;
1804 struct debug_field *f;
1806 f = (struct debug_field *) xmalloc (sizeof *f);
1807 memset (f, 0, sizeof *f);
1811 f->static_member = false;
1812 f->u.f.bitpos = bitpos;
1813 f->u.f.bitsize = bitsize;
1814 f->visibility = visibility;
1819 /* Make a static member of an object. The second argument is the
1820 name. The third argument is the type of the member. The fourth
1821 argument is the physical name of the member (i.e., the name as a
1822 global variable). The fifth argument is the visibility of the
1827 debug_make_static_member (handle, name, type, physname, visibility)
1831 const char *physname;
1832 enum debug_visibility visibility;
1834 struct debug_field *f;
1836 f = (struct debug_field *) xmalloc (sizeof *f);
1837 memset (f, 0, sizeof *f);
1841 f->static_member = true;
1842 f->u.s.physname = physname;
1843 f->visibility = visibility;
1848 /* Make a method. The second argument is the name, and the third
1849 argument is a NULL terminated array of method variants. */
1853 debug_make_method (handle, name, variants)
1856 debug_method_variant *variants;
1858 struct debug_method *m;
1860 m = (struct debug_method *) xmalloc (sizeof *m);
1861 memset (m, 0, sizeof *m);
1864 m->variants = variants;
1869 /* Make a method argument. The second argument is the real name of
1870 the function. The third argument is the type of the function. The
1871 fourth argument is the visibility. The fifth argument is whether
1872 this is a const function. The sixth argument is whether this is a
1873 volatile function. The seventh argument is the offset in the
1874 virtual function table, if any. The eighth argument is the virtual
1875 function context. FIXME: Are the const and volatile arguments
1876 necessary? Could we just use debug_make_const_type? */
1879 debug_method_variant
1880 debug_make_method_variant (handle, physname, type, visibility, constp,
1881 volatilep, voffset, context)
1883 const char *physname;
1885 enum debug_visibility visibility;
1891 struct debug_method_variant *m;
1893 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1894 memset (m, 0, sizeof *m);
1896 m->physname = physname;
1898 m->visibility = visibility;
1900 m->volatilep = volatilep;
1901 m->voffset = voffset;
1902 m->context = context;
1907 /* Make a static method argument. The arguments are the same as for
1908 debug_make_method_variant, except that the last two are omitted
1909 since a static method can not also be virtual. */
1911 debug_method_variant
1912 debug_make_static_method_variant (handle, physname, type, visibility,
1915 const char *physname;
1917 enum debug_visibility visibility;
1921 struct debug_method_variant *m;
1923 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1924 memset (m, 0, sizeof *m);
1926 m->physname = physname;
1928 m->visibility = visibility;
1930 m->volatilep = volatilep;
1931 m->voffset = VOFFSET_STATIC_METHOD;
1939 debug_name_type (handle, name, type)
1944 struct debug_handle *info = (struct debug_handle *) handle;
1945 struct debug_type *t;
1946 struct debug_named_type *n;
1947 struct debug_name *nm;
1949 if (name == NULL || type == NULL)
1950 return DEBUG_TYPE_NULL;
1952 if (info->current_unit == NULL
1953 || info->current_file == NULL)
1955 debug_error ("debug_record_variable: no current file");
1959 t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1961 return DEBUG_TYPE_NULL;
1963 n = (struct debug_named_type *) xmalloc (sizeof *n);
1964 memset (n, 0, sizeof *n);
1970 /* We always add the name to the global namespace. This is probably
1971 wrong in some cases, but it seems to be right for stabs. FIXME. */
1973 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1974 DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
1988 debug_tag_type (handle, name, type)
1993 struct debug_handle *info = (struct debug_handle *) handle;
1994 struct debug_type *t;
1995 struct debug_named_type *n;
1996 struct debug_name *nm;
1998 if (name == NULL || type == NULL)
1999 return DEBUG_TYPE_NULL;
2001 if (info->current_file == NULL)
2003 debug_error ("debug_tag_type: no current file");
2004 return DEBUG_TYPE_NULL;
2007 if (type->kind == DEBUG_KIND_TAGGED)
2009 if (strcmp (type->u.knamed->name->name, name) == 0)
2011 debug_error ("debug_tag_type: extra tag attempted");
2012 return DEBUG_TYPE_NULL;
2015 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
2017 return DEBUG_TYPE_NULL;
2019 n = (struct debug_named_type *) xmalloc (sizeof *n);
2020 memset (n, 0, sizeof *n);
2026 /* We keep a global namespace of tags for each compilation unit. I
2027 don't know if that is the right thing to do. */
2029 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
2030 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
2041 /* Record the size of a given type. */
2045 debug_record_type_size (handle, type, size)
2050 if (type->size != 0 && type->size != size)
2051 fprintf (stderr, "Warning: changing type size from %d to %d\n",
2059 /* Find a named type. */
2062 debug_find_named_type (handle, name)
2066 struct debug_handle *info = (struct debug_handle *) handle;
2067 struct debug_block *b;
2068 struct debug_file *f;
2070 /* We only search the current compilation unit. I don't know if
2071 this is right or not. */
2073 if (info->current_unit == NULL)
2075 debug_error ("debug_find_named_type: no current compilation unit");
2076 return DEBUG_TYPE_NULL;
2079 for (b = info->current_block; b != NULL; b = b->parent)
2081 if (b->locals != NULL)
2083 struct debug_name *n;
2085 for (n = b->locals->list; n != NULL; n = n->next)
2087 if (n->kind == DEBUG_OBJECT_TYPE
2088 && n->name[0] == name[0]
2089 && strcmp (n->name, name) == 0)
2095 for (f = info->current_unit->files; f != NULL; f = f->next)
2097 if (f->globals != NULL)
2099 struct debug_name *n;
2101 for (n = f->globals->list; n != NULL; n = n->next)
2103 if (n->kind == DEBUG_OBJECT_TYPE
2104 && n->name[0] == name[0]
2105 && strcmp (n->name, name) == 0)
2111 return DEBUG_TYPE_NULL;
2114 /* Find a tagged type. */
2117 debug_find_tagged_type (handle, name, kind)
2120 enum debug_type_kind kind;
2122 struct debug_handle *info = (struct debug_handle *) handle;
2123 struct debug_unit *u;
2125 /* We search the globals of all the compilation units. I don't know
2126 if this is correct or not. It would be easy to change. */
2128 for (u = info->units; u != NULL; u = u->next)
2130 struct debug_file *f;
2132 for (f = u->files; f != NULL; f = f->next)
2134 struct debug_name *n;
2136 if (f->globals != NULL)
2138 for (n = f->globals->list; n != NULL; n = n->next)
2140 if (n->kind == DEBUG_OBJECT_TAG
2141 && (kind == DEBUG_KIND_ILLEGAL
2142 || n->u.tag->kind == kind)
2143 && n->name[0] == name[0]
2144 && strcmp (n->name, name) == 0)
2151 return DEBUG_TYPE_NULL;
2154 /* Get a base type. */
2156 static struct debug_type *
2157 debug_get_real_type (handle, type)
2165 case DEBUG_KIND_INDIRECT:
2166 if (*type->u.kindirect->slot != NULL)
2167 return debug_get_real_type (handle, *type->u.kindirect->slot);
2169 case DEBUG_KIND_NAMED:
2170 return debug_get_real_type (handle, type->u.knamed->type);
2175 /* Get the kind of a type. */
2177 enum debug_type_kind
2178 debug_get_type_kind (handle, type)
2183 return DEBUG_KIND_ILLEGAL;
2184 type = debug_get_real_type (handle, type);
2188 /* Get the name of a type. */
2191 debug_get_type_name (handle, type)
2195 if (type->kind == DEBUG_KIND_INDIRECT)
2197 if (*type->u.kindirect->slot != NULL)
2198 return debug_get_type_name (handle, *type->u.kindirect->slot);
2199 return type->u.kindirect->tag;
2201 if (type->kind == DEBUG_KIND_NAMED
2202 || type->kind == DEBUG_KIND_TAGGED)
2203 return type->u.knamed->name->name;
2207 /* Get the return type of a function or method type. */
2210 debug_get_return_type (handle, type)
2215 return DEBUG_TYPE_NULL;
2216 type = debug_get_real_type (handle, type);
2220 return DEBUG_TYPE_NULL;
2221 case DEBUG_KIND_FUNCTION:
2222 return type->u.kfunction->return_type;
2223 case DEBUG_KIND_METHOD:
2224 return type->u.kmethod->return_type;
2229 /* Get the parameter types of a function or method type (except that
2230 we don't currently store the parameter types of a function). */
2233 debug_get_parameter_types (handle, type)
2239 type = debug_get_real_type (handle, type);
2244 case DEBUG_KIND_METHOD:
2245 return type->u.kmethod->arg_types;
2250 /* Get the NULL terminated array of fields for a struct, union, or
2254 debug_get_fields (handle, type)
2260 type = debug_get_real_type (handle, type);
2265 case DEBUG_KIND_STRUCT:
2266 case DEBUG_KIND_UNION:
2267 case DEBUG_KIND_CLASS:
2268 case DEBUG_KIND_UNION_CLASS:
2269 return type->u.kclass->fields;
2274 /* Get the type of a field. */
2278 debug_get_field_type (handle, field)
2287 /* Write out the debugging information. This is given a handle to
2288 debugging information, and a set of function pointers to call. */
2291 debug_write (handle, fns, fhandle)
2293 const struct debug_write_fns *fns;
2296 struct debug_handle *info = (struct debug_handle *) handle;
2297 struct debug_unit *u;
2299 /* We use a mark to tell whether we have already written out a
2300 particular name. We use an integer, so that we don't have to
2301 clear the mark fields if we happen to write out the same
2302 information more than once. */
2305 /* The base_id field holds an ID value which will never be used, so
2306 that we can tell whether we have assigned an ID during this call
2308 info->base_id = info->class_id;
2310 for (u = info->units; u != NULL; u = u->next)
2312 struct debug_file *f;
2314 struct debug_lineno *l;
2316 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2320 for (f = u->files; f != NULL; f = f->next)
2322 struct debug_name *n;
2328 if (! (*fns->start_source) (fhandle, f->filename))
2332 if (f->globals != NULL)
2334 for (n = f->globals->list; n != NULL; n = n->next)
2336 if (! debug_write_name (info, fns, fhandle, n))
2342 for (l = u->linenos; l != NULL; l = l->next)
2346 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
2348 if (l->linenos[i] == (unsigned long) -1)
2350 if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
2360 /* Write out an element in a namespace. */
2363 debug_write_name (info, fns, fhandle, n)
2364 struct debug_handle *info;
2365 const struct debug_write_fns *fns;
2367 struct debug_name *n;
2369 /* The class_mark field is used to prevent recursively outputting a
2375 case DEBUG_OBJECT_TYPE:
2376 if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2377 || ! (*fns->typdef) (fhandle, n->name))
2380 case DEBUG_OBJECT_TAG:
2381 if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2383 return (*fns->tag) (fhandle, n->name);
2384 case DEBUG_OBJECT_VARIABLE:
2385 if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2386 (struct debug_name *) NULL))
2388 return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2389 n->u.variable->val);
2390 case DEBUG_OBJECT_FUNCTION:
2391 return debug_write_function (info, fns, fhandle, n->name,
2392 n->linkage, n->u.function);
2393 case DEBUG_OBJECT_INT_CONSTANT:
2394 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2395 case DEBUG_OBJECT_FLOAT_CONSTANT:
2396 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2397 case DEBUG_OBJECT_TYPED_CONSTANT:
2398 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2399 (struct debug_name *) NULL))
2401 return (*fns->typed_constant) (fhandle, n->name,
2402 n->u.typed_constant->val);
2410 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2411 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2412 are about to call typedef or tag. If the type is anything else,
2413 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2414 points to this one. */
2417 debug_write_type (info, fns, fhandle, type, name)
2418 struct debug_handle *info;
2419 const struct debug_write_fns *fns;
2421 struct debug_type *type;
2422 struct debug_name *name;
2427 /* If we have a name for this type, just output it. We only output
2428 typedef names after they have been defined. We output type tags
2429 whenever we are not actually defining them. */
2430 if ((type->kind == DEBUG_KIND_NAMED
2431 || type->kind == DEBUG_KIND_TAGGED)
2432 && (type->u.knamed->name->mark == info->mark
2433 || (type->kind == DEBUG_KIND_TAGGED
2434 && type->u.knamed->name != name)))
2436 if (type->kind == DEBUG_KIND_NAMED)
2437 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2439 return (*fns->tag_type) (fhandle, type->u.knamed->name->name, 0,
2440 type->u.knamed->type->kind);
2443 /* Mark the name after we have already looked for a known name, so
2444 that we don't just define a type in terms of itself. We need to
2445 mark the name here so that a struct containing a pointer to
2446 itself will work. */
2448 name->mark = info->mark;
2452 && type->kind != DEBUG_KIND_NAMED
2453 && type->kind != DEBUG_KIND_TAGGED)
2455 assert (name->kind == DEBUG_OBJECT_TAG);
2461 case DEBUG_KIND_ILLEGAL:
2462 debug_error ("debug_write_type: illegal type encountered");
2464 case DEBUG_KIND_INDIRECT:
2465 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2466 return (*fns->empty_type) (fhandle);
2467 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2468 (struct debug_name *) NULL);
2469 case DEBUG_KIND_VOID:
2470 return (*fns->void_type) (fhandle);
2471 case DEBUG_KIND_INT:
2472 return (*fns->int_type) (fhandle, type->size, type->u.kint);
2473 case DEBUG_KIND_FLOAT:
2474 return (*fns->float_type) (fhandle, type->size);
2475 case DEBUG_KIND_COMPLEX:
2476 return (*fns->complex_type) (fhandle, type->size);
2477 case DEBUG_KIND_BOOL:
2478 return (*fns->bool_type) (fhandle, type->size);
2479 case DEBUG_KIND_STRUCT:
2480 case DEBUG_KIND_UNION:
2481 if (type->u.kclass != NULL)
2483 if (info->class_mark == type->u.kclass->mark
2484 || type->u.kclass->id > info->base_id)
2486 /* We are currently outputting this struct, or we have
2487 already output it. I don't know if this can happen,
2488 but it can happen for a class. */
2489 assert (type->u.kclass->id > info->base_id);
2490 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2493 type->u.kclass->mark = info->class_mark;
2495 type->u.kclass->id = info->class_id;
2498 if (! (*fns->start_struct_type) (fhandle, tag,
2499 (type->u.kclass != NULL
2500 ? type->u.kclass->id
2502 type->kind == DEBUG_KIND_STRUCT,
2505 if (type->u.kclass != NULL
2506 && type->u.kclass->fields != NULL)
2508 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2510 struct debug_field *f;
2512 f = type->u.kclass->fields[i];
2513 if (! debug_write_type (info, fns, fhandle, f->type,
2514 (struct debug_name *) NULL)
2515 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2516 f->u.f.bitsize, f->visibility))
2520 return (*fns->end_struct_type) (fhandle);
2521 case DEBUG_KIND_CLASS:
2522 case DEBUG_KIND_UNION_CLASS:
2523 return debug_write_class_type (info, fns, fhandle, type, tag);
2524 case DEBUG_KIND_ENUM:
2525 if (type->u.kenum == NULL)
2526 return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
2527 (bfd_signed_vma *) NULL);
2528 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2529 type->u.kenum->values);
2530 case DEBUG_KIND_POINTER:
2531 if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2532 (struct debug_name *) NULL))
2534 return (*fns->pointer_type) (fhandle);
2535 case DEBUG_KIND_FUNCTION:
2536 if (! debug_write_type (info, fns, fhandle,
2537 type->u.kfunction->return_type,
2538 (struct debug_name *) NULL))
2540 return (*fns->function_type) (fhandle);
2541 case DEBUG_KIND_REFERENCE:
2542 if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2543 (struct debug_name *) NULL))
2545 return (*fns->reference_type) (fhandle);
2546 case DEBUG_KIND_RANGE:
2547 if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2548 (struct debug_name *) NULL))
2550 return (*fns->range_type) (fhandle, type->u.krange->lower,
2551 type->u.krange->upper);
2552 case DEBUG_KIND_ARRAY:
2553 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2554 (struct debug_name *) NULL)
2555 || ! debug_write_type (info, fns, fhandle,
2556 type->u.karray->range_type,
2557 (struct debug_name *) NULL))
2559 return (*fns->array_type) (fhandle, type->u.karray->lower,
2560 type->u.karray->upper,
2561 type->u.karray->stringp);
2562 case DEBUG_KIND_SET:
2563 if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2564 (struct debug_name *) NULL))
2566 return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2567 case DEBUG_KIND_OFFSET:
2568 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2569 (struct debug_name *) NULL)
2570 || ! debug_write_type (info, fns, fhandle,
2571 type->u.koffset->target_type,
2572 (struct debug_name *) NULL))
2574 return (*fns->offset_type) (fhandle);
2575 case DEBUG_KIND_METHOD:
2576 if (! debug_write_type (info, fns, fhandle,
2577 type->u.kmethod->return_type,
2578 (struct debug_name *) NULL))
2580 if (type->u.kmethod->arg_types == NULL)
2584 for (i = 0; type->u.kmethod->arg_types[i] != NULL; i++)
2586 if (ELLIPSIS_P (type->u.kmethod->arg_types[i]))
2588 if (! (*fns->ellipsis_type) (fhandle))
2593 if (! debug_write_type (info, fns, fhandle,
2594 type->u.kmethod->arg_types[i],
2595 (struct debug_name *) NULL))
2600 if (type->u.kmethod->domain_type != NULL)
2602 if (! debug_write_type (info, fns, fhandle,
2603 type->u.kmethod->domain_type,
2604 (struct debug_name *) NULL))
2607 return (*fns->method_type) (fhandle,
2608 type->u.kmethod->domain_type != NULL,
2610 case DEBUG_KIND_CONST:
2611 if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2612 (struct debug_name *) NULL))
2614 return (*fns->const_type) (fhandle);
2615 case DEBUG_KIND_VOLATILE:
2616 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2617 (struct debug_name *) NULL))
2619 return (*fns->volatile_type) (fhandle);
2620 case DEBUG_KIND_NAMED:
2621 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2622 (struct debug_name *) NULL);
2623 case DEBUG_KIND_TAGGED:
2624 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2625 type->u.knamed->name);
2632 /* Write out a class type. */
2635 debug_write_class_type (info, fns, fhandle, type, tag)
2636 struct debug_handle *info;
2637 const struct debug_write_fns *fns;
2639 struct debug_type *type;
2644 struct debug_type *vptrbase;
2646 if (type->u.kclass == NULL)
2653 if (info->class_mark == type->u.kclass->mark
2654 || type->u.kclass->id > info->base_id)
2656 /* We are currently outputting this class, or we have
2657 already output it. This can happen when there are
2658 methods for an anonymous class. */
2659 assert (type->u.kclass->id > info->base_id);
2660 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2663 type->u.kclass->mark = info->class_mark;
2665 id = info->class_id;
2666 type->u.kclass->id = id;
2668 vptrbase = type->u.kclass->vptrbase;
2669 if (vptrbase != NULL && vptrbase != type)
2671 if (! debug_write_type (info, fns, fhandle, vptrbase,
2672 (struct debug_name *) NULL))
2677 if (! (*fns->start_class_type) (fhandle, tag, id,
2678 type->kind == DEBUG_KIND_CLASS,
2684 if (type->u.kclass != NULL)
2686 if (type->u.kclass->fields != NULL)
2688 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2690 struct debug_field *f;
2692 f = type->u.kclass->fields[i];
2693 if (! debug_write_type (info, fns, fhandle, f->type,
2694 (struct debug_name *) NULL))
2696 if (f->static_member)
2698 if (! (*fns->class_static_member) (fhandle, f->name,
2705 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2706 f->u.f.bitsize, f->visibility))
2712 if (type->u.kclass->baseclasses != NULL)
2714 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2716 struct debug_baseclass *b;
2718 b = type->u.kclass->baseclasses[i];
2719 if (! debug_write_type (info, fns, fhandle, b->type,
2720 (struct debug_name *) NULL))
2722 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
2728 if (type->u.kclass->methods != NULL)
2730 for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2732 struct debug_method *m;
2735 m = type->u.kclass->methods[i];
2736 if (! (*fns->class_start_method) (fhandle, m->name))
2738 for (j = 0; m->variants[j] != NULL; j++)
2740 struct debug_method_variant *v;
2743 if (v->context != NULL)
2745 if (! debug_write_type (info, fns, fhandle, v->context,
2746 (struct debug_name *) NULL))
2749 if (! debug_write_type (info, fns, fhandle, v->type,
2750 (struct debug_name *) NULL))
2752 if (v->voffset != VOFFSET_STATIC_METHOD)
2754 if (! (*fns->class_method_variant) (fhandle, v->physname,
2759 v->context != NULL))
2764 if (! (*fns->class_static_method_variant) (fhandle,
2772 if (! (*fns->class_end_method) (fhandle))
2778 return (*fns->end_class_type) (fhandle);
2781 /* Write out information for a function. */
2784 debug_write_function (info, fns, fhandle, name, linkage, function)
2785 struct debug_handle *info;
2786 const struct debug_write_fns *fns;
2789 enum debug_object_linkage linkage;
2790 struct debug_function *function;
2792 struct debug_parameter *p;
2793 struct debug_block *b;
2795 if (! debug_write_type (info, fns, fhandle, function->return_type,
2796 (struct debug_name *) NULL))
2799 if (! (*fns->start_function) (fhandle, name,
2800 linkage == DEBUG_LINKAGE_GLOBAL))
2803 for (p = function->parameters; p != NULL; p = p->next)
2805 if (! debug_write_type (info, fns, fhandle, p->type,
2806 (struct debug_name *) NULL)
2807 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2811 for (b = function->blocks; b != NULL; b = b->next)
2813 if (! debug_write_block (info, fns, fhandle, b))
2817 return (*fns->end_function) (fhandle);
2820 /* Write out information for a block. */
2823 debug_write_block (info, fns, fhandle, block)
2824 struct debug_handle *info;
2825 const struct debug_write_fns *fns;
2827 struct debug_block *block;
2829 struct debug_name *n;
2830 struct debug_block *b;
2832 if (! (*fns->start_block) (fhandle, block->start))
2835 if (block->locals != NULL)
2837 for (n = block->locals->list; n != NULL; n = n->next)
2839 if (! debug_write_name (info, fns, fhandle, n))
2844 for (b = block->children; b != NULL; b = b->next)
2846 if (! debug_write_block (info, fns, fhandle, b))
2850 return (*fns->end_block) (fhandle, block->end);