* rs6000-core.c (rs6000coff_core_p): If CORE_TRUNC is set, print
[deliverable/binutils-gdb.git] / gdb / xcoffread.c
CommitLineData
9b280a7f 1/* Read AIX xcoff symbol tables and convert to internal format, for GDB.
211b564e 2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
9b280a7f 3 Free Software Foundation, Inc.
e38e0312
JG
4 Derived from coffread.c, dbxread.c, and a lot of hacking.
5 Contributed by IBM Corporation.
6
7This file is part of GDB.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
6c9638b4 21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
e38e0312 22
dd469789
JG
23#include "defs.h"
24#include "bfd.h"
25
e38e0312
JG
26#include <sys/types.h>
27#include <fcntl.h>
28#include <ctype.h>
2b576293 29#include "gdb_string.h"
e38e0312 30
e38e0312 31#include <sys/param.h>
5e4d4b0f 32#ifndef NO_SYS_FILE
e38e0312 33#include <sys/file.h>
5e4d4b0f 34#endif
2b576293 35#include "gdb_stat.h"
e38e0312 36
a367db89 37#include "coff/internal.h"
27ad511f 38#include "libcoff.h" /* FIXME, internal data from BFD */
a367db89 39#include "coff/rs6000.h"
27ad511f 40
e38e0312 41#include "symtab.h"
1ab3bf1b 42#include "gdbtypes.h"
e38e0312 43#include "symfile.h"
5e2e79f8 44#include "objfiles.h"
e38e0312 45#include "buildsym.h"
d07734e3 46#include "stabsread.h"
df1e1074
PS
47#include "expression.h"
48#include "language.h" /* Needed inside partial-stab.h */
dd469789 49#include "complaints.h"
e38e0312 50
a81ce07d
JK
51#include "gdb-stabs.h"
52
73262420 53/* For interface with stabsread.c. */
c41e08c4 54#include "aout/stab_gnu.h"
1eeba686 55
a367db89
JK
56/* For interface with partial-stab.h. */
57#define N_UNDF 0 /* Undefined symbol */
58#undef N_ABS
59#define N_ABS 2
60#define N_TEXT 4 /* Text sym -- defined at offset in text seg */
61#define N_DATA 6 /* Data sym -- defined at offset in data seg */
62#define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
63#define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
64#define N_FN 0x1f /* File name of .o file */
65#define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
66/* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
67 N_DATA, or N_BSS. When the low-order bit of other types is set,
68 (e.g. N_WARNING versus N_FN), they are two different types. */
69#define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
70#define N_INDR 0x0a
71
72/* The following symbols refer to set elements.
73 All the N_SET[ATDB] symbols with the same name form one set.
74 Space is allocated for the set in the text section, and each set
75 elements value is stored into one word of the space.
76 The first word of the space is the length of the set (number of elements).
77
78 The address of the set is made into an N_SETV symbol
79 whose name is the same as the name of the set.
80 This symbol acts like a N_DATA global symbol
81 in that it can satisfy undefined external references. */
82
83/* These appear as input to LD, in a .o file. */
84#define N_SETA 0x14 /* Absolute set element symbol */
85#define N_SETT 0x16 /* Text set element symbol */
86#define N_SETD 0x18 /* Data set element symbol */
87#define N_SETB 0x1A /* Bss set element symbol */
88
89/* This is output from LD. */
90#define N_SETV 0x1C /* Pointer to set vector in data area. */
062cb0d3
FF
91
92/* Hook for recording the toc offset value of a symbol table into
93 the ldinfo structure. */
94
95void (*xcoff_add_toc_to_loadinfo_hook) PARAMS ((unsigned long)) = NULL;
96
97/* Hook for recording how to call xcoff_init_loadinfo for a native
98 rs6000 config only. */
99
100void (*xcoff_init_loadinfo_hook) PARAMS ((void)) = NULL;
101
a367db89 102\f
bbb053fd
JK
103/* We put a pointer to this structure in the read_symtab_private field
104 of the psymtab. */
a367db89
JK
105
106struct symloc {
107
108 /* First symbol number for this file. */
109
110 int first_symnum;
111
112 /* Number of symbols in the section of the symbol table devoted to
113 this file's symbols (actually, the section bracketed may contain
114 more than just this file's symbols). If numsyms is 0, the only
115 reason for this thing's existence is the dependency list. Nothing
116 else will happen when it is read in. */
117
118 int numsyms;
119
120 /* Position of the start of the line number information for this psymtab. */
121 unsigned int lineno_off;
122};
123
124/* Remember what we deduced to be the source language of this psymtab. */
125
126static enum language psymtab_language = language_unknown;
127
128\f
e38e0312
JG
129/* Simplified internal version of coff symbol table information */
130
131struct coff_symbol {
132 char *c_name;
133 int c_symnum; /* symbol number of this entry */
d4a0983a 134 int c_naux; /* 0 if syment only, 1 if syment + auxent */
e38e0312 135 long c_value;
ef5b809c 136 unsigned char c_sclass;
e38e0312
JG
137 int c_secnum;
138 unsigned int c_type;
139};
140
e38e0312
JG
141/* last function's saved coff symbol `cs' */
142
143static struct coff_symbol fcn_cs_saved;
144
145static bfd *symfile_bfd;
146
147/* Core address of start and end of text of current source file.
148 This is calculated from the first function seen after a C_FILE
149 symbol. */
150
818de002 151
e38e0312
JG
152static CORE_ADDR cur_src_end_addr;
153
154/* Core address of the end of the first object file. */
155
156static CORE_ADDR first_object_file_end;
157
e38e0312
JG
158/* initial symbol-table-debug-string vector length */
159
160#define INITIAL_STABVECTOR_LENGTH 40
161
e38e0312
JG
162/* Nonzero if within a function (so symbols should be local,
163 if nothing says specifically). */
164
165int within_function;
166
a367db89
JK
167/* Size of a COFF symbol. I think it is always 18, so I'm not sure
168 there is any reason not to just use a #define, but might as well
169 ask BFD for the size and store it here, I guess. */
e38e0312
JG
170
171static unsigned local_symesz;
172
e38e0312
JG
173struct coff_symfile_info {
174 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
175 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
a367db89
JK
176
177 /* Pointer to the string table. */
178 char *strtbl;
179
180 /* Pointer to debug section. */
181 char *debugsec;
182
183 /* Pointer to the a.out symbol table. */
184 char *symtbl;
185
186 /* Number of symbols in symtbl. */
187 int symtbl_num_syms;
e38e0312
JG
188};
189
dd469789
JG
190static struct complaint storclass_complaint =
191 {"Unexpected storage class: %d", 0, 0};
192
193static struct complaint bf_notfound_complaint =
194 {"line numbers off, `.bf' symbol not found", 0, 0};
e38e0312 195
df1e1074
PS
196static struct complaint ef_complaint =
197 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
198
199static struct complaint eb_complaint =
200 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
f8203ed0 201
6e0949ae
FF
202static void
203xcoff_initial_scan PARAMS ((struct objfile *, struct section_offsets *, int));
204
205static void
206scan_xcoff_symtab PARAMS ((struct section_offsets *, struct objfile *));
207
208static char *
209xcoff_next_symbol_text PARAMS ((struct objfile *));
210
211static void
212record_include_begin PARAMS ((struct coff_symbol *));
213
1ab3bf1b 214static void
818de002
PB
215enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
216 CORE_ADDR, CORE_ADDR, unsigned *));
1ab3bf1b 217
1ab3bf1b 218static void
d5931d79 219init_stringtab PARAMS ((bfd *, file_ptr, struct objfile *));
1ab3bf1b
JG
220
221static void
9b280a7f 222xcoff_symfile_init PARAMS ((struct objfile *));
80d68b1d
FF
223
224static void
9b280a7f 225xcoff_new_init PARAMS ((struct objfile *));
80d68b1d 226
1ab3bf1b 227static void
9b280a7f 228xcoff_symfile_finish PARAMS ((struct objfile *));
1ab3bf1b 229
fe0b60b2 230static struct section_offsets *
9b280a7f 231xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
2670f34d 232
1ab3bf1b
JG
233static void
234find_linenos PARAMS ((bfd *, sec_ptr, PTR));
235
e8abe489 236static char *
a367db89 237coff_getfilename PARAMS ((union internal_auxent *, struct objfile *));
e8abe489 238
3c02636b
JK
239static void
240read_symbol PARAMS ((struct internal_syment *, int));
241
1ab3bf1b 242static int
c84a96d7 243read_symbol_lineno PARAMS ((int));
1ab3bf1b
JG
244
245static int
c84a96d7 246read_symbol_nvalue PARAMS ((int));
1ab3bf1b
JG
247
248static struct symbol *
249process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
250
251static void
a367db89 252read_xcoff_symtab PARAMS ((struct partial_symtab *));
1ab3bf1b 253
6e0949ae 254#if 0
1ab3bf1b
JG
255static void
256add_stab_to_list PARAMS ((char *, struct pending_stabs **));
6e0949ae
FF
257#endif
258
259static int
260compare_lte PARAMS ((const void *, const void *));
261
262static struct linetable *
263arrange_linetable PARAMS ((struct linetable *));
264
265static void
266record_include_end PARAMS ((struct coff_symbol *));
267
268static void
269process_linenos PARAMS ((CORE_ADDR, CORE_ADDR));
1ab3bf1b 270
a81ce07d 271\f
a367db89
JK
272/* Translate from a COFF section number (target_index) to a SECT_OFF_*
273 code. */
274static int secnum_to_section PARAMS ((int, struct objfile *));
211b564e 275static asection * secnum_to_bfd_section PARAMS ((int, struct objfile *));
a81ce07d
JK
276
277struct find_targ_sec_arg {
278 int targ_index;
279 int *resultp;
211b564e 280 asection **bfd_sect;
a81ce07d
JK
281};
282
283static void find_targ_sec PARAMS ((bfd *, asection *, void *));
284
285static void find_targ_sec (abfd, sect, obj)
286 bfd *abfd;
287 asection *sect;
288 PTR obj;
289{
290 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
291 if (sect->target_index == args->targ_index)
292 {
293 /* This is the section. Figure out what SECT_OFF_* code it is. */
294 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
295 *args->resultp = SECT_OFF_TEXT;
296 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
297 *args->resultp = SECT_OFF_DATA;
298 else
299 *args->resultp = SECT_OFF_BSS;
211b564e 300 *args->bfd_sect = sect;
a81ce07d
JK
301 }
302}
303
304/* Return the section number (SECT_OFF_*) that CS points to. */
305static int
a367db89
JK
306secnum_to_section (secnum, objfile)
307 int secnum;
a81ce07d
JK
308 struct objfile *objfile;
309{
310 int off = SECT_OFF_TEXT;
211b564e 311 asection *sect = NULL;
a81ce07d 312 struct find_targ_sec_arg args;
a367db89 313 args.targ_index = secnum;
a81ce07d 314 args.resultp = &off;
211b564e 315 args.bfd_sect = &sect;
a81ce07d
JK
316 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
317 return off;
318}
211b564e
PS
319
320/* Return the BFD section that CS points to. */
321static asection *
322secnum_to_bfd_section (secnum, objfile)
323 int secnum;
324 struct objfile *objfile;
325{
326 int off = SECT_OFF_TEXT;
327 asection *sect = NULL;
328 struct find_targ_sec_arg args;
329 args.targ_index = secnum;
330 args.resultp = &off;
331 args.bfd_sect = &sect;
332 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
333 return sect;
334}
a81ce07d 335\f
e38e0312
JG
336/* add a given stab string into given stab vector. */
337
6e0949ae
FF
338#if 0
339
e38e0312
JG
340static void
341add_stab_to_list (stabname, stabvector)
342char *stabname;
343struct pending_stabs **stabvector;
344{
345 if ( *stabvector == NULL) {
346 *stabvector = (struct pending_stabs *)
347 xmalloc (sizeof (struct pending_stabs) +
348 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
349 (*stabvector)->count = 0;
350 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
351 }
352 else if ((*stabvector)->count >= (*stabvector)->length) {
353 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
354 *stabvector = (struct pending_stabs *)
1ab3bf1b 355 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
e38e0312
JG
356 (*stabvector)->length * sizeof (char*));
357 }
358 (*stabvector)->stab [(*stabvector)->count++] = stabname;
359}
6e0949ae
FF
360
361#endif
362
194d98c6
JK
363\f
364/* Linenos are processed on a file-by-file basis.
365
366 Two reasons:
367
368 1) xlc (IBM's native c compiler) postpones static function code
369 emission to the end of a compilation unit. This way it can
370 determine if those functions (statics) are needed or not, and
371 can do some garbage collection (I think). This makes line
372 numbers and corresponding addresses unordered, and we end up
373 with a line table like:
374
375
376 lineno addr
377 foo() 10 0x100
378 20 0x200
379 30 0x300
380
381 foo3() 70 0x400
382 80 0x500
383 90 0x600
384
385 static foo2()
386 40 0x700
387 50 0x800
388 60 0x900
389
390 and that breaks gdb's binary search on line numbers, if the
391 above table is not sorted on line numbers. And that sort
392 should be on function based, since gcc can emit line numbers
393 like:
394
395 10 0x100 - for the init/test part of a for stmt.
396 20 0x200
397 30 0x300
398 10 0x400 - for the increment part of a for stmt.
e38e0312 399
194d98c6 400 arrange_linetable() will do this sorting.
e38e0312 401
194d98c6 402 2) aix symbol table might look like:
818de002 403
194d98c6
JK
404 c_file // beginning of a new file
405 .bi // beginning of include file
406 .ei // end of include file
407 .bi
408 .ei
818de002 409
194d98c6
JK
410 basically, .bi/.ei pairs do not necessarily encapsulate
411 their scope. They need to be recorded, and processed later
412 on when we come the end of the compilation unit.
413 Include table (inclTable) and process_linenos() handle
414 that. */
818de002
PB
415
416/* compare line table entry addresses. */
417
194d98c6 418static int
6e0949ae
FF
419compare_lte (lte1p, lte2p)
420 const void *lte1p;
421 const void *lte2p;
818de002 422{
6e0949ae
FF
423 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
424 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
818de002
PB
425 return lte1->pc - lte2->pc;
426}
427
3f37b696
FF
428/* Given a line table with function entries are marked, arrange its functions
429 in ascending order and strip off function entry markers and return it in
818de002 430 a newly created table. If the old one is good enough, return the old one. */
c438b3af
JK
431/* FIXME: I think all this stuff can be replaced by just passing
432 sort_linevec = 1 to end_symtab. */
818de002
PB
433
434static struct linetable *
435arrange_linetable (oldLineTb)
a367db89 436 struct linetable *oldLineTb; /* old linetable */
818de002
PB
437{
438 int ii, jj,
439 newline, /* new line count */
440 function_count; /* # of functions */
441
442 struct linetable_entry *fentry; /* function entry vector */
443 int fentry_size; /* # of function entries */
444 struct linetable *newLineTb; /* new line table */
445
446#define NUM_OF_FUNCTIONS 20
447
448 fentry_size = NUM_OF_FUNCTIONS;
449 fentry = (struct linetable_entry*)
ecfd2b60 450 xmalloc (fentry_size * sizeof (struct linetable_entry));
818de002
PB
451
452 for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {
453
454 if (oldLineTb->item[ii].line == 0) { /* function entry found. */
455
456 if (function_count >= fentry_size) { /* make sure you have room. */
457 fentry_size *= 2;
458 fentry = (struct linetable_entry*)
ecfd2b60 459 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
818de002
PB
460 }
461 fentry[function_count].line = ii;
462 fentry[function_count].pc = oldLineTb->item[ii].pc;
463 ++function_count;
464 }
465 }
466
467 if (function_count == 0) {
468 free (fentry);
469 return oldLineTb;
470 }
471 else if (function_count > 1)
472 qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);
473
474 /* allocate a new line table. */
ecfd2b60
JK
475 newLineTb = (struct linetable *)
476 xmalloc
477 (sizeof (struct linetable) +
478 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
818de002
PB
479
480 /* if line table does not start with a function beginning, copy up until
481 a function begin. */
482
483 newline = 0;
484 if (oldLineTb->item[0].line != 0)
485 for (newline=0;
486 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
487 newLineTb->item[newline] = oldLineTb->item[newline];
488
489 /* Now copy function lines one by one. */
490
491 for (ii=0; ii < function_count; ++ii) {
492 for (jj = fentry[ii].line + 1;
493 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
494 ++jj, ++newline)
495 newLineTb->item[newline] = oldLineTb->item[jj];
496 }
497 free (fentry);
498 newLineTb->nitems = oldLineTb->nitems - function_count;
499 return newLineTb;
500}
501
818de002
PB
502/* include file support: C_BINCL/C_EINCL pairs will be kept in the
503 following `IncludeChain'. At the end of each symtab (end_symtab),
504 we will determine if we should create additional symtab's to
505 represent if (the include files. */
506
507
508typedef struct _inclTable {
509 char *name; /* include filename */
2aefe6e4
JK
510
511 /* Offsets to the line table. end points to the last entry which is
512 part of this include file. */
513 int begin, end;
514
818de002
PB
515 struct subfile *subfile;
516 unsigned funStartLine; /* start line # of its function */
517} InclTable;
518
519#define INITIAL_INCLUDE_TABLE_LENGTH 20
520static InclTable *inclTable; /* global include table */
521static int inclIndx; /* last entry to table */
522static int inclLength; /* table length */
523static int inclDepth; /* nested include depth */
524
7f4c8595 525static void allocate_include_entry PARAMS ((void));
818de002
PB
526
527static void
528record_include_begin (cs)
529struct coff_symbol *cs;
530{
818de002 531 if (inclDepth)
486b440e
JK
532 {
533 /* In xcoff, we assume include files cannot be nested (not in .c files
534 of course, but in corresponding .s files.). */
535
67240bb8
JK
536 /* This can happen with old versions of GCC.
537 GCC 2.3.3-930426 does not exhibit this on a test case which
538 a user said produced the message for him. */
b646b438 539 static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
486b440e
JK
540 complain (&msg);
541 }
818de002
PB
542 ++inclDepth;
543
7f4c8595 544 allocate_include_entry ();
818de002
PB
545
546 inclTable [inclIndx].name = cs->c_name;
547 inclTable [inclIndx].begin = cs->c_value;
548}
549
818de002
PB
550static void
551record_include_end (cs)
552struct coff_symbol *cs;
553{
554 InclTable *pTbl;
555
556 if (inclDepth == 0)
486b440e 557 {
b646b438 558 static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
486b440e
JK
559 complain (&msg);
560 }
818de002 561
7f4c8595
SS
562 allocate_include_entry ();
563
818de002
PB
564 pTbl = &inclTable [inclIndx];
565 pTbl->end = cs->c_value;
566
567 --inclDepth;
568 ++inclIndx;
569}
570
7f4c8595
SS
571static void
572allocate_include_entry ()
573{
574 if (inclTable == NULL)
575 {
576 inclTable = (InclTable *)
577 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
578 memset (inclTable,
579 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
580 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
581 inclIndx = 0;
582 }
583 else if (inclIndx >= inclLength)
584 {
585 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
586 inclTable = (InclTable *)
587 xrealloc (inclTable, sizeof (InclTable) * inclLength);
588 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
589 '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
590 }
591}
818de002 592
a367db89
JK
593/* Global variable to pass the psymtab down to all the routines involved
594 in psymtab to symtab processing. */
595static struct partial_symtab *this_symtab_psymtab;
596
7f4c8595
SS
597/* given the start and end addresses of a compilation unit (or a csect,
598 at times) process its lines and create appropriate line vectors. */
818de002
PB
599
600static void
601process_linenos (start, end)
a367db89 602 CORE_ADDR start, end;
818de002 603{
818de002 604 int offset, ii;
a367db89
JK
605 file_ptr max_offset =
606 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
607 ->max_lineno_offset;
818de002 608
5cba5d26
JK
609 /* subfile structure for the main compilation unit. */
610 struct subfile main_subfile;
818de002 611
5cba5d26
JK
612 /* In the main source file, any time we see a function entry, we
613 reset this variable to function's absolute starting line number.
614 All the following line numbers in the function are relative to
615 this, and we record absolute line numbers in record_line(). */
818de002 616
df1e1074 617 unsigned int main_source_baseline = 0;
818de002 618
818de002 619 unsigned *firstLine;
818de002 620
a367db89
JK
621 offset =
622 ((struct symloc *)this_symtab_psymtab->read_symtab_private)->lineno_off;
623 if (offset == 0)
818de002
PB
624 goto return_after_cleanup;
625
4ed97c9a 626 memset (&main_subfile, '\0', sizeof (main_subfile));
818de002
PB
627
628 if (inclIndx == 0)
556f3d90
PB
629 /* All source lines were in the main source file. None in include files. */
630
818de002
PB
631 enter_line_range (&main_subfile, offset, 0, start, end,
632 &main_source_baseline);
633
5cba5d26
JK
634 else
635 {
636 /* There was source with line numbers in include files. */
637 main_source_baseline = 0;
638 for (ii=0; ii < inclIndx; ++ii)
639 {
640 struct subfile *tmpSubfile;
818de002 641
5cba5d26
JK
642 /* If there is main file source before include file, enter it. */
643 if (offset < inclTable[ii].begin)
644 {
645 enter_line_range
646 (&main_subfile, offset, inclTable[ii].begin - LINESZ,
647 start, 0, &main_source_baseline);
648 }
818de002 649
5cba5d26 650 /* Have a new subfile for the include file. */
818de002 651
5cba5d26
JK
652 tmpSubfile = inclTable[ii].subfile =
653 (struct subfile *) xmalloc (sizeof (struct subfile));
818de002 654
5cba5d26
JK
655 memset (tmpSubfile, '\0', sizeof (struct subfile));
656 firstLine = &(inclTable[ii].funStartLine);
818de002 657
5cba5d26
JK
658 /* Enter include file's lines now. */
659 enter_line_range (tmpSubfile, inclTable[ii].begin,
660 inclTable[ii].end, start, 0, firstLine);
818de002 661
d2fee216 662 if (offset <= inclTable[ii].end)
fc564b18 663 offset = inclTable[ii].end + LINESZ;
5cba5d26 664 }
818de002 665
5cba5d26
JK
666 /* All the include files' line have been processed at this point. Now,
667 enter remaining lines of the main file, if any left. */
a367db89 668 if (offset < max_offset + 1 - LINESZ)
5cba5d26
JK
669 {
670 enter_line_range (&main_subfile, offset, 0, start, end,
671 &main_source_baseline);
672 }
818de002
PB
673 }
674
5cba5d26
JK
675 /* Process main file's line numbers. */
676 if (main_subfile.line_vector)
677 {
678 struct linetable *lineTb, *lv;
818de002 679
5cba5d26 680 lv = main_subfile.line_vector;
818de002 681
5cba5d26
JK
682 /* Line numbers are not necessarily ordered. xlc compilation will
683 put static function to the end. */
818de002 684
5cba5d26
JK
685 lineTb = arrange_linetable (lv);
686 if (lv == lineTb)
687 {
688 current_subfile->line_vector = (struct linetable *)
689 xrealloc (lv, (sizeof (struct linetable)
690 + lv->nitems * sizeof (struct linetable_entry)));
691 }
692 else
693 {
694 free (lv);
695 current_subfile->line_vector = lineTb;
696 }
818de002 697
5cba5d26
JK
698 current_subfile->line_vector_length =
699 current_subfile->line_vector->nitems;
818de002 700 }
818de002 701
5cba5d26 702 /* Now, process included files' line numbers. */
818de002 703
5cba5d26
JK
704 for (ii=0; ii < inclIndx; ++ii)
705 {
706 if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */
707 {
708 struct linetable *lineTb, *lv;
818de002 709
5cba5d26 710 lv = (inclTable[ii].subfile)->line_vector;
818de002 711
5cba5d26
JK
712 /* Line numbers are not necessarily ordered. xlc compilation will
713 put static function to the end. */
818de002 714
5cba5d26 715 lineTb = arrange_linetable (lv);
818de002 716
5cba5d26 717 push_subfile ();
818de002 718
5cba5d26
JK
719 /* For the same include file, we might want to have more than one
720 subfile. This happens if we have something like:
818de002 721
818de002
PB
722 ......
723 #include "foo.h"
724 ......
725 #include "foo.h"
726 ......
727
5cba5d26
JK
728 while foo.h including code in it. (stupid but possible)
729 Since start_subfile() looks at the name and uses an
730 existing one if finds, we need to provide a fake name and
731 fool it. */
732
733#if 0
734 start_subfile (inclTable[ii].name, (char*)0);
735#else
736 {
737 /* Pick a fake name that will produce the same results as this
738 one when passed to deduce_language_from_filename. Kludge on
739 top of kludge. */
740 char *fakename = strrchr (inclTable[ii].name, '.');
741 if (fakename == NULL)
742 fakename = " ?";
743 start_subfile (fakename, (char*)0);
744 free (current_subfile->name);
745 }
746 current_subfile->name = strdup (inclTable[ii].name);
747#endif
818de002 748
5cba5d26
JK
749 if (lv == lineTb)
750 {
751 current_subfile->line_vector =
752 (struct linetable *) xrealloc
753 (lv, (sizeof (struct linetable)
818de002
PB
754 + lv->nitems * sizeof (struct linetable_entry)));
755
5cba5d26
JK
756 }
757 else
758 {
759 free (lv);
760 current_subfile->line_vector = lineTb;
761 }
818de002 762
5cba5d26
JK
763 current_subfile->line_vector_length =
764 current_subfile->line_vector->nitems;
765 start_subfile (pop_subfile (), (char*)0);
766 }
818de002 767 }
818de002 768
5cba5d26 769 return_after_cleanup:
818de002 770
5cba5d26 771 /* We don't want to keep alloc/free'ing the global include file table. */
818de002
PB
772 inclIndx = 0;
773
5cba5d26 774 /* Start with a fresh subfile structure for the next file. */
4ed97c9a 775 memset (&main_subfile, '\0', sizeof (struct subfile));
818de002
PB
776}
777
778void
779aix_process_linenos ()
780{
781 /* process line numbers and enter them into line vector */
782 process_linenos (last_source_start_addr, cur_src_end_addr);
783}
784
785
e38e0312
JG
786/* Enter a given range of lines into the line vector.
787 can be called in the following two ways:
818de002 788 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
2aefe6e4
JK
789 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
790
791 endoffset points to the last line table entry that we should pay
792 attention to. */
e38e0312
JG
793
794static void
a367db89
JK
795enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr,
796 firstLine)
797 struct subfile *subfile;
798 unsigned beginoffset, endoffset; /* offsets to line table */
799 CORE_ADDR startaddr, endaddr;
800 unsigned *firstLine;
e38e0312 801{
a367db89
JK
802 unsigned int curoffset;
803 CORE_ADDR addr;
804 struct external_lineno ext_lnno;
805 struct internal_lineno int_lnno;
806 unsigned int limit_offset;
807 bfd *abfd;
818de002 808
a367db89
JK
809 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
810 return;
811 curoffset = beginoffset;
812 limit_offset =
813 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
814 ->max_lineno_offset;
e38e0312 815
a367db89 816 if (endoffset != 0)
2aefe6e4 817 {
a367db89
JK
818 if (endoffset >= limit_offset)
819 {
820 static struct complaint msg =
821 {"Bad line table offset in C_EINCL directive", 0, 0};
822 complain (&msg);
823 return;
824 }
825 limit_offset = endoffset;
2aefe6e4 826 }
a367db89
JK
827 else
828 limit_offset -= 1;
829 abfd = this_symtab_psymtab->objfile->obfd;
e38e0312 830
a367db89
JK
831 while (curoffset <= limit_offset)
832 {
833 bfd_seek (abfd, curoffset, SEEK_SET);
834 bfd_read (&ext_lnno, sizeof (struct external_lineno), 1, abfd);
835 bfd_coff_swap_lineno_in (abfd, &ext_lnno, &int_lnno);
e38e0312 836
a367db89
JK
837 /* Find the address this line represents. */
838 addr = (int_lnno.l_lnno
839 ? int_lnno.l_addr.l_paddr
840 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
841 addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
842 SECT_OFF_TEXT);
e38e0312 843
a367db89
JK
844 if (addr < startaddr || (endaddr && addr >= endaddr))
845 return;
e38e0312 846
a367db89
JK
847 if (int_lnno.l_lnno == 0)
848 {
849 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
850 record_line (subfile, 0, addr);
851 --(*firstLine);
852 }
853 else
854 record_line (subfile, *firstLine + int_lnno.l_lnno, addr);
855 curoffset += LINESZ;
e38e0312 856 }
818de002
PB
857}
858
818de002 859
e38e0312
JG
860/* Save the vital information for use when closing off the current file.
861 NAME is the file name the symbols came from, START_ADDR is the first
862 text address for the file, and SIZE is the number of bytes of text. */
863
864#define complete_symtab(name, start_addr) { \
865 last_source_file = savestring (name, strlen (name)); \
818de002 866 last_source_start_addr = start_addr; \
e38e0312
JG
867}
868
869
870/* Refill the symbol table input buffer
871 and set the variables that control fetching entries from it.
872 Reports an error if no data available.
873 This function can read past the end of the symbol table
874 (into the string table) but this does no harm. */
875
876/* Reading symbol table has to be fast! Keep the followings as macros, rather
877 than functions. */
878
a367db89 879#define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
e38e0312
JG
880{ \
881 char *namestr; \
a81ce07d
JK
882 namestr = (NAME); \
883 if (namestr[0] == '.') ++namestr; \
3c02636b 884 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
86fdcdaf 885 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
818de002 886 misc_func_recorded = 1; \
e38e0312
JG
887}
888
889
9b280a7f 890/* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
e38e0312
JG
891 nested. At any given time, a symbol can only be in one static block.
892 This is the base address of current static block, zero if non exists. */
893
894static int static_block_base = 0;
895
3c02636b
JK
896/* Section number for the current static block. */
897
898static int static_block_section = -1;
899
e38e0312
JG
900/* true if space for symbol name has been allocated. */
901
902static int symname_alloced = 0;
903
34d265dc
JK
904/* Next symbol to read. Pointer into raw seething symbol table. */
905
906static char *raw_symbol;
907
908/* This is the function which stabsread.c calls to get symbol
909 continuations. */
6e0949ae 910
34d265dc 911static char *
2dd30c72
FF
912xcoff_next_symbol_text (objfile)
913 struct objfile *objfile;
34d265dc
JK
914{
915 struct internal_syment symbol;
916 static struct complaint msg =
917 {"Unexpected symbol continuation", 0, 0};
963dbabe 918 char *retval;
2dd30c72
FF
919 /* FIXME: is this the same as the passed arg? */
920 objfile = this_symtab_psymtab->objfile;
34d265dc 921
a367db89 922 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
afbdbbd7 923 if (symbol.n_zeroes)
963dbabe
JK
924 {
925 complain (&msg);
926
927 /* Return something which points to '\0' and hope the symbol reading
928 code does something reasonable. */
929 retval = "";
930 }
afbdbbd7 931 else if (symbol.n_sclass & 0x80)
963dbabe 932 {
a367db89
JK
933 retval =
934 ((struct coff_symfile_info *)objfile->sym_private)->debugsec
935 + symbol.n_offset;
936 raw_symbol +=
937 coff_data (objfile->obfd)->local_symesz;
963dbabe
JK
938 ++symnum;
939 }
34d265dc 940 else
963dbabe
JK
941 {
942 complain (&msg);
943
944 /* Return something which points to '\0' and hope the symbol reading
945 code does something reasonable. */
946 retval = "";
947 }
948 return retval;
34d265dc
JK
949}
950
a367db89 951/* Read symbols for a given partial symbol table. */
e38e0312 952
1ab3bf1b 953static void
a367db89
JK
954read_xcoff_symtab (pst)
955 struct partial_symtab *pst;
e38e0312 956{
a367db89 957 struct objfile *objfile = pst->objfile;
e38e0312 958 bfd *abfd = objfile->obfd;
e38e0312 959 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
a367db89
JK
960 char *strtbl = ((struct coff_symfile_info *)objfile->sym_private)->strtbl;
961 char *debugsec =
962 ((struct coff_symfile_info *)objfile->sym_private)->debugsec;
818de002 963
e38e0312 964 struct internal_syment symbol[1];
6657a0c7 965 union internal_auxent main_aux;
e38e0312
JG
966 struct coff_symbol cs[1];
967 CORE_ADDR file_start_addr = 0;
968 CORE_ADDR file_end_addr = 0;
969
970 int next_file_symnum = -1;
a367db89 971 unsigned int max_symnum;
e38e0312
JG
972 int just_started = 1;
973 int depth = 0;
df1e1074 974 int fcn_start_addr = 0;
e38e0312 975
1eeba686
PB
976 struct coff_symbol fcn_stab_saved;
977
e38e0312
JG
978 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
979 union internal_auxent fcn_aux_saved;
980 struct context_stack *new;
981
982 char *filestring = " _start_ "; /* Name of the current file. */
818de002
PB
983
984 char *last_csect_name; /* last seen csect's name and value */
985 CORE_ADDR last_csect_val;
3c02636b 986 int last_csect_sec;
e38e0312 987
a367db89 988 this_symtab_psymtab = pst;
1ab3bf1b 989
a81ce07d
JK
990 /* Get the appropriate COFF "constants" related to the file we're
991 handling. */
e38e0312
JG
992 local_symesz = coff_data (abfd)->local_symesz;
993
d07734e3 994 last_source_file = NULL;
818de002
PB
995 last_csect_name = 0;
996 last_csect_val = 0;
e38e0312 997
d07734e3 998 start_stabs ();
e38e0312 999 start_symtab (filestring, (char *)NULL, file_start_addr);
609fd033 1000 record_debugformat ("XCOFF");
a367db89
JK
1001 symnum = ((struct symloc *)pst->read_symtab_private)->first_symnum;
1002 max_symnum =
1003 symnum + ((struct symloc *)pst->read_symtab_private)->numsyms;
e38e0312
JG
1004 first_object_file_end = 0;
1005
a367db89
JK
1006 raw_symbol =
1007 ((struct coff_symfile_info *) objfile->sym_private)->symtbl
1008 + symnum * local_symesz;
34d265dc 1009
a367db89 1010 while (symnum < max_symnum)
a81ce07d 1011 {
e38e0312 1012
a81ce07d 1013 QUIT; /* make this command interruptable. */
e38e0312 1014
a81ce07d
JK
1015 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1016 /* read one symbol into `cs' structure. After processing the
1017 whole symbol table, only string table will be kept in memory,
1018 symbol table and debug section of xcoff will be freed. Thus
1019 we can mark symbols with names in string table as
1020 `alloced'. */
1021 {
1022 int ii;
1023
1024 /* Swap and align the symbol into a reasonable C structure. */
1025 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1026
1027 cs->c_symnum = symnum;
1028 cs->c_naux = symbol->n_numaux;
1029 if (symbol->n_zeroes)
786757a9 1030 {
a81ce07d
JK
1031 symname_alloced = 0;
1032 /* We must use the original, unswapped, name here so the name field
1033 pointed to by cs->c_name will persist throughout xcoffread. If
1034 we use the new field, it gets overwritten for each symbol. */
1035 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
1036 /* If it's exactly E_SYMNMLEN characters long it isn't
1037 '\0'-terminated. */
1038 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1039 {
1040 char *p;
1041 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
1042 strncpy (p, cs->c_name, E_SYMNMLEN);
1043 p[E_SYMNMLEN] = '\0';
1044 cs->c_name = p;
1045 symname_alloced = 1;
1046 }
1047 }
1048 else if (symbol->n_sclass & 0x80)
1049 {
1050 cs->c_name = debugsec + symbol->n_offset;
1051 symname_alloced = 0;
1052 }
1053 else
1054 {
1055 /* in string table */
1056 cs->c_name = strtbl + (int)symbol->n_offset;
786757a9
JK
1057 symname_alloced = 1;
1058 }
a81ce07d
JK
1059 cs->c_value = symbol->n_value;
1060 cs->c_sclass = symbol->n_sclass;
1061 cs->c_secnum = symbol->n_scnum;
1062 cs->c_type = (unsigned)symbol->n_type;
e38e0312 1063
a81ce07d
JK
1064 raw_symbol += coff_data (abfd)->local_symesz;
1065 ++symnum;
e38e0312 1066
a81ce07d
JK
1067 /* Save addr of first aux entry. */
1068 raw_auxptr = raw_symbol;
e38e0312 1069
a81ce07d
JK
1070 /* Skip all the auxents associated with this symbol. */
1071 for (ii = symbol->n_numaux; ii; --ii)
1072 {
1073 raw_symbol += coff_data (abfd)->local_auxesz;
1074 ++symnum;
1075 }
e38e0312 1076 }
e38e0312 1077
a81ce07d
JK
1078 /* if symbol name starts with ".$" or "$", ignore it. */
1079 if (cs->c_name[0] == '$'
1080 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1081 continue;
e38e0312 1082
a81ce07d 1083 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
d07734e3 1084 {
a81ce07d
JK
1085 if (last_source_file)
1086 {
a367db89 1087 pst->symtab =
436d4143 1088 end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT);
a81ce07d
JK
1089 end_stabs ();
1090 }
e38e0312 1091
a81ce07d
JK
1092 start_stabs ();
1093 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
609fd033 1094 record_debugformat ("XCOFF");
a81ce07d
JK
1095 cur_src_end_addr = first_object_file_end;
1096 /* done with all files, everything from here on is globals */
1097 }
e38e0312 1098
a81ce07d
JK
1099 /* if explicitly specified as a function, treat is as one. */
1100 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF)
1101 {
1102 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1103 0, cs->c_naux, &main_aux);
1104 goto function_entry_point;
1105 }
e38e0312 1106
a81ce07d
JK
1107 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1108 && cs->c_naux == 1)
1109 {
1110 /* Dealing with a symbol with a csect entry. */
e38e0312 1111
a81ce07d
JK
1112#define CSECT(PP) ((PP)->x_csect)
1113#define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1114#define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1115#define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1116#define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
e38e0312 1117
a81ce07d
JK
1118 /* Convert the auxent to something we can access. */
1119 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1120 0, cs->c_naux, &main_aux);
e38e0312 1121
a81ce07d
JK
1122 switch (CSECT_SMTYP (&main_aux))
1123 {
e38e0312 1124
a81ce07d
JK
1125 case XTY_ER:
1126 /* Ignore all external references. */
1127 continue;
e38e0312 1128
a81ce07d
JK
1129 case XTY_SD:
1130 /* A section description. */
e38e0312 1131 {
a81ce07d
JK
1132 switch (CSECT_SCLAS (&main_aux))
1133 {
1134
1135 case XMC_PR:
1136 {
1137
1138 /* A program csect is seen. We have to allocate one
1139 symbol table for each program csect. Normally gdb
1140 prefers one symtab for each source file. In case
1141 of AIX, one source file might include more than one
1142 [PR] csect, and they don't have to be adjacent in
1143 terms of the space they occupy in memory. Thus, one
1144 single source file might get fragmented in the
1145 memory and gdb's file start and end address
1146 approach does not work! GCC (and I think xlc) seem
1147 to put all the code in the unnamed program csect. */
1148
1149 if (last_csect_name)
1150 {
a81ce07d
JK
1151 complete_symtab (filestring, file_start_addr);
1152 cur_src_end_addr = file_end_addr;
436d4143 1153 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
a81ce07d
JK
1154 end_stabs ();
1155 start_stabs ();
1156 /* Give all csects for this source file the same
1157 name. */
1158 start_symtab (filestring, NULL, (CORE_ADDR)0);
609fd033 1159 record_debugformat ("XCOFF");
a81ce07d
JK
1160 }
1161
1162 /* If this is the very first csect seen,
1163 basically `__start'. */
1164 if (just_started)
1165 {
1166 first_object_file_end
1167 = cs->c_value + CSECT_LEN (&main_aux);
1168 just_started = 0;
1169 }
1170
a367db89
JK
1171 file_start_addr =
1172 cs->c_value + ANOFFSET (objfile->section_offsets,
1173 SECT_OFF_TEXT);
1174 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
a81ce07d
JK
1175
1176 if (cs->c_name && cs->c_name[0] == '.')
1177 {
1178 last_csect_name = cs->c_name;
1179 last_csect_val = cs->c_value;
a367db89 1180 last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
a81ce07d
JK
1181 }
1182 }
a81ce07d
JK
1183 continue;
1184
df1e1074
PS
1185 /* All other symbols are put into the minimal symbol
1186 table only. */
a81ce07d 1187
df1e1074
PS
1188 case XMC_RW:
1189 continue;
a81ce07d
JK
1190
1191 case XMC_TC0:
a81ce07d
JK
1192 continue;
1193
1194 case XMC_TC:
a367db89 1195 continue;
e38e0312 1196
a81ce07d
JK
1197 default:
1198 /* Ignore the symbol. */
1199 continue;
818de002 1200 }
e38e0312 1201 }
e38e0312
JG
1202 break;
1203
a81ce07d
JK
1204 case XTY_LD:
1205
1206 switch (CSECT_SCLAS (&main_aux))
1207 {
1208 case XMC_PR:
1209 /* a function entry point. */
1210 function_entry_point:
a81ce07d 1211
a81ce07d
JK
1212 fcn_start_addr = cs->c_value;
1213
1214 /* save the function header info, which will be used
1215 when `.bf' is seen. */
1216 fcn_cs_saved = *cs;
1217 fcn_aux_saved = main_aux;
a81ce07d
JK
1218 continue;
1219
1220 case XMC_GL:
1221 /* shared library function trampoline code entry point. */
a81ce07d
JK
1222 continue;
1223
1224 case XMC_DS:
1225 /* The symbols often have the same names as debug symbols for
1226 functions, and confuse lookup_symbol. */
1227 continue;
1228
1229 default:
1230 /* xlc puts each variable in a separate csect, so we get
1231 an XTY_SD for each variable. But gcc puts several
1232 variables in a csect, so that each variable only gets
df1e1074
PS
1233 an XTY_LD. This will typically be XMC_RW; I suspect
1234 XMC_RO and XMC_BS might be possible too.
1235 These variables are put in the minimal symbol table
1236 only. */
1237 continue;
a81ce07d 1238 }
df1e1074
PS
1239 break;
1240
1241 case XTY_CM:
1242 /* Common symbols are put into the minimal symbol table only. */
1243 continue;
e38e0312 1244
a81ce07d
JK
1245 default:
1246 break;
e38e0312 1247 }
a81ce07d 1248 }
e38e0312 1249
a81ce07d
JK
1250 switch (cs->c_sclass)
1251 {
e38e0312 1252
a81ce07d 1253 case C_FILE:
818de002 1254
a81ce07d
JK
1255 /* c_value field contains symnum of next .file entry in table
1256 or symnum of first global after last .file. */
818de002 1257
a81ce07d 1258 next_file_symnum = cs->c_value;
818de002 1259
a81ce07d
JK
1260 /* Complete symbol table for last object file containing
1261 debugging information. */
818de002 1262
a81ce07d
JK
1263 /* Whether or not there was a csect in the previous file, we
1264 have to call `end_stabs' and `start_stabs' to reset
1265 type_vector, line_vector, etc. structures. */
818de002 1266
a81ce07d
JK
1267 complete_symtab (filestring, file_start_addr);
1268 cur_src_end_addr = file_end_addr;
436d4143 1269 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
a81ce07d 1270 end_stabs ();
818de002 1271
a81ce07d
JK
1272 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1273 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1274 standard COFF way and put it in the auxent. We use the auxent if
1275 the symbol is ".file" and an auxent exists, otherwise use the symbol
1276 itself. Simple enough. */
1277 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1278 {
1279 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1280 0, cs->c_naux, &main_aux);
a367db89 1281 filestring = coff_getfilename (&main_aux, objfile);
818de002 1282 }
a81ce07d
JK
1283 else
1284 filestring = cs->c_name;
d4cedfe4 1285
a81ce07d
JK
1286 start_stabs ();
1287 start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
609fd033 1288 record_debugformat ("XCOFF");
a81ce07d 1289 last_csect_name = 0;
507e4004 1290
a81ce07d
JK
1291 /* reset file start and end addresses. A compilation unit with no text
1292 (only data) should have zero file boundaries. */
1293 file_start_addr = file_end_addr = 0;
e38e0312 1294 break;
e38e0312 1295
a81ce07d
JK
1296 case C_FUN:
1297 fcn_stab_saved = *cs;
1298 break;
e38e0312 1299
a81ce07d
JK
1300 case C_FCN:
1301 if (STREQ (cs->c_name, ".bf"))
1302 {
a367db89
JK
1303 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1304 SECT_OFF_TEXT);
a81ce07d
JK
1305 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1306 0, cs->c_naux, &main_aux);
818de002 1307
a81ce07d 1308 within_function = 1;
818de002 1309
a367db89 1310 new = push_context (0, fcn_start_addr + off);
e38e0312 1311
a81ce07d 1312 new->name = define_symbol
a367db89
JK
1313 (fcn_cs_saved.c_value + off,
1314 fcn_stab_saved.c_name, 0, 0, objfile);
a81ce07d 1315 if (new->name != NULL)
a367db89 1316 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT;
a81ce07d
JK
1317 }
1318 else if (STREQ (cs->c_name, ".ef"))
1319 {
e38e0312 1320
a81ce07d
JK
1321 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1322 0, cs->c_naux, &main_aux);
1323
1324 /* The value of .ef is the address of epilogue code;
1325 not useful for gdb. */
1326 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1327 contains number of lines to '}' */
1328
df1e1074
PS
1329 if (context_stack_depth <= 0)
1330 { /* We attempted to pop an empty context stack */
1331 complain (&ef_complaint, cs->c_symnum);
1332 within_function = 0;
1333 break;
1334 }
a81ce07d 1335 new = pop_context ();
f8203ed0
JK
1336 /* Stack must be empty now. */
1337 if (context_stack_depth > 0 || new == NULL)
1338 {
1339 complain (&ef_complaint, cs->c_symnum);
1340 within_function = 0;
1341 break;
1342 }
a81ce07d
JK
1343
1344 finish_block (new->name, &local_symbols, new->old_blocks,
1345 new->start_addr,
a367db89
JK
1346 (fcn_cs_saved.c_value
1347 + fcn_aux_saved.x_sym.x_misc.x_fsize
1348 + ANOFFSET (objfile->section_offsets,
1349 SECT_OFF_TEXT)),
1350 objfile);
a81ce07d
JK
1351 within_function = 0;
1352 }
1353 break;
818de002 1354
a81ce07d
JK
1355 case C_BSTAT:
1356 /* Begin static block. */
1357 {
1358 struct internal_syment symbol;
af8b7906 1359
a81ce07d
JK
1360 read_symbol (&symbol, cs->c_value);
1361 static_block_base = symbol.n_value;
a367db89
JK
1362 static_block_section =
1363 secnum_to_section (symbol.n_scnum, objfile);
a81ce07d
JK
1364 }
1365 break;
af8b7906 1366
a81ce07d
JK
1367 case C_ESTAT:
1368 /* End of static block. */
1369 static_block_base = 0;
1370 static_block_section = -1;
1371 break;
e38e0312 1372
a81ce07d
JK
1373 case C_ARG:
1374 case C_REGPARM:
f8203ed0 1375 case C_REG:
a81ce07d
JK
1376 case C_TPDEF:
1377 case C_STRTAG:
1378 case C_UNTAG:
1379 case C_ENTAG:
f8203ed0
JK
1380 {
1381 static struct complaint msg =
1382 {"Unrecognized storage class %d.", 0, 0};
1383 complain (&msg, cs->c_sclass);
1384 }
a81ce07d 1385 break;
e38e0312 1386
a81ce07d
JK
1387 case C_LABEL:
1388 case C_NULL:
1389 /* Ignore these. */
1390 break;
e38e0312 1391
a81ce07d 1392 case C_HIDEXT:
df1e1074 1393 case C_STAT:
a81ce07d 1394 break;
e38e0312 1395
a81ce07d
JK
1396 case C_BINCL:
1397 /* beginning of include file */
1398 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1399 order. Thus, when wee see them, we might not know enough info
1400 to process them. Thus, we'll be saving them into a table
1401 (inclTable) and postpone their processing. */
e38e0312 1402
a81ce07d
JK
1403 record_include_begin (cs);
1404 break;
e38e0312 1405
a81ce07d
JK
1406 case C_EINCL:
1407 /* End of include file. */
1408 /* See the comment after case C_BINCL. */
1409 record_include_end (cs);
1410 break;
1eeba686 1411
a81ce07d
JK
1412 case C_BLOCK:
1413 if (STREQ (cs->c_name, ".bb"))
1414 {
1415 depth++;
a367db89
JK
1416 new = push_context (depth,
1417 (cs->c_value
1418 + ANOFFSET (objfile->section_offsets,
1419 SECT_OFF_TEXT)));
a81ce07d
JK
1420 }
1421 else if (STREQ (cs->c_name, ".eb"))
1422 {
df1e1074
PS
1423 if (context_stack_depth <= 0)
1424 { /* We attempted to pop an empty context stack */
1425 complain (&eb_complaint, cs->c_symnum);
1426 break;
1427 }
a81ce07d 1428 new = pop_context ();
f8203ed0
JK
1429 if (depth-- != new->depth)
1430 {
df1e1074 1431 complain (&eb_complaint, cs->c_symnum);
f8203ed0
JK
1432 break;
1433 }
a81ce07d
JK
1434 if (local_symbols && context_stack_depth > 0)
1435 {
1436 /* Make a block for the local symbols within. */
1437 finish_block (new->name, &local_symbols, new->old_blocks,
a367db89
JK
1438 new->start_addr,
1439 (cs->c_value
1440 + ANOFFSET (objfile->section_offsets,
1441 SECT_OFF_TEXT)),
1442 objfile);
a81ce07d
JK
1443 }
1444 local_symbols = new->locals;
1445 }
1446 break;
e38e0312 1447
a81ce07d
JK
1448 default:
1449 process_xcoff_symbol (cs, objfile);
1450 break;
e38e0312 1451 }
e38e0312
JG
1452 }
1453
e38e0312 1454 if (last_source_file)
d07734e3 1455 {
a367db89
JK
1456 struct symtab *s;
1457
1458 complete_symtab (filestring, file_start_addr);
1459 cur_src_end_addr = file_end_addr;
436d4143 1460 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
a367db89
JK
1461 /* When reading symbols for the last C_FILE of the objfile, try
1462 to make sure that we set pst->symtab to the symtab for the
1463 file, not to the _globals_ symtab. I'm not sure whether this
1464 actually works right or when/if it comes up. */
1465 if (pst->symtab == NULL)
1466 pst->symtab = s;
d07734e3
FF
1467 end_stabs ();
1468 }
e38e0312
JG
1469}
1470
1471#define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1472 (SYMBOL2) = (struct symbol *) \
1ab3bf1b 1473 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
e38e0312
JG
1474 *(SYMBOL2) = *(SYMBOL1);
1475
1476
1477#define SYMNAME_ALLOC(NAME, ALLOCED) \
ace4b8d7 1478 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
e38e0312
JG
1479
1480
a81ce07d
JK
1481static struct type *func_symbol_type;
1482static struct type *var_symbol_type;
1483
e38e0312
JG
1484/* process one xcoff symbol. */
1485
1486static struct symbol *
1ab3bf1b 1487process_xcoff_symbol (cs, objfile)
e38e0312 1488 register struct coff_symbol *cs;
1ab3bf1b 1489 struct objfile *objfile;
e38e0312
JG
1490{
1491 struct symbol onesymbol;
1492 register struct symbol *sym = &onesymbol;
1493 struct symbol *sym2 = NULL;
df1e1074 1494 char *name, *pp;
e38e0312 1495
a367db89
JK
1496 int sec;
1497 CORE_ADDR off;
1498
1499 if (cs->c_secnum < 0)
1500 {
1501 /* The value is a register number, offset within a frame, etc.,
1502 and does not get relocated. */
1503 off = 0;
1504 sec = -1;
1505 }
1506 else
1507 {
1508 sec = secnum_to_section (cs->c_secnum, objfile);
1509 off = ANOFFSET (objfile->section_offsets, sec);
1510 }
1511
e38e0312
JG
1512 name = cs->c_name;
1513 if (name[0] == '.')
1514 ++name;
1515
4ed97c9a 1516 memset (sym, '\0', sizeof (struct symbol));
e38e0312
JG
1517
1518 /* default assumptions */
a367db89 1519 SYMBOL_VALUE (sym) = cs->c_value + off;
e38e0312 1520 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
a367db89 1521 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
e38e0312 1522
a81ce07d
JK
1523 if (ISFCN (cs->c_type))
1524 {
1525 /* At this point, we don't know the type of the function. This
1526 will be patched with the type from its stab entry later on in
1527 patch_block_stabs (), unless the file was compiled without -g. */
e38e0312 1528
a81ce07d
JK
1529 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1530 SYMBOL_TYPE (sym) = func_symbol_type;
e38e0312 1531
a81ce07d
JK
1532 SYMBOL_CLASS (sym) = LOC_BLOCK;
1533 SYMBOL_DUP (sym, sym2);
e38e0312 1534
a81ce07d
JK
1535 if (cs->c_sclass == C_EXT)
1536 add_symbol_to_list (sym2, &global_symbols);
1537 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1538 add_symbol_to_list (sym2, &file_symbols);
1539 }
1540 else
e38e0312 1541 {
a81ce07d
JK
1542 /* In case we can't figure out the type, provide default. */
1543 SYMBOL_TYPE (sym) = var_symbol_type;
1544
1545 switch (cs->c_sclass)
1546 {
818de002 1547#if 0
df1e1074
PS
1548 /* The values of functions and global symbols are now resolved
1549 via the global_sym_chain in stabsread.c. */
a81ce07d
JK
1550 case C_FUN:
1551 if (fcn_cs_saved.c_sclass == C_EXT)
1552 add_stab_to_list (name, &global_stabs);
1553 else
1554 add_stab_to_list (name, &file_stabs);
1555 break;
e38e0312 1556
a81ce07d
JK
1557 case C_GSYM:
1558 add_stab_to_list (name, &global_stabs);
1559 break;
df1e1074 1560#endif
e38e0312 1561
a81ce07d
JK
1562 case C_BCOMM:
1563 common_block_start (cs->c_name, objfile);
1564 break;
9438d642 1565
a81ce07d
JK
1566 case C_ECOMM:
1567 common_block_end (objfile);
1568 break;
9438d642 1569
a81ce07d
JK
1570 default:
1571 complain (&storclass_complaint, cs->c_sclass);
1572 /* FALLTHROUGH */
9438d642 1573
a81ce07d
JK
1574 case C_DECL:
1575 case C_PSYM:
1576 case C_RPSYM:
1577 case C_ECOML:
a367db89
JK
1578 case C_LSYM:
1579 case C_RSYM:
df1e1074 1580 case C_GSYM:
1eeba686 1581
a367db89
JK
1582 {
1583 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1584 if (sym != NULL)
1585 {
1586 SYMBOL_SECTION (sym) = sec;
1587 }
1588 return sym;
1589 }
e38e0312 1590
a81ce07d 1591 case C_STSYM:
1eeba686 1592
a81ce07d
JK
1593 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1594 all statics and we need to distinguish file-scope versus
1595 function-scope using within_function. We do this by
1596 changing the string we pass to define_symbol to use 'S'
1597 where we need to, which is not necessarily super-clean,
1598 but seems workable enough. */
91cc45da 1599
a81ce07d
JK
1600 if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
1601 return NULL;
91cc45da 1602
a81ce07d
JK
1603 ++pp;
1604 if (*pp == 'V' && !within_function)
1605 *pp = 'S';
a367db89
JK
1606 sym = define_symbol ((cs->c_value
1607 + ANOFFSET (objfile->section_offsets,
1608 static_block_section)),
1609 cs->c_name, 0, 0, objfile);
a81ce07d
JK
1610 if (sym != NULL)
1611 {
1612 SYMBOL_VALUE (sym) += static_block_base;
1613 SYMBOL_SECTION (sym) = static_block_section;
1614 }
1615 return sym;
e38e0312 1616
1eeba686 1617 }
e38e0312 1618 }
e38e0312
JG
1619 return sym2;
1620}
1621
e8abe489
PS
1622/* Extract the file name from the aux entry of a C_FILE symbol. Return
1623 only the last component of the name. Result is in static storage and
1624 is only good for temporary use. */
1625
1626static char *
a367db89
JK
1627coff_getfilename (aux_entry, objfile)
1628 union internal_auxent *aux_entry;
1629 struct objfile *objfile;
e8abe489
PS
1630{
1631 static char buffer[BUFSIZ];
1632 register char *temp;
1633 char *result;
1634
1635 if (aux_entry->x_file.x_n.x_zeroes == 0)
a367db89
JK
1636 strcpy (buffer,
1637 ((struct coff_symfile_info *)objfile->sym_private)->strtbl
1638 + aux_entry->x_file.x_n.x_offset);
e8abe489
PS
1639 else
1640 {
1641 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1642 buffer[FILNMLEN] = '\0';
1643 }
1644 result = buffer;
1645
1646 /* FIXME: We should not be throwing away the information about what
1647 directory. It should go into dirname of the symtab, or some such
1648 place. */
1649 if ((temp = strrchr (result, '/')) != NULL)
1650 result = temp + 1;
1651 return (result);
1652}
1653
3c02636b
JK
1654/* Set *SYMBOL to symbol number symno in symtbl. */
1655static void
1656read_symbol (symbol, symno)
1657 struct internal_syment *symbol;
e38e0312
JG
1658 int symno;
1659{
a367db89
JK
1660 int nsyms =
1661 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1662 ->symtbl_num_syms;
1663 char *stbl =
1664 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1665 ->symtbl;
1666 if (symno < 0 || symno >= nsyms)
c84a96d7 1667 {
b646b438 1668 static struct complaint msg =
c84a96d7
JK
1669 {"Invalid symbol offset", 0, 0};
1670 complain (&msg);
3c02636b
JK
1671 symbol->n_value = 0;
1672 symbol->n_scnum = -1;
1673 return;
c84a96d7 1674 }
a367db89
JK
1675 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1676 stbl + (symno*local_symesz),
1677 symbol);
3c02636b
JK
1678}
1679
1680/* Get value corresponding to symbol number symno in symtbl. */
1681
1682static int
1683read_symbol_nvalue (symno)
1684 int symno;
1685{
1686 struct internal_syment symbol[1];
1687
1688 read_symbol (symbol, symno);
e38e0312
JG
1689 return symbol->n_value;
1690}
1691
1692
c84a96d7
JK
1693/* Find the address of the function corresponding to symno, where
1694 symno is the symbol pointed to by the linetable. */
1695
e38e0312 1696static int
c84a96d7 1697read_symbol_lineno (symno)
a367db89 1698 int symno;
e38e0312 1699{
a367db89
JK
1700 int nsyms =
1701 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1702 ->symtbl_num_syms;
1703 char *stbl =
1704 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1705 ->symtbl;
e38e0312
JG
1706 struct internal_syment symbol[1];
1707 union internal_auxent main_aux[1];
1708
a367db89
JK
1709 if (symno < 0)
1710 {
1711 complain (&bf_notfound_complaint);
1712 return 0;
1713 }
1714
c84a96d7
JK
1715 /* Note that just searching for a short distance (e.g. 50 symbols)
1716 is not enough, at least in the following case.
1717
1718 .extern foo
1719 [many .stabx entries]
1720 [a few functions, referring to foo]
1721 .globl foo
1722 .bf
e38e0312 1723
c84a96d7
JK
1724 What happens here is that the assembler moves the .stabx entries
1725 to right before the ".bf" for foo, but the symbol for "foo" is before
1726 all the stabx entries. See PR gdb/2222. */
a367db89
JK
1727
1728 /* Maintaining a table of .bf entries might be preferable to this search.
1729 If I understand things correctly it would need to be done only for
1730 the duration of a single psymtab to symtab conversion. */
1731 while (symno < nsyms)
1732 {
1733 bfd_coff_swap_sym_in (symfile_bfd,
1734 stbl + (symno * local_symesz), symbol);
1735 if (symbol->n_sclass == C_FCN && STREQ (symbol->n_name, ".bf"))
1736 goto gotit;
1737 symno += symbol->n_numaux + 1;
1738 }
e38e0312 1739
e9916390 1740 complain (&bf_notfound_complaint);
e38e0312
JG
1741 return 0;
1742
1743gotit:
1744 /* take aux entry and return its lineno */
1745 symno++;
a367db89
JK
1746 bfd_coff_swap_aux_in (this_symtab_psymtab->objfile->obfd,
1747 stbl + symno * local_symesz,
bf8d9d28
ILT
1748 symbol->n_type, symbol->n_sclass,
1749 0, symbol->n_numaux, main_aux);
e38e0312
JG
1750
1751 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1752}
1753
1754/* Support for line number handling */
1755
1756/* This function is called for every section; it finds the outer limits
1757 * of the line table (minimum and maximum file offset) so that the
1758 * mainline code can read the whole thing for efficiency.
1759 */
1760static void
a367db89
JK
1761find_linenos (abfd, asect, vpinfo)
1762 bfd *abfd;
1763 sec_ptr asect;
1764 PTR vpinfo;
e38e0312
JG
1765{
1766 struct coff_symfile_info *info;
1767 int size, count;
1768 file_ptr offset, maxoff;
1769
1770 count = asect->lineno_count;
1771
2e4964ad 1772 if (!STREQ (asect->name, ".text") || count == 0)
e38e0312
JG
1773 return;
1774
a367db89
JK
1775 size = count * coff_data (abfd)->local_linesz;
1776 info = (struct coff_symfile_info *)vpinfo;
e38e0312
JG
1777 offset = asect->line_filepos;
1778 maxoff = offset + size;
1779
1780 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1781 info->min_lineno_offset = offset;
1782
1783 if (maxoff > info->max_lineno_offset)
1784 info->max_lineno_offset = maxoff;
1785}
a367db89
JK
1786\f
1787static void xcoff_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
e38e0312 1788
a367db89
JK
1789static void
1790xcoff_psymtab_to_symtab_1 (pst)
1791 struct partial_symtab *pst;
e38e0312 1792{
a367db89
JK
1793 struct cleanup *old_chain;
1794 int i;
1795
1796 if (!pst)
1797 return;
1798
1799 if (pst->readin)
1800 {
1801 fprintf_unfiltered
1802 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1803 pst->filename);
1804 return;
1805 }
e38e0312 1806
a367db89
JK
1807 /* Read in all partial symtabs on which this one is dependent */
1808 for (i = 0; i < pst->number_of_dependencies; i++)
1809 if (!pst->dependencies[i]->readin)
1810 {
1811 /* Inform about additional files that need to be read in. */
1812 if (info_verbose)
1813 {
1814 fputs_filtered (" ", gdb_stdout);
1815 wrap_here ("");
1816 fputs_filtered ("and ", gdb_stdout);
1817 wrap_here ("");
1818 printf_filtered ("%s...", pst->dependencies[i]->filename);
1819 wrap_here (""); /* Flush output */
1820 gdb_flush (gdb_stdout);
1821 }
1822 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1823 }
0eb22669 1824
a367db89
JK
1825 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0)
1826 {
1827 /* Init stuff necessary for reading in symbols. */
1828 stabsread_init ();
1829 buildsym_init ();
1830 old_chain = make_cleanup (really_free_pendings, 0);
e38e0312 1831
a367db89
JK
1832 read_xcoff_symtab (pst);
1833 sort_symtab_syms (pst->symtab);
e38e0312 1834
a367db89
JK
1835 do_cleanups (old_chain);
1836 }
e38e0312 1837
a367db89 1838 pst->readin = 1;
e38e0312 1839}
0eb22669 1840
a367db89
JK
1841static void xcoff_psymtab_to_symtab PARAMS ((struct partial_symtab *));
1842
1843/* Read in all of the symbols for a given psymtab for real.
1844 Be verbose about it if the user wants that. */
1845
0eb22669 1846static void
a367db89
JK
1847xcoff_psymtab_to_symtab (pst)
1848 struct partial_symtab *pst;
0eb22669 1849{
a367db89
JK
1850 bfd *sym_bfd;
1851
1852 if (!pst)
1853 return;
1854
1855 if (pst->readin)
1856 {
1857 fprintf_unfiltered
1858 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1859 pst->filename);
1860 return;
1861 }
1862
1863 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0
1864 || pst->number_of_dependencies)
1865 {
1866 /* Print the message now, before reading the string table,
1867 to avoid disconcerting pauses. */
1868 if (info_verbose)
1869 {
1870 printf_filtered ("Reading in symbols for %s...", pst->filename);
1871 gdb_flush (gdb_stdout);
1872 }
1873
1874 sym_bfd = pst->objfile->obfd;
1875
1876 next_symbol_text_func = xcoff_next_symbol_text;
1877
1878 xcoff_psymtab_to_symtab_1 (pst);
1879
1880 /* Match with global symbols. This only needs to be done once,
1881 after all of the symtabs and dependencies have been read in. */
1882 scan_file_globals (pst->objfile);
1883
1884 /* Finish up the debug error message. */
1885 if (info_verbose)
1886 printf_filtered ("done.\n");
1887 }
1888}
93fe4e33 1889\f
1ab3bf1b 1890static void
9b280a7f 1891xcoff_new_init (objfile)
80d68b1d 1892 struct objfile *objfile;
e38e0312 1893{
df1e1074
PS
1894 stabsread_new_init ();
1895 buildsym_new_init ();
e38e0312
JG
1896}
1897
a367db89 1898/* Do initialization in preparation for reading symbols from OBJFILE.
dd469789
JG
1899
1900 We will only be called if this is an XCOFF or XCOFF-like file.
1901 BFD handles figuring out the format of the file, and code in symfile.c
a367db89 1902 uses BFD's determination to vector to us. */
dd469789 1903
1ab3bf1b 1904static void
9b280a7f 1905xcoff_symfile_init (objfile)
a367db89 1906 struct objfile *objfile;
e38e0312 1907{
e38e0312 1908 /* Allocate struct to keep track of the symfile */
80d68b1d
FF
1909 objfile -> sym_private = xmmalloc (objfile -> md,
1910 sizeof (struct coff_symfile_info));
436d4143
JL
1911
1912 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1913 find this causes a significant slowdown in gdb then we could
1914 set it in the debug symbol readers only when necessary. */
1915 objfile->flags |= OBJF_REORDERED;
1916
5e2e79f8 1917 init_entry_point_info (objfile);
e38e0312
JG
1918}
1919
80d68b1d
FF
1920/* Perform any local cleanups required when we are done with a particular
1921 objfile. I.E, we are in the process of discarding all symbol information
1922 for an objfile, freeing up all memory held for it, and unlinking the
1923 objfile struct from the global list of known objfiles. */
1924
1925static void
9b280a7f 1926xcoff_symfile_finish (objfile)
80d68b1d
FF
1927 struct objfile *objfile;
1928{
1929 if (objfile -> sym_private != NULL)
1930 {
1931 mfree (objfile -> md, objfile -> sym_private);
1932 }
1933
a367db89 1934 /* Start with a fresh include table for the next objfile. */
80d68b1d
FF
1935 if (inclTable)
1936 {
1937 free (inclTable);
1938 inclTable = NULL;
1939 }
1940 inclIndx = inclLength = inclDepth = 0;
1941}
1942
e38e0312 1943
a367db89
JK
1944static void
1945init_stringtab (abfd, offset, objfile)
e38e0312 1946 bfd *abfd;
d5931d79 1947 file_ptr offset;
1ab3bf1b 1948 struct objfile *objfile;
e38e0312
JG
1949{
1950 long length;
1951 int val;
1952 unsigned char lengthbuf[4];
a367db89 1953 char *strtbl;
e38e0312 1954
a367db89 1955 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = NULL;
e38e0312 1956
987622b5 1957 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
a367db89
JK
1958 error ("cannot seek to string table in %s: %s",
1959 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1960
1961 val = bfd_read ((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
1962 length = bfd_h_get_32 (abfd, lengthbuf);
e38e0312
JG
1963
1964 /* If no string table is needed, then the file may end immediately
a367db89 1965 after the symbols. Just return with `strtbl' set to NULL. */
e38e0312 1966
a367db89
JK
1967 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1968 return;
e38e0312
JG
1969
1970 /* Allocate string table from symbol_obstack. We will need this table
1971 as long as we have its symbol table around. */
1972
a367db89
JK
1973 strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
1974 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = strtbl;
e38e0312 1975
df1e1074
PS
1976 /* Copy length buffer, the first byte is usually zero and is
1977 used for stabs with a name length of zero. */
1978 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
a367db89
JK
1979 if (length == sizeof lengthbuf)
1980 return;
e38e0312 1981
a367db89
JK
1982 val = bfd_read (strtbl + sizeof lengthbuf, 1, length - sizeof lengthbuf,
1983 abfd);
e38e0312 1984
a367db89
JK
1985 if (val != length - sizeof lengthbuf)
1986 error ("cannot read string table from %s: %s",
1987 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1988 if (strtbl[length - 1] != '\0')
1989 error ("bad symbol file: string table does not end with null character");
e38e0312 1990
a367db89 1991 return;
e38e0312 1992}
a367db89
JK
1993\f
1994/* If we have not yet seen a function for this psymtab, this is 0. If we
1995 have seen one, it is the offset in the line numbers of the line numbers
1996 for the psymtab. */
1997static unsigned int first_fun_line_offset;
e38e0312 1998
a367db89
JK
1999static struct partial_symtab *xcoff_start_psymtab
2000 PARAMS ((struct objfile *, struct section_offsets *, char *, int,
2ad5709f 2001 struct partial_symbol **, struct partial_symbol **));
a367db89
JK
2002
2003/* Allocate and partially fill a partial symtab. It will be
2004 completely filled at the end of the symbol list.
2005
2006 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2007 is the address relative to which its symbols are (incremental) or 0
2008 (normal). */
2009
2010static struct partial_symtab *
2011xcoff_start_psymtab (objfile, section_offsets,
2012 filename, first_symnum, global_syms, static_syms)
2013 struct objfile *objfile;
2014 struct section_offsets *section_offsets;
2015 char *filename;
2016 int first_symnum;
2ad5709f
FF
2017 struct partial_symbol **global_syms;
2018 struct partial_symbol **static_syms;
e38e0312 2019{
a367db89
JK
2020 struct partial_symtab *result =
2021 start_psymtab_common (objfile, section_offsets,
2022 filename,
2023 /* We fill in textlow later. */
2024 0,
2025 global_syms, static_syms);
2026
2027 result->read_symtab_private = (char *)
2028 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
2029 ((struct symloc *)result->read_symtab_private)->first_symnum = first_symnum;
2030 result->read_symtab = xcoff_psymtab_to_symtab;
2031
2032 /* Deduce the source language from the filename for this psymtab. */
2033 psymtab_language = deduce_language_from_filename (filename);
2034
2035 return result;
2036}
e38e0312 2037
a367db89
JK
2038static struct partial_symtab *xcoff_end_psymtab
2039 PARAMS ((struct partial_symtab *, char **, int, int,
68aadb90 2040 struct partial_symtab **, int, int));
e38e0312 2041
a367db89
JK
2042/* Close off the current usage of PST.
2043 Returns PST, or NULL if the partial symtab was empty and thrown away.
e38e0312 2044
a367db89 2045 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
e38e0312 2046
a367db89
JK
2047 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2048 are the information for includes and dependencies. */
e38e0312 2049
a367db89
JK
2050static struct partial_symtab *
2051xcoff_end_psymtab (pst, include_list, num_includes, capping_symbol_number,
68aadb90 2052 dependency_list, number_dependencies, textlow_not_set)
a367db89
JK
2053 struct partial_symtab *pst;
2054 char **include_list;
2055 int num_includes;
2056 int capping_symbol_number;
2057 struct partial_symtab **dependency_list;
2058 int number_dependencies;
68aadb90 2059 int textlow_not_set;
a367db89
JK
2060{
2061 int i;
2062 struct objfile *objfile = pst -> objfile;
2063
2064 if (capping_symbol_number != -1)
2065 ((struct symloc *)pst->read_symtab_private)->numsyms =
2066 capping_symbol_number
2067 - ((struct symloc *)pst->read_symtab_private)->first_symnum;
2068 ((struct symloc *)pst->read_symtab_private)->lineno_off =
2069 first_fun_line_offset;
2070 first_fun_line_offset = 0;
2071 pst->n_global_syms =
2072 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2073 pst->n_static_syms =
2074 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2075
2076 pst->number_of_dependencies = number_dependencies;
2077 if (number_dependencies)
2078 {
2079 pst->dependencies = (struct partial_symtab **)
2080 obstack_alloc (&objfile->psymbol_obstack,
2081 number_dependencies * sizeof (struct partial_symtab *));
2082 memcpy (pst->dependencies, dependency_list,
2083 number_dependencies * sizeof (struct partial_symtab *));
2084 }
2085 else
2086 pst->dependencies = 0;
2087
2088 for (i = 0; i < num_includes; i++)
2089 {
2090 struct partial_symtab *subpst =
2091 allocate_psymtab (include_list[i], objfile);
2092
2093 subpst->section_offsets = pst->section_offsets;
2094 subpst->read_symtab_private =
2095 (char *) obstack_alloc (&objfile->psymbol_obstack,
2096 sizeof (struct symloc));
2097 ((struct symloc *)subpst->read_symtab_private)->first_symnum = 0;
2098 ((struct symloc *)subpst->read_symtab_private)->numsyms = 0;
2099 subpst->textlow = 0;
2100 subpst->texthigh = 0;
2101
2102 /* We could save slight bits of space by only making one of these,
2103 shared by the entire set of include files. FIXME-someday. */
2104 subpst->dependencies = (struct partial_symtab **)
2105 obstack_alloc (&objfile->psymbol_obstack,
2106 sizeof (struct partial_symtab *));
2107 subpst->dependencies[0] = pst;
2108 subpst->number_of_dependencies = 1;
2109
2110 subpst->globals_offset =
2111 subpst->n_global_syms =
2112 subpst->statics_offset =
2113 subpst->n_static_syms = 0;
2114
2115 subpst->readin = 0;
2116 subpst->symtab = 0;
2117 subpst->read_symtab = pst->read_symtab;
2118 }
2119
2120 sort_pst_symbols (pst);
2121
2122 /* If there is already a psymtab or symtab for a file of this name,
2123 remove it. (If there is a symtab, more drastic things also
2124 happen.) This happens in VxWorks. */
2125 free_named_symtabs (pst->filename);
2126
2127 if (num_includes == 0
2128 && number_dependencies == 0
2129 && pst->n_global_syms == 0
2130 && pst->n_static_syms == 0)
2131 {
2132 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2133 it is on the obstack, but we can forget to chain it on the list. */
2134 /* Empty psymtabs happen as a result of header files which don't have
df1e1074 2135 any symbols in them. There can be a lot of them. */
a367db89
JK
2136 struct partial_symtab *prev_pst;
2137
2138 /* First, snip it out of the psymtab chain */
2139
2140 if (pst->objfile->psymtabs == pst)
2141 pst->objfile->psymtabs = pst->next;
2142 else
2143 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
2144 if (prev_pst->next == pst)
2145 prev_pst->next = pst->next;
2146
2147 /* Next, put it on a free list for recycling */
2148
2149 pst->next = pst->objfile->free_psymtabs;
2150 pst->objfile->free_psymtabs = pst;
2151
2152 /* Indicate that psymtab was thrown away. */
2153 pst = (struct partial_symtab *)NULL;
2154 }
2155 return pst;
2156}
2157
2158static void swap_sym PARAMS ((struct internal_syment *,
2159 union internal_auxent *, char **, char **,
2160 unsigned int *,
2161 struct objfile *));
2162
2163/* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2164 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2165 the symbol and its auxents. */
2166
2167static void
2168swap_sym (symbol, aux, name, raw, symnump, objfile)
2169 struct internal_syment *symbol;
2170 union internal_auxent *aux;
2171 char **name;
2172 char **raw;
2173 unsigned int *symnump;
2174 struct objfile *objfile;
2175{
2176 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2177 if (symbol->n_zeroes)
2178 {
2179 /* If it's exactly E_SYMNMLEN characters long it isn't
2180 '\0'-terminated. */
2181 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2182 {
2183 /* FIXME: wastes memory for symbols which we don't end up putting
2184 into the minimal symbols. */
2185 char *p;
2186 p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1);
2187 strncpy (p, symbol->n_name, E_SYMNMLEN);
2188 p[E_SYMNMLEN] = '\0';
2189 *name = p;
2190 }
2191 else
2192 /* Point to the unswapped name as that persists as long as the
2193 objfile does. */
2194 *name = ((struct external_syment *)*raw)->e.e_name;
2195 }
2196 else if (symbol->n_sclass & 0x80)
2197 {
2198 *name = ((struct coff_symfile_info *)objfile->sym_private)->debugsec
2199 + symbol->n_offset;
2200 }
2201 else
2202 {
2203 *name = ((struct coff_symfile_info *)objfile->sym_private)->strtbl
2204 + symbol->n_offset;
2205 }
2206 ++*symnump;
2207 *raw += coff_data (objfile->obfd)->local_symesz;
2208 if (symbol->n_numaux > 0)
2209 {
2210 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2211 symbol->n_sclass, 0, symbol->n_numaux, aux);
2212
2213 *symnump += symbol->n_numaux;
2214 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2215 }
e38e0312
JG
2216}
2217
2218static void
a367db89
JK
2219scan_xcoff_symtab (section_offsets, objfile)
2220 struct section_offsets *section_offsets;
2221 struct objfile *objfile;
e38e0312 2222{
211b564e 2223 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
df1e1074 2224 char *filestring = NULL;
a367db89
JK
2225
2226 char *namestring;
a367db89 2227 int past_first_source_file = 0;
a367db89 2228 bfd *abfd;
211b564e 2229 asection *bfd_sect;
a367db89
JK
2230 unsigned int nsyms;
2231
2232 /* Current partial symtab */
2233 struct partial_symtab *pst;
2234
2235 /* List of current psymtab's include files */
2236 char **psymtab_include_list;
2237 int includes_allocated;
2238 int includes_used;
2239
2240 /* Index within current psymtab dependency list */
2241 struct partial_symtab **dependency_list;
2242 int dependencies_used, dependencies_allocated;
2243
2244 char *sraw_symbol;
2245 struct internal_syment symbol;
2246 union internal_auxent main_aux;
2247 unsigned int ssymnum;
2248
2249 char *last_csect_name = NULL; /* last seen csect's name and value */
df1e1074
PS
2250 CORE_ADDR last_csect_val = 0;
2251 int last_csect_sec = 0;
2252 int misc_func_recorded = 0; /* true if any misc. function */
3a179be1 2253 int textlow_not_set = 1;
a367db89
JK
2254
2255 pst = (struct partial_symtab *) 0;
2256
2257 includes_allocated = 30;
2258 includes_used = 0;
2259 psymtab_include_list = (char **) alloca (includes_allocated *
2260 sizeof (char *));
2261
2262 dependencies_allocated = 30;
2263 dependencies_used = 0;
2264 dependency_list =
2265 (struct partial_symtab **) alloca (dependencies_allocated *
2266 sizeof (struct partial_symtab *));
2267
2268 last_source_file = NULL;
2269
2270 abfd = objfile->obfd;
2271
2272 sraw_symbol = ((struct coff_symfile_info *)objfile->sym_private)->symtbl;
2273 nsyms = ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms;
2274 ssymnum = 0;
2275 while (ssymnum < nsyms)
2276 {
df1e1074 2277 int sclass = ((struct external_syment *)sraw_symbol)->e_sclass[0] & 0xff;
a367db89
JK
2278 /* This is the type we pass to partial-stab.h. A less kludgy solution
2279 would be to break out partial-stab.h into its various parts--shuffle
2280 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2281 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2282 int stype;
2283
2284 QUIT;
2285
2286 switch (sclass)
2287 {
2288 case C_EXT:
2289 case C_HIDEXT:
2290 {
2291 /* The CSECT auxent--always the last auxent. */
2292 union internal_auxent csect_aux;
2293 unsigned int symnum_before = ssymnum;
2294
2295 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2296 &ssymnum, objfile);
2297 if (symbol.n_numaux > 1)
2298 {
2299 bfd_coff_swap_aux_in
2300 (objfile->obfd,
2301 sraw_symbol - coff_data(abfd)->local_symesz,
2302 symbol.n_type,
2303 symbol.n_sclass,
2304 symbol.n_numaux - 1,
2305 symbol.n_numaux,
2306 &csect_aux);
2307 }
2308 else
2309 csect_aux = main_aux;
2310
df1e1074
PS
2311 /* If symbol name starts with ".$" or "$", ignore it. */
2312 if (namestring[0] == '$'
2313 || (namestring[0] == '.' && namestring[1] == '$'))
2314 break;
2315
a367db89
JK
2316 switch (csect_aux.x_csect.x_smtyp & 0x7)
2317 {
2318 case XTY_SD:
2319 switch (csect_aux.x_csect.x_smclas)
2320 {
2321 case XMC_PR:
2322 if (last_csect_name)
2323 {
2324 /* If no misc. function recorded in the last
2325 seen csect, enter it as a function. This
2326 will take care of functions like strcmp()
2327 compiled by xlc. */
2328
2329 if (!misc_func_recorded)
2330 {
2331 RECORD_MINIMAL_SYMBOL
2332 (last_csect_name, last_csect_val,
2333 mst_text, last_csect_sec,
2334 objfile);
2335 }
2336
2337 if (pst != NULL)
2338 {
2339 /* We have to allocate one psymtab for
2340 each program csect, because their text
2341 sections need not be adjacent. */
2342 xcoff_end_psymtab
68aadb90
FF
2343 (pst, psymtab_include_list, includes_used,
2344 symnum_before, dependency_list,
2345 dependencies_used, textlow_not_set);
a367db89
JK
2346 includes_used = 0;
2347 dependencies_used = 0;
2348 /* Give all psymtabs for this source file the same
2349 name. */
2350 pst = xcoff_start_psymtab
2351 (objfile, section_offsets,
2352 filestring,
2353 symnum_before,
2354 objfile->global_psymbols.next,
2355 objfile->static_psymbols.next);
2356 }
2357 }
2358 if (namestring && namestring[0] == '.')
2359 {
2360 last_csect_name = namestring;
2361 last_csect_val = symbol.n_value;
2362 last_csect_sec =
2363 secnum_to_section (symbol.n_scnum, objfile);
2364 }
2365 if (pst != NULL)
2366 {
2367 CORE_ADDR highval =
2368 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2369 if (highval > pst->texthigh)
2370 pst->texthigh = highval;
2371 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2372 pst->textlow = symbol.n_value;
2373 }
2374 misc_func_recorded = 0;
2375 break;
df1e1074 2376
a367db89 2377 case XMC_RW:
df1e1074
PS
2378 /* Data variables are recorded in the minimal symbol
2379 table, except for section symbols. */
2380 if (*namestring != '.')
2381 prim_record_minimal_symbol_and_info
2382 (namestring, symbol.n_value,
2383 sclass == C_HIDEXT ? mst_file_data : mst_data,
2384 NULL, secnum_to_section (symbol.n_scnum, objfile),
86fdcdaf 2385 NULL, objfile);
a367db89 2386 break;
df1e1074 2387
a367db89
JK
2388 case XMC_TC0:
2389 if (toc_offset)
2390 warning ("More than one XMC_TC0 symbol found.");
2391 toc_offset = symbol.n_value;
211b564e
PS
2392
2393 /* Make TOC offset relative to start address of section. */
2394 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2395 if (bfd_sect)
2396 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
a367db89 2397 break;
df1e1074 2398
a367db89
JK
2399 case XMC_TC:
2400 /* These symbols tell us where the TOC entry for a
2401 variable is, not the variable itself. */
2402 break;
df1e1074 2403
a367db89
JK
2404 default:
2405 break;
2406 }
2407 break;
2408
2409 case XTY_LD:
2410 switch (csect_aux.x_csect.x_smclas)
2411 {
2412 case XMC_PR:
df1e1074
PS
2413 /* A function entry point. */
2414
2415 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2416 first_fun_line_offset =
2417 main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
2418 RECORD_MINIMAL_SYMBOL
2419 (namestring, symbol.n_value,
2420 sclass == C_HIDEXT ? mst_file_text : mst_text,
2421 secnum_to_section (symbol.n_scnum, objfile),
2422 objfile);
a367db89 2423 break;
df1e1074 2424
a367db89
JK
2425 case XMC_GL:
2426 /* shared library function trampoline code entry
2427 point. */
2428
2429 /* record trampoline code entries as
2430 mst_solib_trampoline symbol. When we lookup mst
2431 symbols, we will choose mst_text over
2432 mst_solib_trampoline. */
2433 RECORD_MINIMAL_SYMBOL
2434 (namestring, symbol.n_value,
2435 mst_solib_trampoline,
2436 secnum_to_section (symbol.n_scnum, objfile),
2437 objfile);
2438 break;
2439
2440 case XMC_DS:
2441 /* The symbols often have the same names as
2442 debug symbols for functions, and confuse
2443 lookup_symbol. */
2444 break;
2445
2446 default:
2447
2448 /* xlc puts each variable in a separate csect,
2449 so we get an XTY_SD for each variable. But
2450 gcc puts several variables in a csect, so
2451 that each variable only gets an XTY_LD. We
2452 still need to record them. This will
2453 typically be XMC_RW; I suspect XMC_RO and
2454 XMC_BS might be possible too. */
df1e1074
PS
2455 if (*namestring != '.')
2456 prim_record_minimal_symbol_and_info
2457 (namestring, symbol.n_value,
2458 sclass == C_HIDEXT ? mst_file_data : mst_data,
2459 NULL, secnum_to_section (symbol.n_scnum, objfile),
86fdcdaf 2460 NULL, objfile);
df1e1074
PS
2461 break;
2462 }
2463 break;
a367db89 2464
df1e1074
PS
2465 case XTY_CM:
2466 switch (csect_aux.x_csect.x_smclas)
2467 {
2468 case XMC_RW:
2469 case XMC_BS:
2470 /* Common variables are recorded in the minimal symbol
2471 table, except for section symbols. */
2472 if (*namestring != '.')
2473 prim_record_minimal_symbol_and_info
2474 (namestring, symbol.n_value,
2475 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2476 NULL, secnum_to_section (symbol.n_scnum, objfile),
86fdcdaf 2477 NULL, objfile);
a367db89
JK
2478 break;
2479 }
df1e1074
PS
2480 break;
2481
a367db89
JK
2482 default:
2483 break;
2484 }
2485 }
2486 break;
2487 case C_FILE:
2488 {
2489 unsigned int symnum_before;
2490
2491 symnum_before = ssymnum;
2492 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2493 &ssymnum, objfile);
2494
2495 /* See if the last csect needs to be recorded. */
2496
2497 if (last_csect_name && !misc_func_recorded)
2498 {
2499
2500 /* If no misc. function recorded in the last seen csect, enter
2501 it as a function. This will take care of functions like
2502 strcmp() compiled by xlc. */
2503
2504 RECORD_MINIMAL_SYMBOL
2505 (last_csect_name, last_csect_val,
2506 mst_text, last_csect_sec, objfile);
2507 }
2508
2509 if (pst)
2510 {
2511 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
68aadb90
FF
2512 symnum_before, dependency_list,
2513 dependencies_used, textlow_not_set);
a367db89
JK
2514 includes_used = 0;
2515 dependencies_used = 0;
2516 }
2517 first_fun_line_offset = 0;
2518
2519 /* XCOFF, according to the AIX 3.2 documentation, puts the
2520 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2521 do things the standard COFF way and put it in the auxent.
2522 We use the auxent if the symbol is ".file" and an auxent
2523 exists, otherwise use the symbol itself. */
2524 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2525 {
2526 filestring = coff_getfilename (&main_aux, objfile);
2527 }
2528 else
2529 filestring = namestring;
2530
2531 pst = xcoff_start_psymtab (objfile, section_offsets,
2532 filestring,
2533 symnum_before,
2534 objfile->global_psymbols.next,
2535 objfile->static_psymbols.next);
2536 last_csect_name = NULL;
2537 }
2538 break;
2539
2540 default:
2541 {
2542 static struct complaint msg =
2543 {"Storage class %d not recognized during scan", 0, 0};
2544 complain (&msg, sclass);
2545 }
2546 /* FALLTHROUGH */
2547
2548 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2549 to handle only the C_FUN and C_EXT. */
2550 case C_FCN:
2551
2552 case C_BSTAT:
2553 case C_ESTAT:
2554 case C_ARG:
2555 case C_REGPARM:
2556 case C_REG:
2557 case C_TPDEF:
2558 case C_STRTAG:
2559 case C_UNTAG:
2560 case C_ENTAG:
2561 case C_LABEL:
2562 case C_NULL:
2563
2564 /* C_EINCL means we are switching back to the main file. But there
2565 is no reason to care; the only thing we want to know about
2566 includes is the names of all the included (.h) files. */
2567 case C_EINCL:
2568
2569 case C_BLOCK:
2570
2571 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2572 used instead. */
2573 case C_STAT:
2574
2575 /* I don't think the name of the common block (as opposed to the
2576 variables within it) is something which is user visible
2577 currently. */
2578 case C_BCOMM:
2579 case C_ECOMM:
2580
2581 case C_PSYM:
2582 case C_RPSYM:
2583
2584 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2585 so C_LSYM would appear to be only for locals. */
2586 case C_LSYM:
2587
2588 case C_AUTO:
2589 case C_RSYM:
2590 {
2591 /* We probably could save a few instructions by assuming that
2592 C_LSYM, C_PSYM, etc., never have auxents. */
2593 int naux1 =
2594 ((struct external_syment *)sraw_symbol)->e_numaux[0] + 1;
2595 ssymnum += naux1;
2596 sraw_symbol += sizeof (struct external_syment) * naux1;
2597 }
2598 break;
2599
2600 case C_BINCL:
2601 stype = N_SOL;
2602 goto pstab;
2603
2604 case C_FUN:
2605 /* The value of the C_FUN is not the address of the function (it
2606 appears to be the address before linking), but as long as it
2607 is smaller than the actual address, then find_pc_partial_function
2608 will use the minimal symbols instead. I hope. */
2609
2610 case C_GSYM:
2611 case C_ECOML:
2612 case C_DECL:
2613 case C_STSYM:
2614 stype = N_LSYM;
2615 pstab:;
2616 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2617 &ssymnum, objfile);
2618#define CUR_SYMBOL_TYPE stype
2619#define CUR_SYMBOL_VALUE symbol.n_value
2620
2621/* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2622 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2623 variable. */
2624#define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
68aadb90 2625#define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
a367db89
JK
2626 do {} while (0)
2627/* We have already set the namestring. */
df1e1074 2628#define SET_NAMESTRING() /* */
a367db89
JK
2629
2630#include "partial-stab.h"
2631 }
2632 }
a367db89
JK
2633
2634 if (pst)
2635 {
2636 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
68aadb90
FF
2637 ssymnum, dependency_list,
2638 dependencies_used, textlow_not_set);
a367db89
JK
2639 }
2640
2641 /* Record the toc offset value of this symbol table into ldinfo structure.
2642 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2643 this information would be file auxiliary header. */
2644
062cb0d3
FF
2645 if (xcoff_add_toc_to_loadinfo_hook != NULL)
2646 (*xcoff_add_toc_to_loadinfo_hook) ((unsigned long) toc_offset);
e38e0312
JG
2647}
2648
a367db89
JK
2649/* Scan and build partial symbols for a symbol file.
2650 We have been initialized by a call to dbx_symfile_init, which
2651 put all the relevant info into a "struct dbx_symfile_info",
2652 hung off the objfile structure.
e38e0312 2653
a367db89
JK
2654 SECTION_OFFSETS contains offsets relative to which the symbols in the
2655 various sections are (depending where the sections were actually loaded).
2656 MAINLINE is true if we are reading the main symbol
2657 table (as opposed to a shared lib or dynamically loaded file). */
e38e0312 2658
1ab3bf1b 2659static void
a367db89
JK
2660xcoff_initial_scan (objfile, section_offsets, mainline)
2661 struct objfile *objfile;
2662 struct section_offsets *section_offsets;
2663 int mainline; /* FIXME comments above */
e38e0312 2664{
a367db89
JK
2665 bfd *abfd;
2666 int val;
2667 struct cleanup *back_to;
d5931d79
JG
2668 int num_symbols; /* # of symbols */
2669 file_ptr symtab_offset; /* symbol table and */
2670 file_ptr stringtab_offset; /* string table file offsets */
80d68b1d 2671 struct coff_symfile_info *info;
e38e0312 2672 char *name;
a367db89
JK
2673 unsigned int size;
2674
a367db89 2675 /* Initialize load info structure. */
062cb0d3
FF
2676 if (mainline && xcoff_init_loadinfo_hook != NULL)
2677 (*xcoff_init_loadinfo_hook) ();
e38e0312 2678
80d68b1d
FF
2679 info = (struct coff_symfile_info *) objfile -> sym_private;
2680 symfile_bfd = abfd = objfile->obfd;
2681 name = objfile->name;
e38e0312
JG
2682
2683 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2684 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2685 stringtab_offset = symtab_offset +
2686 num_symbols * coff_data(abfd)->local_symesz;
2687
2688 info->min_lineno_offset = 0;
2689 info->max_lineno_offset = 0;
2690 bfd_map_over_sections (abfd, find_linenos, info);
2691
9d61147e
JK
2692 if (num_symbols > 0)
2693 {
a367db89
JK
2694 /* Read the string table. */
2695 init_stringtab (abfd, stringtab_offset, objfile);
e38e0312 2696
a367db89
JK
2697 /* Read the .debug section, if present. */
2698 {
2699 sec_ptr secp;
2700 bfd_size_type length;
2701 char *debugsec = NULL;
2702
2703 secp = bfd_get_section_by_name (abfd, ".debug");
2704 if (secp)
2705 {
2706 length = bfd_section_size (abfd, secp);
2707 if (length)
2708 {
2709 debugsec =
2710 (char *) obstack_alloc (&objfile->symbol_obstack, length);
2711
2712 if (!bfd_get_section_contents (abfd, secp, debugsec,
2713 (file_ptr) 0, length))
2714 {
2715 error ("Error reading .debug section of `%s': %s",
2716 name, bfd_errmsg (bfd_get_error ()));
2717 }
2718 }
2719 }
2720 ((struct coff_symfile_info *)objfile->sym_private)->debugsec =
2721 debugsec;
9d61147e
JK
2722 }
2723 }
e38e0312 2724
a367db89
JK
2725 /* Read the symbols. We keep them in core because we will want to
2726 access them randomly in read_symbol*. */
987622b5 2727 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
e38e0312 2728 if (val < 0)
a367db89
JK
2729 error ("Error reading symbols from %s: %s",
2730 name, bfd_errmsg (bfd_get_error ()));
2731 size = coff_data (abfd)->local_symesz * num_symbols;
2732 ((struct coff_symfile_info *)objfile->sym_private)->symtbl =
2733 obstack_alloc (&objfile->symbol_obstack, size);
2734 ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms =
2735 num_symbols;
2736
2737 val = bfd_read (((struct coff_symfile_info *)objfile->sym_private)->symtbl,
2738 size, 1, abfd);
2739 if (val != size)
2740 perror_with_name ("reading symbol table");
2741
2742 /* If we are reinitializing, or if we have never loaded syms yet, init */
2743 if (mainline
2744 || objfile->global_psymbols.size == 0
2745 || objfile->static_psymbols.size == 0)
2746 /* I'm not sure how how good num_symbols is; the rule of thumb in
2747 init_psymbol_list was developed for a.out. On the one hand,
2748 num_symbols includes auxents. On the other hand, it doesn't
2749 include N_SLINE. */
2750 init_psymbol_list (objfile, num_symbols);
e38e0312 2751
a7f56d5a 2752 free_pending_blocks ();
a367db89 2753 back_to = make_cleanup (really_free_pendings, 0);
e38e0312 2754
1ab3bf1b
JG
2755 init_minimal_symbol_collection ();
2756 make_cleanup (discard_minimal_symbols, 0);
e38e0312 2757
a367db89
JK
2758 /* Now that the symbol table data of the executable file are all in core,
2759 process them and define symbols accordingly. */
e38e0312 2760
a367db89 2761 scan_xcoff_symtab (section_offsets, objfile);
e38e0312 2762
1ab3bf1b
JG
2763 /* Install any minimal symbols that have been collected as the current
2764 minimal symbols for this objfile. */
2765
80d68b1d 2766 install_minimal_symbols (objfile);
0eb22669
PS
2767
2768 do_cleanups (back_to);
e38e0312 2769}
a367db89 2770\f
e2adc41a 2771static struct section_offsets *
9b280a7f 2772xcoff_symfile_offsets (objfile, addr)
2670f34d
JG
2773 struct objfile *objfile;
2774 CORE_ADDR addr;
2775{
2776 struct section_offsets *section_offsets;
2777 int i;
3c02636b 2778
e2adc41a 2779 objfile->num_sections = SECT_OFF_MAX;
2670f34d 2780 section_offsets = (struct section_offsets *)
3c02636b
JK
2781 obstack_alloc
2782 (&objfile -> psymbol_obstack,
2783 sizeof (struct section_offsets)
e2adc41a 2784 + sizeof (section_offsets->offsets) * objfile->num_sections);
2670f34d 2785
1d7e34e1
JK
2786 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2787 of the .text section. This strikes me as wrong--whether the
2788 offset to be applied to symbol reading is relative to the start
2789 address of the section depends on the symbol format. In any
2790 event, this whole "addr" concept is pretty broken (it doesn't
2791 handle any section but .text sensibly), so just ignore the addr
a367db89
JK
2792 parameter and use 0. rs6000-nat.c will set the correct section
2793 offsets via objfile_relocate. */
e2adc41a 2794 for (i = 0; i < objfile->num_sections; ++i)
38fb211b 2795 ANOFFSET (section_offsets, i) = 0;
e2adc41a 2796
2670f34d
JG
2797 return section_offsets;
2798}
0eed42de
JK
2799
2800/* Register our ability to parse symbols for xcoff BFD files. */
e38e0312 2801
9b280a7f 2802static struct sym_fns xcoff_sym_fns =
e38e0312 2803{
0eed42de
JK
2804
2805 /* Because the bfd uses coff_flavour, we need to specially kludge
e2adc41a
JK
2806 the flavour. It is possible that coff and xcoff should be merged as
2807 they do have fundamental similarities (for example, the extra storage
2808 classes used for stabs could presumably be recognized in any COFF file).
2809 However, in addition to obvious things like all the csect hair, there are
2810 some subtler differences between xcoffread.c and coffread.c, notably
2811 the fact that coffread.c has no need to read in all the symbols, but
2812 xcoffread.c reads all the symbols and does in fact randomly access them
a367db89 2813 (in C_BSTAT and line number processing). */
0eed42de 2814
52912aac 2815 (enum bfd_flavour)-1,
0eed42de 2816
9b280a7f
JG
2817 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2818 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
a367db89 2819 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
9b280a7f
JG
2820 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
2821 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
80d68b1d 2822 NULL /* next: pointer to next struct sym_fns */
e38e0312
JG
2823};
2824
2825void
2826_initialize_xcoffread ()
2827{
9b280a7f 2828 add_symtab_fns(&xcoff_sym_fns);
e5eeaaf8 2829
a81ce07d
JK
2830 func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
2831 "<function, no debug info>", NULL);
2832 TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
2833 var_symbol_type =
2834 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
2835 "<variable, no debug info>", NULL);
e38e0312 2836}
This page took 0.533989 seconds and 4 git commands to generate.