~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to pstack/debug.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

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