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