1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file implements a generic debugging format. We may eventually
23 have readers which convert different formats into this generic
24 format, and writers which write it out. The initial impetus for
25 this was writing a convertor from stabs to HP IEEE-695 debugging
33 #include "libiberty.h"
36 /* Global information we keep for debugging. A pointer to this
37 structure is the debugging handle passed to all the routines. */
41 /* A linked list of compilation units. */
42 struct debug_unit *units;
43 /* The current compilation unit. */
44 struct debug_unit *current_unit;
45 /* The current source file. */
46 struct debug_file *current_file;
47 /* The current function. */
48 struct debug_function *current_function;
49 /* The current block. */
50 struct debug_block *current_block;
51 /* The current line number information for the current unit. */
52 struct debug_lineno *current_lineno;
53 /* Mark. This is used by debug_write. */
55 /* Another mark used by debug_write. */
56 unsigned int class_mark;
57 /* A struct/class ID used by debug_write. */
58 unsigned int class_id;
59 /* The base for class_id for this call to debug_write. */
63 /* Information we keep for a single compilation unit. */
67 /* The next compilation unit. */
68 struct debug_unit *next;
69 /* A list of files included in this compilation unit. The first
70 file is always the main one, and that is where the main file name
72 struct debug_file *files;
73 /* Line number information for this compilation unit. This is not
74 stored by function, because assembler code may have line number
75 information without function information. */
76 struct debug_lineno *linenos;
79 /* Information kept for a single source file. */
83 /* The next source file in this compilation unit. */
84 struct debug_file *next;
85 /* The name of the source file. */
87 /* Global functions, variables, types, etc. */
88 struct debug_namespace *globals;
96 enum debug_type_kind kind;
97 /* Size of type (0 if not known). */
99 /* Type which is a pointer to this type. */
101 /* Tagged union with additional information about the type. */
104 /* DEBUG_KIND_INDIRECT. */
105 struct debug_indirect_type *kindirect;
106 /* DEBUG_KIND_INT. */
107 /* Whether the integer is unsigned. */
109 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
110 DEBUG_KIND_UNION_CLASS. */
111 struct debug_class_type *kclass;
112 /* DEBUG_KIND_ENUM. */
113 struct debug_enum_type *kenum;
114 /* DEBUG_KIND_POINTER. */
115 struct debug_type *kpointer;
116 /* DEBUG_KIND_FUNCTION. */
117 struct debug_function_type *kfunction;
118 /* DEBUG_KIND_REFERENCE. */
119 struct debug_type *kreference;
120 /* DEBUG_KIND_RANGE. */
121 struct debug_range_type *krange;
122 /* DEBUG_KIND_ARRAY. */
123 struct debug_array_type *karray;
124 /* DEBUG_KIND_SET. */
125 struct debug_set_type *kset;
126 /* DEBUG_KIND_OFFSET. */
127 struct debug_offset_type *koffset;
128 /* DEBUG_KIND_METHOD. */
129 struct debug_method_type *kmethod;
130 /* DEBUG_KIND_CONST. */
131 struct debug_type *kconst;
132 /* DEBUG_KIND_VOLATILE. */
133 struct debug_type *kvolatile;
134 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
135 struct debug_named_type *knamed;
139 /* Information kept for an indirect type. */
141 struct debug_indirect_type
143 /* Slot where the final type will appear. */
149 /* Information kept for a struct, union, or class. */
151 struct debug_class_type
153 /* NULL terminated array of fields. */
155 /* A mark field used to avoid recursively printing out structs. */
157 /* This is used to uniquely identify unnamed structs when printing. */
159 /* The remaining fields are only used for DEBUG_KIND_CLASS and
160 DEBUG_KIND_UNION_CLASS. */
161 /* NULL terminated array of base classes. */
162 debug_baseclass *baseclasses;
163 /* NULL terminated array of methods. */
164 debug_method *methods;
165 /* The type of the class providing the virtual function table for
166 this class. This may point to the type itself. */
170 /* Information kept for an enum. */
172 struct debug_enum_type
174 /* NULL terminated array of names. */
176 /* Array of corresponding values. */
177 bfd_signed_vma *values;
180 /* Information kept for a function. FIXME: We should be able to
181 record the parameter types. */
183 struct debug_function_type
186 debug_type return_type;
187 /* NULL terminated array of argument types. */
188 debug_type *arg_types;
189 /* Whether the function takes a variable number of arguments. */
193 /* Information kept for a range. */
195 struct debug_range_type
197 /* Range base type. */
200 bfd_signed_vma lower;
202 bfd_signed_vma upper;
205 /* Information kept for an array. */
207 struct debug_array_type
210 debug_type element_type;
212 debug_type range_type;
214 bfd_signed_vma lower;
216 bfd_signed_vma upper;
217 /* Whether this array is really a string. */
221 /* Information kept for a set. */
223 struct debug_set_type
227 /* Whether this set is really a bitstring. */
231 /* Information kept for an offset type (a based pointer). */
233 struct debug_offset_type
235 /* The type the pointer is an offset from. */
236 debug_type base_type;
237 /* The type the pointer points to. */
238 debug_type target_type;
241 /* Information kept for a method type. */
243 struct debug_method_type
245 /* The return type. */
246 debug_type return_type;
247 /* The object type which this method is for. */
248 debug_type domain_type;
249 /* A NULL terminated array of argument types. */
250 debug_type *arg_types;
251 /* Whether the method takes a variable number of arguments. */
255 /* Information kept for a named type. */
257 struct debug_named_type
260 struct debug_name *name;
265 /* A field in a struct or union. */
269 /* Name of the field. */
271 /* Type of the field. */
272 struct debug_type *type;
273 /* Visibility of the field. */
274 enum debug_visibility visibility;
275 /* Whether this is a static member. */
276 boolean static_member;
279 /* If static_member is false. */
282 /* Bit position of the field in the struct. */
284 /* Size of the field in bits. */
285 unsigned int bitsize;
287 /* If static_member is true. */
290 const char *physname;
295 /* A base class for an object. */
297 struct debug_baseclass
299 /* Type of the base class. */
300 struct debug_type *type;
301 /* Bit position of the base class in the object. */
303 /* Whether the base class is virtual. */
305 /* Visibility of the base class. */
306 enum debug_visibility visibility;
309 /* A method of an object. */
313 /* The name of the method. */
315 /* A NULL terminated array of different types of variants. */
316 struct debug_method_variant **variants;
319 /* The variants of a method function of an object. These indicate
320 which method to run. */
322 struct debug_method_variant
324 /* The physical name of the function. */
325 const char *physname;
326 /* The type of the function. */
327 struct debug_type *type;
328 /* The visibility of the function. */
329 enum debug_visibility visibility;
330 /* Whether the function is const. */
332 /* Whether the function is volatile. */
334 /* The offset to the function in the virtual function table. */
336 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
337 #define VOFFSET_STATIC_METHOD (1)
338 /* Context of a virtual method function. */
339 struct debug_type *context;
342 /* A variable. This is the information we keep for a variable object.
343 This has no name; a name is associated with a variable in a
344 debug_name structure. */
346 struct debug_variable
348 /* Kind of variable. */
349 enum debug_var_kind kind;
352 /* Value. The interpretation of the value depends upon kind. */
356 /* A function. This has no name; a name is associated with a function
357 in a debug_name structure. */
359 struct debug_function
362 debug_type return_type;
363 /* Parameter information. */
364 struct debug_parameter *parameters;
365 /* Block information. The first structure on the list is the main
366 block of the function, and describes function local variables. */
367 struct debug_block *blocks;
370 /* A function parameter. */
372 struct debug_parameter
374 /* Next parameter. */
375 struct debug_parameter *next;
381 enum debug_parm_kind kind;
382 /* Value (meaning depends upon kind). */
386 /* A typed constant. */
388 struct debug_typed_constant
392 /* Value. FIXME: We may eventually need to support non-integral
397 /* Information about a block within a function. */
401 /* Next block with the same parent. */
402 struct debug_block *next;
404 struct debug_block *parent;
405 /* List of child blocks. */
406 struct debug_block *children;
407 /* Start address of the block. */
409 /* End address of the block. */
411 /* Local variables. */
412 struct debug_namespace *locals;
415 /* Line number information we keep for a compilation unit. FIXME:
416 This structure is easy to create, but can be very space
421 /* More line number information for this block. */
422 struct debug_lineno *next;
424 struct debug_file *file;
425 /* Line numbers, terminated by a -1 or the end of the array. */
426 #define DEBUG_LINENO_COUNT 10
427 unsigned long linenos[DEBUG_LINENO_COUNT];
428 /* Addresses for the line numbers. */
429 bfd_vma addrs[DEBUG_LINENO_COUNT];
432 /* A namespace. This is a mapping from names to objects. FIXME: This
433 should be implemented as a hash table. */
435 struct debug_namespace
437 /* List of items in this namespace. */
438 struct debug_name *list;
439 /* Pointer to where the next item in this namespace should go. */
440 struct debug_name **tail;
443 /* Kinds of objects that appear in a namespace. */
445 enum debug_object_kind
449 /* A tagged type (really a different sort of namespace). */
452 DEBUG_OBJECT_VARIABLE,
454 DEBUG_OBJECT_FUNCTION,
455 /* An integer constant. */
456 DEBUG_OBJECT_INT_CONSTANT,
457 /* A floating point constant. */
458 DEBUG_OBJECT_FLOAT_CONSTANT,
459 /* A typed constant. */
460 DEBUG_OBJECT_TYPED_CONSTANT
463 /* Linkage of an object that appears in a namespace. */
465 enum debug_object_linkage
467 /* Local variable. */
468 DEBUG_LINKAGE_AUTOMATIC,
469 /* Static--either file static or function static, depending upon the
471 DEBUG_LINKAGE_STATIC,
473 DEBUG_LINKAGE_GLOBAL,
478 /* A name in a namespace. */
482 /* Next name in this namespace. */
483 struct debug_name *next;
486 /* Mark. This is used by debug_write. */
488 /* Kind of object. */
489 enum debug_object_kind kind;
490 /* Linkage of object. */
491 enum debug_object_linkage linkage;
492 /* Tagged union with additional information about the object. */
495 /* DEBUG_OBJECT_TYPE. */
496 struct debug_type *type;
497 /* DEBUG_OBJECT_TAG. */
498 struct debug_type *tag;
499 /* DEBUG_OBJECT_VARIABLE. */
500 struct debug_variable *variable;
501 /* DEBUG_OBJECT_FUNCTION. */
502 struct debug_function *function;
503 /* DEBUG_OBJECT_INT_CONSTANT. */
504 bfd_vma int_constant;
505 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
506 double float_constant;
507 /* DEBUG_OBJECT_TYPED_CONSTANT. */
508 struct debug_typed_constant *typed_constant;
512 /* Local functions. */
514 static void debug_error PARAMS ((const char *));
515 static struct debug_name *debug_add_to_namespace
516 PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
517 enum debug_object_kind, enum debug_object_linkage));
518 static struct debug_name *debug_add_to_current_namespace
519 PARAMS ((struct debug_handle *, const char *, enum debug_object_kind,
520 enum debug_object_linkage));
521 static struct debug_type *debug_make_type
522 PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
523 static struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type));
524 static boolean debug_write_name
525 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
526 struct debug_name *));
527 static boolean debug_write_type
528 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
529 struct debug_type *, struct debug_name *));
530 static boolean debug_write_class_type
531 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
532 struct debug_type *, const char *));
533 static boolean debug_write_function
534 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
535 const char *, enum debug_object_linkage, struct debug_function *));
536 static boolean debug_write_block
537 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
538 struct debug_block *));
540 /* Issue an error message. */
543 debug_error (message)
546 fprintf (stderr, "%s\n", message);
549 /* Add an object to a namespace. */
551 static struct debug_name *
552 debug_add_to_namespace (info, nsp, name, kind, linkage)
553 struct debug_handle *info;
554 struct debug_namespace **nsp;
556 enum debug_object_kind kind;
557 enum debug_object_linkage linkage;
559 struct debug_name *n;
560 struct debug_namespace *ns;
562 n = (struct debug_name *) xmalloc (sizeof *n);
563 memset (n, 0, sizeof *n);
567 n->linkage = linkage;
572 ns = (struct debug_namespace *) xmalloc (sizeof *ns);
573 memset (ns, 0, sizeof *ns);
575 ns->tail = &ns->list;
586 /* Add an object to the current namespace. */
588 static struct debug_name *
589 debug_add_to_current_namespace (info, name, kind, linkage)
590 struct debug_handle *info;
592 enum debug_object_kind kind;
593 enum debug_object_linkage linkage;
595 struct debug_namespace **nsp;
597 if (info->current_unit == NULL
598 || info->current_file == NULL)
600 debug_error ("debug_add_to_current_namespace: no current file");
604 if (info->current_block != NULL)
605 nsp = &info->current_block->locals;
607 nsp = &info->current_file->globals;
609 return debug_add_to_namespace (info, nsp, name, kind, linkage);
612 /* Return a handle for debugging information. */
617 struct debug_handle *ret;
619 ret = (struct debug_handle *) xmalloc (sizeof *ret);
620 memset (ret, 0, sizeof *ret);
624 /* Set the source filename. This implicitly starts a new compilation
628 debug_set_filename (handle, name)
632 struct debug_handle *info = (struct debug_handle *) handle;
633 struct debug_file *nfile;
634 struct debug_unit *nunit;
639 nfile = (struct debug_file *) xmalloc (sizeof *nfile);
640 memset (nfile, 0, sizeof *nfile);
642 nfile->filename = name;
644 nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
645 memset (nunit, 0, sizeof *nunit);
647 nunit->files = nfile;
648 info->current_file = nfile;
650 if (info->current_unit != NULL)
651 info->current_unit->next = nunit;
654 assert (info->units == NULL);
658 info->current_unit = nunit;
660 info->current_function = NULL;
661 info->current_block = NULL;
662 info->current_lineno = NULL;
667 /* Change source files to the given file name. This is used for
668 include files in a single compilation unit. */
671 debug_start_source (handle, name)
675 struct debug_handle *info = (struct debug_handle *) handle;
676 struct debug_file *f, **pf;
681 if (info->current_unit == NULL)
683 debug_error ("debug_start_source: no debug_set_filename call");
687 for (f = info->current_unit->files; f != NULL; f = f->next)
689 if (f->filename[0] == name[0]
690 && f->filename[1] == name[1]
691 && strcmp (f->filename, name) == 0)
693 info->current_file = f;
698 f = (struct debug_file *) xmalloc (sizeof *f);
699 memset (f, 0, sizeof *f);
703 for (pf = &info->current_file->next;
709 info->current_file = f;
714 /* Record a function definition. This implicitly starts a function
715 block. The debug_type argument is the type of the return value.
716 The boolean indicates whether the function is globally visible.
717 The bfd_vma is the address of the start of the function. Currently
718 the parameter types are specified by calls to
719 debug_record_parameter. FIXME: There is no way to specify nested
720 functions. FIXME: I don't think there is any way to record where a
724 debug_record_function (handle, name, return_type, global, addr)
727 debug_type return_type;
731 struct debug_handle *info = (struct debug_handle *) handle;
732 struct debug_function *f;
733 struct debug_block *b;
734 struct debug_name *n;
738 if (return_type == NULL)
741 if (info->current_unit == NULL)
743 debug_error ("debug_record_function: no debug_set_filename call");
747 f = (struct debug_function *) xmalloc (sizeof *f);
748 memset (f, 0, sizeof *f);
750 f->return_type = return_type;
752 b = (struct debug_block *) xmalloc (sizeof *b);
753 memset (b, 0, sizeof *b);
756 b->end = (bfd_vma) -1;
760 info->current_function = f;
761 info->current_block = b;
763 /* FIXME: If we could handle nested functions, this would be the
764 place: we would want to use a different namespace. */
765 n = debug_add_to_namespace (info,
766 &info->current_file->globals,
768 DEBUG_OBJECT_FUNCTION,
770 ? DEBUG_LINKAGE_GLOBAL
771 : DEBUG_LINKAGE_STATIC));
780 /* Record a parameter for the current function. */
783 debug_record_parameter (handle, name, type, kind, val)
787 enum debug_parm_kind kind;
790 struct debug_handle *info = (struct debug_handle *) handle;
791 struct debug_parameter *p, **pp;
793 if (name == NULL || type == NULL)
796 if (info->current_unit == NULL
797 || info->current_function == NULL)
799 debug_error ("debug_record_parameter: no current function");
803 p = (struct debug_parameter *) xmalloc (sizeof *p);
804 memset (p, 0, sizeof *p);
811 for (pp = &info->current_function->parameters;
820 /* End a function. FIXME: This should handle function nesting. */
823 debug_end_function (handle, addr)
827 struct debug_handle *info = (struct debug_handle *) handle;
829 if (info->current_unit == NULL
830 || info->current_block == NULL
831 || info->current_function == NULL)
833 debug_error ("debug_end_function: no current function");
837 if (info->current_block->parent != NULL)
839 debug_error ("debug_end_function: some blocks were not closed");
843 info->current_block->end = addr;
845 info->current_function = NULL;
846 info->current_block = NULL;
851 /* Start a block in a function. All local information will be
852 recorded in this block, until the matching call to debug_end_block.
853 debug_start_block and debug_end_block may be nested. The bfd_vma
854 argument is the address at which this block starts. */
857 debug_start_block (handle, addr)
861 struct debug_handle *info = (struct debug_handle *) handle;
862 struct debug_block *b, **pb;
864 /* We must always have a current block: debug_record_function sets
866 if (info->current_unit == NULL
867 || info->current_block == NULL)
869 debug_error ("debug_start_block: no current block");
873 b = (struct debug_block *) xmalloc (sizeof *b);
874 memset (b, 0, sizeof *b);
876 b->parent = info->current_block;
878 b->end = (bfd_vma) -1;
880 /* This new block is a child of the current block. */
881 for (pb = &info->current_block->children;
887 info->current_block = b;
892 /* Finish a block in a function. This matches the call to
893 debug_start_block. The argument is the address at which this block
897 debug_end_block (handle, addr)
901 struct debug_handle *info = (struct debug_handle *) handle;
902 struct debug_block *parent;
904 if (info->current_unit == NULL
905 || info->current_block == NULL)
907 debug_error ("debug_end_block: no current block");
911 parent = info->current_block->parent;
914 debug_error ("debug_end_block: attempt to close top level block");
918 info->current_block->end = addr;
920 info->current_block = parent;
925 /* Associate a line number in the current source file and function
926 with a given address. */
929 debug_record_line (handle, lineno, addr)
931 unsigned long lineno;
934 struct debug_handle *info = (struct debug_handle *) handle;
935 struct debug_lineno *l;
938 if (info->current_unit == NULL)
940 debug_error ("debug_record_line: no current unit");
944 l = info->current_lineno;
945 if (l != NULL && l->file == info->current_file)
947 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
949 if (l->linenos[i] == (unsigned long) -1)
951 l->linenos[i] = lineno;
958 /* If we get here, then either 1) there is no current_lineno
959 structure, which means this is the first line number in this
960 compilation unit, 2) the current_lineno structure is for a
961 different file, or 3) the current_lineno structure is full.
962 Regardless, we want to allocate a new debug_lineno structure, put
963 it in the right place, and make it the new current_lineno
966 l = (struct debug_lineno *) xmalloc (sizeof *l);
967 memset (l, 0, sizeof *l);
969 l->file = info->current_file;
970 l->linenos[0] = lineno;
972 for (i = 1; i < DEBUG_LINENO_COUNT; i++)
973 l->linenos[i] = (unsigned long) -1;
975 if (info->current_lineno != NULL)
976 info->current_lineno->next = l;
978 info->current_unit->linenos = l;
980 info->current_lineno = l;
985 /* Start a named common block. This is a block of variables that may
989 debug_start_common_block (handle, name)
994 debug_error ("debug_start_common_block: not implemented");
998 /* End a named common block. */
1001 debug_end_common_block (handle, name)
1006 debug_error ("debug_end_common_block: not implemented");
1010 /* Record a named integer constant. */
1013 debug_record_int_const (handle, name, val)
1018 struct debug_handle *info = (struct debug_handle *) handle;
1019 struct debug_name *n;
1024 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
1025 DEBUG_LINKAGE_NONE);
1029 n->u.int_constant = val;
1034 /* Record a named floating point constant. */
1037 debug_record_float_const (handle, name, val)
1042 struct debug_handle *info = (struct debug_handle *) handle;
1043 struct debug_name *n;
1048 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
1049 DEBUG_LINKAGE_NONE);
1053 n->u.float_constant = val;
1058 /* Record a typed constant with an integral value. */
1061 debug_record_typed_const (handle, name, type, val)
1067 struct debug_handle *info = (struct debug_handle *) handle;
1068 struct debug_name *n;
1069 struct debug_typed_constant *tc;
1071 if (name == NULL || type == NULL)
1074 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
1075 DEBUG_LINKAGE_NONE);
1079 tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
1080 memset (tc, 0, sizeof *tc);
1085 n->u.typed_constant = tc;
1090 /* Record a label. */
1093 debug_record_label (handle, name, type, addr)
1100 debug_error ("debug_record_label not implemented");
1104 /* Record a variable. */
1107 debug_record_variable (handle, name, type, kind, val)
1111 enum debug_var_kind kind;
1114 struct debug_handle *info = (struct debug_handle *) handle;
1115 struct debug_namespace **nsp;
1116 enum debug_object_linkage linkage;
1117 struct debug_name *n;
1118 struct debug_variable *v;
1120 if (name == NULL || type == NULL)
1123 if (info->current_unit == NULL
1124 || info->current_file == NULL)
1126 debug_error ("debug_record_variable: no current file");
1130 if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
1132 nsp = &info->current_file->globals;
1133 if (kind == DEBUG_GLOBAL)
1134 linkage = DEBUG_LINKAGE_GLOBAL;
1136 linkage = DEBUG_LINKAGE_STATIC;
1140 if (info->current_block == NULL)
1142 debug_error ("debug_record_variable: no current block");
1145 nsp = &info->current_block->locals;
1146 linkage = DEBUG_LINKAGE_AUTOMATIC;
1149 n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
1153 v = (struct debug_variable *) xmalloc (sizeof *v);
1154 memset (v, 0, sizeof *v);
1165 /* Make a type with a given kind and size. */
1168 static struct debug_type *
1169 debug_make_type (info, kind, size)
1170 struct debug_handle *info;
1171 enum debug_type_kind kind;
1174 struct debug_type *t;
1176 t = (struct debug_type *) xmalloc (sizeof *t);
1177 memset (t, 0, sizeof *t);
1185 /* Make an indirect type which may be used as a placeholder for a type
1186 which is referenced before it is defined. */
1189 debug_make_indirect_type (handle, slot, tag)
1194 struct debug_handle *info = (struct debug_handle *) handle;
1195 struct debug_type *t;
1196 struct debug_indirect_type *i;
1198 t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
1200 return DEBUG_TYPE_NULL;
1202 i = (struct debug_indirect_type *) xmalloc (sizeof *i);
1203 memset (i, 0, sizeof *i);
1213 /* Make a void type. There is only one of these. */
1216 debug_make_void_type (handle)
1219 struct debug_handle *info = (struct debug_handle *) handle;
1221 return debug_make_type (info, DEBUG_KIND_VOID, 0);
1224 /* Make an integer type of a given size. The boolean argument is true
1225 if the integer is unsigned. */
1228 debug_make_int_type (handle, size, unsignedp)
1233 struct debug_handle *info = (struct debug_handle *) handle;
1234 struct debug_type *t;
1236 t = debug_make_type (info, DEBUG_KIND_INT, size);
1238 return DEBUG_TYPE_NULL;
1240 t->u.kint = unsignedp;
1245 /* Make a floating point type of a given size. FIXME: On some
1246 platforms, like an Alpha, you probably need to be able to specify
1250 debug_make_float_type (handle, size)
1254 struct debug_handle *info = (struct debug_handle *) handle;
1256 return debug_make_type (info, DEBUG_KIND_FLOAT, size);
1259 /* Make a boolean type of a given size. */
1262 debug_make_bool_type (handle, size)
1266 struct debug_handle *info = (struct debug_handle *) handle;
1268 return debug_make_type (info, DEBUG_KIND_BOOL, size);
1271 /* Make a complex type of a given size. */
1274 debug_make_complex_type (handle, size)
1278 struct debug_handle *info = (struct debug_handle *) handle;
1280 return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
1283 /* Make a structure type. The second argument is true for a struct,
1284 false for a union. The third argument is the size of the struct.
1285 The fourth argument is a NULL terminated array of fields. */
1288 debug_make_struct_type (handle, structp, size, fields)
1292 debug_field *fields;
1294 struct debug_handle *info = (struct debug_handle *) handle;
1295 struct debug_type *t;
1296 struct debug_class_type *c;
1298 t = debug_make_type (info,
1299 structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
1302 return DEBUG_TYPE_NULL;
1304 c = (struct debug_class_type *) xmalloc (sizeof *c);
1305 memset (c, 0, sizeof *c);
1314 /* Make an object type. The first three arguments after the handle
1315 are the same as for debug_make_struct_type. The next arguments are
1316 a NULL terminated array of base classes, a NULL terminated array of
1317 methods, the type of the object holding the virtual function table
1318 if it is not this object, and a boolean which is true if this
1319 object has its own virtual function table. */
1322 debug_make_object_type (handle, structp, size, fields, baseclasses,
1323 methods, vptrbase, ownvptr)
1327 debug_field *fields;
1328 debug_baseclass *baseclasses;
1329 debug_method *methods;
1330 debug_type vptrbase;
1333 struct debug_handle *info = (struct debug_handle *) handle;
1334 struct debug_type *t;
1335 struct debug_class_type *c;
1337 t = debug_make_type (info,
1338 structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
1341 return DEBUG_TYPE_NULL;
1343 c = (struct debug_class_type *) xmalloc (sizeof *c);
1344 memset (c, 0, sizeof *c);
1347 c->baseclasses = baseclasses;
1348 c->methods = methods;
1352 c->vptrbase = vptrbase;
1359 /* Make an enumeration type. The arguments are a null terminated
1360 array of strings, and an array of corresponding values. */
1363 debug_make_enum_type (handle, names, values)
1366 bfd_signed_vma *values;
1368 struct debug_handle *info = (struct debug_handle *) handle;
1369 struct debug_type *t;
1370 struct debug_enum_type *e;
1372 t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
1374 return DEBUG_TYPE_NULL;
1376 e = (struct debug_enum_type *) xmalloc (sizeof *e);
1377 memset (e, 0, sizeof *e);
1387 /* Make a pointer to a given type. */
1390 debug_make_pointer_type (handle, type)
1394 struct debug_handle *info = (struct debug_handle *) handle;
1395 struct debug_type *t;
1398 return DEBUG_TYPE_NULL;
1400 if (type->pointer != DEBUG_TYPE_NULL)
1401 return type->pointer;
1403 t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
1405 return DEBUG_TYPE_NULL;
1407 t->u.kpointer = type;
1414 /* Make a function returning a given type. FIXME: We should be able
1415 to record the parameter types. */
1418 debug_make_function_type (handle, type, arg_types, varargs)
1421 debug_type *arg_types;
1424 struct debug_handle *info = (struct debug_handle *) handle;
1425 struct debug_type *t;
1426 struct debug_function_type *f;
1429 return DEBUG_TYPE_NULL;
1431 t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
1433 return DEBUG_TYPE_NULL;
1435 f = (struct debug_function_type *) xmalloc (sizeof *f);
1436 memset (f, 0, sizeof *f);
1438 f->return_type = type;
1439 f->arg_types = arg_types;
1440 f->varargs = varargs;
1447 /* Make a reference to a given type. */
1450 debug_make_reference_type (handle, type)
1454 struct debug_handle *info = (struct debug_handle *) handle;
1455 struct debug_type *t;
1458 return DEBUG_TYPE_NULL;
1460 t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
1462 return DEBUG_TYPE_NULL;
1464 t->u.kreference = type;
1469 /* Make a range of a given type from a lower to an upper bound. */
1472 debug_make_range_type (handle, type, lower, upper)
1475 bfd_signed_vma lower;
1476 bfd_signed_vma upper;
1478 struct debug_handle *info = (struct debug_handle *) handle;
1479 struct debug_type *t;
1480 struct debug_range_type *r;
1483 return DEBUG_TYPE_NULL;
1485 t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
1487 return DEBUG_TYPE_NULL;
1489 r = (struct debug_range_type *) xmalloc (sizeof *r);
1490 memset (r, 0, sizeof *r);
1501 /* Make an array type. The second argument is the type of an element
1502 of the array. The third argument is the type of a range of the
1503 array. The fourth and fifth argument are the lower and upper
1504 bounds, respectively. The sixth argument is true if this array is
1505 actually a string, as in C. */
1508 debug_make_array_type (handle, element_type, range_type, lower, upper,
1511 debug_type element_type;
1512 debug_type range_type;
1513 bfd_signed_vma lower;
1514 bfd_signed_vma upper;
1517 struct debug_handle *info = (struct debug_handle *) handle;
1518 struct debug_type *t;
1519 struct debug_array_type *a;
1521 if (element_type == NULL || range_type == NULL)
1522 return DEBUG_TYPE_NULL;
1524 t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
1526 return DEBUG_TYPE_NULL;
1528 a = (struct debug_array_type *) xmalloc (sizeof *a);
1529 memset (a, 0, sizeof *a);
1531 a->element_type = element_type;
1532 a->range_type = range_type;
1535 a->stringp = stringp;
1542 /* Make a set of a given type. For example, a Pascal set type. The
1543 boolean argument is true if this set is actually a bitstring, as in
1547 debug_make_set_type (handle, type, bitstringp)
1552 struct debug_handle *info = (struct debug_handle *) handle;
1553 struct debug_type *t;
1554 struct debug_set_type *s;
1557 return DEBUG_TYPE_NULL;
1559 t = debug_make_type (info, DEBUG_KIND_SET, 0);
1561 return DEBUG_TYPE_NULL;
1563 s = (struct debug_set_type *) xmalloc (sizeof *s);
1564 memset (s, 0, sizeof *s);
1567 s->bitstringp = bitstringp;
1574 /* Make a type for a pointer which is relative to an object. The
1575 second argument is the type of the object to which the pointer is
1576 relative. The third argument is the type that the pointer points
1580 debug_make_offset_type (handle, base_type, target_type)
1582 debug_type base_type;
1583 debug_type target_type;
1585 struct debug_handle *info = (struct debug_handle *) handle;
1586 struct debug_type *t;
1587 struct debug_offset_type *o;
1589 if (base_type == NULL || target_type == NULL)
1590 return DEBUG_TYPE_NULL;
1592 t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
1594 return DEBUG_TYPE_NULL;
1596 o = (struct debug_offset_type *) xmalloc (sizeof *o);
1597 memset (o, 0, sizeof *o);
1599 o->base_type = base_type;
1600 o->target_type = target_type;
1607 /* Make a type for a method function. The second argument is the
1608 return type, the third argument is the domain, and the fourth
1609 argument is a NULL terminated array of argument types. */
1612 debug_make_method_type (handle, return_type, domain_type, arg_types, varargs)
1614 debug_type return_type;
1615 debug_type domain_type;
1616 debug_type *arg_types;
1619 struct debug_handle *info = (struct debug_handle *) handle;
1620 struct debug_type *t;
1621 struct debug_method_type *m;
1623 if (return_type == NULL)
1624 return DEBUG_TYPE_NULL;
1626 t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
1628 return DEBUG_TYPE_NULL;
1630 m = (struct debug_method_type *) xmalloc (sizeof *m);
1631 memset (m, 0, sizeof *m);
1633 m->return_type = return_type;
1634 m->domain_type = domain_type;
1635 m->arg_types = arg_types;
1636 m->varargs = varargs;
1643 /* Make a const qualified version of a given type. */
1646 debug_make_const_type (handle, type)
1650 struct debug_handle *info = (struct debug_handle *) handle;
1651 struct debug_type *t;
1654 return DEBUG_TYPE_NULL;
1656 t = debug_make_type (info, DEBUG_KIND_CONST, 0);
1658 return DEBUG_TYPE_NULL;
1665 /* Make a volatile qualified version of a given type. */
1668 debug_make_volatile_type (handle, type)
1672 struct debug_handle *info = (struct debug_handle *) handle;
1673 struct debug_type *t;
1676 return DEBUG_TYPE_NULL;
1678 t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
1680 return DEBUG_TYPE_NULL;
1682 t->u.kvolatile = type;
1687 /* Make an undefined tagged type. For example, a struct which has
1688 been mentioned, but not defined. */
1691 debug_make_undefined_tagged_type (handle, name, kind)
1694 enum debug_type_kind kind;
1696 struct debug_handle *info = (struct debug_handle *) handle;
1697 struct debug_type *t;
1700 return DEBUG_TYPE_NULL;
1704 case DEBUG_KIND_STRUCT:
1705 case DEBUG_KIND_UNION:
1706 case DEBUG_KIND_CLASS:
1707 case DEBUG_KIND_UNION_CLASS:
1708 case DEBUG_KIND_ENUM:
1712 debug_error ("debug_make_undefined_type: unsupported kind");
1713 return DEBUG_TYPE_NULL;
1716 t = debug_make_type (info, kind, 0);
1718 return DEBUG_TYPE_NULL;
1720 return debug_tag_type (handle, name, t);
1723 /* Make a base class for an object. The second argument is the base
1724 class type. The third argument is the bit position of this base
1725 class in the object (always 0 unless doing multiple inheritance).
1726 The fourth argument is whether this is a virtual class. The fifth
1727 argument is the visibility of the base class. */
1731 debug_make_baseclass (handle, type, bitpos, virtual, visibility)
1736 enum debug_visibility visibility;
1738 struct debug_baseclass *b;
1740 b = (struct debug_baseclass *) xmalloc (sizeof *b);
1741 memset (b, 0, sizeof *b);
1745 b->virtual = virtual;
1746 b->visibility = visibility;
1751 /* Make a field for a struct. The second argument is the name. The
1752 third argument is the type of the field. The fourth argument is
1753 the bit position of the field. The fifth argument is the size of
1754 the field (it may be zero). The sixth argument is the visibility
1759 debug_make_field (handle, name, type, bitpos, bitsize, visibility)
1765 enum debug_visibility visibility;
1767 struct debug_field *f;
1769 f = (struct debug_field *) xmalloc (sizeof *f);
1770 memset (f, 0, sizeof *f);
1774 f->static_member = false;
1775 f->u.f.bitpos = bitpos;
1776 f->u.f.bitsize = bitsize;
1777 f->visibility = visibility;
1782 /* Make a static member of an object. The second argument is the
1783 name. The third argument is the type of the member. The fourth
1784 argument is the physical name of the member (i.e., the name as a
1785 global variable). The fifth argument is the visibility of the
1790 debug_make_static_member (handle, name, type, physname, visibility)
1794 const char *physname;
1795 enum debug_visibility visibility;
1797 struct debug_field *f;
1799 f = (struct debug_field *) xmalloc (sizeof *f);
1800 memset (f, 0, sizeof *f);
1804 f->static_member = true;
1805 f->u.s.physname = physname;
1806 f->visibility = visibility;
1811 /* Make a method. The second argument is the name, and the third
1812 argument is a NULL terminated array of method variants. */
1816 debug_make_method (handle, name, variants)
1819 debug_method_variant *variants;
1821 struct debug_method *m;
1823 m = (struct debug_method *) xmalloc (sizeof *m);
1824 memset (m, 0, sizeof *m);
1827 m->variants = variants;
1832 /* Make a method argument. The second argument is the real name of
1833 the function. The third argument is the type of the function. The
1834 fourth argument is the visibility. The fifth argument is whether
1835 this is a const function. The sixth argument is whether this is a
1836 volatile function. The seventh argument is the offset in the
1837 virtual function table, if any. The eighth argument is the virtual
1838 function context. FIXME: Are the const and volatile arguments
1839 necessary? Could we just use debug_make_const_type? */
1842 debug_method_variant
1843 debug_make_method_variant (handle, physname, type, visibility, constp,
1844 volatilep, voffset, context)
1846 const char *physname;
1848 enum debug_visibility visibility;
1854 struct debug_method_variant *m;
1856 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1857 memset (m, 0, sizeof *m);
1859 m->physname = physname;
1861 m->visibility = visibility;
1863 m->volatilep = volatilep;
1864 m->voffset = voffset;
1865 m->context = context;
1870 /* Make a static method argument. The arguments are the same as for
1871 debug_make_method_variant, except that the last two are omitted
1872 since a static method can not also be virtual. */
1874 debug_method_variant
1875 debug_make_static_method_variant (handle, physname, type, visibility,
1878 const char *physname;
1880 enum debug_visibility visibility;
1884 struct debug_method_variant *m;
1886 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1887 memset (m, 0, sizeof *m);
1889 m->physname = physname;
1891 m->visibility = visibility;
1893 m->volatilep = volatilep;
1894 m->voffset = VOFFSET_STATIC_METHOD;
1902 debug_name_type (handle, name, type)
1907 struct debug_handle *info = (struct debug_handle *) handle;
1908 struct debug_type *t;
1909 struct debug_named_type *n;
1910 struct debug_name *nm;
1912 if (name == NULL || type == NULL)
1913 return DEBUG_TYPE_NULL;
1915 if (info->current_unit == NULL
1916 || info->current_file == NULL)
1918 debug_error ("debug_record_variable: no current file");
1922 t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1924 return DEBUG_TYPE_NULL;
1926 n = (struct debug_named_type *) xmalloc (sizeof *n);
1927 memset (n, 0, sizeof *n);
1933 /* We always add the name to the global namespace. This is probably
1934 wrong in some cases, but it seems to be right for stabs. FIXME. */
1936 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1937 DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
1951 debug_tag_type (handle, name, type)
1956 struct debug_handle *info = (struct debug_handle *) handle;
1957 struct debug_type *t;
1958 struct debug_named_type *n;
1959 struct debug_name *nm;
1961 if (name == NULL || type == NULL)
1962 return DEBUG_TYPE_NULL;
1964 if (info->current_file == NULL)
1966 debug_error ("debug_tag_type: no current file");
1967 return DEBUG_TYPE_NULL;
1970 if (type->kind == DEBUG_KIND_TAGGED)
1972 if (strcmp (type->u.knamed->name->name, name) == 0)
1974 debug_error ("debug_tag_type: extra tag attempted");
1975 return DEBUG_TYPE_NULL;
1978 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
1980 return DEBUG_TYPE_NULL;
1982 n = (struct debug_named_type *) xmalloc (sizeof *n);
1983 memset (n, 0, sizeof *n);
1989 /* We keep a global namespace of tags for each compilation unit. I
1990 don't know if that is the right thing to do. */
1992 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1993 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
2004 /* Record the size of a given type. */
2008 debug_record_type_size (handle, type, size)
2013 if (type->size != 0 && type->size != size)
2014 fprintf (stderr, "Warning: changing type size from %d to %d\n",
2022 /* Find a named type. */
2025 debug_find_named_type (handle, name)
2029 struct debug_handle *info = (struct debug_handle *) handle;
2030 struct debug_block *b;
2031 struct debug_file *f;
2033 /* We only search the current compilation unit. I don't know if
2034 this is right or not. */
2036 if (info->current_unit == NULL)
2038 debug_error ("debug_find_named_type: no current compilation unit");
2039 return DEBUG_TYPE_NULL;
2042 for (b = info->current_block; b != NULL; b = b->parent)
2044 if (b->locals != NULL)
2046 struct debug_name *n;
2048 for (n = b->locals->list; n != NULL; n = n->next)
2050 if (n->kind == DEBUG_OBJECT_TYPE
2051 && n->name[0] == name[0]
2052 && strcmp (n->name, name) == 0)
2058 for (f = info->current_unit->files; f != NULL; f = f->next)
2060 if (f->globals != NULL)
2062 struct debug_name *n;
2064 for (n = f->globals->list; n != NULL; n = n->next)
2066 if (n->kind == DEBUG_OBJECT_TYPE
2067 && n->name[0] == name[0]
2068 && strcmp (n->name, name) == 0)
2074 return DEBUG_TYPE_NULL;
2077 /* Find a tagged type. */
2080 debug_find_tagged_type (handle, name, kind)
2083 enum debug_type_kind kind;
2085 struct debug_handle *info = (struct debug_handle *) handle;
2086 struct debug_unit *u;
2088 /* We search the globals of all the compilation units. I don't know
2089 if this is correct or not. It would be easy to change. */
2091 for (u = info->units; u != NULL; u = u->next)
2093 struct debug_file *f;
2095 for (f = u->files; f != NULL; f = f->next)
2097 struct debug_name *n;
2099 if (f->globals != NULL)
2101 for (n = f->globals->list; n != NULL; n = n->next)
2103 if (n->kind == DEBUG_OBJECT_TAG
2104 && (kind == DEBUG_KIND_ILLEGAL
2105 || n->u.tag->kind == kind)
2106 && n->name[0] == name[0]
2107 && strcmp (n->name, name) == 0)
2114 return DEBUG_TYPE_NULL;
2117 /* Get a base type. */
2119 static struct debug_type *
2120 debug_get_real_type (handle, type)
2128 case DEBUG_KIND_INDIRECT:
2129 if (*type->u.kindirect->slot != NULL)
2130 return debug_get_real_type (handle, *type->u.kindirect->slot);
2132 case DEBUG_KIND_NAMED:
2133 case DEBUG_KIND_TAGGED:
2134 return debug_get_real_type (handle, type->u.knamed->type);
2139 /* Get the kind of a type. */
2141 enum debug_type_kind
2142 debug_get_type_kind (handle, type)
2147 return DEBUG_KIND_ILLEGAL;
2148 type = debug_get_real_type (handle, type);
2152 /* Get the name of a type. */
2155 debug_get_type_name (handle, type)
2159 if (type->kind == DEBUG_KIND_INDIRECT)
2161 if (*type->u.kindirect->slot != NULL)
2162 return debug_get_type_name (handle, *type->u.kindirect->slot);
2163 return type->u.kindirect->tag;
2165 if (type->kind == DEBUG_KIND_NAMED
2166 || type->kind == DEBUG_KIND_TAGGED)
2167 return type->u.knamed->name->name;
2171 /* Get the size of a type. */
2174 debug_get_type_size (handle, type)
2181 /* We don't call debug_get_real_type, because somebody might have
2182 called debug_record_type_size on a named or indirect type. */
2184 if (type->size != 0)
2191 case DEBUG_KIND_INDIRECT:
2192 if (*type->u.kindirect->slot != NULL)
2193 return debug_get_type_size (handle, *type->u.kindirect->slot);
2195 case DEBUG_KIND_NAMED:
2196 case DEBUG_KIND_TAGGED:
2197 return debug_get_type_size (handle, type->u.knamed->type);
2202 /* Get the return type of a function or method type. */
2205 debug_get_return_type (handle, type)
2210 return DEBUG_TYPE_NULL;
2211 type = debug_get_real_type (handle, type);
2215 return DEBUG_TYPE_NULL;
2216 case DEBUG_KIND_FUNCTION:
2217 return type->u.kfunction->return_type;
2218 case DEBUG_KIND_METHOD:
2219 return type->u.kmethod->return_type;
2224 /* Get the parameter types of a function or method type (except that
2225 we don't currently store the parameter types of a function). */
2228 debug_get_parameter_types (handle, type, pvarargs)
2235 type = debug_get_real_type (handle, type);
2240 case DEBUG_KIND_FUNCTION:
2241 *pvarargs = type->u.kfunction->varargs;
2242 return type->u.kfunction->arg_types;
2243 case DEBUG_KIND_METHOD:
2244 *pvarargs = type->u.kmethod->varargs;
2245 return type->u.kmethod->arg_types;
2250 /* Get the target type of a type. */
2253 debug_get_target_type (handle, type)
2259 type = debug_get_real_type (handle, type);
2264 case DEBUG_KIND_POINTER:
2265 return type->u.kpointer;
2266 case DEBUG_KIND_REFERENCE:
2267 return type->u.kreference;
2268 case DEBUG_KIND_CONST:
2269 return type->u.kconst;
2270 case DEBUG_KIND_VOLATILE:
2271 return type->u.kvolatile;
2276 /* Get the NULL terminated array of fields for a struct, union, or
2280 debug_get_fields (handle, type)
2286 type = debug_get_real_type (handle, type);
2291 case DEBUG_KIND_STRUCT:
2292 case DEBUG_KIND_UNION:
2293 case DEBUG_KIND_CLASS:
2294 case DEBUG_KIND_UNION_CLASS:
2295 return type->u.kclass->fields;
2300 /* Get the type of a field. */
2304 debug_get_field_type (handle, field)
2313 /* Get the name of a field. */
2317 debug_get_field_name (handle, field)
2326 /* Get the bit position of a field. */
2330 debug_get_field_bitpos (handle, field)
2334 if (field == NULL || field->static_member)
2335 return (bfd_vma) -1;
2336 return field->u.f.bitpos;
2339 /* Get the bit size of a field. */
2343 debug_get_field_bitsize (handle, field)
2347 if (field == NULL || field->static_member)
2348 return (bfd_vma) -1;
2349 return field->u.f.bitsize;
2352 /* Get the visibility of a field. */
2355 enum debug_visibility
2356 debug_get_field_visibility (handle, field)
2361 return DEBUG_VISIBILITY_IGNORE;
2362 return field->visibility;
2365 /* Get the physical name of a field. */
2368 debug_get_field_physname (handle, field)
2372 if (field == NULL || ! field->static_member)
2374 return field->u.s.physname;
2377 /* Write out the debugging information. This is given a handle to
2378 debugging information, and a set of function pointers to call. */
2381 debug_write (handle, fns, fhandle)
2383 const struct debug_write_fns *fns;
2386 struct debug_handle *info = (struct debug_handle *) handle;
2387 struct debug_unit *u;
2389 /* We use a mark to tell whether we have already written out a
2390 particular name. We use an integer, so that we don't have to
2391 clear the mark fields if we happen to write out the same
2392 information more than once. */
2395 /* The base_id field holds an ID value which will never be used, so
2396 that we can tell whether we have assigned an ID during this call
2398 info->base_id = info->class_id;
2400 for (u = info->units; u != NULL; u = u->next)
2402 struct debug_file *f;
2404 struct debug_lineno *l;
2406 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2410 for (f = u->files; f != NULL; f = f->next)
2412 struct debug_name *n;
2418 if (! (*fns->start_source) (fhandle, f->filename))
2422 if (f->globals != NULL)
2424 for (n = f->globals->list; n != NULL; n = n->next)
2426 if (! debug_write_name (info, fns, fhandle, n))
2432 for (l = u->linenos; l != NULL; l = l->next)
2436 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
2438 if (l->linenos[i] == (unsigned long) -1)
2440 if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
2450 /* Write out an element in a namespace. */
2453 debug_write_name (info, fns, fhandle, n)
2454 struct debug_handle *info;
2455 const struct debug_write_fns *fns;
2457 struct debug_name *n;
2459 /* The class_mark field is used to prevent recursively outputting a
2465 case DEBUG_OBJECT_TYPE:
2466 if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2467 || ! (*fns->typdef) (fhandle, n->name))
2470 case DEBUG_OBJECT_TAG:
2471 if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2473 return (*fns->tag) (fhandle, n->name);
2474 case DEBUG_OBJECT_VARIABLE:
2475 if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2476 (struct debug_name *) NULL))
2478 return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2479 n->u.variable->val);
2480 case DEBUG_OBJECT_FUNCTION:
2481 return debug_write_function (info, fns, fhandle, n->name,
2482 n->linkage, n->u.function);
2483 case DEBUG_OBJECT_INT_CONSTANT:
2484 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2485 case DEBUG_OBJECT_FLOAT_CONSTANT:
2486 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2487 case DEBUG_OBJECT_TYPED_CONSTANT:
2488 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2489 (struct debug_name *) NULL))
2491 return (*fns->typed_constant) (fhandle, n->name,
2492 n->u.typed_constant->val);
2500 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2501 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2502 are about to call typedef or tag. If the type is anything else,
2503 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2504 points to this one. */
2507 debug_write_type (info, fns, fhandle, type, name)
2508 struct debug_handle *info;
2509 const struct debug_write_fns *fns;
2511 struct debug_type *type;
2512 struct debug_name *name;
2518 /* If we have a name for this type, just output it. We only output
2519 typedef names after they have been defined. We output type tags
2520 whenever we are not actually defining them. */
2521 if ((type->kind == DEBUG_KIND_NAMED
2522 || type->kind == DEBUG_KIND_TAGGED)
2523 && (type->u.knamed->name->mark == info->mark
2524 || (type->kind == DEBUG_KIND_TAGGED
2525 && type->u.knamed->name != name)))
2527 if (type->kind == DEBUG_KIND_NAMED)
2528 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2531 struct debug_type *real;
2533 real = debug_get_real_type ((PTR) info, type);
2534 return (*fns->tag_type) (fhandle, type->u.knamed->name->name, 0,
2539 /* Mark the name after we have already looked for a known name, so
2540 that we don't just define a type in terms of itself. We need to
2541 mark the name here so that a struct containing a pointer to
2542 itself will work. */
2544 name->mark = info->mark;
2548 && type->kind != DEBUG_KIND_NAMED
2549 && type->kind != DEBUG_KIND_TAGGED)
2551 assert (name->kind == DEBUG_OBJECT_TAG);
2557 case DEBUG_KIND_ILLEGAL:
2558 debug_error ("debug_write_type: illegal type encountered");
2560 case DEBUG_KIND_INDIRECT:
2561 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2562 return (*fns->empty_type) (fhandle);
2563 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2565 case DEBUG_KIND_VOID:
2566 return (*fns->void_type) (fhandle);
2567 case DEBUG_KIND_INT:
2568 return (*fns->int_type) (fhandle, type->size, type->u.kint);
2569 case DEBUG_KIND_FLOAT:
2570 return (*fns->float_type) (fhandle, type->size);
2571 case DEBUG_KIND_COMPLEX:
2572 return (*fns->complex_type) (fhandle, type->size);
2573 case DEBUG_KIND_BOOL:
2574 return (*fns->bool_type) (fhandle, type->size);
2575 case DEBUG_KIND_STRUCT:
2576 case DEBUG_KIND_UNION:
2577 if (type->u.kclass != NULL)
2579 if (info->class_mark == type->u.kclass->mark
2580 || type->u.kclass->id > info->base_id)
2582 /* We are currently outputting this struct, or we have
2583 already output it. I don't know if this can happen,
2584 but it can happen for a class. */
2585 assert (type->u.kclass->id > info->base_id);
2586 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2589 type->u.kclass->mark = info->class_mark;
2591 type->u.kclass->id = info->class_id;
2594 if (! (*fns->start_struct_type) (fhandle, tag,
2595 (type->u.kclass != NULL
2596 ? type->u.kclass->id
2598 type->kind == DEBUG_KIND_STRUCT,
2601 if (type->u.kclass != NULL
2602 && type->u.kclass->fields != NULL)
2604 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2606 struct debug_field *f;
2608 f = type->u.kclass->fields[i];
2609 if (! debug_write_type (info, fns, fhandle, f->type,
2610 (struct debug_name *) NULL)
2611 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2612 f->u.f.bitsize, f->visibility))
2616 return (*fns->end_struct_type) (fhandle);
2617 case DEBUG_KIND_CLASS:
2618 case DEBUG_KIND_UNION_CLASS:
2619 return debug_write_class_type (info, fns, fhandle, type, tag);
2620 case DEBUG_KIND_ENUM:
2621 if (type->u.kenum == NULL)
2622 return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
2623 (bfd_signed_vma *) NULL);
2624 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2625 type->u.kenum->values);
2626 case DEBUG_KIND_POINTER:
2627 if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2628 (struct debug_name *) NULL))
2630 return (*fns->pointer_type) (fhandle);
2631 case DEBUG_KIND_FUNCTION:
2632 if (type->u.kfunction->arg_types == NULL)
2636 for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
2637 if (! debug_write_type (info, fns, fhandle,
2638 type->u.kfunction->arg_types[is],
2639 (struct debug_name *) NULL))
2642 if (! debug_write_type (info, fns, fhandle,
2643 type->u.kfunction->return_type,
2644 (struct debug_name *) NULL))
2646 return (*fns->function_type) (fhandle, is,
2647 type->u.kfunction->varargs);
2648 case DEBUG_KIND_REFERENCE:
2649 if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2650 (struct debug_name *) NULL))
2652 return (*fns->reference_type) (fhandle);
2653 case DEBUG_KIND_RANGE:
2654 if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2655 (struct debug_name *) NULL))
2657 return (*fns->range_type) (fhandle, type->u.krange->lower,
2658 type->u.krange->upper);
2659 case DEBUG_KIND_ARRAY:
2660 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2661 (struct debug_name *) NULL)
2662 || ! debug_write_type (info, fns, fhandle,
2663 type->u.karray->range_type,
2664 (struct debug_name *) NULL))
2666 return (*fns->array_type) (fhandle, type->u.karray->lower,
2667 type->u.karray->upper,
2668 type->u.karray->stringp);
2669 case DEBUG_KIND_SET:
2670 if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2671 (struct debug_name *) NULL))
2673 return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2674 case DEBUG_KIND_OFFSET:
2675 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2676 (struct debug_name *) NULL)
2677 || ! debug_write_type (info, fns, fhandle,
2678 type->u.koffset->target_type,
2679 (struct debug_name *) NULL))
2681 return (*fns->offset_type) (fhandle);
2682 case DEBUG_KIND_METHOD:
2683 if (! debug_write_type (info, fns, fhandle,
2684 type->u.kmethod->return_type,
2685 (struct debug_name *) NULL))
2687 if (type->u.kmethod->arg_types == NULL)
2691 for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
2692 if (! debug_write_type (info, fns, fhandle,
2693 type->u.kmethod->arg_types[is],
2694 (struct debug_name *) NULL))
2697 if (type->u.kmethod->domain_type != NULL)
2699 if (! debug_write_type (info, fns, fhandle,
2700 type->u.kmethod->domain_type,
2701 (struct debug_name *) NULL))
2704 return (*fns->method_type) (fhandle,
2705 type->u.kmethod->domain_type != NULL,
2707 type->u.kmethod->varargs);
2708 case DEBUG_KIND_CONST:
2709 if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2710 (struct debug_name *) NULL))
2712 return (*fns->const_type) (fhandle);
2713 case DEBUG_KIND_VOLATILE:
2714 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2715 (struct debug_name *) NULL))
2717 return (*fns->volatile_type) (fhandle);
2718 case DEBUG_KIND_NAMED:
2719 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2720 (struct debug_name *) NULL);
2721 case DEBUG_KIND_TAGGED:
2722 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2723 type->u.knamed->name);
2730 /* Write out a class type. */
2733 debug_write_class_type (info, fns, fhandle, type, tag)
2734 struct debug_handle *info;
2735 const struct debug_write_fns *fns;
2737 struct debug_type *type;
2742 struct debug_type *vptrbase;
2744 if (type->u.kclass == NULL)
2751 if (info->class_mark == type->u.kclass->mark
2752 || type->u.kclass->id > info->base_id)
2754 /* We are currently outputting this class, or we have
2755 already output it. This can happen when there are
2756 methods for an anonymous class. */
2757 assert (type->u.kclass->id > info->base_id);
2758 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2761 type->u.kclass->mark = info->class_mark;
2763 id = info->class_id;
2764 type->u.kclass->id = id;
2766 vptrbase = type->u.kclass->vptrbase;
2767 if (vptrbase != NULL && vptrbase != type)
2769 if (! debug_write_type (info, fns, fhandle, vptrbase,
2770 (struct debug_name *) NULL))
2775 if (! (*fns->start_class_type) (fhandle, tag, id,
2776 type->kind == DEBUG_KIND_CLASS,
2782 if (type->u.kclass != NULL)
2784 if (type->u.kclass->fields != NULL)
2786 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2788 struct debug_field *f;
2790 f = type->u.kclass->fields[i];
2791 if (! debug_write_type (info, fns, fhandle, f->type,
2792 (struct debug_name *) NULL))
2794 if (f->static_member)
2796 if (! (*fns->class_static_member) (fhandle, f->name,
2803 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2804 f->u.f.bitsize, f->visibility))
2810 if (type->u.kclass->baseclasses != NULL)
2812 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2814 struct debug_baseclass *b;
2816 b = type->u.kclass->baseclasses[i];
2817 if (! debug_write_type (info, fns, fhandle, b->type,
2818 (struct debug_name *) NULL))
2820 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
2826 if (type->u.kclass->methods != NULL)
2828 for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2830 struct debug_method *m;
2833 m = type->u.kclass->methods[i];
2834 if (! (*fns->class_start_method) (fhandle, m->name))
2836 for (j = 0; m->variants[j] != NULL; j++)
2838 struct debug_method_variant *v;
2841 if (v->context != NULL)
2843 if (! debug_write_type (info, fns, fhandle, v->context,
2844 (struct debug_name *) NULL))
2847 if (! debug_write_type (info, fns, fhandle, v->type,
2848 (struct debug_name *) NULL))
2850 if (v->voffset != VOFFSET_STATIC_METHOD)
2852 if (! (*fns->class_method_variant) (fhandle, v->physname,
2857 v->context != NULL))
2862 if (! (*fns->class_static_method_variant) (fhandle,
2870 if (! (*fns->class_end_method) (fhandle))
2876 return (*fns->end_class_type) (fhandle);
2879 /* Write out information for a function. */
2882 debug_write_function (info, fns, fhandle, name, linkage, function)
2883 struct debug_handle *info;
2884 const struct debug_write_fns *fns;
2887 enum debug_object_linkage linkage;
2888 struct debug_function *function;
2890 struct debug_parameter *p;
2891 struct debug_block *b;
2893 if (! debug_write_type (info, fns, fhandle, function->return_type,
2894 (struct debug_name *) NULL))
2897 if (! (*fns->start_function) (fhandle, name,
2898 linkage == DEBUG_LINKAGE_GLOBAL))
2901 for (p = function->parameters; p != NULL; p = p->next)
2903 if (! debug_write_type (info, fns, fhandle, p->type,
2904 (struct debug_name *) NULL)
2905 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2909 for (b = function->blocks; b != NULL; b = b->next)
2911 if (! debug_write_block (info, fns, fhandle, b))
2915 return (*fns->end_function) (fhandle);
2918 /* Write out information for a block. */
2921 debug_write_block (info, fns, fhandle, block)
2922 struct debug_handle *info;
2923 const struct debug_write_fns *fns;
2925 struct debug_block *block;
2927 struct debug_name *n;
2928 struct debug_block *b;
2930 if (! (*fns->start_block) (fhandle, block->start))
2933 if (block->locals != NULL)
2935 for (n = block->locals->list; n != NULL; n = n->next)
2937 if (! debug_write_name (info, fns, fhandle, n))
2942 for (b = block->children; b != NULL; b = b->next)
2944 if (! debug_write_block (info, fns, fhandle, b))
2948 return (*fns->end_block) (fhandle, block->end);