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