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