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
/
xcoffread.c
3006 lines (2470 loc) · 84.7 KB
/
xcoffread.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 AIX xcoff symbol tables and convert to internal format, for GDB.
Copyright (C) 1986-2024 Free Software Foundation, Inc.
Derived from coffread.c, dbxread.c, and a lot of hacking.
Contributed by IBM Corporation.
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/>. */
#include "defs.h"
#include "bfd.h"
#include <sys/types.h>
#include <fcntl.h>
#include <ctype.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#include <sys/stat.h>
#include <algorithm>
#include "coff/internal.h"
#include "libcoff.h"
#include "coff/xcoff.h"
#include "libxcoff.h"
#include "coff/rs6000.h"
#include "xcoffread.h"
#include "symtab.h"
#include "gdbtypes.h"
/* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
#include "symfile.h"
#include "objfiles.h"
#include "buildsym-legacy.h"
#include "stabsread.h"
#include "expression.h"
#include "complaints.h"
#include "psymtab.h"
#include "dwarf2/sect-names.h"
#include "dwarf2/public.h"
#include "gdb-stabs.h"
/* For interface with stabsread.c. */
#include "aout/stab_gnu.h"
/* We put a pointer to this structure in the read_symtab_private field
of the psymtab. */
struct xcoff_symloc
{
/* First symbol number for this file. */
int first_symnum;
/* Number of symbols in the section of the symbol table devoted to
this file's symbols (actually, the section bracketed may contain
more than just this file's symbols). If numsyms is 0, the only
reason for this thing's existence is the dependency list. Nothing
else will happen when it is read in. */
int numsyms;
/* Position of the start of the line number information for this
psymtab. */
unsigned int lineno_off;
};
/* Remember what we deduced to be the source language of this psymtab. */
static enum language psymtab_language = language_unknown;
/* Simplified internal version of coff symbol table information. */
struct xcoff_symbol
{
char *c_name;
int c_symnum; /* Symbol number of this entry. */
int c_naux; /* 0 if syment only, 1 if syment + auxent. */
CORE_ADDR c_value;
unsigned char c_sclass;
int c_secnum;
unsigned int c_type;
};
/* Last function's saved coff symbol `cs'. */
static struct xcoff_symbol fcn_cs_saved;
static bfd *symfile_bfd;
/* Core address of start and end of text of current source file.
This is calculated from the first function seen after a C_FILE
symbol. */
static CORE_ADDR cur_src_end_addr;
/* Core address of the end of the first object file. */
static CORE_ADDR first_object_file_end;
/* Initial symbol-table-debug-string vector length. */
#define INITIAL_STABVECTOR_LENGTH 40
/* Size of a COFF symbol. I think it is always 18, so I'm not sure
there is any reason not to just use a #define, but might as well
ask BFD for the size and store it here, I guess. */
static unsigned local_symesz;
struct xcoff_symfile_info
{
file_ptr min_lineno_offset {}; /* Where in file lowest line#s are. */
file_ptr max_lineno_offset {}; /* 1+last byte of line#s in file. */
/* Pointer to the string table. */
char *strtbl = nullptr;
/* Pointer to debug section. */
char *debugsec = nullptr;
/* Pointer to the a.out symbol table. */
char *symtbl = nullptr;
/* Number of symbols in symtbl. */
int symtbl_num_syms = 0;
/* Offset in data section to TOC anchor. */
CORE_ADDR toc_offset = 0;
};
/* Key for XCOFF-associated data. */
static const registry<objfile>::key<xcoff_symfile_info> xcoff_objfile_data_key;
/* Convenience macro to access the per-objfile XCOFF data. */
#define XCOFF_DATA(objfile) \
xcoff_objfile_data_key.get (objfile)
/* XCOFF names for dwarf sections. There is no compressed sections. */
static const struct dwarf2_debug_sections dwarf2_xcoff_names = {
{ ".dwinfo", NULL },
{ ".dwabrev", NULL },
{ ".dwline", NULL },
{ ".dwloc", NULL },
{ NULL, NULL }, /* debug_loclists */
/* AIX XCOFF defines one, named DWARF section for macro debug information.
XLC does not generate debug_macinfo for DWARF4 and below.
The section is assigned to debug_macro for DWARF5 and above. */
{ NULL, NULL },
{ ".dwmac", NULL },
{ ".dwstr", NULL },
{ NULL, NULL }, /* debug_str_offsets */
{ NULL, NULL }, /* debug_line_str */
{ ".dwrnges", NULL },
{ NULL, NULL }, /* debug_rnglists */
{ ".dwpbtyp", NULL },
{ NULL, NULL }, /* debug_addr */
{ ".dwframe", NULL },
{ NULL, NULL }, /* eh_frame */
{ NULL, NULL }, /* gdb_index */
{ NULL, NULL }, /* debug_names */
{ NULL, NULL }, /* debug_aranges */
23
};
static void
bf_notfound_complaint (void)
{
complaint (_("line numbers off, `.bf' symbol not found"));
}
static void
ef_complaint (int arg1)
{
complaint (_("Mismatched .ef symbol ignored starting at symnum %d"), arg1);
}
static void
eb_complaint (int arg1)
{
complaint (_("Mismatched .eb symbol ignored starting at symnum %d"), arg1);
}
static void xcoff_initial_scan (struct objfile *, symfile_add_flags);
static void scan_xcoff_symtab (minimal_symbol_reader &,
psymtab_storage *partial_symtabs,
struct objfile *);
static const char *xcoff_next_symbol_text (struct objfile *);
static void record_include_begin (struct xcoff_symbol *);
static void
enter_line_range (struct subfile *, unsigned, unsigned,
CORE_ADDR, CORE_ADDR, unsigned *);
static void init_stringtab (bfd *, file_ptr, struct objfile *);
static void xcoff_symfile_init (struct objfile *);
static void xcoff_new_init (struct objfile *);
static void xcoff_symfile_finish (struct objfile *);
static char *coff_getfilename (union internal_auxent *, struct objfile *);
static void read_symbol (struct internal_syment *, int);
static int read_symbol_lineno (int);
static CORE_ADDR read_symbol_nvalue (int);
static struct symbol *process_xcoff_symbol (struct xcoff_symbol *,
struct objfile *);
static void read_xcoff_symtab (struct objfile *, legacy_psymtab *);
#if 0
static void add_stab_to_list (char *, struct pending_stabs **);
#endif
static void record_include_end (struct xcoff_symbol *);
static void process_linenos (CORE_ADDR, CORE_ADDR);
/* Translate from a COFF section number (target_index) to a SECT_OFF_*
code. */
static int secnum_to_section (int, struct objfile *);
static asection *secnum_to_bfd_section (int, struct objfile *);
struct xcoff_find_targ_sec_arg
{
int targ_index;
int *resultp;
asection **bfd_sect;
struct objfile *objfile;
};
static void find_targ_sec (bfd *, asection *, void *);
static void
find_targ_sec (bfd *abfd, asection *sect, void *obj)
{
struct xcoff_find_targ_sec_arg *args
= (struct xcoff_find_targ_sec_arg *) obj;
struct objfile *objfile = args->objfile;
if (sect->target_index == args->targ_index)
{
/* This is the section. Figure out what SECT_OFF_* code it is. */
if (bfd_section_flags (sect) & SEC_CODE)
*args->resultp = SECT_OFF_TEXT (objfile);
else if (bfd_section_flags (sect) & SEC_LOAD)
*args->resultp = SECT_OFF_DATA (objfile);
else
*args->resultp = gdb_bfd_section_index (abfd, sect);
*args->bfd_sect = sect;
}
}
/* Search all BFD sections for the section whose target_index is
equal to N_SCNUM. Set *BFD_SECT to that section. The section's
associated index in the objfile's section_offset table is also
stored in *SECNUM.
If no match is found, *BFD_SECT is set to NULL, and *SECNUM
is set to the text section's number. */
static void
xcoff_secnum_to_sections (int n_scnum, struct objfile *objfile,
asection **bfd_sect, int *secnum)
{
struct xcoff_find_targ_sec_arg args;
args.targ_index = n_scnum;
args.resultp = secnum;
args.bfd_sect = bfd_sect;
args.objfile = objfile;
*bfd_sect = NULL;
*secnum = SECT_OFF_TEXT (objfile);
bfd_map_over_sections (objfile->obfd.get (), find_targ_sec, &args);
}
/* Return the section number (SECT_OFF_*) that N_SCNUM points to. */
static int
secnum_to_section (int n_scnum, struct objfile *objfile)
{
int secnum;
asection *ignored;
xcoff_secnum_to_sections (n_scnum, objfile, &ignored, &secnum);
return secnum;
}
/* Return the BFD section that N_SCNUM points to. */
static asection *
secnum_to_bfd_section (int n_scnum, struct objfile *objfile)
{
int ignored;
asection *bfd_sect;
xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &ignored);
return bfd_sect;
}
/* add a given stab string into given stab vector. */
#if 0
static void
add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
{
if (*stabvector == NULL)
{
*stabvector = (struct pending_stabs *)
xmalloc (sizeof (struct pending_stabs) +
INITIAL_STABVECTOR_LENGTH * sizeof (char *));
(*stabvector)->count = 0;
(*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
}
else if ((*stabvector)->count >= (*stabvector)->length)
{
(*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
*stabvector = (struct pending_stabs *)
xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
(*stabvector)->length * sizeof (char *));
}
(*stabvector)->stab[(*stabvector)->count++] = stabname;
}
#endif
/* Linenos are processed on a file-by-file basis.
Two reasons:
1) xlc (IBM's native c compiler) postpones static function code
emission to the end of a compilation unit. This way it can
determine if those functions (statics) are needed or not, and
can do some garbage collection (I think). This makes line
numbers and corresponding addresses unordered, and we end up
with a line table like:
lineno addr
foo() 10 0x100
20 0x200
30 0x300
foo3() 70 0x400
80 0x500
90 0x600
static foo2()
40 0x700
50 0x800
60 0x900
and that breaks gdb's binary search on line numbers, if the
above table is not sorted on line numbers. And that sort
should be on function based, since gcc can emit line numbers
like:
10 0x100 - for the init/test part of a for stmt.
20 0x200
30 0x300
10 0x400 - for the increment part of a for stmt.
arrange_linetable() will do this sorting.
2) aix symbol table might look like:
c_file // beginning of a new file
.bi // beginning of include file
.ei // end of include file
.bi
.ei
basically, .bi/.ei pairs do not necessarily encapsulate
their scope. They need to be recorded, and processed later
on when we come the end of the compilation unit.
Include table (inclTable) and process_linenos() handle
that. */
/* Given a line table with function entries are marked, arrange its
functions in ascending order and strip off function entry markers
and return it in a newly created table. */
/* FIXME: I think all this stuff can be replaced by just passing
sort_linevec = 1 to end_compunit_symtab. */
static void
arrange_linetable (std::vector<linetable_entry> &old_linetable)
{
std::vector<linetable_entry> fentries;
for (int ii = 0; ii < old_linetable.size (); ++ii)
{
if (!old_linetable[ii].is_stmt)
continue;
if (old_linetable[ii].line == 0)
{
/* Function entry found. */
linetable_entry &e = fentries.emplace_back ();
e.line = ii;
e.is_stmt = true;
e.set_unrelocated_pc (old_linetable[ii].unrelocated_pc ());
}
}
if (fentries.empty ())
return;
std::sort (fentries.begin (), fentries.end ());
/* Allocate a new line table. */
std::vector<linetable_entry> new_linetable;
new_linetable.reserve (old_linetable.size ());
/* If line table does not start with a function beginning, copy up until
a function begin. */
for (int i = 0; i < old_linetable.size () && old_linetable[i].line != 0; ++i)
new_linetable.push_back (old_linetable[i]);
/* Now copy function lines one by one. */
for (const linetable_entry &entry : fentries)
{
/* If the function was compiled with XLC, we may have to add an
extra line to cover the function prologue. */
int jj = entry.line;
if (jj + 1 < old_linetable.size ()
&& (old_linetable[jj].unrelocated_pc ()
!= old_linetable[jj + 1].unrelocated_pc ()))
{
new_linetable.push_back (old_linetable[jj]);
new_linetable.back ().line = old_linetable[jj + 1].line;
}
for (jj = entry.line + 1;
jj < old_linetable.size () && old_linetable[jj].line != 0;
++jj)
new_linetable.push_back (old_linetable[jj]);
}
new_linetable.shrink_to_fit ();
old_linetable = std::move (new_linetable);
}
/* include file support: C_BINCL/C_EINCL pairs will be kept in the
following `IncludeChain'. At the end of each symtab (end_compunit_symtab),
we will determine if we should create additional symtab's to
represent if (the include files. */
typedef struct _inclTable
{
char *name; /* include filename */
/* Offsets to the line table. end points to the last entry which is
part of this include file. */
int begin, end;
struct subfile *subfile;
unsigned funStartLine; /* Start line # of its function. */
}
InclTable;
#define INITIAL_INCLUDE_TABLE_LENGTH 20
static InclTable *inclTable; /* global include table */
static int inclIndx; /* last entry to table */
static int inclLength; /* table length */
static int inclDepth; /* nested include depth */
/* subfile structure for the main compilation unit. */
static subfile *main_subfile;
static void allocate_include_entry (void);
static void
record_include_begin (struct xcoff_symbol *cs)
{
if (inclDepth)
{
/* In xcoff, we assume include files cannot be nested (not in .c files
of course, but in corresponding .s files.). */
/* This can happen with old versions of GCC.
GCC 2.3.3-930426 does not exhibit this on a test case which
a user said produced the message for him. */
complaint (_("Nested C_BINCL symbols"));
}
++inclDepth;
allocate_include_entry ();
inclTable[inclIndx].name = cs->c_name;
inclTable[inclIndx].begin = cs->c_value;
}
static void
record_include_end (struct xcoff_symbol *cs)
{
InclTable *pTbl;
if (inclDepth == 0)
{
complaint (_("Mismatched C_BINCL/C_EINCL pair"));
}
allocate_include_entry ();
pTbl = &inclTable[inclIndx];
pTbl->end = cs->c_value;
--inclDepth;
++inclIndx;
}
static void
allocate_include_entry (void)
{
if (inclTable == NULL)
{
inclTable = XCNEWVEC (InclTable, INITIAL_INCLUDE_TABLE_LENGTH);
inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
inclIndx = 0;
main_subfile = new subfile;
}
else if (inclIndx >= inclLength)
{
inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
inclTable = XRESIZEVEC (InclTable, inclTable, inclLength);
memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
'\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
}
}
/* Global variable to pass the psymtab down to all the routines involved
in psymtab to symtab processing. */
static legacy_psymtab *this_symtab_psymtab;
/* Objfile related to this_symtab_psymtab; set at the same time. */
static struct objfile *this_symtab_objfile;
/* given the start and end addresses of a compilation unit (or a csect,
at times) process its lines and create appropriate line vectors. */
static void
process_linenos (CORE_ADDR start, CORE_ADDR end)
{
int offset;
file_ptr max_offset
= XCOFF_DATA (this_symtab_objfile)->max_lineno_offset;
/* In the main source file, any time we see a function entry, we
reset this variable to function's absolute starting line number.
All the following line numbers in the function are relative to
this, and we record absolute line numbers in record_line(). */
unsigned int main_source_baseline = 0;
unsigned *firstLine;
offset =
((struct xcoff_symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
if (offset == 0)
goto return_after_cleanup;
if (inclIndx == 0)
/* All source lines were in the main source file. None in include
files. */
enter_line_range (main_subfile, offset, 0, start, end,
&main_source_baseline);
else
{
/* There was source with line numbers in include files. */
int linesz =
coff_data (this_symtab_objfile->obfd)->local_linesz;
main_source_baseline = 0;
for (int ii = 0; ii < inclIndx; ++ii)
{
/* If there is main file source before include file, enter it. */
if (offset < inclTable[ii].begin)
{
enter_line_range
(main_subfile, offset, inclTable[ii].begin - linesz,
start, 0, &main_source_baseline);
}
if (strcmp (inclTable[ii].name, get_last_source_file ()) == 0)
{
/* The entry in the include table refers to the main source
file. Add the lines to the main subfile. */
main_source_baseline = inclTable[ii].funStartLine;
enter_line_range
(main_subfile, inclTable[ii].begin, inclTable[ii].end,
start, 0, &main_source_baseline);
inclTable[ii].subfile = main_subfile;
}
else
{
/* Have a new subfile for the include file. */
inclTable[ii].subfile = new subfile;
firstLine = &(inclTable[ii].funStartLine);
/* Enter include file's lines now. */
enter_line_range (inclTable[ii].subfile, inclTable[ii].begin,
inclTable[ii].end, start, 0, firstLine);
}
if (offset <= inclTable[ii].end)
offset = inclTable[ii].end + linesz;
}
/* All the include files' line have been processed at this point. Now,
enter remaining lines of the main file, if any left. */
if (offset < max_offset + 1 - linesz)
{
enter_line_range (main_subfile, offset, 0, start, end,
&main_source_baseline);
}
}
/* Process main file's line numbers. */
if (!main_subfile->line_vector_entries.empty ())
{
/* Line numbers are not necessarily ordered. xlc compilation will
put static function to the end. */
arrange_linetable (main_subfile->line_vector_entries);
}
/* Now, process included files' line numbers. */
for (int ii = 0; ii < inclIndx; ++ii)
{
if (inclTable[ii].subfile != main_subfile
&& !inclTable[ii].subfile->line_vector_entries.empty ())
{
/* Line numbers are not necessarily ordered. xlc compilation will
put static function to the end. */
arrange_linetable (inclTable[ii].subfile->line_vector_entries);
push_subfile ();
/* For the same include file, we might want to have more than one
subfile. This happens if we have something like:
......
#include "foo.h"
......
#include "foo.h"
......
while foo.h including code in it. (stupid but possible)
Since start_subfile() looks at the name and uses an
existing one if finds, we need to provide a fake name and
fool it. */
#if 0
start_subfile (inclTable[ii].name);
#else
{
/* Pick a fake name that will produce the same results as this
one when passed to deduce_language_from_filename. Kludge on
top of kludge. */
const char *fakename = strrchr (inclTable[ii].name, '.');
if (fakename == NULL)
fakename = " ?";
start_subfile (fakename);
}
struct subfile *current_subfile = get_current_subfile ();
current_subfile->name = inclTable[ii].name;
current_subfile->name_for_id = inclTable[ii].name;
#endif
start_subfile (pop_subfile ());
}
}
return_after_cleanup:
/* We don't want to keep alloc/free'ing the global include file table. */
inclIndx = 0;
}
static void
aix_process_linenos (struct objfile *objfile)
{
/* There is no linenos to read if there are only dwarf info. */
if (this_symtab_psymtab == NULL)
return;
/* Process line numbers and enter them into line vector. */
process_linenos (get_last_source_start_addr (), cur_src_end_addr);
}
/* Enter a given range of lines into the line vector.
can be called in the following two ways:
enter_line_range (subfile, beginoffset, endoffset,
startaddr, 0, firstLine) or
enter_line_range (subfile, beginoffset, 0,
startaddr, endaddr, firstLine)
endoffset points to the last line table entry that we should pay
attention to. */
static void
enter_line_range (struct subfile *subfile, unsigned beginoffset,
unsigned endoffset, /* offsets to line table */
CORE_ADDR startaddr, /* offsets to line table */
CORE_ADDR endaddr, unsigned *firstLine)
{
struct objfile *objfile = this_symtab_objfile;
struct gdbarch *gdbarch = objfile->arch ();
unsigned int curoffset;
CORE_ADDR addr;
void *ext_lnno;
struct internal_lineno int_lnno;
unsigned int limit_offset;
bfd *abfd;
int linesz;
if (endoffset == 0 && startaddr == 0 && endaddr == 0)
return;
curoffset = beginoffset;
limit_offset = XCOFF_DATA (objfile)->max_lineno_offset;
if (endoffset != 0)
{
if (endoffset >= limit_offset)
{
complaint (_("Bad line table offset in C_EINCL directive"));
return;
}
limit_offset = endoffset;
}
else
limit_offset -= 1;
abfd = objfile->obfd.get ();
linesz = coff_data (abfd)->local_linesz;
ext_lnno = alloca (linesz);
while (curoffset <= limit_offset)
{
if (bfd_seek (abfd, curoffset, SEEK_SET) != 0
|| bfd_read (ext_lnno, linesz, abfd) != linesz)
return;
bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
/* Find the address this line represents. */
addr = (int_lnno.l_lnno
? int_lnno.l_addr.l_paddr
: read_symbol_nvalue (int_lnno.l_addr.l_symndx));
addr += objfile->text_section_offset ();
if (addr < startaddr || (endaddr && addr >= endaddr))
return;
CORE_ADDR record_addr = (gdbarch_addr_bits_remove (gdbarch, addr)
- objfile->text_section_offset ());
if (int_lnno.l_lnno == 0)
{
*firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
record_line (subfile, 0, unrelocated_addr (record_addr));
--(*firstLine);
}
else
record_line (subfile, *firstLine + int_lnno.l_lnno,
unrelocated_addr (record_addr));
curoffset += linesz;
}
}
/* Save the vital information for use when closing off the current file.
NAME is the file name the symbols came from, START_ADDR is the first
text address for the file, and SIZE is the number of bytes of text. */
#define complete_symtab(name, start_addr) { \
set_last_source_file (name); \
set_last_source_start_addr (start_addr); \
}
/* Refill the symbol table input buffer
and set the variables that control fetching entries from it.
Reports an error if no data available.
This function can read past the end of the symbol table
(into the string table) but this does no harm. */
/* Create a new minimal symbol (using record_with_info).
Creation of all new minimal symbols should go through this function
rather than calling the various record functions in order
to make sure that all symbol addresses get properly relocated.
Arguments are:
NAME - the symbol's name (but if NAME starts with a period, that
leading period is discarded).
ADDRESS - the symbol's address, prior to relocation. This function
relocates the address before recording the minimal symbol.
MS_TYPE - the symbol's type.
N_SCNUM - the symbol's XCOFF section number.
OBJFILE - the objfile associated with the minimal symbol. */
static void
record_minimal_symbol (minimal_symbol_reader &reader,
const char *name, unrelocated_addr address,
enum minimal_symbol_type ms_type,
int n_scnum,
struct objfile *objfile)
{
if (name[0] == '.')
++name;
reader.record_with_info (name, address, ms_type,
secnum_to_section (n_scnum, objfile));
}
/* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
nested. At any given time, a symbol can only be in one static block.
This is the base address of current static block, zero if non exists. */
static int static_block_base = 0;
/* Section number for the current static block. */
static int static_block_section = -1;
/* true if space for symbol name has been allocated. */
static int symname_alloced = 0;
/* Next symbol to read. Pointer into raw seething symbol table. */
static char *raw_symbol;
/* This is the function which stabsread.c calls to get symbol
continuations. */
static const char *
xcoff_next_symbol_text (struct objfile *objfile)
{
struct internal_syment symbol;
const char *retval;
/* FIXME: is this the same as the passed arg? */
if (this_symtab_objfile)
objfile = this_symtab_objfile;
bfd_coff_swap_sym_in (objfile->obfd.get (), raw_symbol, &symbol);
if (symbol.n_zeroes)
{
complaint (_("Unexpected symbol continuation"));
/* Return something which points to '\0' and hope the symbol reading
code does something reasonable. */
retval = "";
}
else if (symbol.n_sclass & 0x80)
{
retval = XCOFF_DATA (objfile)->debugsec + symbol.n_offset;
raw_symbol += coff_data (objfile->obfd)->local_symesz;
++symnum;
}
else
{
complaint (_("Unexpected symbol continuation"));
/* Return something which points to '\0' and hope the symbol reading
code does something reasonable. */
retval = "";
}
return retval;
}
/* Read symbols for a given partial symbol table. */
static void
read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
{
bfd *abfd = objfile->obfd.get ();
char *raw_auxptr; /* Pointer to first raw aux entry for sym. */
struct xcoff_symfile_info *xcoff = XCOFF_DATA (objfile);
char *strtbl = xcoff->strtbl;
char *debugsec = xcoff->debugsec;
const char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF";
struct internal_syment symbol[1];
union internal_auxent main_aux;
struct xcoff_symbol cs[1];
CORE_ADDR file_start_addr = 0;
CORE_ADDR file_end_addr = 0;
int next_file_symnum = -1;
unsigned int max_symnum;
int just_started = 1;
int depth = 0;
CORE_ADDR fcn_start_addr = 0;
enum language pst_symtab_language;
struct xcoff_symbol fcn_stab_saved = { 0 };
/* fcn_cs_saved is global because process_xcoff_symbol needs it. */
union internal_auxent fcn_aux_saved {};
struct context_stack *newobj;
const char *filestring = pst->filename; /* Name of the current file. */
const char *last_csect_name; /* Last seen csect's name. */
this_symtab_psymtab = pst;
this_symtab_objfile = objfile;
/* Get the appropriate COFF "constants" related to the file we're
handling. */
local_symesz = coff_data (abfd)->local_symesz;
set_last_source_file (NULL);
last_csect_name = 0;
pst_symtab_language = deduce_language_from_filename (filestring);
start_stabs ();
start_compunit_symtab (objfile, filestring, NULL, file_start_addr,
pst_symtab_language);
record_debugformat (debugfmt);
symnum = ((struct xcoff_symloc *) pst->read_symtab_private)->first_symnum;
max_symnum =
symnum + ((struct xcoff_symloc *) pst->read_symtab_private)->numsyms;
first_object_file_end = 0;
raw_symbol = xcoff->symtbl + symnum * local_symesz;
while (symnum < max_symnum)
{
QUIT; /* make this command interruptable. */
/* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
/* read one symbol into `cs' structure. After processing the
whole symbol table, only string table will be kept in memory,
symbol table and debug section of xcoff will be freed. Thus
we can mark symbols with names in string table as
`alloced'. */
{
int ii;
/* Swap and align the symbol into a reasonable C structure. */
bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
cs->c_symnum = symnum;
cs->c_naux = symbol->n_numaux;
if (symbol->n_zeroes)
{
symname_alloced = 0;
/* We must use the original, unswapped, name here so the name field
pointed to by cs->c_name will persist throughout xcoffread. If
we use the new field, it gets overwritten for each symbol. */
cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
/* If it's exactly E_SYMNMLEN characters long it isn't
'\0'-terminated. */
if (cs->c_name[E_SYMNMLEN - 1] != '\0')
{
char *p;