xref: /dflybsd-src/contrib/binutils-2.27/binutils/debug.c (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj /* debug.c -- Handle generic debugging information.
2*a9fa9459Szrj    Copyright (C) 1995-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj    Written by Ian Lance Taylor <ian@cygnus.com>.
4*a9fa9459Szrj 
5*a9fa9459Szrj    This file is part of GNU Binutils.
6*a9fa9459Szrj 
7*a9fa9459Szrj    This program is free software; you can redistribute it and/or modify
8*a9fa9459Szrj    it under the terms of the GNU General Public License as published by
9*a9fa9459Szrj    the Free Software Foundation; either version 3 of the License, or
10*a9fa9459Szrj    (at your option) any later version.
11*a9fa9459Szrj 
12*a9fa9459Szrj    This program is distributed in the hope that it will be useful,
13*a9fa9459Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a9fa9459Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*a9fa9459Szrj    GNU General Public License for more details.
16*a9fa9459Szrj 
17*a9fa9459Szrj    You should have received a copy of the GNU General Public License
18*a9fa9459Szrj    along with this program; if not, write to the Free Software
19*a9fa9459Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20*a9fa9459Szrj    02110-1301, USA.  */
21*a9fa9459Szrj 
22*a9fa9459Szrj 
23*a9fa9459Szrj /* This file implements a generic debugging format.  We may eventually
24*a9fa9459Szrj    have readers which convert different formats into this generic
25*a9fa9459Szrj    format, and writers which write it out.  The initial impetus for
26*a9fa9459Szrj    this was writing a converter from stabs to HP IEEE-695 debugging
27*a9fa9459Szrj    format.  */
28*a9fa9459Szrj 
29*a9fa9459Szrj #include "sysdep.h"
30*a9fa9459Szrj #include <assert.h>
31*a9fa9459Szrj #include "bfd.h"
32*a9fa9459Szrj #include "libiberty.h"
33*a9fa9459Szrj #include "filenames.h"
34*a9fa9459Szrj #include "debug.h"
35*a9fa9459Szrj 
36*a9fa9459Szrj /* Global information we keep for debugging.  A pointer to this
37*a9fa9459Szrj    structure is the debugging handle passed to all the routines.  */
38*a9fa9459Szrj 
39*a9fa9459Szrj struct debug_handle
40*a9fa9459Szrj {
41*a9fa9459Szrj   /* A linked list of compilation units.  */
42*a9fa9459Szrj   struct debug_unit *units;
43*a9fa9459Szrj   /* The current compilation unit.  */
44*a9fa9459Szrj   struct debug_unit *current_unit;
45*a9fa9459Szrj   /* The current source file.  */
46*a9fa9459Szrj   struct debug_file *current_file;
47*a9fa9459Szrj   /* The current function.  */
48*a9fa9459Szrj   struct debug_function *current_function;
49*a9fa9459Szrj   /* The current block.  */
50*a9fa9459Szrj   struct debug_block *current_block;
51*a9fa9459Szrj   /* The current line number information for the current unit.  */
52*a9fa9459Szrj   struct debug_lineno *current_lineno;
53*a9fa9459Szrj   /* Mark.  This is used by debug_write.  */
54*a9fa9459Szrj   unsigned int mark;
55*a9fa9459Szrj   /* A struct/class ID used by debug_write.  */
56*a9fa9459Szrj   unsigned int class_id;
57*a9fa9459Szrj   /* The base for class_id for this call to debug_write.  */
58*a9fa9459Szrj   unsigned int base_id;
59*a9fa9459Szrj   /* The current line number in debug_write.  */
60*a9fa9459Szrj   struct debug_lineno *current_write_lineno;
61*a9fa9459Szrj   unsigned int current_write_lineno_index;
62*a9fa9459Szrj   /* A list of classes which have assigned ID's during debug_write.
63*a9fa9459Szrj      This is linked through the next_id field of debug_class_type.  */
64*a9fa9459Szrj   struct debug_class_id *id_list;
65*a9fa9459Szrj   /* A list used to avoid recursion during debug_type_samep.  */
66*a9fa9459Szrj   struct debug_type_compare_list *compare_list;
67*a9fa9459Szrj };
68*a9fa9459Szrj 
69*a9fa9459Szrj /* Information we keep for a single compilation unit.  */
70*a9fa9459Szrj 
71*a9fa9459Szrj struct debug_unit
72*a9fa9459Szrj {
73*a9fa9459Szrj   /* The next compilation unit.  */
74*a9fa9459Szrj   struct debug_unit *next;
75*a9fa9459Szrj   /* A list of files included in this compilation unit.  The first
76*a9fa9459Szrj      file is always the main one, and that is where the main file name
77*a9fa9459Szrj      is stored.  */
78*a9fa9459Szrj   struct debug_file *files;
79*a9fa9459Szrj   /* Line number information for this compilation unit.  This is not
80*a9fa9459Szrj      stored by function, because assembler code may have line number
81*a9fa9459Szrj      information without function information.  */
82*a9fa9459Szrj   struct debug_lineno *linenos;
83*a9fa9459Szrj };
84*a9fa9459Szrj 
85*a9fa9459Szrj /* Information kept for a single source file.  */
86*a9fa9459Szrj 
87*a9fa9459Szrj struct debug_file
88*a9fa9459Szrj {
89*a9fa9459Szrj   /* The next source file in this compilation unit.  */
90*a9fa9459Szrj   struct debug_file *next;
91*a9fa9459Szrj   /* The name of the source file.  */
92*a9fa9459Szrj   const char *filename;
93*a9fa9459Szrj   /* Global functions, variables, types, etc.  */
94*a9fa9459Szrj   struct debug_namespace *globals;
95*a9fa9459Szrj };
96*a9fa9459Szrj 
97*a9fa9459Szrj /* A type.  */
98*a9fa9459Szrj 
99*a9fa9459Szrj struct debug_type_s
100*a9fa9459Szrj {
101*a9fa9459Szrj   /* Kind of type.  */
102*a9fa9459Szrj   enum debug_type_kind kind;
103*a9fa9459Szrj   /* Size of type (0 if not known).  */
104*a9fa9459Szrj   unsigned int size;
105*a9fa9459Szrj   /* Type which is a pointer to this type.  */
106*a9fa9459Szrj   debug_type pointer;
107*a9fa9459Szrj   /* Tagged union with additional information about the type.  */
108*a9fa9459Szrj   union
109*a9fa9459Szrj     {
110*a9fa9459Szrj       /* DEBUG_KIND_INDIRECT.  */
111*a9fa9459Szrj       struct debug_indirect_type *kindirect;
112*a9fa9459Szrj       /* DEBUG_KIND_INT.  */
113*a9fa9459Szrj       /* Whether the integer is unsigned.  */
114*a9fa9459Szrj       bfd_boolean kint;
115*a9fa9459Szrj       /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
116*a9fa9459Szrj          DEBUG_KIND_UNION_CLASS.  */
117*a9fa9459Szrj       struct debug_class_type *kclass;
118*a9fa9459Szrj       /* DEBUG_KIND_ENUM.  */
119*a9fa9459Szrj       struct debug_enum_type *kenum;
120*a9fa9459Szrj       /* DEBUG_KIND_POINTER.  */
121*a9fa9459Szrj       struct debug_type_s *kpointer;
122*a9fa9459Szrj       /* DEBUG_KIND_FUNCTION.  */
123*a9fa9459Szrj       struct debug_function_type *kfunction;
124*a9fa9459Szrj       /* DEBUG_KIND_REFERENCE.  */
125*a9fa9459Szrj       struct debug_type_s *kreference;
126*a9fa9459Szrj       /* DEBUG_KIND_RANGE.  */
127*a9fa9459Szrj       struct debug_range_type *krange;
128*a9fa9459Szrj       /* DEBUG_KIND_ARRAY.  */
129*a9fa9459Szrj       struct debug_array_type *karray;
130*a9fa9459Szrj       /* DEBUG_KIND_SET.  */
131*a9fa9459Szrj       struct debug_set_type *kset;
132*a9fa9459Szrj       /* DEBUG_KIND_OFFSET.  */
133*a9fa9459Szrj       struct debug_offset_type *koffset;
134*a9fa9459Szrj       /* DEBUG_KIND_METHOD.  */
135*a9fa9459Szrj       struct debug_method_type *kmethod;
136*a9fa9459Szrj       /* DEBUG_KIND_CONST.  */
137*a9fa9459Szrj       struct debug_type_s *kconst;
138*a9fa9459Szrj       /* DEBUG_KIND_VOLATILE.  */
139*a9fa9459Szrj       struct debug_type_s *kvolatile;
140*a9fa9459Szrj       /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED.  */
141*a9fa9459Szrj       struct debug_named_type *knamed;
142*a9fa9459Szrj     } u;
143*a9fa9459Szrj };
144*a9fa9459Szrj 
145*a9fa9459Szrj /* Information kept for an indirect type.  */
146*a9fa9459Szrj 
147*a9fa9459Szrj struct debug_indirect_type
148*a9fa9459Szrj {
149*a9fa9459Szrj   /* Slot where the final type will appear.  */
150*a9fa9459Szrj   debug_type *slot;
151*a9fa9459Szrj   /* Tag.  */
152*a9fa9459Szrj   const char *tag;
153*a9fa9459Szrj };
154*a9fa9459Szrj 
155*a9fa9459Szrj /* Information kept for a struct, union, or class.  */
156*a9fa9459Szrj 
157*a9fa9459Szrj struct debug_class_type
158*a9fa9459Szrj {
159*a9fa9459Szrj   /* NULL terminated array of fields.  */
160*a9fa9459Szrj   debug_field *fields;
161*a9fa9459Szrj   /* A mark field which indicates whether the struct has already been
162*a9fa9459Szrj      printed.  */
163*a9fa9459Szrj   unsigned int mark;
164*a9fa9459Szrj   /* This is used to uniquely identify unnamed structs when printing.  */
165*a9fa9459Szrj   unsigned int id;
166*a9fa9459Szrj   /* The remaining fields are only used for DEBUG_KIND_CLASS and
167*a9fa9459Szrj      DEBUG_KIND_UNION_CLASS.  */
168*a9fa9459Szrj   /* NULL terminated array of base classes.  */
169*a9fa9459Szrj   debug_baseclass *baseclasses;
170*a9fa9459Szrj   /* NULL terminated array of methods.  */
171*a9fa9459Szrj   debug_method *methods;
172*a9fa9459Szrj   /* The type of the class providing the virtual function table for
173*a9fa9459Szrj      this class.  This may point to the type itself.  */
174*a9fa9459Szrj   debug_type vptrbase;
175*a9fa9459Szrj };
176*a9fa9459Szrj 
177*a9fa9459Szrj /* Information kept for an enum.  */
178*a9fa9459Szrj 
179*a9fa9459Szrj struct debug_enum_type
180*a9fa9459Szrj {
181*a9fa9459Szrj   /* NULL terminated array of names.  */
182*a9fa9459Szrj   const char **names;
183*a9fa9459Szrj   /* Array of corresponding values.  */
184*a9fa9459Szrj   bfd_signed_vma *values;
185*a9fa9459Szrj };
186*a9fa9459Szrj 
187*a9fa9459Szrj /* Information kept for a function.  FIXME: We should be able to
188*a9fa9459Szrj    record the parameter types.  */
189*a9fa9459Szrj 
190*a9fa9459Szrj struct debug_function_type
191*a9fa9459Szrj {
192*a9fa9459Szrj   /* Return type.  */
193*a9fa9459Szrj   debug_type return_type;
194*a9fa9459Szrj   /* NULL terminated array of argument types.  */
195*a9fa9459Szrj   debug_type *arg_types;
196*a9fa9459Szrj   /* Whether the function takes a variable number of arguments.  */
197*a9fa9459Szrj   bfd_boolean varargs;
198*a9fa9459Szrj };
199*a9fa9459Szrj 
200*a9fa9459Szrj /* Information kept for a range.  */
201*a9fa9459Szrj 
202*a9fa9459Szrj struct debug_range_type
203*a9fa9459Szrj {
204*a9fa9459Szrj   /* Range base type.  */
205*a9fa9459Szrj   debug_type type;
206*a9fa9459Szrj   /* Lower bound.  */
207*a9fa9459Szrj   bfd_signed_vma lower;
208*a9fa9459Szrj   /* Upper bound.  */
209*a9fa9459Szrj   bfd_signed_vma upper;
210*a9fa9459Szrj };
211*a9fa9459Szrj 
212*a9fa9459Szrj /* Information kept for an array.  */
213*a9fa9459Szrj 
214*a9fa9459Szrj struct debug_array_type
215*a9fa9459Szrj {
216*a9fa9459Szrj   /* Element type.  */
217*a9fa9459Szrj   debug_type element_type;
218*a9fa9459Szrj   /* Range type.  */
219*a9fa9459Szrj   debug_type range_type;
220*a9fa9459Szrj   /* Lower bound.  */
221*a9fa9459Szrj   bfd_signed_vma lower;
222*a9fa9459Szrj   /* Upper bound.  */
223*a9fa9459Szrj   bfd_signed_vma upper;
224*a9fa9459Szrj   /* Whether this array is really a string.  */
225*a9fa9459Szrj   bfd_boolean stringp;
226*a9fa9459Szrj };
227*a9fa9459Szrj 
228*a9fa9459Szrj /* Information kept for a set.  */
229*a9fa9459Szrj 
230*a9fa9459Szrj struct debug_set_type
231*a9fa9459Szrj {
232*a9fa9459Szrj   /* Base type.  */
233*a9fa9459Szrj   debug_type type;
234*a9fa9459Szrj   /* Whether this set is really a bitstring.  */
235*a9fa9459Szrj   bfd_boolean bitstringp;
236*a9fa9459Szrj };
237*a9fa9459Szrj 
238*a9fa9459Szrj /* Information kept for an offset type (a based pointer).  */
239*a9fa9459Szrj 
240*a9fa9459Szrj struct debug_offset_type
241*a9fa9459Szrj {
242*a9fa9459Szrj   /* The type the pointer is an offset from.  */
243*a9fa9459Szrj   debug_type base_type;
244*a9fa9459Szrj   /* The type the pointer points to.  */
245*a9fa9459Szrj   debug_type target_type;
246*a9fa9459Szrj };
247*a9fa9459Szrj 
248*a9fa9459Szrj /* Information kept for a method type.  */
249*a9fa9459Szrj 
250*a9fa9459Szrj struct debug_method_type
251*a9fa9459Szrj {
252*a9fa9459Szrj   /* The return type.  */
253*a9fa9459Szrj   debug_type return_type;
254*a9fa9459Szrj   /* The object type which this method is for.  */
255*a9fa9459Szrj   debug_type domain_type;
256*a9fa9459Szrj   /* A NULL terminated array of argument types.  */
257*a9fa9459Szrj   debug_type *arg_types;
258*a9fa9459Szrj   /* Whether the method takes a variable number of arguments.  */
259*a9fa9459Szrj   bfd_boolean varargs;
260*a9fa9459Szrj };
261*a9fa9459Szrj 
262*a9fa9459Szrj /* Information kept for a named type.  */
263*a9fa9459Szrj 
264*a9fa9459Szrj struct debug_named_type
265*a9fa9459Szrj {
266*a9fa9459Szrj   /* Name.  */
267*a9fa9459Szrj   struct debug_name *name;
268*a9fa9459Szrj   /* Real type.  */
269*a9fa9459Szrj   debug_type type;
270*a9fa9459Szrj };
271*a9fa9459Szrj 
272*a9fa9459Szrj /* A field in a struct or union.  */
273*a9fa9459Szrj 
274*a9fa9459Szrj struct debug_field_s
275*a9fa9459Szrj {
276*a9fa9459Szrj   /* Name of the field.  */
277*a9fa9459Szrj   const char *name;
278*a9fa9459Szrj   /* Type of the field.  */
279*a9fa9459Szrj   struct debug_type_s *type;
280*a9fa9459Szrj   /* Visibility of the field.  */
281*a9fa9459Szrj   enum debug_visibility visibility;
282*a9fa9459Szrj   /* Whether this is a static member.  */
283*a9fa9459Szrj   bfd_boolean static_member;
284*a9fa9459Szrj   union
285*a9fa9459Szrj     {
286*a9fa9459Szrj       /* If static_member is false.  */
287*a9fa9459Szrj       struct
288*a9fa9459Szrj 	{
289*a9fa9459Szrj 	  /* Bit position of the field in the struct.  */
290*a9fa9459Szrj 	  unsigned int bitpos;
291*a9fa9459Szrj 	  /* Size of the field in bits.  */
292*a9fa9459Szrj 	  unsigned int bitsize;
293*a9fa9459Szrj 	} f;
294*a9fa9459Szrj       /* If static_member is true.  */
295*a9fa9459Szrj       struct
296*a9fa9459Szrj 	{
297*a9fa9459Szrj 	  const char *physname;
298*a9fa9459Szrj 	} s;
299*a9fa9459Szrj     } u;
300*a9fa9459Szrj };
301*a9fa9459Szrj 
302*a9fa9459Szrj /* A base class for an object.  */
303*a9fa9459Szrj 
304*a9fa9459Szrj struct debug_baseclass_s
305*a9fa9459Szrj {
306*a9fa9459Szrj   /* Type of the base class.  */
307*a9fa9459Szrj   struct debug_type_s *type;
308*a9fa9459Szrj   /* Bit position of the base class in the object.  */
309*a9fa9459Szrj   unsigned int bitpos;
310*a9fa9459Szrj   /* Whether the base class is virtual.  */
311*a9fa9459Szrj   bfd_boolean is_virtual;
312*a9fa9459Szrj   /* Visibility of the base class.  */
313*a9fa9459Szrj   enum debug_visibility visibility;
314*a9fa9459Szrj };
315*a9fa9459Szrj 
316*a9fa9459Szrj /* A method of an object.  */
317*a9fa9459Szrj 
318*a9fa9459Szrj struct debug_method_s
319*a9fa9459Szrj {
320*a9fa9459Szrj   /* The name of the method.  */
321*a9fa9459Szrj   const char *name;
322*a9fa9459Szrj   /* A NULL terminated array of different types of variants.  */
323*a9fa9459Szrj   struct debug_method_variant_s **variants;
324*a9fa9459Szrj };
325*a9fa9459Szrj 
326*a9fa9459Szrj /* The variants of a method function of an object.  These indicate
327*a9fa9459Szrj    which method to run.  */
328*a9fa9459Szrj 
329*a9fa9459Szrj struct debug_method_variant_s
330*a9fa9459Szrj {
331*a9fa9459Szrj   /* The physical name of the function.  */
332*a9fa9459Szrj   const char *physname;
333*a9fa9459Szrj   /* The type of the function.  */
334*a9fa9459Szrj   struct debug_type_s *type;
335*a9fa9459Szrj   /* The visibility of the function.  */
336*a9fa9459Szrj   enum debug_visibility visibility;
337*a9fa9459Szrj   /* Whether the function is const.  */
338*a9fa9459Szrj   bfd_boolean constp;
339*a9fa9459Szrj   /* Whether the function is volatile.  */
340*a9fa9459Szrj   bfd_boolean volatilep;
341*a9fa9459Szrj   /* The offset to the function in the virtual function table.  */
342*a9fa9459Szrj   bfd_vma voffset;
343*a9fa9459Szrj   /* If voffset is VOFFSET_STATIC_METHOD, this is a static method.  */
344*a9fa9459Szrj #define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
345*a9fa9459Szrj   /* Context of a virtual method function.  */
346*a9fa9459Szrj   struct debug_type_s *context;
347*a9fa9459Szrj };
348*a9fa9459Szrj 
349*a9fa9459Szrj /* A variable.  This is the information we keep for a variable object.
350*a9fa9459Szrj    This has no name; a name is associated with a variable in a
351*a9fa9459Szrj    debug_name structure.  */
352*a9fa9459Szrj 
353*a9fa9459Szrj struct debug_variable
354*a9fa9459Szrj {
355*a9fa9459Szrj   /* Kind of variable.  */
356*a9fa9459Szrj   enum debug_var_kind kind;
357*a9fa9459Szrj   /* Type.  */
358*a9fa9459Szrj   debug_type type;
359*a9fa9459Szrj   /* Value.  The interpretation of the value depends upon kind.  */
360*a9fa9459Szrj   bfd_vma val;
361*a9fa9459Szrj };
362*a9fa9459Szrj 
363*a9fa9459Szrj /* A function.  This has no name; a name is associated with a function
364*a9fa9459Szrj    in a debug_name structure.  */
365*a9fa9459Szrj 
366*a9fa9459Szrj struct debug_function
367*a9fa9459Szrj {
368*a9fa9459Szrj   /* Return type.  */
369*a9fa9459Szrj   debug_type return_type;
370*a9fa9459Szrj   /* Parameter information.  */
371*a9fa9459Szrj   struct debug_parameter *parameters;
372*a9fa9459Szrj   /* Block information.  The first structure on the list is the main
373*a9fa9459Szrj      block of the function, and describes function local variables.  */
374*a9fa9459Szrj   struct debug_block *blocks;
375*a9fa9459Szrj };
376*a9fa9459Szrj 
377*a9fa9459Szrj /* A function parameter.  */
378*a9fa9459Szrj 
379*a9fa9459Szrj struct debug_parameter
380*a9fa9459Szrj {
381*a9fa9459Szrj   /* Next parameter.  */
382*a9fa9459Szrj   struct debug_parameter *next;
383*a9fa9459Szrj   /* Name.  */
384*a9fa9459Szrj   const char *name;
385*a9fa9459Szrj   /* Type.  */
386*a9fa9459Szrj   debug_type type;
387*a9fa9459Szrj   /* Kind.  */
388*a9fa9459Szrj   enum debug_parm_kind kind;
389*a9fa9459Szrj   /* Value (meaning depends upon kind).  */
390*a9fa9459Szrj   bfd_vma val;
391*a9fa9459Szrj };
392*a9fa9459Szrj 
393*a9fa9459Szrj /* A typed constant.  */
394*a9fa9459Szrj 
395*a9fa9459Szrj struct debug_typed_constant
396*a9fa9459Szrj {
397*a9fa9459Szrj   /* Type.  */
398*a9fa9459Szrj   debug_type type;
399*a9fa9459Szrj   /* Value.  FIXME: We may eventually need to support non-integral
400*a9fa9459Szrj      values.  */
401*a9fa9459Szrj   bfd_vma val;
402*a9fa9459Szrj };
403*a9fa9459Szrj 
404*a9fa9459Szrj /* Information about a block within a function.  */
405*a9fa9459Szrj 
406*a9fa9459Szrj struct debug_block
407*a9fa9459Szrj {
408*a9fa9459Szrj   /* Next block with the same parent.  */
409*a9fa9459Szrj   struct debug_block *next;
410*a9fa9459Szrj   /* Parent block.  */
411*a9fa9459Szrj   struct debug_block *parent;
412*a9fa9459Szrj   /* List of child blocks.  */
413*a9fa9459Szrj   struct debug_block *children;
414*a9fa9459Szrj   /* Start address of the block.  */
415*a9fa9459Szrj   bfd_vma start;
416*a9fa9459Szrj   /* End address of the block.  */
417*a9fa9459Szrj   bfd_vma end;
418*a9fa9459Szrj   /* Local variables.  */
419*a9fa9459Szrj   struct debug_namespace *locals;
420*a9fa9459Szrj };
421*a9fa9459Szrj 
422*a9fa9459Szrj /* Line number information we keep for a compilation unit.  FIXME:
423*a9fa9459Szrj    This structure is easy to create, but can be very space
424*a9fa9459Szrj    inefficient.  */
425*a9fa9459Szrj 
426*a9fa9459Szrj struct debug_lineno
427*a9fa9459Szrj {
428*a9fa9459Szrj   /* More line number information for this block.  */
429*a9fa9459Szrj   struct debug_lineno *next;
430*a9fa9459Szrj   /* Source file.  */
431*a9fa9459Szrj   struct debug_file *file;
432*a9fa9459Szrj   /* Line numbers, terminated by a -1 or the end of the array.  */
433*a9fa9459Szrj #define DEBUG_LINENO_COUNT 10
434*a9fa9459Szrj   unsigned long linenos[DEBUG_LINENO_COUNT];
435*a9fa9459Szrj   /* Addresses for the line numbers.  */
436*a9fa9459Szrj   bfd_vma addrs[DEBUG_LINENO_COUNT];
437*a9fa9459Szrj };
438*a9fa9459Szrj 
439*a9fa9459Szrj /* A namespace.  This is a mapping from names to objects.  FIXME: This
440*a9fa9459Szrj    should be implemented as a hash table.  */
441*a9fa9459Szrj 
442*a9fa9459Szrj struct debug_namespace
443*a9fa9459Szrj {
444*a9fa9459Szrj   /* List of items in this namespace.  */
445*a9fa9459Szrj   struct debug_name *list;
446*a9fa9459Szrj   /* Pointer to where the next item in this namespace should go.  */
447*a9fa9459Szrj   struct debug_name **tail;
448*a9fa9459Szrj };
449*a9fa9459Szrj 
450*a9fa9459Szrj /* Kinds of objects that appear in a namespace.  */
451*a9fa9459Szrj 
452*a9fa9459Szrj enum debug_object_kind
453*a9fa9459Szrj {
454*a9fa9459Szrj   /* A type.  */
455*a9fa9459Szrj   DEBUG_OBJECT_TYPE,
456*a9fa9459Szrj   /* A tagged type (really a different sort of namespace).  */
457*a9fa9459Szrj   DEBUG_OBJECT_TAG,
458*a9fa9459Szrj   /* A variable.  */
459*a9fa9459Szrj   DEBUG_OBJECT_VARIABLE,
460*a9fa9459Szrj   /* A function.  */
461*a9fa9459Szrj   DEBUG_OBJECT_FUNCTION,
462*a9fa9459Szrj   /* An integer constant.  */
463*a9fa9459Szrj   DEBUG_OBJECT_INT_CONSTANT,
464*a9fa9459Szrj   /* A floating point constant.  */
465*a9fa9459Szrj   DEBUG_OBJECT_FLOAT_CONSTANT,
466*a9fa9459Szrj   /* A typed constant.  */
467*a9fa9459Szrj   DEBUG_OBJECT_TYPED_CONSTANT
468*a9fa9459Szrj };
469*a9fa9459Szrj 
470*a9fa9459Szrj /* Linkage of an object that appears in a namespace.  */
471*a9fa9459Szrj 
472*a9fa9459Szrj enum debug_object_linkage
473*a9fa9459Szrj {
474*a9fa9459Szrj   /* Local variable.  */
475*a9fa9459Szrj   DEBUG_LINKAGE_AUTOMATIC,
476*a9fa9459Szrj   /* Static--either file static or function static, depending upon the
477*a9fa9459Szrj      namespace is.  */
478*a9fa9459Szrj   DEBUG_LINKAGE_STATIC,
479*a9fa9459Szrj   /* Global.  */
480*a9fa9459Szrj   DEBUG_LINKAGE_GLOBAL,
481*a9fa9459Szrj   /* No linkage.  */
482*a9fa9459Szrj   DEBUG_LINKAGE_NONE
483*a9fa9459Szrj };
484*a9fa9459Szrj 
485*a9fa9459Szrj /* A name in a namespace.  */
486*a9fa9459Szrj 
487*a9fa9459Szrj struct debug_name
488*a9fa9459Szrj {
489*a9fa9459Szrj   /* Next name in this namespace.  */
490*a9fa9459Szrj   struct debug_name *next;
491*a9fa9459Szrj   /* Name.  */
492*a9fa9459Szrj   const char *name;
493*a9fa9459Szrj   /* Mark.  This is used by debug_write.  */
494*a9fa9459Szrj   unsigned int mark;
495*a9fa9459Szrj   /* Kind of object.  */
496*a9fa9459Szrj   enum debug_object_kind kind;
497*a9fa9459Szrj   /* Linkage of object.  */
498*a9fa9459Szrj   enum debug_object_linkage linkage;
499*a9fa9459Szrj   /* Tagged union with additional information about the object.  */
500*a9fa9459Szrj   union
501*a9fa9459Szrj     {
502*a9fa9459Szrj       /* DEBUG_OBJECT_TYPE.  */
503*a9fa9459Szrj       struct debug_type_s *type;
504*a9fa9459Szrj       /* DEBUG_OBJECT_TAG.  */
505*a9fa9459Szrj       struct debug_type_s *tag;
506*a9fa9459Szrj       /* DEBUG_OBJECT_VARIABLE.  */
507*a9fa9459Szrj       struct debug_variable *variable;
508*a9fa9459Szrj       /* DEBUG_OBJECT_FUNCTION.  */
509*a9fa9459Szrj       struct debug_function *function;
510*a9fa9459Szrj       /* DEBUG_OBJECT_INT_CONSTANT.  */
511*a9fa9459Szrj       bfd_vma int_constant;
512*a9fa9459Szrj       /* DEBUG_OBJECT_FLOAT_CONSTANT.  */
513*a9fa9459Szrj       double float_constant;
514*a9fa9459Szrj       /* DEBUG_OBJECT_TYPED_CONSTANT.  */
515*a9fa9459Szrj       struct debug_typed_constant *typed_constant;
516*a9fa9459Szrj     } u;
517*a9fa9459Szrj };
518*a9fa9459Szrj 
519*a9fa9459Szrj /* During debug_write, a linked list of these structures is used to
520*a9fa9459Szrj    keep track of ID numbers that have been assigned to classes.  */
521*a9fa9459Szrj 
522*a9fa9459Szrj struct debug_class_id
523*a9fa9459Szrj {
524*a9fa9459Szrj   /* Next ID number.  */
525*a9fa9459Szrj   struct debug_class_id *next;
526*a9fa9459Szrj   /* The type with the ID.  */
527*a9fa9459Szrj   struct debug_type_s *type;
528*a9fa9459Szrj   /* The tag; NULL if no tag.  */
529*a9fa9459Szrj   const char *tag;
530*a9fa9459Szrj };
531*a9fa9459Szrj 
532*a9fa9459Szrj /* During debug_type_samep, a linked list of these structures is kept
533*a9fa9459Szrj    on the stack to avoid infinite recursion.  */
534*a9fa9459Szrj 
535*a9fa9459Szrj struct debug_type_compare_list
536*a9fa9459Szrj {
537*a9fa9459Szrj   /* Next type on list.  */
538*a9fa9459Szrj   struct debug_type_compare_list *next;
539*a9fa9459Szrj   /* The types we are comparing.  */
540*a9fa9459Szrj   struct debug_type_s *t1;
541*a9fa9459Szrj   struct debug_type_s *t2;
542*a9fa9459Szrj };
543*a9fa9459Szrj 
544*a9fa9459Szrj /* During debug_get_real_type, a linked list of these structures is
545*a9fa9459Szrj    kept on the stack to avoid infinite recursion.  */
546*a9fa9459Szrj 
547*a9fa9459Szrj struct debug_type_real_list
548*a9fa9459Szrj {
549*a9fa9459Szrj   /* Next type on list.  */
550*a9fa9459Szrj   struct debug_type_real_list *next;
551*a9fa9459Szrj   /* The type we are checking.  */
552*a9fa9459Szrj   struct debug_type_s *t;
553*a9fa9459Szrj };
554*a9fa9459Szrj 
555*a9fa9459Szrj /* Local functions.  */
556*a9fa9459Szrj 
557*a9fa9459Szrj static void debug_error (const char *);
558*a9fa9459Szrj static struct debug_name *debug_add_to_namespace
559*a9fa9459Szrj   (struct debug_handle *, struct debug_namespace **, const char *,
560*a9fa9459Szrj    enum debug_object_kind, enum debug_object_linkage);
561*a9fa9459Szrj static struct debug_name *debug_add_to_current_namespace
562*a9fa9459Szrj   (struct debug_handle *, const char *, enum debug_object_kind,
563*a9fa9459Szrj    enum debug_object_linkage);
564*a9fa9459Szrj static struct debug_type_s *debug_make_type
565*a9fa9459Szrj   (struct debug_handle *, enum debug_type_kind, unsigned int);
566*a9fa9459Szrj static struct debug_type_s *debug_get_real_type
567*a9fa9459Szrj   (void *, debug_type, struct debug_type_real_list *);
568*a9fa9459Szrj static bfd_boolean debug_write_name
569*a9fa9459Szrj   (struct debug_handle *, const struct debug_write_fns *, void *,
570*a9fa9459Szrj    struct debug_name *);
571*a9fa9459Szrj static bfd_boolean debug_write_type
572*a9fa9459Szrj   (struct debug_handle *, const struct debug_write_fns *, void *,
573*a9fa9459Szrj    struct debug_type_s *, struct debug_name *);
574*a9fa9459Szrj static bfd_boolean debug_write_class_type
575*a9fa9459Szrj   (struct debug_handle *, const struct debug_write_fns *, void *,
576*a9fa9459Szrj    struct debug_type_s *, const char *);
577*a9fa9459Szrj static bfd_boolean debug_write_function
578*a9fa9459Szrj   (struct debug_handle *, const struct debug_write_fns *, void *,
579*a9fa9459Szrj    const char *, enum debug_object_linkage, struct debug_function *);
580*a9fa9459Szrj static bfd_boolean debug_write_block
581*a9fa9459Szrj   (struct debug_handle *, const struct debug_write_fns *, void *,
582*a9fa9459Szrj    struct debug_block *);
583*a9fa9459Szrj static bfd_boolean debug_write_linenos
584*a9fa9459Szrj   (struct debug_handle *, const struct debug_write_fns *, void *, bfd_vma);
585*a9fa9459Szrj static bfd_boolean debug_set_class_id
586*a9fa9459Szrj   (struct debug_handle *, const char *, struct debug_type_s *);
587*a9fa9459Szrj static bfd_boolean debug_type_samep
588*a9fa9459Szrj   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
589*a9fa9459Szrj static bfd_boolean debug_class_type_samep
590*a9fa9459Szrj   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
591*a9fa9459Szrj 
592*a9fa9459Szrj /* Issue an error message.  */
593*a9fa9459Szrj 
594*a9fa9459Szrj static void
debug_error(const char * message)595*a9fa9459Szrj debug_error (const char *message)
596*a9fa9459Szrj {
597*a9fa9459Szrj   fprintf (stderr, "%s\n", message);
598*a9fa9459Szrj }
599*a9fa9459Szrj 
600*a9fa9459Szrj /* Add an object to a namespace.  */
601*a9fa9459Szrj 
602*a9fa9459Szrj static struct debug_name *
debug_add_to_namespace(struct debug_handle * info ATTRIBUTE_UNUSED,struct debug_namespace ** nsp,const char * name,enum debug_object_kind kind,enum debug_object_linkage linkage)603*a9fa9459Szrj debug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
604*a9fa9459Szrj 			struct debug_namespace **nsp, const char *name,
605*a9fa9459Szrj 			enum debug_object_kind kind,
606*a9fa9459Szrj 			enum debug_object_linkage linkage)
607*a9fa9459Szrj {
608*a9fa9459Szrj   struct debug_name *n;
609*a9fa9459Szrj   struct debug_namespace *ns;
610*a9fa9459Szrj 
611*a9fa9459Szrj   n = (struct debug_name *) xmalloc (sizeof *n);
612*a9fa9459Szrj   memset (n, 0, sizeof *n);
613*a9fa9459Szrj 
614*a9fa9459Szrj   n->name = name;
615*a9fa9459Szrj   n->kind = kind;
616*a9fa9459Szrj   n->linkage = linkage;
617*a9fa9459Szrj 
618*a9fa9459Szrj   ns = *nsp;
619*a9fa9459Szrj   if (ns == NULL)
620*a9fa9459Szrj     {
621*a9fa9459Szrj       ns = (struct debug_namespace *) xmalloc (sizeof *ns);
622*a9fa9459Szrj       memset (ns, 0, sizeof *ns);
623*a9fa9459Szrj 
624*a9fa9459Szrj       ns->tail = &ns->list;
625*a9fa9459Szrj 
626*a9fa9459Szrj       *nsp = ns;
627*a9fa9459Szrj     }
628*a9fa9459Szrj 
629*a9fa9459Szrj   *ns->tail = n;
630*a9fa9459Szrj   ns->tail = &n->next;
631*a9fa9459Szrj 
632*a9fa9459Szrj   return n;
633*a9fa9459Szrj }
634*a9fa9459Szrj 
635*a9fa9459Szrj /* Add an object to the current namespace.  */
636*a9fa9459Szrj 
637*a9fa9459Szrj static struct debug_name *
debug_add_to_current_namespace(struct debug_handle * info,const char * name,enum debug_object_kind kind,enum debug_object_linkage linkage)638*a9fa9459Szrj debug_add_to_current_namespace (struct debug_handle *info, const char *name,
639*a9fa9459Szrj 				enum debug_object_kind kind,
640*a9fa9459Szrj 				enum debug_object_linkage linkage)
641*a9fa9459Szrj {
642*a9fa9459Szrj   struct debug_namespace **nsp;
643*a9fa9459Szrj 
644*a9fa9459Szrj   if (info->current_unit == NULL
645*a9fa9459Szrj       || info->current_file == NULL)
646*a9fa9459Szrj     {
647*a9fa9459Szrj       debug_error (_("debug_add_to_current_namespace: no current file"));
648*a9fa9459Szrj       return NULL;
649*a9fa9459Szrj     }
650*a9fa9459Szrj 
651*a9fa9459Szrj   if (info->current_block != NULL)
652*a9fa9459Szrj     nsp = &info->current_block->locals;
653*a9fa9459Szrj   else
654*a9fa9459Szrj     nsp = &info->current_file->globals;
655*a9fa9459Szrj 
656*a9fa9459Szrj   return debug_add_to_namespace (info, nsp, name, kind, linkage);
657*a9fa9459Szrj }
658*a9fa9459Szrj 
659*a9fa9459Szrj /* Return a handle for debugging information.  */
660*a9fa9459Szrj 
661*a9fa9459Szrj void *
debug_init(void)662*a9fa9459Szrj debug_init (void)
663*a9fa9459Szrj {
664*a9fa9459Szrj   struct debug_handle *ret;
665*a9fa9459Szrj 
666*a9fa9459Szrj   ret = (struct debug_handle *) xmalloc (sizeof *ret);
667*a9fa9459Szrj   memset (ret, 0, sizeof *ret);
668*a9fa9459Szrj   return (void *) ret;
669*a9fa9459Szrj }
670*a9fa9459Szrj 
671*a9fa9459Szrj /* Set the source filename.  This implicitly starts a new compilation
672*a9fa9459Szrj    unit.  */
673*a9fa9459Szrj 
674*a9fa9459Szrj bfd_boolean
debug_set_filename(void * handle,const char * name)675*a9fa9459Szrj debug_set_filename (void *handle, const char *name)
676*a9fa9459Szrj {
677*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
678*a9fa9459Szrj   struct debug_file *nfile;
679*a9fa9459Szrj   struct debug_unit *nunit;
680*a9fa9459Szrj 
681*a9fa9459Szrj   if (name == NULL)
682*a9fa9459Szrj     name = "";
683*a9fa9459Szrj 
684*a9fa9459Szrj   nfile = (struct debug_file *) xmalloc (sizeof *nfile);
685*a9fa9459Szrj   memset (nfile, 0, sizeof *nfile);
686*a9fa9459Szrj 
687*a9fa9459Szrj   nfile->filename = name;
688*a9fa9459Szrj 
689*a9fa9459Szrj   nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
690*a9fa9459Szrj   memset (nunit, 0, sizeof *nunit);
691*a9fa9459Szrj 
692*a9fa9459Szrj   nunit->files = nfile;
693*a9fa9459Szrj   info->current_file = nfile;
694*a9fa9459Szrj 
695*a9fa9459Szrj   if (info->current_unit != NULL)
696*a9fa9459Szrj     info->current_unit->next = nunit;
697*a9fa9459Szrj   else
698*a9fa9459Szrj     {
699*a9fa9459Szrj       assert (info->units == NULL);
700*a9fa9459Szrj       info->units = nunit;
701*a9fa9459Szrj     }
702*a9fa9459Szrj 
703*a9fa9459Szrj   info->current_unit = nunit;
704*a9fa9459Szrj 
705*a9fa9459Szrj   info->current_function = NULL;
706*a9fa9459Szrj   info->current_block = NULL;
707*a9fa9459Szrj   info->current_lineno = NULL;
708*a9fa9459Szrj 
709*a9fa9459Szrj   return TRUE;
710*a9fa9459Szrj }
711*a9fa9459Szrj 
712*a9fa9459Szrj /* Change source files to the given file name.  This is used for
713*a9fa9459Szrj    include files in a single compilation unit.  */
714*a9fa9459Szrj 
715*a9fa9459Szrj bfd_boolean
debug_start_source(void * handle,const char * name)716*a9fa9459Szrj debug_start_source (void *handle, const char *name)
717*a9fa9459Szrj {
718*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
719*a9fa9459Szrj   struct debug_file *f, **pf;
720*a9fa9459Szrj 
721*a9fa9459Szrj   if (name == NULL)
722*a9fa9459Szrj     name = "";
723*a9fa9459Szrj 
724*a9fa9459Szrj   if (info->current_unit == NULL)
725*a9fa9459Szrj     {
726*a9fa9459Szrj       debug_error (_("debug_start_source: no debug_set_filename call"));
727*a9fa9459Szrj       return FALSE;
728*a9fa9459Szrj     }
729*a9fa9459Szrj 
730*a9fa9459Szrj   for (f = info->current_unit->files; f != NULL; f = f->next)
731*a9fa9459Szrj     {
732*a9fa9459Szrj       if (filename_cmp (f->filename, name) == 0)
733*a9fa9459Szrj 	{
734*a9fa9459Szrj 	  info->current_file = f;
735*a9fa9459Szrj 	  return TRUE;
736*a9fa9459Szrj 	}
737*a9fa9459Szrj     }
738*a9fa9459Szrj 
739*a9fa9459Szrj   f = (struct debug_file *) xmalloc (sizeof *f);
740*a9fa9459Szrj   memset (f, 0, sizeof *f);
741*a9fa9459Szrj 
742*a9fa9459Szrj   f->filename = name;
743*a9fa9459Szrj 
744*a9fa9459Szrj   for (pf = &info->current_file->next;
745*a9fa9459Szrj        *pf != NULL;
746*a9fa9459Szrj        pf = &(*pf)->next)
747*a9fa9459Szrj     ;
748*a9fa9459Szrj   *pf = f;
749*a9fa9459Szrj 
750*a9fa9459Szrj   info->current_file = f;
751*a9fa9459Szrj 
752*a9fa9459Szrj   return TRUE;
753*a9fa9459Szrj }
754*a9fa9459Szrj 
755*a9fa9459Szrj /* Record a function definition.  This implicitly starts a function
756*a9fa9459Szrj    block.  The debug_type argument is the type of the return value.
757*a9fa9459Szrj    The boolean indicates whether the function is globally visible.
758*a9fa9459Szrj    The bfd_vma is the address of the start of the function.  Currently
759*a9fa9459Szrj    the parameter types are specified by calls to
760*a9fa9459Szrj    debug_record_parameter.  FIXME: There is no way to specify nested
761*a9fa9459Szrj    functions.  */
762*a9fa9459Szrj 
763*a9fa9459Szrj bfd_boolean
debug_record_function(void * handle,const char * name,debug_type return_type,bfd_boolean global,bfd_vma addr)764*a9fa9459Szrj debug_record_function (void *handle, const char *name,
765*a9fa9459Szrj 		       debug_type return_type, bfd_boolean global,
766*a9fa9459Szrj 		       bfd_vma addr)
767*a9fa9459Szrj {
768*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
769*a9fa9459Szrj   struct debug_function *f;
770*a9fa9459Szrj   struct debug_block *b;
771*a9fa9459Szrj   struct debug_name *n;
772*a9fa9459Szrj 
773*a9fa9459Szrj   if (name == NULL)
774*a9fa9459Szrj     name = "";
775*a9fa9459Szrj   if (return_type == NULL)
776*a9fa9459Szrj     return FALSE;
777*a9fa9459Szrj 
778*a9fa9459Szrj   if (info->current_unit == NULL)
779*a9fa9459Szrj     {
780*a9fa9459Szrj       debug_error (_("debug_record_function: no debug_set_filename call"));
781*a9fa9459Szrj       return FALSE;
782*a9fa9459Szrj     }
783*a9fa9459Szrj 
784*a9fa9459Szrj   f = (struct debug_function *) xmalloc (sizeof *f);
785*a9fa9459Szrj   memset (f, 0, sizeof *f);
786*a9fa9459Szrj 
787*a9fa9459Szrj   f->return_type = return_type;
788*a9fa9459Szrj 
789*a9fa9459Szrj   b = (struct debug_block *) xmalloc (sizeof *b);
790*a9fa9459Szrj   memset (b, 0, sizeof *b);
791*a9fa9459Szrj 
792*a9fa9459Szrj   b->start = addr;
793*a9fa9459Szrj   b->end = (bfd_vma) -1;
794*a9fa9459Szrj 
795*a9fa9459Szrj   f->blocks = b;
796*a9fa9459Szrj 
797*a9fa9459Szrj   info->current_function = f;
798*a9fa9459Szrj   info->current_block = b;
799*a9fa9459Szrj 
800*a9fa9459Szrj   /* FIXME: If we could handle nested functions, this would be the
801*a9fa9459Szrj      place: we would want to use a different namespace.  */
802*a9fa9459Szrj   n = debug_add_to_namespace (info,
803*a9fa9459Szrj 			      &info->current_file->globals,
804*a9fa9459Szrj 			      name,
805*a9fa9459Szrj 			      DEBUG_OBJECT_FUNCTION,
806*a9fa9459Szrj 			      (global
807*a9fa9459Szrj 			       ? DEBUG_LINKAGE_GLOBAL
808*a9fa9459Szrj 			       : DEBUG_LINKAGE_STATIC));
809*a9fa9459Szrj   if (n == NULL)
810*a9fa9459Szrj     return FALSE;
811*a9fa9459Szrj 
812*a9fa9459Szrj   n->u.function = f;
813*a9fa9459Szrj 
814*a9fa9459Szrj   return TRUE;
815*a9fa9459Szrj }
816*a9fa9459Szrj 
817*a9fa9459Szrj /* Record a parameter for the current function.  */
818*a9fa9459Szrj 
819*a9fa9459Szrj bfd_boolean
debug_record_parameter(void * handle,const char * name,debug_type type,enum debug_parm_kind kind,bfd_vma val)820*a9fa9459Szrj debug_record_parameter (void *handle, const char *name, debug_type type,
821*a9fa9459Szrj 			enum debug_parm_kind kind, bfd_vma val)
822*a9fa9459Szrj {
823*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
824*a9fa9459Szrj   struct debug_parameter *p, **pp;
825*a9fa9459Szrj 
826*a9fa9459Szrj   if (name == NULL || type == NULL)
827*a9fa9459Szrj     return FALSE;
828*a9fa9459Szrj 
829*a9fa9459Szrj   if (info->current_unit == NULL
830*a9fa9459Szrj       || info->current_function == NULL)
831*a9fa9459Szrj     {
832*a9fa9459Szrj       debug_error (_("debug_record_parameter: no current function"));
833*a9fa9459Szrj       return FALSE;
834*a9fa9459Szrj     }
835*a9fa9459Szrj 
836*a9fa9459Szrj   p = (struct debug_parameter *) xmalloc (sizeof *p);
837*a9fa9459Szrj   memset (p, 0, sizeof *p);
838*a9fa9459Szrj 
839*a9fa9459Szrj   p->name = name;
840*a9fa9459Szrj   p->type = type;
841*a9fa9459Szrj   p->kind = kind;
842*a9fa9459Szrj   p->val = val;
843*a9fa9459Szrj 
844*a9fa9459Szrj   for (pp = &info->current_function->parameters;
845*a9fa9459Szrj        *pp != NULL;
846*a9fa9459Szrj        pp = &(*pp)->next)
847*a9fa9459Szrj     ;
848*a9fa9459Szrj   *pp = p;
849*a9fa9459Szrj 
850*a9fa9459Szrj   return TRUE;
851*a9fa9459Szrj }
852*a9fa9459Szrj 
853*a9fa9459Szrj /* End a function.  FIXME: This should handle function nesting.  */
854*a9fa9459Szrj 
855*a9fa9459Szrj bfd_boolean
debug_end_function(void * handle,bfd_vma addr)856*a9fa9459Szrj debug_end_function (void *handle, bfd_vma addr)
857*a9fa9459Szrj {
858*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
859*a9fa9459Szrj 
860*a9fa9459Szrj   if (info->current_unit == NULL
861*a9fa9459Szrj       || info->current_block == NULL
862*a9fa9459Szrj       || info->current_function == NULL)
863*a9fa9459Szrj     {
864*a9fa9459Szrj       debug_error (_("debug_end_function: no current function"));
865*a9fa9459Szrj       return FALSE;
866*a9fa9459Szrj     }
867*a9fa9459Szrj 
868*a9fa9459Szrj   if (info->current_block->parent != NULL)
869*a9fa9459Szrj     {
870*a9fa9459Szrj       debug_error (_("debug_end_function: some blocks were not closed"));
871*a9fa9459Szrj       return FALSE;
872*a9fa9459Szrj     }
873*a9fa9459Szrj 
874*a9fa9459Szrj   info->current_block->end = addr;
875*a9fa9459Szrj 
876*a9fa9459Szrj   info->current_function = NULL;
877*a9fa9459Szrj   info->current_block = NULL;
878*a9fa9459Szrj 
879*a9fa9459Szrj   return TRUE;
880*a9fa9459Szrj }
881*a9fa9459Szrj 
882*a9fa9459Szrj /* Start a block in a function.  All local information will be
883*a9fa9459Szrj    recorded in this block, until the matching call to debug_end_block.
884*a9fa9459Szrj    debug_start_block and debug_end_block may be nested.  The bfd_vma
885*a9fa9459Szrj    argument is the address at which this block starts.  */
886*a9fa9459Szrj 
887*a9fa9459Szrj bfd_boolean
debug_start_block(void * handle,bfd_vma addr)888*a9fa9459Szrj debug_start_block (void *handle, bfd_vma addr)
889*a9fa9459Szrj {
890*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
891*a9fa9459Szrj   struct debug_block *b, **pb;
892*a9fa9459Szrj 
893*a9fa9459Szrj   /* We must always have a current block: debug_record_function sets
894*a9fa9459Szrj      one up.  */
895*a9fa9459Szrj   if (info->current_unit == NULL
896*a9fa9459Szrj       || info->current_block == NULL)
897*a9fa9459Szrj     {
898*a9fa9459Szrj       debug_error (_("debug_start_block: no current block"));
899*a9fa9459Szrj       return FALSE;
900*a9fa9459Szrj     }
901*a9fa9459Szrj 
902*a9fa9459Szrj   b = (struct debug_block *) xmalloc (sizeof *b);
903*a9fa9459Szrj   memset (b, 0, sizeof *b);
904*a9fa9459Szrj 
905*a9fa9459Szrj   b->parent = info->current_block;
906*a9fa9459Szrj   b->start = addr;
907*a9fa9459Szrj   b->end = (bfd_vma) -1;
908*a9fa9459Szrj 
909*a9fa9459Szrj   /* This new block is a child of the current block.  */
910*a9fa9459Szrj   for (pb = &info->current_block->children;
911*a9fa9459Szrj        *pb != NULL;
912*a9fa9459Szrj        pb = &(*pb)->next)
913*a9fa9459Szrj     ;
914*a9fa9459Szrj   *pb = b;
915*a9fa9459Szrj 
916*a9fa9459Szrj   info->current_block = b;
917*a9fa9459Szrj 
918*a9fa9459Szrj   return TRUE;
919*a9fa9459Szrj }
920*a9fa9459Szrj 
921*a9fa9459Szrj /* Finish a block in a function.  This matches the call to
922*a9fa9459Szrj    debug_start_block.  The argument is the address at which this block
923*a9fa9459Szrj    ends.  */
924*a9fa9459Szrj 
925*a9fa9459Szrj bfd_boolean
debug_end_block(void * handle,bfd_vma addr)926*a9fa9459Szrj debug_end_block (void *handle, bfd_vma addr)
927*a9fa9459Szrj {
928*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
929*a9fa9459Szrj   struct debug_block *parent;
930*a9fa9459Szrj 
931*a9fa9459Szrj   if (info->current_unit == NULL
932*a9fa9459Szrj       || info->current_block == NULL)
933*a9fa9459Szrj     {
934*a9fa9459Szrj       debug_error (_("debug_end_block: no current block"));
935*a9fa9459Szrj       return FALSE;
936*a9fa9459Szrj     }
937*a9fa9459Szrj 
938*a9fa9459Szrj   parent = info->current_block->parent;
939*a9fa9459Szrj   if (parent == NULL)
940*a9fa9459Szrj     {
941*a9fa9459Szrj       debug_error (_("debug_end_block: attempt to close top level block"));
942*a9fa9459Szrj       return FALSE;
943*a9fa9459Szrj     }
944*a9fa9459Szrj 
945*a9fa9459Szrj   info->current_block->end = addr;
946*a9fa9459Szrj 
947*a9fa9459Szrj   info->current_block = parent;
948*a9fa9459Szrj 
949*a9fa9459Szrj   return TRUE;
950*a9fa9459Szrj }
951*a9fa9459Szrj 
952*a9fa9459Szrj /* Associate a line number in the current source file and function
953*a9fa9459Szrj    with a given address.  */
954*a9fa9459Szrj 
955*a9fa9459Szrj bfd_boolean
debug_record_line(void * handle,unsigned long lineno,bfd_vma addr)956*a9fa9459Szrj debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
957*a9fa9459Szrj {
958*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
959*a9fa9459Szrj   struct debug_lineno *l;
960*a9fa9459Szrj   unsigned int i;
961*a9fa9459Szrj 
962*a9fa9459Szrj   if (info->current_unit == NULL)
963*a9fa9459Szrj     {
964*a9fa9459Szrj       debug_error (_("debug_record_line: no current unit"));
965*a9fa9459Szrj       return FALSE;
966*a9fa9459Szrj     }
967*a9fa9459Szrj 
968*a9fa9459Szrj   l = info->current_lineno;
969*a9fa9459Szrj   if (l != NULL && l->file == info->current_file)
970*a9fa9459Szrj     {
971*a9fa9459Szrj       for (i = 0; i < DEBUG_LINENO_COUNT; i++)
972*a9fa9459Szrj 	{
973*a9fa9459Szrj 	  if (l->linenos[i] == (unsigned long) -1)
974*a9fa9459Szrj 	    {
975*a9fa9459Szrj 	      l->linenos[i] = lineno;
976*a9fa9459Szrj 	      l->addrs[i] = addr;
977*a9fa9459Szrj 	      return TRUE;
978*a9fa9459Szrj 	    }
979*a9fa9459Szrj 	}
980*a9fa9459Szrj     }
981*a9fa9459Szrj 
982*a9fa9459Szrj   /* If we get here, then either 1) there is no current_lineno
983*a9fa9459Szrj      structure, which means this is the first line number in this
984*a9fa9459Szrj      compilation unit, 2) the current_lineno structure is for a
985*a9fa9459Szrj      different file, or 3) the current_lineno structure is full.
986*a9fa9459Szrj      Regardless, we want to allocate a new debug_lineno structure, put
987*a9fa9459Szrj      it in the right place, and make it the new current_lineno
988*a9fa9459Szrj      structure.  */
989*a9fa9459Szrj 
990*a9fa9459Szrj   l = (struct debug_lineno *) xmalloc (sizeof *l);
991*a9fa9459Szrj   memset (l, 0, sizeof *l);
992*a9fa9459Szrj 
993*a9fa9459Szrj   l->file = info->current_file;
994*a9fa9459Szrj   l->linenos[0] = lineno;
995*a9fa9459Szrj   l->addrs[0] = addr;
996*a9fa9459Szrj   for (i = 1; i < DEBUG_LINENO_COUNT; i++)
997*a9fa9459Szrj     l->linenos[i] = (unsigned long) -1;
998*a9fa9459Szrj 
999*a9fa9459Szrj   if (info->current_lineno != NULL)
1000*a9fa9459Szrj     info->current_lineno->next = l;
1001*a9fa9459Szrj   else
1002*a9fa9459Szrj     info->current_unit->linenos = l;
1003*a9fa9459Szrj 
1004*a9fa9459Szrj   info->current_lineno = l;
1005*a9fa9459Szrj 
1006*a9fa9459Szrj   return TRUE;
1007*a9fa9459Szrj }
1008*a9fa9459Szrj 
1009*a9fa9459Szrj /* Start a named common block.  This is a block of variables that may
1010*a9fa9459Szrj    move in memory.  */
1011*a9fa9459Szrj 
1012*a9fa9459Szrj bfd_boolean
debug_start_common_block(void * handle ATTRIBUTE_UNUSED,const char * name ATTRIBUTE_UNUSED)1013*a9fa9459Szrj debug_start_common_block (void *handle ATTRIBUTE_UNUSED,
1014*a9fa9459Szrj 			  const char *name ATTRIBUTE_UNUSED)
1015*a9fa9459Szrj {
1016*a9fa9459Szrj   /* FIXME */
1017*a9fa9459Szrj   debug_error (_("debug_start_common_block: not implemented"));
1018*a9fa9459Szrj   return FALSE;
1019*a9fa9459Szrj }
1020*a9fa9459Szrj 
1021*a9fa9459Szrj /* End a named common block.  */
1022*a9fa9459Szrj 
1023*a9fa9459Szrj bfd_boolean
debug_end_common_block(void * handle ATTRIBUTE_UNUSED,const char * name ATTRIBUTE_UNUSED)1024*a9fa9459Szrj debug_end_common_block (void *handle ATTRIBUTE_UNUSED,
1025*a9fa9459Szrj 			const char *name ATTRIBUTE_UNUSED)
1026*a9fa9459Szrj {
1027*a9fa9459Szrj   /* FIXME */
1028*a9fa9459Szrj   debug_error (_("debug_end_common_block: not implemented"));
1029*a9fa9459Szrj   return FALSE;
1030*a9fa9459Szrj }
1031*a9fa9459Szrj 
1032*a9fa9459Szrj /* Record a named integer constant.  */
1033*a9fa9459Szrj 
1034*a9fa9459Szrj bfd_boolean
debug_record_int_const(void * handle,const char * name,bfd_vma val)1035*a9fa9459Szrj debug_record_int_const (void *handle, const char *name, bfd_vma val)
1036*a9fa9459Szrj {
1037*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1038*a9fa9459Szrj   struct debug_name *n;
1039*a9fa9459Szrj 
1040*a9fa9459Szrj   if (name == NULL)
1041*a9fa9459Szrj     return FALSE;
1042*a9fa9459Szrj 
1043*a9fa9459Szrj   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
1044*a9fa9459Szrj 				      DEBUG_LINKAGE_NONE);
1045*a9fa9459Szrj   if (n == NULL)
1046*a9fa9459Szrj     return FALSE;
1047*a9fa9459Szrj 
1048*a9fa9459Szrj   n->u.int_constant = val;
1049*a9fa9459Szrj 
1050*a9fa9459Szrj   return TRUE;
1051*a9fa9459Szrj }
1052*a9fa9459Szrj 
1053*a9fa9459Szrj /* Record a named floating point constant.  */
1054*a9fa9459Szrj 
1055*a9fa9459Szrj bfd_boolean
debug_record_float_const(void * handle,const char * name,double val)1056*a9fa9459Szrj debug_record_float_const (void *handle, const char *name, double val)
1057*a9fa9459Szrj {
1058*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1059*a9fa9459Szrj   struct debug_name *n;
1060*a9fa9459Szrj 
1061*a9fa9459Szrj   if (name == NULL)
1062*a9fa9459Szrj     return FALSE;
1063*a9fa9459Szrj 
1064*a9fa9459Szrj   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
1065*a9fa9459Szrj 				      DEBUG_LINKAGE_NONE);
1066*a9fa9459Szrj   if (n == NULL)
1067*a9fa9459Szrj     return FALSE;
1068*a9fa9459Szrj 
1069*a9fa9459Szrj   n->u.float_constant = val;
1070*a9fa9459Szrj 
1071*a9fa9459Szrj   return TRUE;
1072*a9fa9459Szrj }
1073*a9fa9459Szrj 
1074*a9fa9459Szrj /* Record a typed constant with an integral value.  */
1075*a9fa9459Szrj 
1076*a9fa9459Szrj bfd_boolean
debug_record_typed_const(void * handle,const char * name,debug_type type,bfd_vma val)1077*a9fa9459Szrj debug_record_typed_const (void *handle, const char *name, debug_type type,
1078*a9fa9459Szrj 			  bfd_vma val)
1079*a9fa9459Szrj {
1080*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1081*a9fa9459Szrj   struct debug_name *n;
1082*a9fa9459Szrj   struct debug_typed_constant *tc;
1083*a9fa9459Szrj 
1084*a9fa9459Szrj   if (name == NULL || type == NULL)
1085*a9fa9459Szrj     return FALSE;
1086*a9fa9459Szrj 
1087*a9fa9459Szrj   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
1088*a9fa9459Szrj 				      DEBUG_LINKAGE_NONE);
1089*a9fa9459Szrj   if (n == NULL)
1090*a9fa9459Szrj     return FALSE;
1091*a9fa9459Szrj 
1092*a9fa9459Szrj   tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
1093*a9fa9459Szrj   memset (tc, 0, sizeof *tc);
1094*a9fa9459Szrj 
1095*a9fa9459Szrj   tc->type = type;
1096*a9fa9459Szrj   tc->val = val;
1097*a9fa9459Szrj 
1098*a9fa9459Szrj   n->u.typed_constant = tc;
1099*a9fa9459Szrj 
1100*a9fa9459Szrj   return TRUE;
1101*a9fa9459Szrj }
1102*a9fa9459Szrj 
1103*a9fa9459Szrj /* Record a label.  */
1104*a9fa9459Szrj 
1105*a9fa9459Szrj bfd_boolean
debug_record_label(void * handle ATTRIBUTE_UNUSED,const char * name ATTRIBUTE_UNUSED,debug_type type ATTRIBUTE_UNUSED,bfd_vma addr ATTRIBUTE_UNUSED)1106*a9fa9459Szrj debug_record_label (void *handle ATTRIBUTE_UNUSED,
1107*a9fa9459Szrj 		    const char *name ATTRIBUTE_UNUSED,
1108*a9fa9459Szrj 		    debug_type type ATTRIBUTE_UNUSED,
1109*a9fa9459Szrj 		    bfd_vma addr ATTRIBUTE_UNUSED)
1110*a9fa9459Szrj {
1111*a9fa9459Szrj   /* FIXME.  */
1112*a9fa9459Szrj   debug_error (_("debug_record_label: not implemented"));
1113*a9fa9459Szrj   return FALSE;
1114*a9fa9459Szrj }
1115*a9fa9459Szrj 
1116*a9fa9459Szrj /* Record a variable.  */
1117*a9fa9459Szrj 
1118*a9fa9459Szrj bfd_boolean
debug_record_variable(void * handle,const char * name,debug_type type,enum debug_var_kind kind,bfd_vma val)1119*a9fa9459Szrj debug_record_variable (void *handle, const char *name, debug_type type,
1120*a9fa9459Szrj 		       enum debug_var_kind kind, bfd_vma val)
1121*a9fa9459Szrj {
1122*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1123*a9fa9459Szrj   struct debug_namespace **nsp;
1124*a9fa9459Szrj   enum debug_object_linkage linkage;
1125*a9fa9459Szrj   struct debug_name *n;
1126*a9fa9459Szrj   struct debug_variable *v;
1127*a9fa9459Szrj 
1128*a9fa9459Szrj   if (name == NULL || type == NULL)
1129*a9fa9459Szrj     return FALSE;
1130*a9fa9459Szrj 
1131*a9fa9459Szrj   if (info->current_unit == NULL
1132*a9fa9459Szrj       || info->current_file == NULL)
1133*a9fa9459Szrj     {
1134*a9fa9459Szrj       debug_error (_("debug_record_variable: no current file"));
1135*a9fa9459Szrj       return FALSE;
1136*a9fa9459Szrj     }
1137*a9fa9459Szrj 
1138*a9fa9459Szrj   if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
1139*a9fa9459Szrj     {
1140*a9fa9459Szrj       nsp = &info->current_file->globals;
1141*a9fa9459Szrj       if (kind == DEBUG_GLOBAL)
1142*a9fa9459Szrj 	linkage = DEBUG_LINKAGE_GLOBAL;
1143*a9fa9459Szrj       else
1144*a9fa9459Szrj 	linkage = DEBUG_LINKAGE_STATIC;
1145*a9fa9459Szrj     }
1146*a9fa9459Szrj   else
1147*a9fa9459Szrj     {
1148*a9fa9459Szrj       if (info->current_block == NULL)
1149*a9fa9459Szrj 	nsp = &info->current_file->globals;
1150*a9fa9459Szrj       else
1151*a9fa9459Szrj 	nsp = &info->current_block->locals;
1152*a9fa9459Szrj       linkage = DEBUG_LINKAGE_AUTOMATIC;
1153*a9fa9459Szrj     }
1154*a9fa9459Szrj 
1155*a9fa9459Szrj   n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
1156*a9fa9459Szrj   if (n == NULL)
1157*a9fa9459Szrj     return FALSE;
1158*a9fa9459Szrj 
1159*a9fa9459Szrj   v = (struct debug_variable *) xmalloc (sizeof *v);
1160*a9fa9459Szrj   memset (v, 0, sizeof *v);
1161*a9fa9459Szrj 
1162*a9fa9459Szrj   v->kind = kind;
1163*a9fa9459Szrj   v->type = type;
1164*a9fa9459Szrj   v->val = val;
1165*a9fa9459Szrj 
1166*a9fa9459Szrj   n->u.variable = v;
1167*a9fa9459Szrj 
1168*a9fa9459Szrj   return TRUE;
1169*a9fa9459Szrj }
1170*a9fa9459Szrj 
1171*a9fa9459Szrj /* Make a type with a given kind and size.  */
1172*a9fa9459Szrj 
1173*a9fa9459Szrj static struct debug_type_s *
debug_make_type(struct debug_handle * info ATTRIBUTE_UNUSED,enum debug_type_kind kind,unsigned int size)1174*a9fa9459Szrj debug_make_type (struct debug_handle *info ATTRIBUTE_UNUSED,
1175*a9fa9459Szrj 		 enum debug_type_kind kind, unsigned int size)
1176*a9fa9459Szrj {
1177*a9fa9459Szrj   struct debug_type_s *t;
1178*a9fa9459Szrj 
1179*a9fa9459Szrj   t = (struct debug_type_s *) xmalloc (sizeof *t);
1180*a9fa9459Szrj   memset (t, 0, sizeof *t);
1181*a9fa9459Szrj 
1182*a9fa9459Szrj   t->kind = kind;
1183*a9fa9459Szrj   t->size = size;
1184*a9fa9459Szrj 
1185*a9fa9459Szrj   return t;
1186*a9fa9459Szrj }
1187*a9fa9459Szrj 
1188*a9fa9459Szrj /* Make an indirect type which may be used as a placeholder for a type
1189*a9fa9459Szrj    which is referenced before it is defined.  */
1190*a9fa9459Szrj 
1191*a9fa9459Szrj debug_type
debug_make_indirect_type(void * handle,debug_type * slot,const char * tag)1192*a9fa9459Szrj debug_make_indirect_type (void *handle, debug_type *slot, const char *tag)
1193*a9fa9459Szrj {
1194*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1195*a9fa9459Szrj   struct debug_type_s *t;
1196*a9fa9459Szrj   struct debug_indirect_type *i;
1197*a9fa9459Szrj 
1198*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
1199*a9fa9459Szrj   if (t == NULL)
1200*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1201*a9fa9459Szrj 
1202*a9fa9459Szrj   i = (struct debug_indirect_type *) xmalloc (sizeof *i);
1203*a9fa9459Szrj   memset (i, 0, sizeof *i);
1204*a9fa9459Szrj 
1205*a9fa9459Szrj   i->slot = slot;
1206*a9fa9459Szrj   i->tag = tag;
1207*a9fa9459Szrj 
1208*a9fa9459Szrj   t->u.kindirect = i;
1209*a9fa9459Szrj 
1210*a9fa9459Szrj   return t;
1211*a9fa9459Szrj }
1212*a9fa9459Szrj 
1213*a9fa9459Szrj /* Make a void type.  There is only one of these.  */
1214*a9fa9459Szrj 
1215*a9fa9459Szrj debug_type
debug_make_void_type(void * handle)1216*a9fa9459Szrj debug_make_void_type (void *handle)
1217*a9fa9459Szrj {
1218*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1219*a9fa9459Szrj 
1220*a9fa9459Szrj   return debug_make_type (info, DEBUG_KIND_VOID, 0);
1221*a9fa9459Szrj }
1222*a9fa9459Szrj 
1223*a9fa9459Szrj /* Make an integer type of a given size.  The boolean argument is true
1224*a9fa9459Szrj    if the integer is unsigned.  */
1225*a9fa9459Szrj 
1226*a9fa9459Szrj debug_type
debug_make_int_type(void * handle,unsigned int size,bfd_boolean unsignedp)1227*a9fa9459Szrj debug_make_int_type (void *handle, unsigned int size, bfd_boolean unsignedp)
1228*a9fa9459Szrj {
1229*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1230*a9fa9459Szrj   struct debug_type_s *t;
1231*a9fa9459Szrj 
1232*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_INT, size);
1233*a9fa9459Szrj   if (t == NULL)
1234*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1235*a9fa9459Szrj 
1236*a9fa9459Szrj   t->u.kint = unsignedp;
1237*a9fa9459Szrj 
1238*a9fa9459Szrj   return t;
1239*a9fa9459Szrj }
1240*a9fa9459Szrj 
1241*a9fa9459Szrj /* Make a floating point type of a given size.  FIXME: On some
1242*a9fa9459Szrj    platforms, like an Alpha, you probably need to be able to specify
1243*a9fa9459Szrj    the format.  */
1244*a9fa9459Szrj 
1245*a9fa9459Szrj debug_type
debug_make_float_type(void * handle,unsigned int size)1246*a9fa9459Szrj debug_make_float_type (void *handle, unsigned int size)
1247*a9fa9459Szrj {
1248*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1249*a9fa9459Szrj 
1250*a9fa9459Szrj   return debug_make_type (info, DEBUG_KIND_FLOAT, size);
1251*a9fa9459Szrj }
1252*a9fa9459Szrj 
1253*a9fa9459Szrj /* Make a boolean type of a given size.  */
1254*a9fa9459Szrj 
1255*a9fa9459Szrj debug_type
debug_make_bool_type(void * handle,unsigned int size)1256*a9fa9459Szrj debug_make_bool_type (void *handle, unsigned int size)
1257*a9fa9459Szrj {
1258*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1259*a9fa9459Szrj 
1260*a9fa9459Szrj   return debug_make_type (info, DEBUG_KIND_BOOL, size);
1261*a9fa9459Szrj }
1262*a9fa9459Szrj 
1263*a9fa9459Szrj /* Make a complex type of a given size.  */
1264*a9fa9459Szrj 
1265*a9fa9459Szrj debug_type
debug_make_complex_type(void * handle,unsigned int size)1266*a9fa9459Szrj debug_make_complex_type (void *handle, unsigned int size)
1267*a9fa9459Szrj {
1268*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1269*a9fa9459Szrj 
1270*a9fa9459Szrj   return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
1271*a9fa9459Szrj }
1272*a9fa9459Szrj 
1273*a9fa9459Szrj /* Make a structure type.  The second argument is true for a struct,
1274*a9fa9459Szrj    false for a union.  The third argument is the size of the struct.
1275*a9fa9459Szrj    The fourth argument is a NULL terminated array of fields.  */
1276*a9fa9459Szrj 
1277*a9fa9459Szrj debug_type
debug_make_struct_type(void * handle,bfd_boolean structp,bfd_vma size,debug_field * fields)1278*a9fa9459Szrj debug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
1279*a9fa9459Szrj 			debug_field *fields)
1280*a9fa9459Szrj {
1281*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1282*a9fa9459Szrj   struct debug_type_s *t;
1283*a9fa9459Szrj   struct debug_class_type *c;
1284*a9fa9459Szrj 
1285*a9fa9459Szrj   t = debug_make_type (info,
1286*a9fa9459Szrj 		       structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
1287*a9fa9459Szrj 		       size);
1288*a9fa9459Szrj   if (t == NULL)
1289*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1290*a9fa9459Szrj 
1291*a9fa9459Szrj   c = (struct debug_class_type *) xmalloc (sizeof *c);
1292*a9fa9459Szrj   memset (c, 0, sizeof *c);
1293*a9fa9459Szrj 
1294*a9fa9459Szrj   c->fields = fields;
1295*a9fa9459Szrj 
1296*a9fa9459Szrj   t->u.kclass = c;
1297*a9fa9459Szrj 
1298*a9fa9459Szrj   return t;
1299*a9fa9459Szrj }
1300*a9fa9459Szrj 
1301*a9fa9459Szrj /* Make an object type.  The first three arguments after the handle
1302*a9fa9459Szrj    are the same as for debug_make_struct_type.  The next arguments are
1303*a9fa9459Szrj    a NULL terminated array of base classes, a NULL terminated array of
1304*a9fa9459Szrj    methods, the type of the object holding the virtual function table
1305*a9fa9459Szrj    if it is not this object, and a boolean which is true if this
1306*a9fa9459Szrj    object has its own virtual function table.  */
1307*a9fa9459Szrj 
1308*a9fa9459Szrj debug_type
debug_make_object_type(void * handle,bfd_boolean structp,bfd_vma size,debug_field * fields,debug_baseclass * baseclasses,debug_method * methods,debug_type vptrbase,bfd_boolean ownvptr)1309*a9fa9459Szrj debug_make_object_type (void *handle, bfd_boolean structp, bfd_vma size,
1310*a9fa9459Szrj 			debug_field *fields, debug_baseclass *baseclasses,
1311*a9fa9459Szrj 			debug_method *methods, debug_type vptrbase,
1312*a9fa9459Szrj 			bfd_boolean ownvptr)
1313*a9fa9459Szrj {
1314*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1315*a9fa9459Szrj   struct debug_type_s *t;
1316*a9fa9459Szrj   struct debug_class_type *c;
1317*a9fa9459Szrj 
1318*a9fa9459Szrj   t = debug_make_type (info,
1319*a9fa9459Szrj 		       structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
1320*a9fa9459Szrj 		       size);
1321*a9fa9459Szrj   if (t == NULL)
1322*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1323*a9fa9459Szrj 
1324*a9fa9459Szrj   c = (struct debug_class_type *) xmalloc (sizeof *c);
1325*a9fa9459Szrj   memset (c, 0, sizeof *c);
1326*a9fa9459Szrj 
1327*a9fa9459Szrj   c->fields = fields;
1328*a9fa9459Szrj   c->baseclasses = baseclasses;
1329*a9fa9459Szrj   c->methods = methods;
1330*a9fa9459Szrj   if (ownvptr)
1331*a9fa9459Szrj     c->vptrbase = t;
1332*a9fa9459Szrj   else
1333*a9fa9459Szrj     c->vptrbase = vptrbase;
1334*a9fa9459Szrj 
1335*a9fa9459Szrj   t->u.kclass = c;
1336*a9fa9459Szrj 
1337*a9fa9459Szrj   return t;
1338*a9fa9459Szrj }
1339*a9fa9459Szrj 
1340*a9fa9459Szrj /* Make an enumeration type.  The arguments are a null terminated
1341*a9fa9459Szrj    array of strings, and an array of corresponding values.  */
1342*a9fa9459Szrj 
1343*a9fa9459Szrj debug_type
debug_make_enum_type(void * handle,const char ** names,bfd_signed_vma * values)1344*a9fa9459Szrj debug_make_enum_type (void *handle, const char **names,
1345*a9fa9459Szrj 		      bfd_signed_vma *values)
1346*a9fa9459Szrj {
1347*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1348*a9fa9459Szrj   struct debug_type_s *t;
1349*a9fa9459Szrj   struct debug_enum_type *e;
1350*a9fa9459Szrj 
1351*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
1352*a9fa9459Szrj   if (t == NULL)
1353*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1354*a9fa9459Szrj 
1355*a9fa9459Szrj   e = (struct debug_enum_type *) xmalloc (sizeof *e);
1356*a9fa9459Szrj   memset (e, 0, sizeof *e);
1357*a9fa9459Szrj 
1358*a9fa9459Szrj   e->names = names;
1359*a9fa9459Szrj   e->values = values;
1360*a9fa9459Szrj 
1361*a9fa9459Szrj   t->u.kenum = e;
1362*a9fa9459Szrj 
1363*a9fa9459Szrj   return t;
1364*a9fa9459Szrj }
1365*a9fa9459Szrj 
1366*a9fa9459Szrj /* Make a pointer to a given type.  */
1367*a9fa9459Szrj 
1368*a9fa9459Szrj debug_type
debug_make_pointer_type(void * handle,debug_type type)1369*a9fa9459Szrj debug_make_pointer_type (void *handle, debug_type type)
1370*a9fa9459Szrj {
1371*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1372*a9fa9459Szrj   struct debug_type_s *t;
1373*a9fa9459Szrj 
1374*a9fa9459Szrj   if (type == NULL)
1375*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1376*a9fa9459Szrj 
1377*a9fa9459Szrj   if (type->pointer != DEBUG_TYPE_NULL)
1378*a9fa9459Szrj     return type->pointer;
1379*a9fa9459Szrj 
1380*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
1381*a9fa9459Szrj   if (t == NULL)
1382*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1383*a9fa9459Szrj 
1384*a9fa9459Szrj   t->u.kpointer = type;
1385*a9fa9459Szrj 
1386*a9fa9459Szrj   type->pointer = t;
1387*a9fa9459Szrj 
1388*a9fa9459Szrj   return t;
1389*a9fa9459Szrj }
1390*a9fa9459Szrj 
1391*a9fa9459Szrj /* Make a function returning a given type.  FIXME: We should be able
1392*a9fa9459Szrj    to record the parameter types.  */
1393*a9fa9459Szrj 
1394*a9fa9459Szrj debug_type
debug_make_function_type(void * handle,debug_type type,debug_type * arg_types,bfd_boolean varargs)1395*a9fa9459Szrj debug_make_function_type (void *handle, debug_type type,
1396*a9fa9459Szrj 			  debug_type *arg_types, bfd_boolean varargs)
1397*a9fa9459Szrj {
1398*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1399*a9fa9459Szrj   struct debug_type_s *t;
1400*a9fa9459Szrj   struct debug_function_type *f;
1401*a9fa9459Szrj 
1402*a9fa9459Szrj   if (type == NULL)
1403*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1404*a9fa9459Szrj 
1405*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
1406*a9fa9459Szrj   if (t == NULL)
1407*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1408*a9fa9459Szrj 
1409*a9fa9459Szrj   f = (struct debug_function_type *) xmalloc (sizeof *f);
1410*a9fa9459Szrj   memset (f, 0, sizeof *f);
1411*a9fa9459Szrj 
1412*a9fa9459Szrj   f->return_type = type;
1413*a9fa9459Szrj   f->arg_types = arg_types;
1414*a9fa9459Szrj   f->varargs = varargs;
1415*a9fa9459Szrj 
1416*a9fa9459Szrj   t->u.kfunction = f;
1417*a9fa9459Szrj 
1418*a9fa9459Szrj   return t;
1419*a9fa9459Szrj }
1420*a9fa9459Szrj 
1421*a9fa9459Szrj /* Make a reference to a given type.  */
1422*a9fa9459Szrj 
1423*a9fa9459Szrj debug_type
debug_make_reference_type(void * handle,debug_type type)1424*a9fa9459Szrj debug_make_reference_type (void *handle, debug_type type)
1425*a9fa9459Szrj {
1426*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1427*a9fa9459Szrj   struct debug_type_s *t;
1428*a9fa9459Szrj 
1429*a9fa9459Szrj   if (type == NULL)
1430*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1431*a9fa9459Szrj 
1432*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
1433*a9fa9459Szrj   if (t == NULL)
1434*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1435*a9fa9459Szrj 
1436*a9fa9459Szrj   t->u.kreference = type;
1437*a9fa9459Szrj 
1438*a9fa9459Szrj   return t;
1439*a9fa9459Szrj }
1440*a9fa9459Szrj 
1441*a9fa9459Szrj /* Make a range of a given type from a lower to an upper bound.  */
1442*a9fa9459Szrj 
1443*a9fa9459Szrj debug_type
debug_make_range_type(void * handle,debug_type type,bfd_signed_vma lower,bfd_signed_vma upper)1444*a9fa9459Szrj debug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower,
1445*a9fa9459Szrj 		       bfd_signed_vma upper)
1446*a9fa9459Szrj {
1447*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1448*a9fa9459Szrj   struct debug_type_s *t;
1449*a9fa9459Szrj   struct debug_range_type *r;
1450*a9fa9459Szrj 
1451*a9fa9459Szrj   if (type == NULL)
1452*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1453*a9fa9459Szrj 
1454*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
1455*a9fa9459Szrj   if (t == NULL)
1456*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1457*a9fa9459Szrj 
1458*a9fa9459Szrj   r = (struct debug_range_type *) xmalloc (sizeof *r);
1459*a9fa9459Szrj   memset (r, 0, sizeof *r);
1460*a9fa9459Szrj 
1461*a9fa9459Szrj   r->type = type;
1462*a9fa9459Szrj   r->lower = lower;
1463*a9fa9459Szrj   r->upper = upper;
1464*a9fa9459Szrj 
1465*a9fa9459Szrj   t->u.krange = r;
1466*a9fa9459Szrj 
1467*a9fa9459Szrj   return t;
1468*a9fa9459Szrj }
1469*a9fa9459Szrj 
1470*a9fa9459Szrj /* Make an array type.  The second argument is the type of an element
1471*a9fa9459Szrj    of the array.  The third argument is the type of a range of the
1472*a9fa9459Szrj    array.  The fourth and fifth argument are the lower and upper
1473*a9fa9459Szrj    bounds, respectively.  The sixth argument is true if this array is
1474*a9fa9459Szrj    actually a string, as in C.  */
1475*a9fa9459Szrj 
1476*a9fa9459Szrj debug_type
debug_make_array_type(void * handle,debug_type element_type,debug_type range_type,bfd_signed_vma lower,bfd_signed_vma upper,bfd_boolean stringp)1477*a9fa9459Szrj debug_make_array_type (void *handle, debug_type element_type,
1478*a9fa9459Szrj 		       debug_type range_type, bfd_signed_vma lower,
1479*a9fa9459Szrj 		       bfd_signed_vma upper, bfd_boolean stringp)
1480*a9fa9459Szrj {
1481*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1482*a9fa9459Szrj   struct debug_type_s *t;
1483*a9fa9459Szrj   struct debug_array_type *a;
1484*a9fa9459Szrj 
1485*a9fa9459Szrj   if (element_type == NULL || range_type == NULL)
1486*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1487*a9fa9459Szrj 
1488*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
1489*a9fa9459Szrj   if (t == NULL)
1490*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1491*a9fa9459Szrj 
1492*a9fa9459Szrj   a = (struct debug_array_type *) xmalloc (sizeof *a);
1493*a9fa9459Szrj   memset (a, 0, sizeof *a);
1494*a9fa9459Szrj 
1495*a9fa9459Szrj   a->element_type = element_type;
1496*a9fa9459Szrj   a->range_type = range_type;
1497*a9fa9459Szrj   a->lower = lower;
1498*a9fa9459Szrj   a->upper = upper;
1499*a9fa9459Szrj   a->stringp = stringp;
1500*a9fa9459Szrj 
1501*a9fa9459Szrj   t->u.karray = a;
1502*a9fa9459Szrj 
1503*a9fa9459Szrj   return t;
1504*a9fa9459Szrj }
1505*a9fa9459Szrj 
1506*a9fa9459Szrj /* Make a set of a given type.  For example, a Pascal set type.  The
1507*a9fa9459Szrj    boolean argument is true if this set is actually a bitstring, as in
1508*a9fa9459Szrj    CHILL.  */
1509*a9fa9459Szrj 
1510*a9fa9459Szrj debug_type
debug_make_set_type(void * handle,debug_type type,bfd_boolean bitstringp)1511*a9fa9459Szrj debug_make_set_type (void *handle, debug_type type, bfd_boolean bitstringp)
1512*a9fa9459Szrj {
1513*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1514*a9fa9459Szrj   struct debug_type_s *t;
1515*a9fa9459Szrj   struct debug_set_type *s;
1516*a9fa9459Szrj 
1517*a9fa9459Szrj   if (type == NULL)
1518*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1519*a9fa9459Szrj 
1520*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_SET, 0);
1521*a9fa9459Szrj   if (t == NULL)
1522*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1523*a9fa9459Szrj 
1524*a9fa9459Szrj   s = (struct debug_set_type *) xmalloc (sizeof *s);
1525*a9fa9459Szrj   memset (s, 0, sizeof *s);
1526*a9fa9459Szrj 
1527*a9fa9459Szrj   s->type = type;
1528*a9fa9459Szrj   s->bitstringp = bitstringp;
1529*a9fa9459Szrj 
1530*a9fa9459Szrj   t->u.kset = s;
1531*a9fa9459Szrj 
1532*a9fa9459Szrj   return t;
1533*a9fa9459Szrj }
1534*a9fa9459Szrj 
1535*a9fa9459Szrj /* Make a type for a pointer which is relative to an object.  The
1536*a9fa9459Szrj    second argument is the type of the object to which the pointer is
1537*a9fa9459Szrj    relative.  The third argument is the type that the pointer points
1538*a9fa9459Szrj    to.  */
1539*a9fa9459Szrj 
1540*a9fa9459Szrj debug_type
debug_make_offset_type(void * handle,debug_type base_type,debug_type target_type)1541*a9fa9459Szrj debug_make_offset_type (void *handle, debug_type base_type,
1542*a9fa9459Szrj 			debug_type target_type)
1543*a9fa9459Szrj {
1544*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1545*a9fa9459Szrj   struct debug_type_s *t;
1546*a9fa9459Szrj   struct debug_offset_type *o;
1547*a9fa9459Szrj 
1548*a9fa9459Szrj   if (base_type == NULL || target_type == NULL)
1549*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1550*a9fa9459Szrj 
1551*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
1552*a9fa9459Szrj   if (t == NULL)
1553*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1554*a9fa9459Szrj 
1555*a9fa9459Szrj   o = (struct debug_offset_type *) xmalloc (sizeof *o);
1556*a9fa9459Szrj   memset (o, 0, sizeof *o);
1557*a9fa9459Szrj 
1558*a9fa9459Szrj   o->base_type = base_type;
1559*a9fa9459Szrj   o->target_type = target_type;
1560*a9fa9459Szrj 
1561*a9fa9459Szrj   t->u.koffset = o;
1562*a9fa9459Szrj 
1563*a9fa9459Szrj   return t;
1564*a9fa9459Szrj }
1565*a9fa9459Szrj 
1566*a9fa9459Szrj /* Make a type for a method function.  The second argument is the
1567*a9fa9459Szrj    return type, the third argument is the domain, and the fourth
1568*a9fa9459Szrj    argument is a NULL terminated array of argument types.  */
1569*a9fa9459Szrj 
1570*a9fa9459Szrj debug_type
debug_make_method_type(void * handle,debug_type return_type,debug_type domain_type,debug_type * arg_types,bfd_boolean varargs)1571*a9fa9459Szrj debug_make_method_type (void *handle, debug_type return_type,
1572*a9fa9459Szrj 			debug_type domain_type, debug_type *arg_types,
1573*a9fa9459Szrj 			bfd_boolean varargs)
1574*a9fa9459Szrj {
1575*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1576*a9fa9459Szrj   struct debug_type_s *t;
1577*a9fa9459Szrj   struct debug_method_type *m;
1578*a9fa9459Szrj 
1579*a9fa9459Szrj   if (return_type == NULL)
1580*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1581*a9fa9459Szrj 
1582*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
1583*a9fa9459Szrj   if (t == NULL)
1584*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1585*a9fa9459Szrj 
1586*a9fa9459Szrj   m = (struct debug_method_type *) xmalloc (sizeof *m);
1587*a9fa9459Szrj   memset (m, 0, sizeof *m);
1588*a9fa9459Szrj 
1589*a9fa9459Szrj   m->return_type = return_type;
1590*a9fa9459Szrj   m->domain_type = domain_type;
1591*a9fa9459Szrj   m->arg_types = arg_types;
1592*a9fa9459Szrj   m->varargs = varargs;
1593*a9fa9459Szrj 
1594*a9fa9459Szrj   t->u.kmethod = m;
1595*a9fa9459Szrj 
1596*a9fa9459Szrj   return t;
1597*a9fa9459Szrj }
1598*a9fa9459Szrj 
1599*a9fa9459Szrj /* Make a const qualified version of a given type.  */
1600*a9fa9459Szrj 
1601*a9fa9459Szrj debug_type
debug_make_const_type(void * handle,debug_type type)1602*a9fa9459Szrj debug_make_const_type (void *handle, debug_type type)
1603*a9fa9459Szrj {
1604*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1605*a9fa9459Szrj   struct debug_type_s *t;
1606*a9fa9459Szrj 
1607*a9fa9459Szrj   if (type == NULL)
1608*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1609*a9fa9459Szrj 
1610*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_CONST, 0);
1611*a9fa9459Szrj   if (t == NULL)
1612*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1613*a9fa9459Szrj 
1614*a9fa9459Szrj   t->u.kconst = type;
1615*a9fa9459Szrj 
1616*a9fa9459Szrj   return t;
1617*a9fa9459Szrj }
1618*a9fa9459Szrj 
1619*a9fa9459Szrj /* Make a volatile qualified version of a given type.  */
1620*a9fa9459Szrj 
1621*a9fa9459Szrj debug_type
debug_make_volatile_type(void * handle,debug_type type)1622*a9fa9459Szrj debug_make_volatile_type (void *handle, debug_type type)
1623*a9fa9459Szrj {
1624*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1625*a9fa9459Szrj   struct debug_type_s *t;
1626*a9fa9459Szrj 
1627*a9fa9459Szrj   if (type == NULL)
1628*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1629*a9fa9459Szrj 
1630*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
1631*a9fa9459Szrj   if (t == NULL)
1632*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1633*a9fa9459Szrj 
1634*a9fa9459Szrj   t->u.kvolatile = type;
1635*a9fa9459Szrj 
1636*a9fa9459Szrj   return t;
1637*a9fa9459Szrj }
1638*a9fa9459Szrj 
1639*a9fa9459Szrj /* Make an undefined tagged type.  For example, a struct which has
1640*a9fa9459Szrj    been mentioned, but not defined.  */
1641*a9fa9459Szrj 
1642*a9fa9459Szrj debug_type
debug_make_undefined_tagged_type(void * handle,const char * name,enum debug_type_kind kind)1643*a9fa9459Szrj debug_make_undefined_tagged_type (void *handle, const char *name,
1644*a9fa9459Szrj 				  enum debug_type_kind kind)
1645*a9fa9459Szrj {
1646*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1647*a9fa9459Szrj   struct debug_type_s *t;
1648*a9fa9459Szrj 
1649*a9fa9459Szrj   if (name == NULL)
1650*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1651*a9fa9459Szrj 
1652*a9fa9459Szrj   switch (kind)
1653*a9fa9459Szrj     {
1654*a9fa9459Szrj     case DEBUG_KIND_STRUCT:
1655*a9fa9459Szrj     case DEBUG_KIND_UNION:
1656*a9fa9459Szrj     case DEBUG_KIND_CLASS:
1657*a9fa9459Szrj     case DEBUG_KIND_UNION_CLASS:
1658*a9fa9459Szrj     case DEBUG_KIND_ENUM:
1659*a9fa9459Szrj       break;
1660*a9fa9459Szrj 
1661*a9fa9459Szrj     default:
1662*a9fa9459Szrj       debug_error (_("debug_make_undefined_type: unsupported kind"));
1663*a9fa9459Szrj       return DEBUG_TYPE_NULL;
1664*a9fa9459Szrj     }
1665*a9fa9459Szrj 
1666*a9fa9459Szrj   t = debug_make_type (info, kind, 0);
1667*a9fa9459Szrj   if (t == NULL)
1668*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1669*a9fa9459Szrj 
1670*a9fa9459Szrj   return debug_tag_type (handle, name, t);
1671*a9fa9459Szrj }
1672*a9fa9459Szrj 
1673*a9fa9459Szrj /* Make a base class for an object.  The second argument is the base
1674*a9fa9459Szrj    class type.  The third argument is the bit position of this base
1675*a9fa9459Szrj    class in the object (always 0 unless doing multiple inheritance).
1676*a9fa9459Szrj    The fourth argument is whether this is a virtual class.  The fifth
1677*a9fa9459Szrj    argument is the visibility of the base class.  */
1678*a9fa9459Szrj 
1679*a9fa9459Szrj debug_baseclass
debug_make_baseclass(void * handle ATTRIBUTE_UNUSED,debug_type type,bfd_vma bitpos,bfd_boolean is_virtual,enum debug_visibility visibility)1680*a9fa9459Szrj debug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
1681*a9fa9459Szrj 		      bfd_vma bitpos, bfd_boolean is_virtual,
1682*a9fa9459Szrj 		      enum debug_visibility visibility)
1683*a9fa9459Szrj {
1684*a9fa9459Szrj   struct debug_baseclass_s *b;
1685*a9fa9459Szrj 
1686*a9fa9459Szrj   b = (struct debug_baseclass_s *) xmalloc (sizeof *b);
1687*a9fa9459Szrj   memset (b, 0, sizeof *b);
1688*a9fa9459Szrj 
1689*a9fa9459Szrj   b->type = type;
1690*a9fa9459Szrj   b->bitpos = bitpos;
1691*a9fa9459Szrj   b->is_virtual = is_virtual;
1692*a9fa9459Szrj   b->visibility = visibility;
1693*a9fa9459Szrj 
1694*a9fa9459Szrj   return b;
1695*a9fa9459Szrj }
1696*a9fa9459Szrj 
1697*a9fa9459Szrj /* Make a field for a struct.  The second argument is the name.  The
1698*a9fa9459Szrj    third argument is the type of the field.  The fourth argument is
1699*a9fa9459Szrj    the bit position of the field.  The fifth argument is the size of
1700*a9fa9459Szrj    the field (it may be zero).  The sixth argument is the visibility
1701*a9fa9459Szrj    of the field.  */
1702*a9fa9459Szrj 
1703*a9fa9459Szrj debug_field
debug_make_field(void * handle ATTRIBUTE_UNUSED,const char * name,debug_type type,bfd_vma bitpos,bfd_vma bitsize,enum debug_visibility visibility)1704*a9fa9459Szrj debug_make_field (void *handle ATTRIBUTE_UNUSED, const char *name,
1705*a9fa9459Szrj 		  debug_type type, bfd_vma bitpos, bfd_vma bitsize,
1706*a9fa9459Szrj 		  enum debug_visibility visibility)
1707*a9fa9459Szrj {
1708*a9fa9459Szrj   struct debug_field_s *f;
1709*a9fa9459Szrj 
1710*a9fa9459Szrj   f = (struct debug_field_s *) xmalloc (sizeof *f);
1711*a9fa9459Szrj   memset (f, 0, sizeof *f);
1712*a9fa9459Szrj 
1713*a9fa9459Szrj   f->name = name;
1714*a9fa9459Szrj   f->type = type;
1715*a9fa9459Szrj   f->static_member = FALSE;
1716*a9fa9459Szrj   f->u.f.bitpos = bitpos;
1717*a9fa9459Szrj   f->u.f.bitsize = bitsize;
1718*a9fa9459Szrj   f->visibility = visibility;
1719*a9fa9459Szrj 
1720*a9fa9459Szrj   return f;
1721*a9fa9459Szrj }
1722*a9fa9459Szrj 
1723*a9fa9459Szrj /* Make a static member of an object.  The second argument is the
1724*a9fa9459Szrj    name.  The third argument is the type of the member.  The fourth
1725*a9fa9459Szrj    argument is the physical name of the member (i.e., the name as a
1726*a9fa9459Szrj    global variable).  The fifth argument is the visibility of the
1727*a9fa9459Szrj    member.  */
1728*a9fa9459Szrj 
1729*a9fa9459Szrj debug_field
debug_make_static_member(void * handle ATTRIBUTE_UNUSED,const char * name,debug_type type,const char * physname,enum debug_visibility visibility)1730*a9fa9459Szrj debug_make_static_member (void *handle ATTRIBUTE_UNUSED, const char *name,
1731*a9fa9459Szrj 			  debug_type type, const char *physname,
1732*a9fa9459Szrj 			  enum debug_visibility visibility)
1733*a9fa9459Szrj {
1734*a9fa9459Szrj   struct debug_field_s *f;
1735*a9fa9459Szrj 
1736*a9fa9459Szrj   f = (struct debug_field_s *) xmalloc (sizeof *f);
1737*a9fa9459Szrj   memset (f, 0, sizeof *f);
1738*a9fa9459Szrj 
1739*a9fa9459Szrj   f->name = name;
1740*a9fa9459Szrj   f->type = type;
1741*a9fa9459Szrj   f->static_member = TRUE;
1742*a9fa9459Szrj   f->u.s.physname = physname;
1743*a9fa9459Szrj   f->visibility = visibility;
1744*a9fa9459Szrj 
1745*a9fa9459Szrj   return f;
1746*a9fa9459Szrj }
1747*a9fa9459Szrj 
1748*a9fa9459Szrj /* Make a method.  The second argument is the name, and the third
1749*a9fa9459Szrj    argument is a NULL terminated array of method variants.  */
1750*a9fa9459Szrj 
1751*a9fa9459Szrj debug_method
debug_make_method(void * handle ATTRIBUTE_UNUSED,const char * name,debug_method_variant * variants)1752*a9fa9459Szrj debug_make_method (void *handle ATTRIBUTE_UNUSED, const char *name,
1753*a9fa9459Szrj 		   debug_method_variant *variants)
1754*a9fa9459Szrj {
1755*a9fa9459Szrj   struct debug_method_s *m;
1756*a9fa9459Szrj 
1757*a9fa9459Szrj   m = (struct debug_method_s *) xmalloc (sizeof *m);
1758*a9fa9459Szrj   memset (m, 0, sizeof *m);
1759*a9fa9459Szrj 
1760*a9fa9459Szrj   m->name = name;
1761*a9fa9459Szrj   m->variants = variants;
1762*a9fa9459Szrj 
1763*a9fa9459Szrj   return m;
1764*a9fa9459Szrj }
1765*a9fa9459Szrj 
1766*a9fa9459Szrj /* Make a method argument.  The second argument is the real name of
1767*a9fa9459Szrj    the function.  The third argument is the type of the function.  The
1768*a9fa9459Szrj    fourth argument is the visibility.  The fifth argument is whether
1769*a9fa9459Szrj    this is a const function.  The sixth argument is whether this is a
1770*a9fa9459Szrj    volatile function.  The seventh argument is the offset in the
1771*a9fa9459Szrj    virtual function table, if any.  The eighth argument is the virtual
1772*a9fa9459Szrj    function context.  FIXME: Are the const and volatile arguments
1773*a9fa9459Szrj    necessary?  Could we just use debug_make_const_type?  */
1774*a9fa9459Szrj 
1775*a9fa9459Szrj debug_method_variant
debug_make_method_variant(void * handle ATTRIBUTE_UNUSED,const char * physname,debug_type type,enum debug_visibility visibility,bfd_boolean constp,bfd_boolean volatilep,bfd_vma voffset,debug_type context)1776*a9fa9459Szrj debug_make_method_variant (void *handle ATTRIBUTE_UNUSED,
1777*a9fa9459Szrj 			   const char *physname, debug_type type,
1778*a9fa9459Szrj 			   enum debug_visibility visibility,
1779*a9fa9459Szrj 			   bfd_boolean constp, bfd_boolean volatilep,
1780*a9fa9459Szrj 			   bfd_vma voffset, debug_type context)
1781*a9fa9459Szrj {
1782*a9fa9459Szrj   struct debug_method_variant_s *m;
1783*a9fa9459Szrj 
1784*a9fa9459Szrj   m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
1785*a9fa9459Szrj   memset (m, 0, sizeof *m);
1786*a9fa9459Szrj 
1787*a9fa9459Szrj   m->physname = physname;
1788*a9fa9459Szrj   m->type = type;
1789*a9fa9459Szrj   m->visibility = visibility;
1790*a9fa9459Szrj   m->constp = constp;
1791*a9fa9459Szrj   m->volatilep = volatilep;
1792*a9fa9459Szrj   m->voffset = voffset;
1793*a9fa9459Szrj   m->context = context;
1794*a9fa9459Szrj 
1795*a9fa9459Szrj   return m;
1796*a9fa9459Szrj }
1797*a9fa9459Szrj 
1798*a9fa9459Szrj /* Make a static method argument.  The arguments are the same as for
1799*a9fa9459Szrj    debug_make_method_variant, except that the last two are omitted
1800*a9fa9459Szrj    since a static method can not also be virtual.  */
1801*a9fa9459Szrj 
1802*a9fa9459Szrj debug_method_variant
debug_make_static_method_variant(void * handle ATTRIBUTE_UNUSED,const char * physname,debug_type type,enum debug_visibility visibility,bfd_boolean constp,bfd_boolean volatilep)1803*a9fa9459Szrj debug_make_static_method_variant (void *handle ATTRIBUTE_UNUSED,
1804*a9fa9459Szrj 				  const char *physname, debug_type type,
1805*a9fa9459Szrj 				  enum debug_visibility visibility,
1806*a9fa9459Szrj 				  bfd_boolean constp, bfd_boolean volatilep)
1807*a9fa9459Szrj {
1808*a9fa9459Szrj   struct debug_method_variant_s *m;
1809*a9fa9459Szrj 
1810*a9fa9459Szrj   m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
1811*a9fa9459Szrj   memset (m, 0, sizeof *m);
1812*a9fa9459Szrj 
1813*a9fa9459Szrj   m->physname = physname;
1814*a9fa9459Szrj   m->type = type;
1815*a9fa9459Szrj   m->visibility = visibility;
1816*a9fa9459Szrj   m->constp = constp;
1817*a9fa9459Szrj   m->volatilep = volatilep;
1818*a9fa9459Szrj   m->voffset = VOFFSET_STATIC_METHOD;
1819*a9fa9459Szrj 
1820*a9fa9459Szrj   return m;
1821*a9fa9459Szrj }
1822*a9fa9459Szrj 
1823*a9fa9459Szrj /* Name a type.  */
1824*a9fa9459Szrj 
1825*a9fa9459Szrj debug_type
debug_name_type(void * handle,const char * name,debug_type type)1826*a9fa9459Szrj debug_name_type (void *handle, const char *name, debug_type type)
1827*a9fa9459Szrj {
1828*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1829*a9fa9459Szrj   struct debug_type_s *t;
1830*a9fa9459Szrj   struct debug_named_type *n;
1831*a9fa9459Szrj   struct debug_name *nm;
1832*a9fa9459Szrj 
1833*a9fa9459Szrj   if (name == NULL || type == NULL)
1834*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1835*a9fa9459Szrj 
1836*a9fa9459Szrj   if (info->current_unit == NULL
1837*a9fa9459Szrj       || info->current_file == NULL)
1838*a9fa9459Szrj     {
1839*a9fa9459Szrj       debug_error (_("debug_name_type: no current file"));
1840*a9fa9459Szrj       return DEBUG_TYPE_NULL;
1841*a9fa9459Szrj     }
1842*a9fa9459Szrj 
1843*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1844*a9fa9459Szrj   if (t == NULL)
1845*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1846*a9fa9459Szrj 
1847*a9fa9459Szrj   n = (struct debug_named_type *) xmalloc (sizeof *n);
1848*a9fa9459Szrj   memset (n, 0, sizeof *n);
1849*a9fa9459Szrj 
1850*a9fa9459Szrj   n->type = type;
1851*a9fa9459Szrj 
1852*a9fa9459Szrj   t->u.knamed = n;
1853*a9fa9459Szrj 
1854*a9fa9459Szrj   /* We always add the name to the global namespace.  This is probably
1855*a9fa9459Szrj      wrong in some cases, but it seems to be right for stabs.  FIXME.  */
1856*a9fa9459Szrj 
1857*a9fa9459Szrj   nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1858*a9fa9459Szrj 			       DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
1859*a9fa9459Szrj   if (nm == NULL)
1860*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1861*a9fa9459Szrj 
1862*a9fa9459Szrj   nm->u.type = t;
1863*a9fa9459Szrj 
1864*a9fa9459Szrj   n->name = nm;
1865*a9fa9459Szrj 
1866*a9fa9459Szrj   return t;
1867*a9fa9459Szrj }
1868*a9fa9459Szrj 
1869*a9fa9459Szrj /* Tag a type.  */
1870*a9fa9459Szrj 
1871*a9fa9459Szrj debug_type
debug_tag_type(void * handle,const char * name,debug_type type)1872*a9fa9459Szrj debug_tag_type (void *handle, const char *name, debug_type type)
1873*a9fa9459Szrj {
1874*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1875*a9fa9459Szrj   struct debug_type_s *t;
1876*a9fa9459Szrj   struct debug_named_type *n;
1877*a9fa9459Szrj   struct debug_name *nm;
1878*a9fa9459Szrj 
1879*a9fa9459Szrj   if (name == NULL || type == NULL)
1880*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1881*a9fa9459Szrj 
1882*a9fa9459Szrj   if (info->current_file == NULL)
1883*a9fa9459Szrj     {
1884*a9fa9459Szrj       debug_error (_("debug_tag_type: no current file"));
1885*a9fa9459Szrj       return DEBUG_TYPE_NULL;
1886*a9fa9459Szrj     }
1887*a9fa9459Szrj 
1888*a9fa9459Szrj   if (type->kind == DEBUG_KIND_TAGGED)
1889*a9fa9459Szrj     {
1890*a9fa9459Szrj       if (strcmp (type->u.knamed->name->name, name) == 0)
1891*a9fa9459Szrj 	return type;
1892*a9fa9459Szrj       debug_error (_("debug_tag_type: extra tag attempted"));
1893*a9fa9459Szrj       return DEBUG_TYPE_NULL;
1894*a9fa9459Szrj     }
1895*a9fa9459Szrj 
1896*a9fa9459Szrj   t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
1897*a9fa9459Szrj   if (t == NULL)
1898*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1899*a9fa9459Szrj 
1900*a9fa9459Szrj   n = (struct debug_named_type *) xmalloc (sizeof *n);
1901*a9fa9459Szrj   memset (n, 0, sizeof *n);
1902*a9fa9459Szrj 
1903*a9fa9459Szrj   n->type = type;
1904*a9fa9459Szrj 
1905*a9fa9459Szrj   t->u.knamed = n;
1906*a9fa9459Szrj 
1907*a9fa9459Szrj   /* We keep a global namespace of tags for each compilation unit.  I
1908*a9fa9459Szrj      don't know if that is the right thing to do.  */
1909*a9fa9459Szrj 
1910*a9fa9459Szrj   nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1911*a9fa9459Szrj 			       DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
1912*a9fa9459Szrj   if (nm == NULL)
1913*a9fa9459Szrj     return DEBUG_TYPE_NULL;
1914*a9fa9459Szrj 
1915*a9fa9459Szrj   nm->u.tag = t;
1916*a9fa9459Szrj 
1917*a9fa9459Szrj   n->name = nm;
1918*a9fa9459Szrj 
1919*a9fa9459Szrj   return t;
1920*a9fa9459Szrj }
1921*a9fa9459Szrj 
1922*a9fa9459Szrj /* Record the size of a given type.  */
1923*a9fa9459Szrj 
1924*a9fa9459Szrj bfd_boolean
debug_record_type_size(void * handle ATTRIBUTE_UNUSED,debug_type type,unsigned int size)1925*a9fa9459Szrj debug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type,
1926*a9fa9459Szrj 			unsigned int size)
1927*a9fa9459Szrj {
1928*a9fa9459Szrj   if (type->size != 0 && type->size != size)
1929*a9fa9459Szrj     fprintf (stderr, _("Warning: changing type size from %d to %d\n"),
1930*a9fa9459Szrj 	     type->size, size);
1931*a9fa9459Szrj 
1932*a9fa9459Szrj   type->size = size;
1933*a9fa9459Szrj 
1934*a9fa9459Szrj   return TRUE;
1935*a9fa9459Szrj }
1936*a9fa9459Szrj 
1937*a9fa9459Szrj /* Find a named type.  */
1938*a9fa9459Szrj 
1939*a9fa9459Szrj debug_type
debug_find_named_type(void * handle,const char * name)1940*a9fa9459Szrj debug_find_named_type (void *handle, const char *name)
1941*a9fa9459Szrj {
1942*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1943*a9fa9459Szrj   struct debug_block *b;
1944*a9fa9459Szrj   struct debug_file *f;
1945*a9fa9459Szrj 
1946*a9fa9459Szrj   /* We only search the current compilation unit.  I don't know if
1947*a9fa9459Szrj      this is right or not.  */
1948*a9fa9459Szrj 
1949*a9fa9459Szrj   if (info->current_unit == NULL)
1950*a9fa9459Szrj     {
1951*a9fa9459Szrj       debug_error (_("debug_find_named_type: no current compilation unit"));
1952*a9fa9459Szrj       return DEBUG_TYPE_NULL;
1953*a9fa9459Szrj     }
1954*a9fa9459Szrj 
1955*a9fa9459Szrj   for (b = info->current_block; b != NULL; b = b->parent)
1956*a9fa9459Szrj     {
1957*a9fa9459Szrj       if (b->locals != NULL)
1958*a9fa9459Szrj 	{
1959*a9fa9459Szrj 	  struct debug_name *n;
1960*a9fa9459Szrj 
1961*a9fa9459Szrj 	  for (n = b->locals->list; n != NULL; n = n->next)
1962*a9fa9459Szrj 	    {
1963*a9fa9459Szrj 	      if (n->kind == DEBUG_OBJECT_TYPE
1964*a9fa9459Szrj 		  && n->name[0] == name[0]
1965*a9fa9459Szrj 		  && strcmp (n->name, name) == 0)
1966*a9fa9459Szrj 		return n->u.type;
1967*a9fa9459Szrj 	    }
1968*a9fa9459Szrj 	}
1969*a9fa9459Szrj     }
1970*a9fa9459Szrj 
1971*a9fa9459Szrj   for (f = info->current_unit->files; f != NULL; f = f->next)
1972*a9fa9459Szrj     {
1973*a9fa9459Szrj       if (f->globals != NULL)
1974*a9fa9459Szrj 	{
1975*a9fa9459Szrj 	  struct debug_name *n;
1976*a9fa9459Szrj 
1977*a9fa9459Szrj 	  for (n = f->globals->list; n != NULL; n = n->next)
1978*a9fa9459Szrj 	    {
1979*a9fa9459Szrj 	      if (n->kind == DEBUG_OBJECT_TYPE
1980*a9fa9459Szrj 		  && n->name[0] == name[0]
1981*a9fa9459Szrj 		  && strcmp (n->name, name) == 0)
1982*a9fa9459Szrj 		return n->u.type;
1983*a9fa9459Szrj 	    }
1984*a9fa9459Szrj 	}
1985*a9fa9459Szrj     }
1986*a9fa9459Szrj 
1987*a9fa9459Szrj   return DEBUG_TYPE_NULL;
1988*a9fa9459Szrj }
1989*a9fa9459Szrj 
1990*a9fa9459Szrj /* Find a tagged type.  */
1991*a9fa9459Szrj 
1992*a9fa9459Szrj debug_type
debug_find_tagged_type(void * handle,const char * name,enum debug_type_kind kind)1993*a9fa9459Szrj debug_find_tagged_type (void *handle, const char *name,
1994*a9fa9459Szrj 			enum debug_type_kind kind)
1995*a9fa9459Szrj {
1996*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
1997*a9fa9459Szrj   struct debug_unit *u;
1998*a9fa9459Szrj 
1999*a9fa9459Szrj   /* We search the globals of all the compilation units.  I don't know
2000*a9fa9459Szrj      if this is correct or not.  It would be easy to change.  */
2001*a9fa9459Szrj 
2002*a9fa9459Szrj   for (u = info->units; u != NULL; u = u->next)
2003*a9fa9459Szrj     {
2004*a9fa9459Szrj       struct debug_file *f;
2005*a9fa9459Szrj 
2006*a9fa9459Szrj       for (f = u->files; f != NULL; f = f->next)
2007*a9fa9459Szrj 	{
2008*a9fa9459Szrj 	  struct debug_name *n;
2009*a9fa9459Szrj 
2010*a9fa9459Szrj 	  if (f->globals != NULL)
2011*a9fa9459Szrj 	    {
2012*a9fa9459Szrj 	      for (n = f->globals->list; n != NULL; n = n->next)
2013*a9fa9459Szrj 		{
2014*a9fa9459Szrj 		  if (n->kind == DEBUG_OBJECT_TAG
2015*a9fa9459Szrj 		      && (kind == DEBUG_KIND_ILLEGAL
2016*a9fa9459Szrj 			  || n->u.tag->kind == kind)
2017*a9fa9459Szrj 		      && n->name[0] == name[0]
2018*a9fa9459Szrj 		      && strcmp (n->name, name) == 0)
2019*a9fa9459Szrj 		    return n->u.tag;
2020*a9fa9459Szrj 		}
2021*a9fa9459Szrj 	    }
2022*a9fa9459Szrj 	}
2023*a9fa9459Szrj     }
2024*a9fa9459Szrj 
2025*a9fa9459Szrj   return DEBUG_TYPE_NULL;
2026*a9fa9459Szrj }
2027*a9fa9459Szrj 
2028*a9fa9459Szrj /* Get a base type.  We build a linked list on the stack to avoid
2029*a9fa9459Szrj    crashing if the type is defined circularly.  */
2030*a9fa9459Szrj 
2031*a9fa9459Szrj static struct debug_type_s *
debug_get_real_type(void * handle,debug_type type,struct debug_type_real_list * list)2032*a9fa9459Szrj debug_get_real_type (void *handle, debug_type type,
2033*a9fa9459Szrj 		     struct debug_type_real_list *list)
2034*a9fa9459Szrj {
2035*a9fa9459Szrj   struct debug_type_real_list *l;
2036*a9fa9459Szrj   struct debug_type_real_list rl;
2037*a9fa9459Szrj 
2038*a9fa9459Szrj   switch (type->kind)
2039*a9fa9459Szrj     {
2040*a9fa9459Szrj     default:
2041*a9fa9459Szrj       return type;
2042*a9fa9459Szrj 
2043*a9fa9459Szrj     case DEBUG_KIND_INDIRECT:
2044*a9fa9459Szrj     case DEBUG_KIND_NAMED:
2045*a9fa9459Szrj     case DEBUG_KIND_TAGGED:
2046*a9fa9459Szrj       break;
2047*a9fa9459Szrj     }
2048*a9fa9459Szrj 
2049*a9fa9459Szrj   for (l = list; l != NULL; l = l->next)
2050*a9fa9459Szrj     {
2051*a9fa9459Szrj       if (l->t == type || l == l->next)
2052*a9fa9459Szrj 	{
2053*a9fa9459Szrj 	  fprintf (stderr,
2054*a9fa9459Szrj 		   _("debug_get_real_type: circular debug information for %s\n"),
2055*a9fa9459Szrj 		   debug_get_type_name (handle, type));
2056*a9fa9459Szrj 	  return NULL;
2057*a9fa9459Szrj 	}
2058*a9fa9459Szrj     }
2059*a9fa9459Szrj 
2060*a9fa9459Szrj   rl.next = list;
2061*a9fa9459Szrj   rl.t = type;
2062*a9fa9459Szrj 
2063*a9fa9459Szrj   switch (type->kind)
2064*a9fa9459Szrj     {
2065*a9fa9459Szrj       /* The default case is just here to avoid warnings.  */
2066*a9fa9459Szrj     default:
2067*a9fa9459Szrj     case DEBUG_KIND_INDIRECT:
2068*a9fa9459Szrj       if (*type->u.kindirect->slot != NULL)
2069*a9fa9459Szrj 	return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
2070*a9fa9459Szrj       return type;
2071*a9fa9459Szrj     case DEBUG_KIND_NAMED:
2072*a9fa9459Szrj     case DEBUG_KIND_TAGGED:
2073*a9fa9459Szrj       return debug_get_real_type (handle, type->u.knamed->type, &rl);
2074*a9fa9459Szrj     }
2075*a9fa9459Szrj   /*NOTREACHED*/
2076*a9fa9459Szrj }
2077*a9fa9459Szrj 
2078*a9fa9459Szrj /* Get the kind of a type.  */
2079*a9fa9459Szrj 
2080*a9fa9459Szrj enum debug_type_kind
debug_get_type_kind(void * handle,debug_type type)2081*a9fa9459Szrj debug_get_type_kind (void *handle, debug_type type)
2082*a9fa9459Szrj {
2083*a9fa9459Szrj   if (type == NULL)
2084*a9fa9459Szrj     return DEBUG_KIND_ILLEGAL;
2085*a9fa9459Szrj   type = debug_get_real_type (handle, type, NULL);
2086*a9fa9459Szrj   if (type == NULL)
2087*a9fa9459Szrj     return DEBUG_KIND_ILLEGAL;
2088*a9fa9459Szrj   return type->kind;
2089*a9fa9459Szrj }
2090*a9fa9459Szrj 
2091*a9fa9459Szrj /* Get the name of a type.  */
2092*a9fa9459Szrj 
2093*a9fa9459Szrj const char *
debug_get_type_name(void * handle,debug_type type)2094*a9fa9459Szrj debug_get_type_name (void *handle, debug_type type)
2095*a9fa9459Szrj {
2096*a9fa9459Szrj   if (type->kind == DEBUG_KIND_INDIRECT)
2097*a9fa9459Szrj     {
2098*a9fa9459Szrj       if (*type->u.kindirect->slot != NULL)
2099*a9fa9459Szrj 	return debug_get_type_name (handle, *type->u.kindirect->slot);
2100*a9fa9459Szrj       return type->u.kindirect->tag;
2101*a9fa9459Szrj     }
2102*a9fa9459Szrj   if (type->kind == DEBUG_KIND_NAMED
2103*a9fa9459Szrj       || type->kind == DEBUG_KIND_TAGGED)
2104*a9fa9459Szrj     return type->u.knamed->name->name;
2105*a9fa9459Szrj   return NULL;
2106*a9fa9459Szrj }
2107*a9fa9459Szrj 
2108*a9fa9459Szrj /* Get the size of a type.  */
2109*a9fa9459Szrj 
2110*a9fa9459Szrj bfd_vma
debug_get_type_size(void * handle,debug_type type)2111*a9fa9459Szrj debug_get_type_size (void *handle, debug_type type)
2112*a9fa9459Szrj {
2113*a9fa9459Szrj   if (type == NULL)
2114*a9fa9459Szrj     return 0;
2115*a9fa9459Szrj 
2116*a9fa9459Szrj   /* We don't call debug_get_real_type, because somebody might have
2117*a9fa9459Szrj      called debug_record_type_size on a named or indirect type.  */
2118*a9fa9459Szrj 
2119*a9fa9459Szrj   if (type->size != 0)
2120*a9fa9459Szrj     return type->size;
2121*a9fa9459Szrj 
2122*a9fa9459Szrj   switch (type->kind)
2123*a9fa9459Szrj     {
2124*a9fa9459Szrj     default:
2125*a9fa9459Szrj       return 0;
2126*a9fa9459Szrj     case DEBUG_KIND_INDIRECT:
2127*a9fa9459Szrj       if (*type->u.kindirect->slot != NULL)
2128*a9fa9459Szrj 	return debug_get_type_size (handle, *type->u.kindirect->slot);
2129*a9fa9459Szrj       return 0;
2130*a9fa9459Szrj     case DEBUG_KIND_NAMED:
2131*a9fa9459Szrj     case DEBUG_KIND_TAGGED:
2132*a9fa9459Szrj       return debug_get_type_size (handle, type->u.knamed->type);
2133*a9fa9459Szrj     }
2134*a9fa9459Szrj   /*NOTREACHED*/
2135*a9fa9459Szrj }
2136*a9fa9459Szrj 
2137*a9fa9459Szrj /* Get the return type of a function or method type.  */
2138*a9fa9459Szrj 
2139*a9fa9459Szrj debug_type
debug_get_return_type(void * handle,debug_type type)2140*a9fa9459Szrj debug_get_return_type (void *handle, debug_type type)
2141*a9fa9459Szrj {
2142*a9fa9459Szrj   if (type == NULL)
2143*a9fa9459Szrj     return DEBUG_TYPE_NULL;
2144*a9fa9459Szrj 
2145*a9fa9459Szrj   type = debug_get_real_type (handle, type, NULL);
2146*a9fa9459Szrj   if (type == NULL)
2147*a9fa9459Szrj     return DEBUG_TYPE_NULL;
2148*a9fa9459Szrj 
2149*a9fa9459Szrj   switch (type->kind)
2150*a9fa9459Szrj     {
2151*a9fa9459Szrj     default:
2152*a9fa9459Szrj       return DEBUG_TYPE_NULL;
2153*a9fa9459Szrj     case DEBUG_KIND_FUNCTION:
2154*a9fa9459Szrj       return type->u.kfunction->return_type;
2155*a9fa9459Szrj     case DEBUG_KIND_METHOD:
2156*a9fa9459Szrj       return type->u.kmethod->return_type;
2157*a9fa9459Szrj     }
2158*a9fa9459Szrj   /*NOTREACHED*/
2159*a9fa9459Szrj }
2160*a9fa9459Szrj 
2161*a9fa9459Szrj /* Get the parameter types of a function or method type (except that
2162*a9fa9459Szrj    we don't currently store the parameter types of a function).  */
2163*a9fa9459Szrj 
2164*a9fa9459Szrj const debug_type *
debug_get_parameter_types(void * handle,debug_type type,bfd_boolean * pvarargs)2165*a9fa9459Szrj debug_get_parameter_types (void *handle, debug_type type,
2166*a9fa9459Szrj 			   bfd_boolean *pvarargs)
2167*a9fa9459Szrj {
2168*a9fa9459Szrj   if (type == NULL)
2169*a9fa9459Szrj     return NULL;
2170*a9fa9459Szrj 
2171*a9fa9459Szrj   type = debug_get_real_type (handle, type, NULL);
2172*a9fa9459Szrj   if (type == NULL)
2173*a9fa9459Szrj     return NULL;
2174*a9fa9459Szrj 
2175*a9fa9459Szrj   switch (type->kind)
2176*a9fa9459Szrj     {
2177*a9fa9459Szrj     default:
2178*a9fa9459Szrj       return NULL;
2179*a9fa9459Szrj     case DEBUG_KIND_FUNCTION:
2180*a9fa9459Szrj       *pvarargs = type->u.kfunction->varargs;
2181*a9fa9459Szrj       return type->u.kfunction->arg_types;
2182*a9fa9459Szrj     case DEBUG_KIND_METHOD:
2183*a9fa9459Szrj       *pvarargs = type->u.kmethod->varargs;
2184*a9fa9459Szrj       return type->u.kmethod->arg_types;
2185*a9fa9459Szrj     }
2186*a9fa9459Szrj   /*NOTREACHED*/
2187*a9fa9459Szrj }
2188*a9fa9459Szrj 
2189*a9fa9459Szrj /* Get the target type of a type.  */
2190*a9fa9459Szrj 
2191*a9fa9459Szrj debug_type
debug_get_target_type(void * handle,debug_type type)2192*a9fa9459Szrj debug_get_target_type (void *handle, debug_type type)
2193*a9fa9459Szrj {
2194*a9fa9459Szrj   if (type == NULL)
2195*a9fa9459Szrj     return NULL;
2196*a9fa9459Szrj 
2197*a9fa9459Szrj   type = debug_get_real_type (handle, type, NULL);
2198*a9fa9459Szrj   if (type == NULL)
2199*a9fa9459Szrj     return NULL;
2200*a9fa9459Szrj 
2201*a9fa9459Szrj   switch (type->kind)
2202*a9fa9459Szrj     {
2203*a9fa9459Szrj     default:
2204*a9fa9459Szrj       return NULL;
2205*a9fa9459Szrj     case DEBUG_KIND_POINTER:
2206*a9fa9459Szrj       return type->u.kpointer;
2207*a9fa9459Szrj     case DEBUG_KIND_REFERENCE:
2208*a9fa9459Szrj       return type->u.kreference;
2209*a9fa9459Szrj     case DEBUG_KIND_CONST:
2210*a9fa9459Szrj       return type->u.kconst;
2211*a9fa9459Szrj     case DEBUG_KIND_VOLATILE:
2212*a9fa9459Szrj       return type->u.kvolatile;
2213*a9fa9459Szrj     }
2214*a9fa9459Szrj   /*NOTREACHED*/
2215*a9fa9459Szrj }
2216*a9fa9459Szrj 
2217*a9fa9459Szrj /* Get the NULL terminated array of fields for a struct, union, or
2218*a9fa9459Szrj    class.  */
2219*a9fa9459Szrj 
2220*a9fa9459Szrj const debug_field *
debug_get_fields(void * handle,debug_type type)2221*a9fa9459Szrj debug_get_fields (void *handle, debug_type type)
2222*a9fa9459Szrj {
2223*a9fa9459Szrj   if (type == NULL)
2224*a9fa9459Szrj     return NULL;
2225*a9fa9459Szrj 
2226*a9fa9459Szrj   type = debug_get_real_type (handle, type, NULL);
2227*a9fa9459Szrj   if (type == NULL)
2228*a9fa9459Szrj     return NULL;
2229*a9fa9459Szrj 
2230*a9fa9459Szrj   switch (type->kind)
2231*a9fa9459Szrj     {
2232*a9fa9459Szrj     default:
2233*a9fa9459Szrj       return NULL;
2234*a9fa9459Szrj     case DEBUG_KIND_STRUCT:
2235*a9fa9459Szrj     case DEBUG_KIND_UNION:
2236*a9fa9459Szrj     case DEBUG_KIND_CLASS:
2237*a9fa9459Szrj     case DEBUG_KIND_UNION_CLASS:
2238*a9fa9459Szrj       return type->u.kclass->fields;
2239*a9fa9459Szrj     }
2240*a9fa9459Szrj   /*NOTREACHED*/
2241*a9fa9459Szrj }
2242*a9fa9459Szrj 
2243*a9fa9459Szrj /* Get the type of a field.  */
2244*a9fa9459Szrj 
2245*a9fa9459Szrj debug_type
debug_get_field_type(void * handle ATTRIBUTE_UNUSED,debug_field field)2246*a9fa9459Szrj debug_get_field_type (void *handle ATTRIBUTE_UNUSED, debug_field field)
2247*a9fa9459Szrj {
2248*a9fa9459Szrj   if (field == NULL)
2249*a9fa9459Szrj     return NULL;
2250*a9fa9459Szrj   return field->type;
2251*a9fa9459Szrj }
2252*a9fa9459Szrj 
2253*a9fa9459Szrj /* Get the name of a field.  */
2254*a9fa9459Szrj 
2255*a9fa9459Szrj const char *
debug_get_field_name(void * handle ATTRIBUTE_UNUSED,debug_field field)2256*a9fa9459Szrj debug_get_field_name (void *handle ATTRIBUTE_UNUSED, debug_field field)
2257*a9fa9459Szrj {
2258*a9fa9459Szrj   if (field == NULL)
2259*a9fa9459Szrj     return NULL;
2260*a9fa9459Szrj   return field->name;
2261*a9fa9459Szrj }
2262*a9fa9459Szrj 
2263*a9fa9459Szrj /* Get the bit position of a field.  */
2264*a9fa9459Szrj 
2265*a9fa9459Szrj bfd_vma
debug_get_field_bitpos(void * handle ATTRIBUTE_UNUSED,debug_field field)2266*a9fa9459Szrj debug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED, debug_field field)
2267*a9fa9459Szrj {
2268*a9fa9459Szrj   if (field == NULL || field->static_member)
2269*a9fa9459Szrj     return (bfd_vma) -1;
2270*a9fa9459Szrj   return field->u.f.bitpos;
2271*a9fa9459Szrj }
2272*a9fa9459Szrj 
2273*a9fa9459Szrj /* Get the bit size of a field.  */
2274*a9fa9459Szrj 
2275*a9fa9459Szrj bfd_vma
debug_get_field_bitsize(void * handle ATTRIBUTE_UNUSED,debug_field field)2276*a9fa9459Szrj debug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED, debug_field field)
2277*a9fa9459Szrj {
2278*a9fa9459Szrj   if (field == NULL || field->static_member)
2279*a9fa9459Szrj     return (bfd_vma) -1;
2280*a9fa9459Szrj   return field->u.f.bitsize;
2281*a9fa9459Szrj }
2282*a9fa9459Szrj 
2283*a9fa9459Szrj /* Get the visibility of a field.  */
2284*a9fa9459Szrj 
2285*a9fa9459Szrj enum debug_visibility
debug_get_field_visibility(void * handle ATTRIBUTE_UNUSED,debug_field field)2286*a9fa9459Szrj debug_get_field_visibility (void *handle ATTRIBUTE_UNUSED, debug_field field)
2287*a9fa9459Szrj {
2288*a9fa9459Szrj   if (field == NULL)
2289*a9fa9459Szrj     return DEBUG_VISIBILITY_IGNORE;
2290*a9fa9459Szrj   return field->visibility;
2291*a9fa9459Szrj }
2292*a9fa9459Szrj 
2293*a9fa9459Szrj /* Get the physical name of a field.  */
2294*a9fa9459Szrj 
2295*a9fa9459Szrj const char *
debug_get_field_physname(void * handle ATTRIBUTE_UNUSED,debug_field field)2296*a9fa9459Szrj debug_get_field_physname (void *handle ATTRIBUTE_UNUSED, debug_field field)
2297*a9fa9459Szrj {
2298*a9fa9459Szrj   if (field == NULL || ! field->static_member)
2299*a9fa9459Szrj     return NULL;
2300*a9fa9459Szrj   return field->u.s.physname;
2301*a9fa9459Szrj }
2302*a9fa9459Szrj 
2303*a9fa9459Szrj /* Write out the debugging information.  This is given a handle to
2304*a9fa9459Szrj    debugging information, and a set of function pointers to call.  */
2305*a9fa9459Szrj 
2306*a9fa9459Szrj bfd_boolean
debug_write(void * handle,const struct debug_write_fns * fns,void * fhandle)2307*a9fa9459Szrj debug_write (void *handle, const struct debug_write_fns *fns, void *fhandle)
2308*a9fa9459Szrj {
2309*a9fa9459Szrj   struct debug_handle *info = (struct debug_handle *) handle;
2310*a9fa9459Szrj   struct debug_unit *u;
2311*a9fa9459Szrj 
2312*a9fa9459Szrj   /* We use a mark to tell whether we have already written out a
2313*a9fa9459Szrj      particular name.  We use an integer, so that we don't have to
2314*a9fa9459Szrj      clear the mark fields if we happen to write out the same
2315*a9fa9459Szrj      information more than once.  */
2316*a9fa9459Szrj   ++info->mark;
2317*a9fa9459Szrj 
2318*a9fa9459Szrj   /* The base_id field holds an ID value which will never be used, so
2319*a9fa9459Szrj      that we can tell whether we have assigned an ID during this call
2320*a9fa9459Szrj      to debug_write.  */
2321*a9fa9459Szrj   info->base_id = info->class_id;
2322*a9fa9459Szrj 
2323*a9fa9459Szrj   /* We keep a linked list of classes for which was have assigned ID's
2324*a9fa9459Szrj      during this call to debug_write.  */
2325*a9fa9459Szrj   info->id_list = NULL;
2326*a9fa9459Szrj 
2327*a9fa9459Szrj   for (u = info->units; u != NULL; u = u->next)
2328*a9fa9459Szrj     {
2329*a9fa9459Szrj       struct debug_file *f;
2330*a9fa9459Szrj       bfd_boolean first_file;
2331*a9fa9459Szrj 
2332*a9fa9459Szrj       info->current_write_lineno = u->linenos;
2333*a9fa9459Szrj       info->current_write_lineno_index = 0;
2334*a9fa9459Szrj 
2335*a9fa9459Szrj       if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2336*a9fa9459Szrj 	return FALSE;
2337*a9fa9459Szrj 
2338*a9fa9459Szrj       first_file = TRUE;
2339*a9fa9459Szrj       for (f = u->files; f != NULL; f = f->next)
2340*a9fa9459Szrj 	{
2341*a9fa9459Szrj 	  struct debug_name *n;
2342*a9fa9459Szrj 
2343*a9fa9459Szrj 	  if (first_file)
2344*a9fa9459Szrj 	    first_file = FALSE;
2345*a9fa9459Szrj 	  else if (! (*fns->start_source) (fhandle, f->filename))
2346*a9fa9459Szrj 	    return FALSE;
2347*a9fa9459Szrj 
2348*a9fa9459Szrj 	  if (f->globals != NULL)
2349*a9fa9459Szrj 	    for (n = f->globals->list; n != NULL; n = n->next)
2350*a9fa9459Szrj 	      if (! debug_write_name (info, fns, fhandle, n))
2351*a9fa9459Szrj 		return FALSE;
2352*a9fa9459Szrj 	}
2353*a9fa9459Szrj 
2354*a9fa9459Szrj       /* Output any line number information which hasn't already been
2355*a9fa9459Szrj          handled.  */
2356*a9fa9459Szrj       if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
2357*a9fa9459Szrj 	return FALSE;
2358*a9fa9459Szrj     }
2359*a9fa9459Szrj 
2360*a9fa9459Szrj   return TRUE;
2361*a9fa9459Szrj }
2362*a9fa9459Szrj 
2363*a9fa9459Szrj /* Write out an element in a namespace.  */
2364*a9fa9459Szrj 
2365*a9fa9459Szrj static bfd_boolean
debug_write_name(struct debug_handle * info,const struct debug_write_fns * fns,void * fhandle,struct debug_name * n)2366*a9fa9459Szrj debug_write_name (struct debug_handle *info,
2367*a9fa9459Szrj 		  const struct debug_write_fns *fns, void *fhandle,
2368*a9fa9459Szrj 		  struct debug_name *n)
2369*a9fa9459Szrj {
2370*a9fa9459Szrj   switch (n->kind)
2371*a9fa9459Szrj     {
2372*a9fa9459Szrj     case DEBUG_OBJECT_TYPE:
2373*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2374*a9fa9459Szrj 	  || ! (*fns->typdef) (fhandle, n->name))
2375*a9fa9459Szrj 	return FALSE;
2376*a9fa9459Szrj       return TRUE;
2377*a9fa9459Szrj     case DEBUG_OBJECT_TAG:
2378*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2379*a9fa9459Szrj 	return FALSE;
2380*a9fa9459Szrj       return (*fns->tag) (fhandle, n->name);
2381*a9fa9459Szrj     case DEBUG_OBJECT_VARIABLE:
2382*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2383*a9fa9459Szrj 			      (struct debug_name *) NULL))
2384*a9fa9459Szrj 	return FALSE;
2385*a9fa9459Szrj       return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2386*a9fa9459Szrj 			       n->u.variable->val);
2387*a9fa9459Szrj     case DEBUG_OBJECT_FUNCTION:
2388*a9fa9459Szrj       return debug_write_function (info, fns, fhandle, n->name,
2389*a9fa9459Szrj 				   n->linkage, n->u.function);
2390*a9fa9459Szrj     case DEBUG_OBJECT_INT_CONSTANT:
2391*a9fa9459Szrj       return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2392*a9fa9459Szrj     case DEBUG_OBJECT_FLOAT_CONSTANT:
2393*a9fa9459Szrj       return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2394*a9fa9459Szrj     case DEBUG_OBJECT_TYPED_CONSTANT:
2395*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2396*a9fa9459Szrj 			      (struct debug_name *) NULL))
2397*a9fa9459Szrj 	return FALSE;
2398*a9fa9459Szrj       return (*fns->typed_constant) (fhandle, n->name,
2399*a9fa9459Szrj 				     n->u.typed_constant->val);
2400*a9fa9459Szrj     default:
2401*a9fa9459Szrj       abort ();
2402*a9fa9459Szrj       return FALSE;
2403*a9fa9459Szrj     }
2404*a9fa9459Szrj   /*NOTREACHED*/
2405*a9fa9459Szrj }
2406*a9fa9459Szrj 
2407*a9fa9459Szrj /* Write out a type.  If the type is DEBUG_KIND_NAMED or
2408*a9fa9459Szrj    DEBUG_KIND_TAGGED, then the name argument is the name for which we
2409*a9fa9459Szrj    are about to call typedef or tag.  If the type is anything else,
2410*a9fa9459Szrj    then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2411*a9fa9459Szrj    points to this one.  */
2412*a9fa9459Szrj 
2413*a9fa9459Szrj static bfd_boolean
debug_write_type(struct debug_handle * info,const struct debug_write_fns * fns,void * fhandle,struct debug_type_s * type,struct debug_name * name)2414*a9fa9459Szrj debug_write_type (struct debug_handle *info,
2415*a9fa9459Szrj 		  const struct debug_write_fns *fns, void *fhandle,
2416*a9fa9459Szrj 		  struct debug_type_s *type, struct debug_name *name)
2417*a9fa9459Szrj {
2418*a9fa9459Szrj   unsigned int i;
2419*a9fa9459Szrj   int is;
2420*a9fa9459Szrj   const char *tag = NULL;
2421*a9fa9459Szrj 
2422*a9fa9459Szrj   /* If we have a name for this type, just output it.  We only output
2423*a9fa9459Szrj      typedef names after they have been defined.  We output type tags
2424*a9fa9459Szrj      whenever we are not actually defining them.  */
2425*a9fa9459Szrj   if ((type->kind == DEBUG_KIND_NAMED
2426*a9fa9459Szrj        || type->kind == DEBUG_KIND_TAGGED)
2427*a9fa9459Szrj       && (type->u.knamed->name->mark == info->mark
2428*a9fa9459Szrj 	  || (type->kind == DEBUG_KIND_TAGGED
2429*a9fa9459Szrj 	      && type->u.knamed->name != name)))
2430*a9fa9459Szrj     {
2431*a9fa9459Szrj       if (type->kind == DEBUG_KIND_NAMED)
2432*a9fa9459Szrj 	return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2433*a9fa9459Szrj       else
2434*a9fa9459Szrj 	{
2435*a9fa9459Szrj 	  struct debug_type_s *real;
2436*a9fa9459Szrj 	  unsigned int id;
2437*a9fa9459Szrj 
2438*a9fa9459Szrj 	  real = debug_get_real_type ((void *) info, type, NULL);
2439*a9fa9459Szrj 	  if (real == NULL)
2440*a9fa9459Szrj 	    return (*fns->empty_type) (fhandle);
2441*a9fa9459Szrj 	  id = 0;
2442*a9fa9459Szrj 	  if ((real->kind == DEBUG_KIND_STRUCT
2443*a9fa9459Szrj 	       || real->kind == DEBUG_KIND_UNION
2444*a9fa9459Szrj 	       || real->kind == DEBUG_KIND_CLASS
2445*a9fa9459Szrj 	       || real->kind == DEBUG_KIND_UNION_CLASS)
2446*a9fa9459Szrj 	      && real->u.kclass != NULL)
2447*a9fa9459Szrj 	    {
2448*a9fa9459Szrj 	      if (real->u.kclass->id <= info->base_id)
2449*a9fa9459Szrj 		{
2450*a9fa9459Szrj 		  if (! debug_set_class_id (info,
2451*a9fa9459Szrj 					    type->u.knamed->name->name,
2452*a9fa9459Szrj 					    real))
2453*a9fa9459Szrj 		    return FALSE;
2454*a9fa9459Szrj 		}
2455*a9fa9459Szrj 	      id = real->u.kclass->id;
2456*a9fa9459Szrj 	    }
2457*a9fa9459Szrj 
2458*a9fa9459Szrj 	  return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
2459*a9fa9459Szrj 				   real->kind);
2460*a9fa9459Szrj 	}
2461*a9fa9459Szrj     }
2462*a9fa9459Szrj 
2463*a9fa9459Szrj   /* Mark the name after we have already looked for a known name, so
2464*a9fa9459Szrj      that we don't just define a type in terms of itself.  We need to
2465*a9fa9459Szrj      mark the name here so that a struct containing a pointer to
2466*a9fa9459Szrj      itself will work.  */
2467*a9fa9459Szrj   if (name != NULL)
2468*a9fa9459Szrj     name->mark = info->mark;
2469*a9fa9459Szrj 
2470*a9fa9459Szrj   if (name != NULL
2471*a9fa9459Szrj       && type->kind != DEBUG_KIND_NAMED
2472*a9fa9459Szrj       && type->kind != DEBUG_KIND_TAGGED)
2473*a9fa9459Szrj     {
2474*a9fa9459Szrj       assert (name->kind == DEBUG_OBJECT_TAG);
2475*a9fa9459Szrj       tag = name->name;
2476*a9fa9459Szrj     }
2477*a9fa9459Szrj 
2478*a9fa9459Szrj   switch (type->kind)
2479*a9fa9459Szrj     {
2480*a9fa9459Szrj     case DEBUG_KIND_ILLEGAL:
2481*a9fa9459Szrj       debug_error (_("debug_write_type: illegal type encountered"));
2482*a9fa9459Szrj       return FALSE;
2483*a9fa9459Szrj     case DEBUG_KIND_INDIRECT:
2484*a9fa9459Szrj       if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2485*a9fa9459Szrj 	return (*fns->empty_type) (fhandle);
2486*a9fa9459Szrj       return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2487*a9fa9459Szrj 			       name);
2488*a9fa9459Szrj     case DEBUG_KIND_VOID:
2489*a9fa9459Szrj       return (*fns->void_type) (fhandle);
2490*a9fa9459Szrj     case DEBUG_KIND_INT:
2491*a9fa9459Szrj       return (*fns->int_type) (fhandle, type->size, type->u.kint);
2492*a9fa9459Szrj     case DEBUG_KIND_FLOAT:
2493*a9fa9459Szrj       return (*fns->float_type) (fhandle, type->size);
2494*a9fa9459Szrj     case DEBUG_KIND_COMPLEX:
2495*a9fa9459Szrj       return (*fns->complex_type) (fhandle, type->size);
2496*a9fa9459Szrj     case DEBUG_KIND_BOOL:
2497*a9fa9459Szrj       return (*fns->bool_type) (fhandle, type->size);
2498*a9fa9459Szrj     case DEBUG_KIND_STRUCT:
2499*a9fa9459Szrj     case DEBUG_KIND_UNION:
2500*a9fa9459Szrj       if (type->u.kclass != NULL)
2501*a9fa9459Szrj 	{
2502*a9fa9459Szrj 	  if (type->u.kclass->id <= info->base_id)
2503*a9fa9459Szrj 	    {
2504*a9fa9459Szrj 	      if (! debug_set_class_id (info, tag, type))
2505*a9fa9459Szrj 		return FALSE;
2506*a9fa9459Szrj 	    }
2507*a9fa9459Szrj 
2508*a9fa9459Szrj 	  if (info->mark == type->u.kclass->mark)
2509*a9fa9459Szrj 	    {
2510*a9fa9459Szrj 	      /* We are currently outputting this struct, or we have
2511*a9fa9459Szrj 		 already output it.  I don't know if this can happen,
2512*a9fa9459Szrj 		 but it can happen for a class.  */
2513*a9fa9459Szrj 	      assert (type->u.kclass->id > info->base_id);
2514*a9fa9459Szrj 	      return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2515*a9fa9459Szrj 				       type->kind);
2516*a9fa9459Szrj 	    }
2517*a9fa9459Szrj 	  type->u.kclass->mark = info->mark;
2518*a9fa9459Szrj 	}
2519*a9fa9459Szrj 
2520*a9fa9459Szrj       if (! (*fns->start_struct_type) (fhandle, tag,
2521*a9fa9459Szrj 				       (type->u.kclass != NULL
2522*a9fa9459Szrj 					? type->u.kclass->id
2523*a9fa9459Szrj 					: 0),
2524*a9fa9459Szrj 				       type->kind == DEBUG_KIND_STRUCT,
2525*a9fa9459Szrj 				       type->size))
2526*a9fa9459Szrj 	return FALSE;
2527*a9fa9459Szrj       if (type->u.kclass != NULL
2528*a9fa9459Szrj 	  && type->u.kclass->fields != NULL)
2529*a9fa9459Szrj 	{
2530*a9fa9459Szrj 	  for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2531*a9fa9459Szrj 	    {
2532*a9fa9459Szrj 	      struct debug_field_s *f;
2533*a9fa9459Szrj 
2534*a9fa9459Szrj 	      f = type->u.kclass->fields[i];
2535*a9fa9459Szrj 	      if (! debug_write_type (info, fns, fhandle, f->type,
2536*a9fa9459Szrj 				      (struct debug_name *) NULL)
2537*a9fa9459Szrj 		  || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2538*a9fa9459Szrj 					     f->u.f.bitsize, f->visibility))
2539*a9fa9459Szrj 		return FALSE;
2540*a9fa9459Szrj 	    }
2541*a9fa9459Szrj 	}
2542*a9fa9459Szrj       return (*fns->end_struct_type) (fhandle);
2543*a9fa9459Szrj     case DEBUG_KIND_CLASS:
2544*a9fa9459Szrj     case DEBUG_KIND_UNION_CLASS:
2545*a9fa9459Szrj       return debug_write_class_type (info, fns, fhandle, type, tag);
2546*a9fa9459Szrj     case DEBUG_KIND_ENUM:
2547*a9fa9459Szrj       if (type->u.kenum == NULL)
2548*a9fa9459Szrj 	return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
2549*a9fa9459Szrj 				  (bfd_signed_vma *) NULL);
2550*a9fa9459Szrj       return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2551*a9fa9459Szrj 				type->u.kenum->values);
2552*a9fa9459Szrj     case DEBUG_KIND_POINTER:
2553*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2554*a9fa9459Szrj 			      (struct debug_name *) NULL))
2555*a9fa9459Szrj 	return FALSE;
2556*a9fa9459Szrj       return (*fns->pointer_type) (fhandle);
2557*a9fa9459Szrj     case DEBUG_KIND_FUNCTION:
2558*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle,
2559*a9fa9459Szrj 			      type->u.kfunction->return_type,
2560*a9fa9459Szrj 			      (struct debug_name *) NULL))
2561*a9fa9459Szrj 	return FALSE;
2562*a9fa9459Szrj       if (type->u.kfunction->arg_types == NULL)
2563*a9fa9459Szrj 	is = -1;
2564*a9fa9459Szrj       else
2565*a9fa9459Szrj 	{
2566*a9fa9459Szrj 	  for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
2567*a9fa9459Szrj 	    if (! debug_write_type (info, fns, fhandle,
2568*a9fa9459Szrj 				    type->u.kfunction->arg_types[is],
2569*a9fa9459Szrj 				    (struct debug_name *) NULL))
2570*a9fa9459Szrj 	      return FALSE;
2571*a9fa9459Szrj 	}
2572*a9fa9459Szrj       return (*fns->function_type) (fhandle, is,
2573*a9fa9459Szrj 				    type->u.kfunction->varargs);
2574*a9fa9459Szrj     case DEBUG_KIND_REFERENCE:
2575*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2576*a9fa9459Szrj 			      (struct debug_name *) NULL))
2577*a9fa9459Szrj 	return FALSE;
2578*a9fa9459Szrj       return (*fns->reference_type) (fhandle);
2579*a9fa9459Szrj     case DEBUG_KIND_RANGE:
2580*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2581*a9fa9459Szrj 			      (struct debug_name *) NULL))
2582*a9fa9459Szrj 	return FALSE;
2583*a9fa9459Szrj       return (*fns->range_type) (fhandle, type->u.krange->lower,
2584*a9fa9459Szrj 				 type->u.krange->upper);
2585*a9fa9459Szrj     case DEBUG_KIND_ARRAY:
2586*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2587*a9fa9459Szrj 			      (struct debug_name *) NULL)
2588*a9fa9459Szrj 	  || ! debug_write_type (info, fns, fhandle,
2589*a9fa9459Szrj 				 type->u.karray->range_type,
2590*a9fa9459Szrj 				 (struct debug_name *) NULL))
2591*a9fa9459Szrj 	return FALSE;
2592*a9fa9459Szrj       return (*fns->array_type) (fhandle, type->u.karray->lower,
2593*a9fa9459Szrj 				 type->u.karray->upper,
2594*a9fa9459Szrj 				 type->u.karray->stringp);
2595*a9fa9459Szrj     case DEBUG_KIND_SET:
2596*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2597*a9fa9459Szrj 			      (struct debug_name *) NULL))
2598*a9fa9459Szrj 	return FALSE;
2599*a9fa9459Szrj       return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2600*a9fa9459Szrj     case DEBUG_KIND_OFFSET:
2601*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2602*a9fa9459Szrj 			      (struct debug_name *) NULL)
2603*a9fa9459Szrj 	  || ! debug_write_type (info, fns, fhandle,
2604*a9fa9459Szrj 				 type->u.koffset->target_type,
2605*a9fa9459Szrj 				 (struct debug_name *) NULL))
2606*a9fa9459Szrj 	return FALSE;
2607*a9fa9459Szrj       return (*fns->offset_type) (fhandle);
2608*a9fa9459Szrj     case DEBUG_KIND_METHOD:
2609*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle,
2610*a9fa9459Szrj 			      type->u.kmethod->return_type,
2611*a9fa9459Szrj 			      (struct debug_name *) NULL))
2612*a9fa9459Szrj 	return FALSE;
2613*a9fa9459Szrj       if (type->u.kmethod->arg_types == NULL)
2614*a9fa9459Szrj 	is = -1;
2615*a9fa9459Szrj       else
2616*a9fa9459Szrj 	{
2617*a9fa9459Szrj 	  for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
2618*a9fa9459Szrj 	    if (! debug_write_type (info, fns, fhandle,
2619*a9fa9459Szrj 				    type->u.kmethod->arg_types[is],
2620*a9fa9459Szrj 				    (struct debug_name *) NULL))
2621*a9fa9459Szrj 	      return FALSE;
2622*a9fa9459Szrj 	}
2623*a9fa9459Szrj       if (type->u.kmethod->domain_type != NULL)
2624*a9fa9459Szrj 	{
2625*a9fa9459Szrj 	  if (! debug_write_type (info, fns, fhandle,
2626*a9fa9459Szrj 				  type->u.kmethod->domain_type,
2627*a9fa9459Szrj 				  (struct debug_name *) NULL))
2628*a9fa9459Szrj 	    return FALSE;
2629*a9fa9459Szrj 	}
2630*a9fa9459Szrj       return (*fns->method_type) (fhandle,
2631*a9fa9459Szrj 				  type->u.kmethod->domain_type != NULL,
2632*a9fa9459Szrj 				  is,
2633*a9fa9459Szrj 				  type->u.kmethod->varargs);
2634*a9fa9459Szrj     case DEBUG_KIND_CONST:
2635*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2636*a9fa9459Szrj 			      (struct debug_name *) NULL))
2637*a9fa9459Szrj 	return FALSE;
2638*a9fa9459Szrj       return (*fns->const_type) (fhandle);
2639*a9fa9459Szrj     case DEBUG_KIND_VOLATILE:
2640*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2641*a9fa9459Szrj 			      (struct debug_name *) NULL))
2642*a9fa9459Szrj 	return FALSE;
2643*a9fa9459Szrj       return (*fns->volatile_type) (fhandle);
2644*a9fa9459Szrj     case DEBUG_KIND_NAMED:
2645*a9fa9459Szrj       return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2646*a9fa9459Szrj 			       (struct debug_name *) NULL);
2647*a9fa9459Szrj     case DEBUG_KIND_TAGGED:
2648*a9fa9459Szrj       return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2649*a9fa9459Szrj 			       type->u.knamed->name);
2650*a9fa9459Szrj     default:
2651*a9fa9459Szrj       abort ();
2652*a9fa9459Szrj       return FALSE;
2653*a9fa9459Szrj     }
2654*a9fa9459Szrj }
2655*a9fa9459Szrj 
2656*a9fa9459Szrj /* Write out a class type.  */
2657*a9fa9459Szrj 
2658*a9fa9459Szrj static bfd_boolean
debug_write_class_type(struct debug_handle * info,const struct debug_write_fns * fns,void * fhandle,struct debug_type_s * type,const char * tag)2659*a9fa9459Szrj debug_write_class_type (struct debug_handle *info,
2660*a9fa9459Szrj 			const struct debug_write_fns *fns, void *fhandle,
2661*a9fa9459Szrj 			struct debug_type_s *type, const char *tag)
2662*a9fa9459Szrj {
2663*a9fa9459Szrj   unsigned int i;
2664*a9fa9459Szrj   unsigned int id;
2665*a9fa9459Szrj   struct debug_type_s *vptrbase;
2666*a9fa9459Szrj 
2667*a9fa9459Szrj   if (type->u.kclass == NULL)
2668*a9fa9459Szrj     {
2669*a9fa9459Szrj       id = 0;
2670*a9fa9459Szrj       vptrbase = NULL;
2671*a9fa9459Szrj     }
2672*a9fa9459Szrj   else
2673*a9fa9459Szrj     {
2674*a9fa9459Szrj       if (type->u.kclass->id <= info->base_id)
2675*a9fa9459Szrj 	{
2676*a9fa9459Szrj 	  if (! debug_set_class_id (info, tag, type))
2677*a9fa9459Szrj 	    return FALSE;
2678*a9fa9459Szrj 	}
2679*a9fa9459Szrj 
2680*a9fa9459Szrj       if (info->mark == type->u.kclass->mark)
2681*a9fa9459Szrj 	{
2682*a9fa9459Szrj 	  /* We are currently outputting this class, or we have
2683*a9fa9459Szrj 	     already output it.  This can happen when there are
2684*a9fa9459Szrj 	     methods for an anonymous class.  */
2685*a9fa9459Szrj 	  assert (type->u.kclass->id > info->base_id);
2686*a9fa9459Szrj 	  return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
2687*a9fa9459Szrj 				   type->kind);
2688*a9fa9459Szrj 	}
2689*a9fa9459Szrj       type->u.kclass->mark = info->mark;
2690*a9fa9459Szrj       id = type->u.kclass->id;
2691*a9fa9459Szrj 
2692*a9fa9459Szrj       vptrbase = type->u.kclass->vptrbase;
2693*a9fa9459Szrj       if (vptrbase != NULL && vptrbase != type)
2694*a9fa9459Szrj 	{
2695*a9fa9459Szrj 	  if (! debug_write_type (info, fns, fhandle, vptrbase,
2696*a9fa9459Szrj 				  (struct debug_name *) NULL))
2697*a9fa9459Szrj 	    return FALSE;
2698*a9fa9459Szrj 	}
2699*a9fa9459Szrj     }
2700*a9fa9459Szrj 
2701*a9fa9459Szrj   if (! (*fns->start_class_type) (fhandle, tag, id,
2702*a9fa9459Szrj 				  type->kind == DEBUG_KIND_CLASS,
2703*a9fa9459Szrj 				  type->size,
2704*a9fa9459Szrj 				  vptrbase != NULL,
2705*a9fa9459Szrj 				  vptrbase == type))
2706*a9fa9459Szrj     return FALSE;
2707*a9fa9459Szrj 
2708*a9fa9459Szrj   if (type->u.kclass != NULL)
2709*a9fa9459Szrj     {
2710*a9fa9459Szrj       if (type->u.kclass->fields != NULL)
2711*a9fa9459Szrj 	{
2712*a9fa9459Szrj 	  for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2713*a9fa9459Szrj 	    {
2714*a9fa9459Szrj 	      struct debug_field_s *f;
2715*a9fa9459Szrj 
2716*a9fa9459Szrj 	      f = type->u.kclass->fields[i];
2717*a9fa9459Szrj 	      if (! debug_write_type (info, fns, fhandle, f->type,
2718*a9fa9459Szrj 				      (struct debug_name *) NULL))
2719*a9fa9459Szrj 		return FALSE;
2720*a9fa9459Szrj 	      if (f->static_member)
2721*a9fa9459Szrj 		{
2722*a9fa9459Szrj 		  if (! (*fns->class_static_member) (fhandle, f->name,
2723*a9fa9459Szrj 						     f->u.s.physname,
2724*a9fa9459Szrj 						     f->visibility))
2725*a9fa9459Szrj 		    return FALSE;
2726*a9fa9459Szrj 		}
2727*a9fa9459Szrj 	      else
2728*a9fa9459Szrj 		{
2729*a9fa9459Szrj 		  if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2730*a9fa9459Szrj 					      f->u.f.bitsize, f->visibility))
2731*a9fa9459Szrj 		    return FALSE;
2732*a9fa9459Szrj 		}
2733*a9fa9459Szrj 	    }
2734*a9fa9459Szrj 	}
2735*a9fa9459Szrj 
2736*a9fa9459Szrj       if (type->u.kclass->baseclasses != NULL)
2737*a9fa9459Szrj 	{
2738*a9fa9459Szrj 	  for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2739*a9fa9459Szrj 	    {
2740*a9fa9459Szrj 	      struct debug_baseclass_s *b;
2741*a9fa9459Szrj 
2742*a9fa9459Szrj 	      b = type->u.kclass->baseclasses[i];
2743*a9fa9459Szrj 	      if (! debug_write_type (info, fns, fhandle, b->type,
2744*a9fa9459Szrj 				      (struct debug_name *) NULL))
2745*a9fa9459Szrj 		return FALSE;
2746*a9fa9459Szrj 	      if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->is_virtual,
2747*a9fa9459Szrj 					     b->visibility))
2748*a9fa9459Szrj 		return FALSE;
2749*a9fa9459Szrj 	    }
2750*a9fa9459Szrj 	}
2751*a9fa9459Szrj 
2752*a9fa9459Szrj       if (type->u.kclass->methods != NULL)
2753*a9fa9459Szrj 	{
2754*a9fa9459Szrj 	  for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2755*a9fa9459Szrj 	    {
2756*a9fa9459Szrj 	      struct debug_method_s *m;
2757*a9fa9459Szrj 	      unsigned int j;
2758*a9fa9459Szrj 
2759*a9fa9459Szrj 	      m = type->u.kclass->methods[i];
2760*a9fa9459Szrj 	      if (! (*fns->class_start_method) (fhandle, m->name))
2761*a9fa9459Szrj 		return FALSE;
2762*a9fa9459Szrj 	      for (j = 0; m->variants[j] != NULL; j++)
2763*a9fa9459Szrj 		{
2764*a9fa9459Szrj 		  struct debug_method_variant_s *v;
2765*a9fa9459Szrj 
2766*a9fa9459Szrj 		  v = m->variants[j];
2767*a9fa9459Szrj 		  if (v->context != NULL)
2768*a9fa9459Szrj 		    {
2769*a9fa9459Szrj 		      if (! debug_write_type (info, fns, fhandle, v->context,
2770*a9fa9459Szrj 					      (struct debug_name *) NULL))
2771*a9fa9459Szrj 			return FALSE;
2772*a9fa9459Szrj 		    }
2773*a9fa9459Szrj 		  if (! debug_write_type (info, fns, fhandle, v->type,
2774*a9fa9459Szrj 					  (struct debug_name *) NULL))
2775*a9fa9459Szrj 		    return FALSE;
2776*a9fa9459Szrj 		  if (v->voffset != VOFFSET_STATIC_METHOD)
2777*a9fa9459Szrj 		    {
2778*a9fa9459Szrj 		      if (! (*fns->class_method_variant) (fhandle, v->physname,
2779*a9fa9459Szrj 							  v->visibility,
2780*a9fa9459Szrj 							  v->constp,
2781*a9fa9459Szrj 							  v->volatilep,
2782*a9fa9459Szrj 							  v->voffset,
2783*a9fa9459Szrj 							  v->context != NULL))
2784*a9fa9459Szrj 			return FALSE;
2785*a9fa9459Szrj 		    }
2786*a9fa9459Szrj 		  else
2787*a9fa9459Szrj 		    {
2788*a9fa9459Szrj 		      if (! (*fns->class_static_method_variant) (fhandle,
2789*a9fa9459Szrj 								 v->physname,
2790*a9fa9459Szrj 								 v->visibility,
2791*a9fa9459Szrj 								 v->constp,
2792*a9fa9459Szrj 								 v->volatilep))
2793*a9fa9459Szrj 			return FALSE;
2794*a9fa9459Szrj 		    }
2795*a9fa9459Szrj 		}
2796*a9fa9459Szrj 	      if (! (*fns->class_end_method) (fhandle))
2797*a9fa9459Szrj 		return FALSE;
2798*a9fa9459Szrj 	    }
2799*a9fa9459Szrj 	}
2800*a9fa9459Szrj     }
2801*a9fa9459Szrj 
2802*a9fa9459Szrj   return (*fns->end_class_type) (fhandle);
2803*a9fa9459Szrj }
2804*a9fa9459Szrj 
2805*a9fa9459Szrj /* Write out information for a function.  */
2806*a9fa9459Szrj 
2807*a9fa9459Szrj static bfd_boolean
debug_write_function(struct debug_handle * info,const struct debug_write_fns * fns,void * fhandle,const char * name,enum debug_object_linkage linkage,struct debug_function * function)2808*a9fa9459Szrj debug_write_function (struct debug_handle *info,
2809*a9fa9459Szrj 		      const struct debug_write_fns *fns, void *fhandle,
2810*a9fa9459Szrj 		      const char *name, enum debug_object_linkage linkage,
2811*a9fa9459Szrj 		      struct debug_function *function)
2812*a9fa9459Szrj {
2813*a9fa9459Szrj   struct debug_parameter *p;
2814*a9fa9459Szrj   struct debug_block *b;
2815*a9fa9459Szrj 
2816*a9fa9459Szrj   if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
2817*a9fa9459Szrj     return FALSE;
2818*a9fa9459Szrj 
2819*a9fa9459Szrj   if (! debug_write_type (info, fns, fhandle, function->return_type,
2820*a9fa9459Szrj 			  (struct debug_name *) NULL))
2821*a9fa9459Szrj     return FALSE;
2822*a9fa9459Szrj 
2823*a9fa9459Szrj   if (! (*fns->start_function) (fhandle, name,
2824*a9fa9459Szrj 				linkage == DEBUG_LINKAGE_GLOBAL))
2825*a9fa9459Szrj     return FALSE;
2826*a9fa9459Szrj 
2827*a9fa9459Szrj   for (p = function->parameters; p != NULL; p = p->next)
2828*a9fa9459Szrj     {
2829*a9fa9459Szrj       if (! debug_write_type (info, fns, fhandle, p->type,
2830*a9fa9459Szrj 			      (struct debug_name *) NULL)
2831*a9fa9459Szrj 	  || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2832*a9fa9459Szrj 	return FALSE;
2833*a9fa9459Szrj     }
2834*a9fa9459Szrj 
2835*a9fa9459Szrj   for (b = function->blocks; b != NULL; b = b->next)
2836*a9fa9459Szrj     {
2837*a9fa9459Szrj       if (! debug_write_block (info, fns, fhandle, b))
2838*a9fa9459Szrj 	return FALSE;
2839*a9fa9459Szrj     }
2840*a9fa9459Szrj 
2841*a9fa9459Szrj   return (*fns->end_function) (fhandle);
2842*a9fa9459Szrj }
2843*a9fa9459Szrj 
2844*a9fa9459Szrj /* Write out information for a block.  */
2845*a9fa9459Szrj 
2846*a9fa9459Szrj static bfd_boolean
debug_write_block(struct debug_handle * info,const struct debug_write_fns * fns,void * fhandle,struct debug_block * block)2847*a9fa9459Szrj debug_write_block (struct debug_handle *info,
2848*a9fa9459Szrj 		   const struct debug_write_fns *fns, void *fhandle,
2849*a9fa9459Szrj 		   struct debug_block *block)
2850*a9fa9459Szrj {
2851*a9fa9459Szrj   struct debug_name *n;
2852*a9fa9459Szrj   struct debug_block *b;
2853*a9fa9459Szrj 
2854*a9fa9459Szrj   if (! debug_write_linenos (info, fns, fhandle, block->start))
2855*a9fa9459Szrj     return FALSE;
2856*a9fa9459Szrj 
2857*a9fa9459Szrj   /* I can't see any point to writing out a block with no local
2858*a9fa9459Szrj      variables, so we don't bother, except for the top level block.  */
2859*a9fa9459Szrj   if (block->locals != NULL || block->parent == NULL)
2860*a9fa9459Szrj     {
2861*a9fa9459Szrj       if (! (*fns->start_block) (fhandle, block->start))
2862*a9fa9459Szrj 	return FALSE;
2863*a9fa9459Szrj     }
2864*a9fa9459Szrj 
2865*a9fa9459Szrj   if (block->locals != NULL)
2866*a9fa9459Szrj     {
2867*a9fa9459Szrj       for (n = block->locals->list; n != NULL; n = n->next)
2868*a9fa9459Szrj 	{
2869*a9fa9459Szrj 	  if (! debug_write_name (info, fns, fhandle, n))
2870*a9fa9459Szrj 	    return FALSE;
2871*a9fa9459Szrj 	}
2872*a9fa9459Szrj     }
2873*a9fa9459Szrj 
2874*a9fa9459Szrj   for (b = block->children; b != NULL; b = b->next)
2875*a9fa9459Szrj     {
2876*a9fa9459Szrj       if (! debug_write_block (info, fns, fhandle, b))
2877*a9fa9459Szrj 	return FALSE;
2878*a9fa9459Szrj     }
2879*a9fa9459Szrj 
2880*a9fa9459Szrj   if (! debug_write_linenos (info, fns, fhandle, block->end))
2881*a9fa9459Szrj     return FALSE;
2882*a9fa9459Szrj 
2883*a9fa9459Szrj   if (block->locals != NULL || block->parent == NULL)
2884*a9fa9459Szrj     {
2885*a9fa9459Szrj       if (! (*fns->end_block) (fhandle, block->end))
2886*a9fa9459Szrj 	return FALSE;
2887*a9fa9459Szrj     }
2888*a9fa9459Szrj 
2889*a9fa9459Szrj   return TRUE;
2890*a9fa9459Szrj }
2891*a9fa9459Szrj 
2892*a9fa9459Szrj /* Write out line number information up to ADDRESS.  */
2893*a9fa9459Szrj 
2894*a9fa9459Szrj static bfd_boolean
debug_write_linenos(struct debug_handle * info,const struct debug_write_fns * fns,void * fhandle,bfd_vma address)2895*a9fa9459Szrj debug_write_linenos (struct debug_handle *info,
2896*a9fa9459Szrj 		     const struct debug_write_fns *fns, void *fhandle,
2897*a9fa9459Szrj 		     bfd_vma address)
2898*a9fa9459Szrj {
2899*a9fa9459Szrj   while (info->current_write_lineno != NULL)
2900*a9fa9459Szrj     {
2901*a9fa9459Szrj       struct debug_lineno *l;
2902*a9fa9459Szrj 
2903*a9fa9459Szrj       l = info->current_write_lineno;
2904*a9fa9459Szrj 
2905*a9fa9459Szrj       while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
2906*a9fa9459Szrj 	{
2907*a9fa9459Szrj 	  if (l->linenos[info->current_write_lineno_index]
2908*a9fa9459Szrj 	      == (unsigned long) -1)
2909*a9fa9459Szrj 	    break;
2910*a9fa9459Szrj 
2911*a9fa9459Szrj 	  if (l->addrs[info->current_write_lineno_index] >= address)
2912*a9fa9459Szrj 	    return TRUE;
2913*a9fa9459Szrj 
2914*a9fa9459Szrj 	  if (! (*fns->lineno) (fhandle, l->file->filename,
2915*a9fa9459Szrj 				l->linenos[info->current_write_lineno_index],
2916*a9fa9459Szrj 				l->addrs[info->current_write_lineno_index]))
2917*a9fa9459Szrj 	    return FALSE;
2918*a9fa9459Szrj 
2919*a9fa9459Szrj 	  ++info->current_write_lineno_index;
2920*a9fa9459Szrj 	}
2921*a9fa9459Szrj 
2922*a9fa9459Szrj       info->current_write_lineno = l->next;
2923*a9fa9459Szrj       info->current_write_lineno_index = 0;
2924*a9fa9459Szrj     }
2925*a9fa9459Szrj 
2926*a9fa9459Szrj   return TRUE;
2927*a9fa9459Szrj }
2928*a9fa9459Szrj 
2929*a9fa9459Szrj /* Get the ID number for a class.  If during the same call to
2930*a9fa9459Szrj    debug_write we find a struct with the same definition with the same
2931*a9fa9459Szrj    name, we use the same ID.  This type of things happens because the
2932*a9fa9459Szrj    same struct will be defined by multiple compilation units.  */
2933*a9fa9459Szrj 
2934*a9fa9459Szrj static bfd_boolean
debug_set_class_id(struct debug_handle * info,const char * tag,struct debug_type_s * type)2935*a9fa9459Szrj debug_set_class_id (struct debug_handle *info, const char *tag,
2936*a9fa9459Szrj 		    struct debug_type_s *type)
2937*a9fa9459Szrj {
2938*a9fa9459Szrj   struct debug_class_type *c;
2939*a9fa9459Szrj   struct debug_class_id *l;
2940*a9fa9459Szrj 
2941*a9fa9459Szrj   assert (type->kind == DEBUG_KIND_STRUCT
2942*a9fa9459Szrj 	  || type->kind == DEBUG_KIND_UNION
2943*a9fa9459Szrj 	  || type->kind == DEBUG_KIND_CLASS
2944*a9fa9459Szrj 	  || type->kind == DEBUG_KIND_UNION_CLASS);
2945*a9fa9459Szrj 
2946*a9fa9459Szrj   c = type->u.kclass;
2947*a9fa9459Szrj 
2948*a9fa9459Szrj   if (c->id > info->base_id)
2949*a9fa9459Szrj     return TRUE;
2950*a9fa9459Szrj 
2951*a9fa9459Szrj   for (l = info->id_list; l != NULL; l = l->next)
2952*a9fa9459Szrj     {
2953*a9fa9459Szrj       if (l->type->kind != type->kind)
2954*a9fa9459Szrj 	continue;
2955*a9fa9459Szrj 
2956*a9fa9459Szrj       if (tag == NULL)
2957*a9fa9459Szrj 	{
2958*a9fa9459Szrj 	  if (l->tag != NULL)
2959*a9fa9459Szrj 	    continue;
2960*a9fa9459Szrj 	}
2961*a9fa9459Szrj       else
2962*a9fa9459Szrj 	{
2963*a9fa9459Szrj 	  if (l->tag == NULL
2964*a9fa9459Szrj 	      || l->tag[0] != tag[0]
2965*a9fa9459Szrj 	      || strcmp (l->tag, tag) != 0)
2966*a9fa9459Szrj 	    continue;
2967*a9fa9459Szrj 	}
2968*a9fa9459Szrj 
2969*a9fa9459Szrj       if (debug_type_samep (info, l->type, type))
2970*a9fa9459Szrj 	{
2971*a9fa9459Szrj 	  c->id = l->type->u.kclass->id;
2972*a9fa9459Szrj 	  return TRUE;
2973*a9fa9459Szrj 	}
2974*a9fa9459Szrj     }
2975*a9fa9459Szrj 
2976*a9fa9459Szrj   /* There are no identical types.  Use a new ID, and add it to the
2977*a9fa9459Szrj      list.  */
2978*a9fa9459Szrj   ++info->class_id;
2979*a9fa9459Szrj   c->id = info->class_id;
2980*a9fa9459Szrj 
2981*a9fa9459Szrj   l = (struct debug_class_id *) xmalloc (sizeof *l);
2982*a9fa9459Szrj   memset (l, 0, sizeof *l);
2983*a9fa9459Szrj 
2984*a9fa9459Szrj   l->type = type;
2985*a9fa9459Szrj   l->tag = tag;
2986*a9fa9459Szrj 
2987*a9fa9459Szrj   l->next = info->id_list;
2988*a9fa9459Szrj   info->id_list = l;
2989*a9fa9459Szrj 
2990*a9fa9459Szrj   return TRUE;
2991*a9fa9459Szrj }
2992*a9fa9459Szrj 
2993*a9fa9459Szrj /* See if two types are the same.  At this point, we don't care about
2994*a9fa9459Szrj    tags and the like.  */
2995*a9fa9459Szrj 
2996*a9fa9459Szrj static bfd_boolean
debug_type_samep(struct debug_handle * info,struct debug_type_s * t1,struct debug_type_s * t2)2997*a9fa9459Szrj debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
2998*a9fa9459Szrj 		  struct debug_type_s *t2)
2999*a9fa9459Szrj {
3000*a9fa9459Szrj   struct debug_type_compare_list *l;
3001*a9fa9459Szrj   struct debug_type_compare_list top;
3002*a9fa9459Szrj   bfd_boolean ret;
3003*a9fa9459Szrj 
3004*a9fa9459Szrj   if (t1 == NULL)
3005*a9fa9459Szrj     return t2 == NULL;
3006*a9fa9459Szrj   if (t2 == NULL)
3007*a9fa9459Szrj     return FALSE;
3008*a9fa9459Szrj 
3009*a9fa9459Szrj   while (t1->kind == DEBUG_KIND_INDIRECT)
3010*a9fa9459Szrj     {
3011*a9fa9459Szrj       t1 = *t1->u.kindirect->slot;
3012*a9fa9459Szrj       if (t1 == NULL)
3013*a9fa9459Szrj 	return FALSE;
3014*a9fa9459Szrj     }
3015*a9fa9459Szrj   while (t2->kind == DEBUG_KIND_INDIRECT)
3016*a9fa9459Szrj     {
3017*a9fa9459Szrj       t2 = *t2->u.kindirect->slot;
3018*a9fa9459Szrj       if (t2 == NULL)
3019*a9fa9459Szrj 	return FALSE;
3020*a9fa9459Szrj     }
3021*a9fa9459Szrj 
3022*a9fa9459Szrj   if (t1 == t2)
3023*a9fa9459Szrj     return TRUE;
3024*a9fa9459Szrj 
3025*a9fa9459Szrj   /* As a special case, permit a typedef to match a tag, since C++
3026*a9fa9459Szrj      debugging output will sometimes add a typedef where C debugging
3027*a9fa9459Szrj      output will not.  */
3028*a9fa9459Szrj   if (t1->kind == DEBUG_KIND_NAMED
3029*a9fa9459Szrj       && t2->kind == DEBUG_KIND_TAGGED)
3030*a9fa9459Szrj     return debug_type_samep (info, t1->u.knamed->type, t2);
3031*a9fa9459Szrj   else if (t1->kind == DEBUG_KIND_TAGGED
3032*a9fa9459Szrj 	   && t2->kind == DEBUG_KIND_NAMED)
3033*a9fa9459Szrj     return debug_type_samep (info, t1, t2->u.knamed->type);
3034*a9fa9459Szrj 
3035*a9fa9459Szrj   if (t1->kind != t2->kind
3036*a9fa9459Szrj       || t1->size != t2->size)
3037*a9fa9459Szrj     return FALSE;
3038*a9fa9459Szrj 
3039*a9fa9459Szrj   /* Get rid of the trivial cases first.  */
3040*a9fa9459Szrj   switch (t1->kind)
3041*a9fa9459Szrj     {
3042*a9fa9459Szrj     default:
3043*a9fa9459Szrj       break;
3044*a9fa9459Szrj     case DEBUG_KIND_VOID:
3045*a9fa9459Szrj     case DEBUG_KIND_FLOAT:
3046*a9fa9459Szrj     case DEBUG_KIND_COMPLEX:
3047*a9fa9459Szrj     case DEBUG_KIND_BOOL:
3048*a9fa9459Szrj       return TRUE;
3049*a9fa9459Szrj     case DEBUG_KIND_INT:
3050*a9fa9459Szrj       return t1->u.kint == t2->u.kint;
3051*a9fa9459Szrj     }
3052*a9fa9459Szrj 
3053*a9fa9459Szrj   /* We have to avoid an infinite recursion.  We do this by keeping a
3054*a9fa9459Szrj      list of types which we are comparing.  We just keep the list on
3055*a9fa9459Szrj      the stack.  If we encounter a pair of types we are currently
3056*a9fa9459Szrj      comparing, we just assume that they are equal.  */
3057*a9fa9459Szrj   for (l = info->compare_list; l != NULL; l = l->next)
3058*a9fa9459Szrj     {
3059*a9fa9459Szrj       if (l->t1 == t1 && l->t2 == t2)
3060*a9fa9459Szrj 	return TRUE;
3061*a9fa9459Szrj     }
3062*a9fa9459Szrj 
3063*a9fa9459Szrj   top.t1 = t1;
3064*a9fa9459Szrj   top.t2 = t2;
3065*a9fa9459Szrj   top.next = info->compare_list;
3066*a9fa9459Szrj   info->compare_list = &top;
3067*a9fa9459Szrj 
3068*a9fa9459Szrj   switch (t1->kind)
3069*a9fa9459Szrj     {
3070*a9fa9459Szrj     default:
3071*a9fa9459Szrj       abort ();
3072*a9fa9459Szrj       ret = FALSE;
3073*a9fa9459Szrj       break;
3074*a9fa9459Szrj 
3075*a9fa9459Szrj     case DEBUG_KIND_STRUCT:
3076*a9fa9459Szrj     case DEBUG_KIND_UNION:
3077*a9fa9459Szrj     case DEBUG_KIND_CLASS:
3078*a9fa9459Szrj     case DEBUG_KIND_UNION_CLASS:
3079*a9fa9459Szrj       if (t1->u.kclass == NULL)
3080*a9fa9459Szrj 	ret = t2->u.kclass == NULL;
3081*a9fa9459Szrj       else if (t2->u.kclass == NULL)
3082*a9fa9459Szrj 	ret = FALSE;
3083*a9fa9459Szrj       else if (t1->u.kclass->id > info->base_id
3084*a9fa9459Szrj 	       && t1->u.kclass->id == t2->u.kclass->id)
3085*a9fa9459Szrj 	ret = TRUE;
3086*a9fa9459Szrj       else
3087*a9fa9459Szrj 	ret = debug_class_type_samep (info, t1, t2);
3088*a9fa9459Szrj       break;
3089*a9fa9459Szrj 
3090*a9fa9459Szrj     case DEBUG_KIND_ENUM:
3091*a9fa9459Szrj       if (t1->u.kenum == NULL)
3092*a9fa9459Szrj 	ret = t2->u.kenum == NULL;
3093*a9fa9459Szrj       else if (t2->u.kenum == NULL)
3094*a9fa9459Szrj 	ret = FALSE;
3095*a9fa9459Szrj       else
3096*a9fa9459Szrj 	{
3097*a9fa9459Szrj 	  const char **pn1, **pn2;
3098*a9fa9459Szrj 	  bfd_signed_vma *pv1, *pv2;
3099*a9fa9459Szrj 
3100*a9fa9459Szrj 	  pn1 = t1->u.kenum->names;
3101*a9fa9459Szrj 	  pn2 = t2->u.kenum->names;
3102*a9fa9459Szrj 	  pv1 = t1->u.kenum->values;
3103*a9fa9459Szrj 	  pv2 = t2->u.kenum->values;
3104*a9fa9459Szrj 	  while (*pn1 != NULL && *pn2 != NULL)
3105*a9fa9459Szrj 	    {
3106*a9fa9459Szrj 	      if (**pn1 != **pn2
3107*a9fa9459Szrj 		  || *pv1 != *pv2
3108*a9fa9459Szrj 		  || strcmp (*pn1, *pn2) != 0)
3109*a9fa9459Szrj 		break;
3110*a9fa9459Szrj 	      ++pn1;
3111*a9fa9459Szrj 	      ++pn2;
3112*a9fa9459Szrj 	      ++pv1;
3113*a9fa9459Szrj 	      ++pv2;
3114*a9fa9459Szrj 	    }
3115*a9fa9459Szrj 	  ret = *pn1 == NULL && *pn2 == NULL;
3116*a9fa9459Szrj 	}
3117*a9fa9459Szrj       break;
3118*a9fa9459Szrj 
3119*a9fa9459Szrj     case DEBUG_KIND_POINTER:
3120*a9fa9459Szrj       ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
3121*a9fa9459Szrj       break;
3122*a9fa9459Szrj 
3123*a9fa9459Szrj     case DEBUG_KIND_FUNCTION:
3124*a9fa9459Szrj       if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
3125*a9fa9459Szrj 	  || ! debug_type_samep (info, t1->u.kfunction->return_type,
3126*a9fa9459Szrj 				 t2->u.kfunction->return_type)
3127*a9fa9459Szrj 	  || ((t1->u.kfunction->arg_types == NULL)
3128*a9fa9459Szrj 	      != (t2->u.kfunction->arg_types == NULL)))
3129*a9fa9459Szrj 	ret = FALSE;
3130*a9fa9459Szrj       else if (t1->u.kfunction->arg_types == NULL)
3131*a9fa9459Szrj 	ret = TRUE;
3132*a9fa9459Szrj       else
3133*a9fa9459Szrj 	{
3134*a9fa9459Szrj 	  struct debug_type_s **a1, **a2;
3135*a9fa9459Szrj 
3136*a9fa9459Szrj 	  a1 = t1->u.kfunction->arg_types;
3137*a9fa9459Szrj 	  a2 = t2->u.kfunction->arg_types;
3138*a9fa9459Szrj 	  while (*a1 != NULL && *a2 != NULL)
3139*a9fa9459Szrj 	    {
3140*a9fa9459Szrj 	      if (! debug_type_samep (info, *a1, *a2))
3141*a9fa9459Szrj 		break;
3142*a9fa9459Szrj 	      ++a1;
3143*a9fa9459Szrj 	      ++a2;
3144*a9fa9459Szrj 	    }
3145*a9fa9459Szrj 	  ret = *a1 == NULL && *a2 == NULL;
3146*a9fa9459Szrj 	}
3147*a9fa9459Szrj       break;
3148*a9fa9459Szrj 
3149*a9fa9459Szrj     case DEBUG_KIND_REFERENCE:
3150*a9fa9459Szrj       ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
3151*a9fa9459Szrj       break;
3152*a9fa9459Szrj 
3153*a9fa9459Szrj     case DEBUG_KIND_RANGE:
3154*a9fa9459Szrj       ret = (t1->u.krange->lower == t2->u.krange->lower
3155*a9fa9459Szrj 	     && t1->u.krange->upper == t2->u.krange->upper
3156*a9fa9459Szrj 	     && debug_type_samep (info, t1->u.krange->type,
3157*a9fa9459Szrj 				  t2->u.krange->type));
3158*a9fa9459Szrj       break;
3159*a9fa9459Szrj 
3160*a9fa9459Szrj     case DEBUG_KIND_ARRAY:
3161*a9fa9459Szrj       ret = (t1->u.karray->lower == t2->u.karray->lower
3162*a9fa9459Szrj 	     && t1->u.karray->upper == t2->u.karray->upper
3163*a9fa9459Szrj 	     && t1->u.karray->stringp == t2->u.karray->stringp
3164*a9fa9459Szrj 	     && debug_type_samep (info, t1->u.karray->element_type,
3165*a9fa9459Szrj 				  t2->u.karray->element_type));
3166*a9fa9459Szrj       break;
3167*a9fa9459Szrj 
3168*a9fa9459Szrj     case DEBUG_KIND_SET:
3169*a9fa9459Szrj       ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
3170*a9fa9459Szrj 	     && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
3171*a9fa9459Szrj       break;
3172*a9fa9459Szrj 
3173*a9fa9459Szrj     case DEBUG_KIND_OFFSET:
3174*a9fa9459Szrj       ret = (debug_type_samep (info, t1->u.koffset->base_type,
3175*a9fa9459Szrj 			       t2->u.koffset->base_type)
3176*a9fa9459Szrj 	     && debug_type_samep (info, t1->u.koffset->target_type,
3177*a9fa9459Szrj 				  t2->u.koffset->target_type));
3178*a9fa9459Szrj       break;
3179*a9fa9459Szrj 
3180*a9fa9459Szrj     case DEBUG_KIND_METHOD:
3181*a9fa9459Szrj       if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
3182*a9fa9459Szrj 	  || ! debug_type_samep (info, t1->u.kmethod->return_type,
3183*a9fa9459Szrj 				 t2->u.kmethod->return_type)
3184*a9fa9459Szrj 	  || ! debug_type_samep (info, t1->u.kmethod->domain_type,
3185*a9fa9459Szrj 				 t2->u.kmethod->domain_type)
3186*a9fa9459Szrj 	  || ((t1->u.kmethod->arg_types == NULL)
3187*a9fa9459Szrj 	      != (t2->u.kmethod->arg_types == NULL)))
3188*a9fa9459Szrj 	ret = FALSE;
3189*a9fa9459Szrj       else if (t1->u.kmethod->arg_types == NULL)
3190*a9fa9459Szrj 	ret = TRUE;
3191*a9fa9459Szrj       else
3192*a9fa9459Szrj 	{
3193*a9fa9459Szrj 	  struct debug_type_s **a1, **a2;
3194*a9fa9459Szrj 
3195*a9fa9459Szrj 	  a1 = t1->u.kmethod->arg_types;
3196*a9fa9459Szrj 	  a2 = t2->u.kmethod->arg_types;
3197*a9fa9459Szrj 	  while (*a1 != NULL && *a2 != NULL)
3198*a9fa9459Szrj 	    {
3199*a9fa9459Szrj 	      if (! debug_type_samep (info, *a1, *a2))
3200*a9fa9459Szrj 		break;
3201*a9fa9459Szrj 	      ++a1;
3202*a9fa9459Szrj 	      ++a2;
3203*a9fa9459Szrj 	    }
3204*a9fa9459Szrj 	  ret = *a1 == NULL && *a2 == NULL;
3205*a9fa9459Szrj 	}
3206*a9fa9459Szrj       break;
3207*a9fa9459Szrj 
3208*a9fa9459Szrj     case DEBUG_KIND_CONST:
3209*a9fa9459Szrj       ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
3210*a9fa9459Szrj       break;
3211*a9fa9459Szrj 
3212*a9fa9459Szrj     case DEBUG_KIND_VOLATILE:
3213*a9fa9459Szrj       ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
3214*a9fa9459Szrj       break;
3215*a9fa9459Szrj 
3216*a9fa9459Szrj     case DEBUG_KIND_NAMED:
3217*a9fa9459Szrj     case DEBUG_KIND_TAGGED:
3218*a9fa9459Szrj       ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
3219*a9fa9459Szrj 	     && debug_type_samep (info, t1->u.knamed->type,
3220*a9fa9459Szrj 				  t2->u.knamed->type));
3221*a9fa9459Szrj       break;
3222*a9fa9459Szrj     }
3223*a9fa9459Szrj 
3224*a9fa9459Szrj   info->compare_list = top.next;
3225*a9fa9459Szrj 
3226*a9fa9459Szrj   return ret;
3227*a9fa9459Szrj }
3228*a9fa9459Szrj 
3229*a9fa9459Szrj /* See if two classes are the same.  This is a subroutine of
3230*a9fa9459Szrj    debug_type_samep.  */
3231*a9fa9459Szrj 
3232*a9fa9459Szrj static bfd_boolean
debug_class_type_samep(struct debug_handle * info,struct debug_type_s * t1,struct debug_type_s * t2)3233*a9fa9459Szrj debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
3234*a9fa9459Szrj 			struct debug_type_s *t2)
3235*a9fa9459Szrj {
3236*a9fa9459Szrj   struct debug_class_type *c1, *c2;
3237*a9fa9459Szrj 
3238*a9fa9459Szrj   c1 = t1->u.kclass;
3239*a9fa9459Szrj   c2 = t2->u.kclass;
3240*a9fa9459Szrj 
3241*a9fa9459Szrj   if ((c1->fields == NULL) != (c2->fields == NULL)
3242*a9fa9459Szrj       || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
3243*a9fa9459Szrj       || (c1->methods == NULL) != (c2->methods == NULL)
3244*a9fa9459Szrj       || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
3245*a9fa9459Szrj     return FALSE;
3246*a9fa9459Szrj 
3247*a9fa9459Szrj   if (c1->fields != NULL)
3248*a9fa9459Szrj     {
3249*a9fa9459Szrj       struct debug_field_s **pf1, **pf2;
3250*a9fa9459Szrj 
3251*a9fa9459Szrj       for (pf1 = c1->fields, pf2 = c2->fields;
3252*a9fa9459Szrj 	   *pf1 != NULL && *pf2 != NULL;
3253*a9fa9459Szrj 	   pf1++, pf2++)
3254*a9fa9459Szrj 	{
3255*a9fa9459Szrj 	  struct debug_field_s *f1, *f2;
3256*a9fa9459Szrj 
3257*a9fa9459Szrj 	  f1 = *pf1;
3258*a9fa9459Szrj 	  f2 = *pf2;
3259*a9fa9459Szrj 	  if (f1->name[0] != f2->name[0]
3260*a9fa9459Szrj 	      || f1->visibility != f2->visibility
3261*a9fa9459Szrj 	      || f1->static_member != f2->static_member)
3262*a9fa9459Szrj 	    return FALSE;
3263*a9fa9459Szrj 	  if (f1->static_member)
3264*a9fa9459Szrj 	    {
3265*a9fa9459Szrj 	      if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
3266*a9fa9459Szrj 		return FALSE;
3267*a9fa9459Szrj 	    }
3268*a9fa9459Szrj 	  else
3269*a9fa9459Szrj 	    {
3270*a9fa9459Szrj 	      if (f1->u.f.bitpos != f2->u.f.bitpos
3271*a9fa9459Szrj 		  || f1->u.f.bitsize != f2->u.f.bitsize)
3272*a9fa9459Szrj 		return FALSE;
3273*a9fa9459Szrj 	    }
3274*a9fa9459Szrj 	  /* We do the checks which require function calls last.  We
3275*a9fa9459Szrj              don't require that the types of fields have the same
3276*a9fa9459Szrj              names, since that sometimes fails in the presence of
3277*a9fa9459Szrj              typedefs and we really don't care.  */
3278*a9fa9459Szrj 	  if (strcmp (f1->name, f2->name) != 0
3279*a9fa9459Szrj 	      || ! debug_type_samep (info,
3280*a9fa9459Szrj 				     debug_get_real_type ((void *) info,
3281*a9fa9459Szrj 							  f1->type, NULL),
3282*a9fa9459Szrj 				     debug_get_real_type ((void *) info,
3283*a9fa9459Szrj 							  f2->type, NULL)))
3284*a9fa9459Szrj 	    return FALSE;
3285*a9fa9459Szrj 	}
3286*a9fa9459Szrj       if (*pf1 != NULL || *pf2 != NULL)
3287*a9fa9459Szrj 	return FALSE;
3288*a9fa9459Szrj     }
3289*a9fa9459Szrj 
3290*a9fa9459Szrj   if (c1->vptrbase != NULL)
3291*a9fa9459Szrj     {
3292*a9fa9459Szrj       if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
3293*a9fa9459Szrj 	return FALSE;
3294*a9fa9459Szrj     }
3295*a9fa9459Szrj 
3296*a9fa9459Szrj   if (c1->baseclasses != NULL)
3297*a9fa9459Szrj     {
3298*a9fa9459Szrj       struct debug_baseclass_s **pb1, **pb2;
3299*a9fa9459Szrj 
3300*a9fa9459Szrj       for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
3301*a9fa9459Szrj 	   *pb1 != NULL && *pb2 != NULL;
3302*a9fa9459Szrj 	   ++pb1, ++pb2)
3303*a9fa9459Szrj 	{
3304*a9fa9459Szrj 	  struct debug_baseclass_s *b1, *b2;
3305*a9fa9459Szrj 
3306*a9fa9459Szrj 	  b1 = *pb1;
3307*a9fa9459Szrj 	  b2 = *pb2;
3308*a9fa9459Szrj 	  if (b1->bitpos != b2->bitpos
3309*a9fa9459Szrj 	      || b1->is_virtual != b2->is_virtual
3310*a9fa9459Szrj 	      || b1->visibility != b2->visibility
3311*a9fa9459Szrj 	      || ! debug_type_samep (info, b1->type, b2->type))
3312*a9fa9459Szrj 	    return FALSE;
3313*a9fa9459Szrj 	}
3314*a9fa9459Szrj       if (*pb1 != NULL || *pb2 != NULL)
3315*a9fa9459Szrj 	return FALSE;
3316*a9fa9459Szrj     }
3317*a9fa9459Szrj 
3318*a9fa9459Szrj   if (c1->methods != NULL)
3319*a9fa9459Szrj     {
3320*a9fa9459Szrj       struct debug_method_s **pm1, **pm2;
3321*a9fa9459Szrj 
3322*a9fa9459Szrj       for (pm1 = c1->methods, pm2 = c2->methods;
3323*a9fa9459Szrj 	   *pm1 != NULL && *pm2 != NULL;
3324*a9fa9459Szrj 	   ++pm1, ++pm2)
3325*a9fa9459Szrj 	{
3326*a9fa9459Szrj 	  struct debug_method_s *m1, *m2;
3327*a9fa9459Szrj 
3328*a9fa9459Szrj 	  m1 = *pm1;
3329*a9fa9459Szrj 	  m2 = *pm2;
3330*a9fa9459Szrj 	  if (m1->name[0] != m2->name[0]
3331*a9fa9459Szrj 	      || strcmp (m1->name, m2->name) != 0
3332*a9fa9459Szrj 	      || (m1->variants == NULL) != (m2->variants == NULL))
3333*a9fa9459Szrj 	    return FALSE;
3334*a9fa9459Szrj 	  if (m1->variants == NULL)
3335*a9fa9459Szrj 	    {
3336*a9fa9459Szrj 	      struct debug_method_variant_s **pv1, **pv2;
3337*a9fa9459Szrj 
3338*a9fa9459Szrj 	      for (pv1 = m1->variants, pv2 = m2->variants;
3339*a9fa9459Szrj 		   *pv1 != NULL && *pv2 != NULL;
3340*a9fa9459Szrj 		   ++pv1, ++pv2)
3341*a9fa9459Szrj 		{
3342*a9fa9459Szrj 		  struct debug_method_variant_s *v1, *v2;
3343*a9fa9459Szrj 
3344*a9fa9459Szrj 		  v1 = *pv1;
3345*a9fa9459Szrj 		  v2 = *pv2;
3346*a9fa9459Szrj 		  if (v1->physname[0] != v2->physname[0]
3347*a9fa9459Szrj 		      || v1->visibility != v2->visibility
3348*a9fa9459Szrj 		      || v1->constp != v2->constp
3349*a9fa9459Szrj 		      || v1->volatilep != v2->volatilep
3350*a9fa9459Szrj 		      || v1->voffset != v2->voffset
3351*a9fa9459Szrj 		      || (v1->context == NULL) != (v2->context == NULL)
3352*a9fa9459Szrj 		      || strcmp (v1->physname, v2->physname) != 0
3353*a9fa9459Szrj 		      || ! debug_type_samep (info, v1->type, v2->type))
3354*a9fa9459Szrj 		    return FALSE;
3355*a9fa9459Szrj 		  if (v1->context != NULL)
3356*a9fa9459Szrj 		    {
3357*a9fa9459Szrj 		      if (! debug_type_samep (info, v1->context,
3358*a9fa9459Szrj 					      v2->context))
3359*a9fa9459Szrj 			return FALSE;
3360*a9fa9459Szrj 		    }
3361*a9fa9459Szrj 		}
3362*a9fa9459Szrj 	      if (*pv1 != NULL || *pv2 != NULL)
3363*a9fa9459Szrj 		return FALSE;
3364*a9fa9459Szrj 	    }
3365*a9fa9459Szrj 	}
3366*a9fa9459Szrj       if (*pm1 != NULL || *pm2 != NULL)
3367*a9fa9459Szrj 	return FALSE;
3368*a9fa9459Szrj     }
3369*a9fa9459Szrj 
3370*a9fa9459Szrj   return TRUE;
3371*a9fa9459Szrj }
3372