This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdebugread.c
4801 lines (4129 loc) · 138 KB
/
mdebugread.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Read a symbol table in ECOFF format (Third-Eye).
Copyright (C) 1986-2024 Free Software Foundation, Inc.
Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
at Cygnus Support.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This module provides the function mdebug_build_psymtabs. It reads
ECOFF debugging information into partial symbol tables. The
debugging information is read from two structures. A struct
ecoff_debug_swap includes the sizes of each ECOFF structure and
swapping routines; these are fixed for a particular target. A
struct ecoff_debug_info points to the debugging information for a
particular object file.
ECOFF symbol tables are mostly written in the byte order of the
target machine. However, one section of the table (the auxiliary
symbol information) is written in the host byte order. There is a
bit in the other symbol info which describes which host byte order
was used. ECOFF thereby takes the trophy from Intel `b.out' for
the most brain-dead adaptation of a file format to byte order.
This module can read all four of the known byte-order combinations,
on any type of host. */
#include "defs.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "gdbcore.h"
#include "filenames.h"
#include "objfiles.h"
#include "gdbsupport/gdb_obstack.h"
#include "buildsym-legacy.h"
#include "stabsread.h"
#include "complaints.h"
#include "demangle.h"
#include "gdb-demangle.h"
#include "block.h"
#include "dictionary.h"
#include "mdebugread.h"
#include <sys/stat.h>
#include "psymtab.h"
#include "source.h"
#include "bfd.h"
#include "coff/ecoff.h"
#include "libaout.h"
#include "aout/aout64.h"
#include "aout/stab_gnu.h"
#include "expression.h"
#include <algorithm>
/* Provide a way to test if we have both ECOFF and ELF symbol tables.
We use this define in order to know whether we should override a
symbol's ECOFF section with its ELF section. This is necessary in
case the symbol's ELF section could not be represented in ECOFF. */
#define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
&& bfd_get_section_by_name (bfd, ".mdebug") != NULL)
/* The objfile we are currently reading. */
static struct objfile *mdebugread_objfile;
/* We put a pointer to this structure in the read_symtab_private field
of the psymtab. */
struct md_symloc
{
/* Index of the FDR that this psymtab represents. */
int fdr_idx;
/* The BFD that the psymtab was created from. */
bfd *cur_bfd;
const struct ecoff_debug_swap *debug_swap;
struct ecoff_debug_info *debug_info;
struct mdebug_pending **pending_list;
/* Pointer to external symbols for this file. */
EXTR *extern_tab;
/* Size of extern_tab. */
int extern_count;
enum language pst_language;
};
#define PST_PRIVATE(p) ((struct md_symloc *)(p)->read_symtab_private)
#define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
#define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
#define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
#define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
#define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
#define SC_IS_TEXT(sc) ((sc) == scText \
|| (sc) == scRConst \
|| (sc) == scInit \
|| (sc) == scFini)
#define SC_IS_DATA(sc) ((sc) == scData \
|| (sc) == scSData \
|| (sc) == scRData \
|| (sc) == scPData \
|| (sc) == scXData)
#define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
#define SC_IS_BSS(sc) ((sc) == scBss)
#define SC_IS_SBSS(sc) ((sc) == scSBss)
#define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
/* Various complaints about symbol reading that don't abort the process. */
static void
index_complaint (const char *arg1)
{
complaint (_("bad aux index at symbol %s"), arg1);
}
static void
unknown_ext_complaint (const char *arg1)
{
complaint (_("unknown external symbol %s"), arg1);
}
static void
basic_type_complaint (int arg1, const char *arg2)
{
complaint (_("cannot map ECOFF basic type 0x%x for %s"),
arg1, arg2);
}
static void
bad_tag_guess_complaint (const char *arg1)
{
complaint (_("guessed tag type of %s incorrectly"), arg1);
}
static void
bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3)
{
complaint (_("bad rfd entry for %s: file %d, index %d"),
arg1, arg2, arg3);
}
static void
unexpected_type_code_complaint (const char *arg1)
{
complaint (_("unexpected type code for %s"), arg1);
}
/* Macros and extra defs. */
/* Puns: hard to find whether -g was used and how. */
#define MIN_GLEVEL GLEVEL_0
#define compare_glevel(a,b) \
(((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
/* Things that really are local to this module. */
/* Remember what we deduced to be the source language of this psymtab. */
static enum language psymtab_language = language_unknown;
/* Current BFD. */
static bfd *cur_bfd;
/* How to parse debugging information for CUR_BFD. */
static const struct ecoff_debug_swap *debug_swap;
/* Pointers to debugging information for CUR_BFD. */
static struct ecoff_debug_info *debug_info;
/* Pointer to current file descriptor record, and its index. */
static FDR *cur_fdr;
static int cur_fd;
/* Index of current symbol. */
static int cur_sdx;
/* Note how much "debuggable" this image is. We would like
to see at least one FDR with full symbols. */
static int max_gdbinfo;
static int max_glevel;
/* When examining .o files, report on undefined symbols. */
static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
/* Pseudo symbol to use when putting stabs into the symbol table. */
static char stabs_symbol[] = STABS_SYMBOL;
/* Nonzero if we have seen ecoff debugging info for a file. */
static int found_ecoff_debugging_info;
/* Forward declarations. */
static int upgrade_type (int, struct type **, int, union aux_ext *,
int, const char *);
static void parse_partial_symbols (minimal_symbol_reader &,
psymtab_storage *,
struct objfile *);
static int has_opaque_xref (FDR *, SYMR *);
static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
const char **, int, const char *);
static struct symbol *new_symbol (const char *);
static struct type *new_type (char *);
enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
static struct block *new_block (struct objfile *objfile,
enum block_type, enum language);
static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);
static struct linetable *new_linetable (int);
static struct blockvector *new_bvect (int);
static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
int, const char *);
static struct symbol *mylookup_symbol (const char *, const struct block *,
domain_enum, enum address_class);
static void sort_blocks (struct symtab *);
static legacy_psymtab *new_psymtab (const char *, psymtab_storage *,
struct objfile *);
static void mdebug_expand_psymtab (legacy_psymtab *pst,
struct objfile *objfile);
static void add_block (struct block *, struct symtab *);
static void add_symbol (struct symbol *, struct symtab *, struct block *);
static int add_line (struct linetable *, int, CORE_ADDR, int);
static struct linetable *shrink_linetable (struct linetable *);
static void handle_psymbol_enumerators (struct objfile *, psymtab_storage *,
partial_symtab *,
FDR *, int, CORE_ADDR);
static const char *mdebug_next_symbol_text (struct objfile *);
/* Exported procedure: Builds a symtab from the partial symtab SELF.
Restores the environment in effect when SELF was created, delegates
most of the work to an ancillary procedure, and sorts
and reorders the symtab list at the end. SELF is not NULL. */
static void
mdebug_read_symtab (legacy_psymtab *self, struct objfile *objfile)
{
next_symbol_text_func = mdebug_next_symbol_text;
self->expand_psymtab (objfile);
/* Match with global symbols. This only needs to be done once,
after all of the symtabs and dependencies have been read in. */
scan_file_globals (objfile);
}
/* File-level interface functions. */
/* Find a file descriptor given its index RF relative to a file CF. */
static FDR *
get_rfd (int cf, int rf)
{
FDR *fdrs;
FDR *f;
RFDT rfd;
fdrs = debug_info->fdr;
f = fdrs + cf;
/* Object files do not have the RFD table, all refs are absolute. */
if (f->rfdBase == 0)
return fdrs + rf;
(*debug_swap->swap_rfd_in) (cur_bfd,
((char *) debug_info->external_rfd
+ ((f->rfdBase + rf)
* debug_swap->external_rfd_size)),
&rfd);
return fdrs + rfd;
}
/* Return a safer print NAME for a file descriptor. */
static const char *
fdr_name (FDR *f)
{
if (f->rss == -1)
return "<stripped file>";
if (f->rss == 0)
return "<NFY>";
return debug_info->ss + f->issBase + f->rss;
}
/* Read in and parse the symtab of the file OBJFILE. Symbols from
different sections are relocated via the SECTION_OFFSETS. */
void
mdebug_build_psymtabs (minimal_symbol_reader &reader,
struct objfile *objfile,
const struct ecoff_debug_swap *swap,
struct ecoff_debug_info *info)
{
cur_bfd = objfile->obfd.get ();
debug_swap = swap;
debug_info = info;
stabsread_new_init ();
free_header_files ();
init_header_files ();
/* Make sure all the FDR information is swapped in. */
if (info->fdr == NULL)
{
char *fdr_src;
char *fdr_end;
FDR *fdr_ptr;
info->fdr = (FDR *) XOBNEWVEC (&objfile->objfile_obstack, FDR,
info->symbolic_header.ifdMax);
fdr_src = (char *) info->external_fdr;
fdr_end = (fdr_src
+ info->symbolic_header.ifdMax * swap->external_fdr_size);
fdr_ptr = info->fdr;
for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
(*swap->swap_fdr_in) (objfile->obfd.get (), fdr_src, fdr_ptr);
}
psymbol_functions *psf = new psymbol_functions ();
psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
objfile->qf.emplace_front (psf);
parse_partial_symbols (reader, partial_symtabs, objfile);
#if 0
/* Check to make sure file was compiled with -g. If not, warn the
user of this limitation. */
if (compare_glevel (max_glevel, GLEVEL_2) < 0)
{
if (max_gdbinfo == 0)
gdb_printf (_("\n%s not compiled with -g, "
"debugging support is limited.\n"),
objfile->name);
gdb_printf (_("You should compile with -g2 or "
"-g3 for best debugging support.\n"));
}
#endif
}
/* Local utilities */
/* Map of FDR indexes to partial symtabs. */
struct pst_map
{
legacy_psymtab *pst = nullptr; /* the psymtab proper */
long n_globals = 0; /* exported globals (external symbols) */
long globals_offset = 0; /* cumulative */
};
/* Utility stack, used to nest procedures and blocks properly.
It is a doubly linked list, to avoid too many alloc/free.
Since we might need it quite a few times it is NOT deallocated
after use. */
static struct parse_stack
{
struct parse_stack *next, *prev;
struct symtab *cur_st; /* Current symtab. */
struct block *cur_block; /* Block in it. */
/* What are we parsing. stFile, or stBlock are for files and
blocks. stProc or stStaticProc means we have seen the start of a
procedure, but not the start of the block within in. When we see
the start of that block, we change it to stNil, without pushing a
new block, i.e. stNil means both a procedure and a block. */
int blocktype;
struct type *cur_type; /* Type we parse fields for. */
int cur_field; /* Field number in cur_type. */
CORE_ADDR procadr; /* Start addres of this procedure. */
int numargs; /* Its argument count. */
}
*top_stack; /* Top stack ptr */
/* Enter a new lexical context. */
static void
push_parse_stack (void)
{
struct parse_stack *newobj;
/* Reuse frames if possible. */
if (top_stack && top_stack->prev)
newobj = top_stack->prev;
else
newobj = XCNEW (struct parse_stack);
/* Initialize new frame with previous content. */
if (top_stack)
{
struct parse_stack *prev = newobj->prev;
*newobj = *top_stack;
top_stack->prev = newobj;
newobj->prev = prev;
newobj->next = top_stack;
}
top_stack = newobj;
}
/* Exit a lexical context. */
static void
pop_parse_stack (void)
{
if (!top_stack)
return;
if (top_stack->next)
top_stack = top_stack->next;
}
/* Cross-references might be to things we haven't looked at
yet, e.g. type references. To avoid too many type
duplications we keep a quick fixup table, an array
of lists of references indexed by file descriptor. */
struct mdebug_pending
{
struct mdebug_pending *next; /* link */
char *s; /* the unswapped symbol */
struct type *t; /* its partial type descriptor */
};
/* The pending information is kept for an entire object file. We
allocate the pending information table when we create the partial
symbols, and we store a pointer to the single table in each
psymtab. */
static struct mdebug_pending **pending_list;
/* Check whether we already saw symbol SH in file FH. */
static struct mdebug_pending *
is_pending_symbol (FDR *fh, char *sh)
{
int f_idx = fh - debug_info->fdr;
struct mdebug_pending *p;
/* Linear search is ok, list is typically no more than 10 deep. */
for (p = pending_list[f_idx]; p; p = p->next)
if (p->s == sh)
break;
return p;
}
/* Add a new symbol SH of type T. */
static void
add_pending (FDR *fh, char *sh, struct type *t)
{
int f_idx = fh - debug_info->fdr;
struct mdebug_pending *p = is_pending_symbol (fh, sh);
/* Make sure we do not make duplicates. */
if (!p)
{
p = XOBNEW (&mdebugread_objfile->objfile_obstack, mdebug_pending);
p->s = sh;
p->t = t;
p->next = pending_list[f_idx];
pending_list[f_idx] = p;
}
}
/* Parsing Routines proper. */
static void
reg_value_complaint (int regnum, int num_regs, const char *sym)
{
complaint (_("bad register number %d (max %d) in symbol %s"),
regnum, num_regs - 1, sym);
}
/* Parse a single symbol. Mostly just make up a GDB symbol for it.
For blocks, procedures and types we open a new lexical context.
This is basically just a big switch on the symbol's type. Argument
AX is the base pointer of aux symbols for this file (fh->iauxBase).
EXT_SH points to the unswapped symbol, which is needed for struct,
union, etc., types; it is NULL for an EXTR. BIGEND says whether
aux symbols are big-endian or little-endian. Return count of
SYMR's handled (normally one). */
static int
mdebug_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
{
int regno = gdbarch_ecoff_reg_to_regnum (gdbarch, sym->value_longest ());
if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
{
reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
sym->print_name ());
regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless. */
}
return regno;
}
static const struct symbol_register_ops mdebug_register_funcs = {
mdebug_reg_to_regnum
};
/* The "aclass" indices for computed symbols. */
static int mdebug_register_index;
static int mdebug_regparm_index;
/* Common code for symbols describing data. */
static void
add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend,
struct symbol *s, int aclass_index, struct block *b,
struct objfile *objfile, const char *name)
{
s->set_domain (VAR_DOMAIN);
s->set_aclass_index (aclass_index);
add_symbol (s, top_stack->cur_st, b);
/* Type could be missing if file is compiled without debugging info. */
if (SC_IS_UNDEF (sh->sc)
|| sh->sc == scNil || sh->index == indexNil)
s->set_type (builtin_type (objfile)->nodebug_data_symbol);
else
s->set_type (parse_type (cur_fd, ax, sh->index, 0, bigend, name));
/* Value of a data symbol is its memory address. */
}
static int
parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
const section_offsets §ion_offsets, struct objfile *objfile)
{
struct gdbarch *gdbarch = objfile->arch ();
const bfd_size_type external_sym_size = debug_swap->external_sym_size;
void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
const char *name;
struct symbol *s;
struct block *b;
struct mdebug_pending *pend;
struct type *t;
int count = 1;
TIR tir;
long svalue = sh->value;
int bitsize;
if (ext_sh == NULL)
name = debug_info->ssext + sh->iss;
else
name = debug_info->ss + cur_fdr->issBase + sh->iss;
int section_index = -1;
switch (sh->sc)
{
case scText:
case scRConst:
/* Do not relocate relative values.
The value of a stEnd symbol is the displacement from the
corresponding start symbol value.
The value of a stBlock symbol is the displacement from the
procedure address. */
if (sh->st != stEnd && sh->st != stBlock)
section_index = SECT_OFF_TEXT (objfile);
break;
case scData:
case scSData:
case scRData:
case scPData:
case scXData:
section_index = SECT_OFF_DATA (objfile);
break;
case scBss:
case scSBss:
section_index = SECT_OFF_BSS (objfile);
break;
}
if (section_index != -1)
sh->value += section_offsets[section_index];
switch (sh->st)
{
case stNil:
break;
case stGlobal: /* External symbol, goes into global block. */
b = top_stack->cur_st->compunit ()->blockvector ()->global_block ();
s = new_symbol (name);
s->set_section_index (section_index);
s->set_value_address (sh->value);
add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
break;
case stStatic: /* Static data, goes into current block. */
b = top_stack->cur_block;
s = new_symbol (name);
if (SC_IS_COMMON (sh->sc))
{
/* It is a FORTRAN common block. At least for SGI Fortran the
address is not in the symbol; we need to fix it later in
scan_file_globals. */
int bucket = hashname (s->linkage_name ());
s->set_value_chain (global_sym_chain[bucket]);
global_sym_chain[bucket] = s;
}
else
{
s->set_section_index (section_index);
s->set_value_address (sh->value);
}
add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
break;
case stLocal: /* Local variable, goes into current block. */
b = top_stack->cur_block;
s = new_symbol (name);
s->set_value_longest (svalue);
if (sh->sc == scRegister)
add_data_symbol (sh, ax, bigend, s, mdebug_register_index,
b, objfile, name);
else
add_data_symbol (sh, ax, bigend, s, LOC_LOCAL,
b, objfile, name);
break;
case stParam: /* Arg to procedure, goes into current
block. */
max_gdbinfo++;
found_ecoff_debugging_info = 1;
top_stack->numargs++;
/* Special GNU C++ name. */
if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
name = "this"; /* FIXME, not alloc'd in obstack. */
s = new_symbol (name);
s->set_domain (VAR_DOMAIN);
s->set_is_argument (1);
switch (sh->sc)
{
case scRegister:
/* Pass by value in register. */
s->set_aclass_index (mdebug_register_index);
break;
case scVar:
/* Pass by reference on stack. */
s->set_aclass_index (LOC_REF_ARG);
break;
case scVarRegister:
/* Pass by reference in register. */
s->set_aclass_index (mdebug_regparm_index);
break;
default:
/* Pass by value on stack. */
s->set_aclass_index (LOC_ARG);
break;
}
s->set_value_longest (svalue);
s->set_type (parse_type (cur_fd, ax, sh->index, 0, bigend, name));
add_symbol (s, top_stack->cur_st, top_stack->cur_block);
break;
case stLabel: /* label, goes into current block. */
s = new_symbol (name);
s->set_domain (LABEL_DOMAIN); /* So that it can be used */
s->set_aclass_index (LOC_LABEL); /* but not misused. */
s->set_section_index (section_index);
s->set_value_address (sh->value);
s->set_type (builtin_type (objfile)->builtin_int);
add_symbol (s, top_stack->cur_st, top_stack->cur_block);
break;
case stProc: /* Procedure, usually goes into global block. */
case stStaticProc: /* Static procedure, goes into current block. */
/* For stProc symbol records, we need to check the storage class
as well, as only (stProc, scText) entries represent "real"
procedures - See the Compaq document titled "Object File /
Symbol Table Format Specification" for more information.
If the storage class is not scText, we discard the whole block
of symbol records for this stProc. */
if (sh->st == stProc && sh->sc != scText)
{
char *ext_tsym = ext_sh;
int keep_counting = 1;
SYMR tsym;
while (keep_counting)
{
ext_tsym += external_sym_size;
(*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
count++;
switch (tsym.st)
{
case stParam:
break;
case stEnd:
keep_counting = 0;
break;
default:
complaint (_("unknown symbol type 0x%x"), sh->st);
break;
}
}
break;
}
s = new_symbol (name);
s->set_domain (FUNCTION_DOMAIN);
s->set_aclass_index (LOC_BLOCK);
s->set_section_index (section_index);
/* Type of the return value. */
if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
t = builtin_type (objfile)->builtin_int;
else
{
t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
if (strcmp (name, "malloc") == 0
&& t->code () == TYPE_CODE_VOID)
{
/* I don't know why, but, at least under Alpha GNU/Linux,
when linking against a malloc without debugging
symbols, its read as a function returning void---this
is bad because it means we cannot call functions with
string arguments interactively; i.e., "call
printf("howdy\n")" would fail with the error message
"program has no memory available". To avoid this, we
patch up the type and make it void*
instead. (davidm@azstarnet.com). */
t = make_pointer_type (t, NULL);
}
}
b = top_stack->cur_block;
if (sh->st == stProc)
{
struct blockvector *bv
= top_stack->cur_st->compunit ()->blockvector ();
/* The next test should normally be true, but provides a
hook for nested functions (which we don't want to make
global). */
if (b == bv->static_block ())
b = bv->global_block ();
/* Irix 5 sometimes has duplicate names for the same
function. We want to add such names up at the global
level, not as a nested function. */
else if (sh->value == top_stack->procadr)
b = bv->global_block ();
}
add_symbol (s, top_stack->cur_st, b);
/* Make a type for the procedure itself. */
s->set_type (lookup_function_type (t));
/* All functions in C++ have prototypes. For C we don't have enough
information in the debug info. */
if (s->language () == language_cplus)
s->type ()->set_is_prototyped (true);
/* Create and enter a new lexical context. */
b = new_block (objfile, FUNCTION_BLOCK, s->language ());
s->set_value_block (b);
b->set_function (s);
b->set_start (sh->value);
b->set_end (sh->value);
b->set_superblock (top_stack->cur_block);
add_block (b, top_stack->cur_st);
/* Not if we only have partial info. */
if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
break;
push_parse_stack ();
top_stack->cur_block = b;
top_stack->blocktype = sh->st;
top_stack->cur_type = s->type ();
top_stack->cur_field = -1;
top_stack->procadr = sh->value;
top_stack->numargs = 0;
break;
/* Beginning of code for structure, union, and enum definitions.
They all share a common set of local variables, defined here. */
{
enum type_code type_code;
char *ext_tsym;
int nfields;
long max_value;
struct field *f;
case stStruct: /* Start a block defining a struct type. */
type_code = TYPE_CODE_STRUCT;
goto structured_common;
case stUnion: /* Start a block defining a union type. */
type_code = TYPE_CODE_UNION;
goto structured_common;
case stEnum: /* Start a block defining an enum type. */
type_code = TYPE_CODE_ENUM;
goto structured_common;
case stBlock: /* Either a lexical block, or some type. */
if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
goto case_stBlock_code; /* Lexical block */
type_code = TYPE_CODE_UNDEF; /* We have a type. */
/* Common code for handling struct, union, enum, and/or as-yet-
unknown-type blocks of info about structured data. `type_code'
has been set to the proper TYPE_CODE, if we know it. */
structured_common:
found_ecoff_debugging_info = 1;
push_parse_stack ();
top_stack->blocktype = stBlock;
/* First count the number of fields and the highest value. */
nfields = 0;
max_value = 0;
for (ext_tsym = ext_sh + external_sym_size;
;
ext_tsym += external_sym_size)
{
SYMR tsym;
(*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
switch (tsym.st)
{
case stEnd:
/* C++ encodes class types as structures where there the
methods are encoded as stProc. The scope of stProc
symbols also ends with stEnd, thus creating a risk of
taking the wrong stEnd symbol record as the end of
the current struct, which would cause GDB to undercount
the real number of fields in this struct. To make sure
we really reached the right stEnd symbol record, we
check the associated name, and match it against the
struct name. Since method names are mangled while
the class name is not, there is no risk of having a
method whose name is identical to the class name
(in particular constructor method names are different
from the class name). There is therefore no risk that
this check stops the count on the StEnd of a method.
Also, assume that we're really at the end when tsym.iss
is 0 (issNull). */
if (tsym.iss == issNull
|| strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss,
name) == 0)
goto end_of_fields;
break;
case stMember:
if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
{
/* If the type of the member is Nil (or Void),
without qualifiers, assume the tag is an
enumeration.
Alpha cc -migrate enums are recognized by a zero
index and a zero symbol value.
DU 4.0 cc enums are recognized by a member type of
btEnum without qualifiers and a zero symbol value. */
if (tsym.index == indexNil
|| (tsym.index == 0 && sh->value == 0))
type_code = TYPE_CODE_ENUM;
else
{
(*debug_swap->swap_tir_in) (bigend,
&ax[tsym.index].a_ti,
&tir);
if ((tir.bt == btNil || tir.bt == btVoid
|| (tir.bt == btEnum && sh->value == 0))
&& tir.tq0 == tqNil)
type_code = TYPE_CODE_ENUM;
}
}
nfields++;
if (tsym.value > max_value)
max_value = tsym.value;
break;
case stBlock:
case stUnion:
case stEnum:
case stStruct:
{
#if 0
/* This is a no-op; is it trying to tell us something
we should be checking? */
if (tsym.sc == scVariant); /*UNIMPLEMENTED */
#endif
if (tsym.index != 0)
{
/* This is something like a struct within a
struct. Skip over the fields of the inner
struct. The -1 is because the for loop will
increment ext_tsym. */
ext_tsym = ((char *) debug_info->external_sym
+ ((cur_fdr->isymBase + tsym.index - 1)
* external_sym_size));
}
}
break;
case stTypedef:
/* mips cc puts out a typedef for struct x if it is not yet
defined when it encounters
struct y { struct x *xp; };
Just ignore it. */
break;
case stIndirect:
/* Irix5 cc puts out a stIndirect for struct x if it is not
yet defined when it encounters
struct y { struct x *xp; };
Just ignore it. */
break;
default:
complaint (_("declaration block contains "
"unhandled symbol type %d"),
tsym.st);
}
}
end_of_fields:
/* In an stBlock, there is no way to distinguish structs,
unions, and enums at this point. This is a bug in the
original design (that has been fixed with the recent
addition of the stStruct, stUnion, and stEnum symbol
types.) The way you can tell is if/when you see a variable
or field of that type. In that case the variable's type
(in the AUX table) says if the type is struct, union, or
enum, and points back to the stBlock here. So you can
patch the tag kind up later - but only if there actually is
a variable or field of that type.
So until we know for sure, we will guess at this point.
The heuristic is:
If the first member has index==indexNil or a void type,
assume we have an enumeration.
Otherwise, if there is more than one member, and all
the members have offset 0, assume we have a union.
Otherwise, assume we have a struct.
The heuristic could guess wrong in the case of of an
enumeration with no members or a union with one (or zero)
members, or when all except the last field of a struct have
width zero. These are uncommon and/or illegal situations,
and in any case guessing wrong probably doesn't matter
much.