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