Coverage Report

Created: 2026-10-02 09:53

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