Subversion Repositories Kolibri OS

Rev

Rev 5217 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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