* aoutx.h (NAME(aout,print_symbol)): Don't print
[deliverable/binutils-gdb.git] / gdb / xcoffread.c
CommitLineData
e38e0312
JG
1/* Read AIXcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
3 Derived from coffread.c, dbxread.c, and a lot of hacking.
4 Contributed by IBM Corporation.
5
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
3ae444f8 22#include <stdio.h>
e38e0312
JG
23#include "defs.h"
24#include "bfd.h"
e38e0312 25
e38e0312
JG
26/* AIX COFF names have a preceeding dot `.' */
27#define NAMES_HAVE_DOT 1
28
29#include <sys/types.h>
30#include <fcntl.h>
31#include <ctype.h>
32
33#include "obstack.h"
34#include <sys/param.h>
5e4d4b0f 35#ifndef NO_SYS_FILE
e38e0312 36#include <sys/file.h>
5e4d4b0f 37#endif
e38e0312
JG
38#include <sys/stat.h>
39
40#include "symtab.h"
1ab3bf1b 41#include "gdbtypes.h"
e38e0312
JG
42#include "symfile.h"
43#include "buildsym.h"
44
f5f0679a 45#include "coff/internal.h" /* FIXME, internal data from BFD */
e38e0312 46#include "libcoff.h" /* FIXME, internal data from BFD */
f5f0679a 47#include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
e38e0312 48
e38e0312
JG
49/* Simplified internal version of coff symbol table information */
50
51struct coff_symbol {
52 char *c_name;
53 int c_symnum; /* symbol number of this entry */
54 int c_nsyms; /* 0 if syment only, 1 if syment + auxent */
55 long c_value;
56 int c_sclass;
57 int c_secnum;
58 unsigned int c_type;
59};
60
61/* The COFF line table, in raw form. */
62static char *linetab = NULL; /* Its actual contents */
63static long linetab_offset; /* Its offset in the file */
64static unsigned long linetab_size; /* Its size */
65
66/* last function's saved coff symbol `cs' */
67
68static struct coff_symbol fcn_cs_saved;
69
70static bfd *symfile_bfd;
71
72/* Core address of start and end of text of current source file.
73 This is calculated from the first function seen after a C_FILE
74 symbol. */
75
76static CORE_ADDR cur_src_start_addr;
77static CORE_ADDR cur_src_end_addr;
78
79/* Core address of the end of the first object file. */
80
81static CORE_ADDR first_object_file_end;
82
83/* pointer to the string table */
84static char *strtbl;
85
86/* length of the string table */
87static int strtbl_len;
88
89/* pointer to debug section */
90static char *debugsec;
91
92/* pointer to the a.out symbol table */
93static char *symtbl;
94
95/* initial symbol-table-debug-string vector length */
96
97#define INITIAL_STABVECTOR_LENGTH 40
98
99struct pending_stabs *global_stabs;
100struct pending_stabs *file_stabs;
101
102/* Nonzero if within a function (so symbols should be local,
103 if nothing says specifically). */
104
105int within_function;
106
107/* Local variables that hold the shift and mask values for the
108 COFF file that we are currently reading. These come back to us
109 from BFD, and are referenced by their macro names, as well as
110 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
111 macros from ../internalcoff.h . */
112
113static unsigned local_n_btshft;
114static unsigned local_n_tmask;
115
116#undef N_BTSHFT
117#define N_BTSHFT local_n_btshft
118#undef N_TMASK
119#define N_TMASK local_n_tmask
120
121/* Local variables that hold the sizes in the file of various COFF structures.
122 (We only need to know this to read them from the file -- BFD will then
123 translate the data in them, into `internal_xxx' structs in the right
124 byte order, alignment, etc.) */
125
126static unsigned local_symesz;
127
128/* coff_symfile_init()
129 is the coff-specific initialization routine for reading symbols.
130 It is passed a struct sym_fns which contains, among other things,
131 the BFD for the file whose symbols are being read, and a slot for
132 a pointer to "private data" which we fill with cookies and other
133 treats for coff_symfile_read().
134
135 We will only be called if this is a COFF or COFF-like file.
136 BFD handles figuring out the format of the file, and code in symtab.c
137 uses BFD's determination to vector to us.
138
139 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
140
141struct coff_symfile_info {
142 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
143 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
144};
145
146
1ab3bf1b
JG
147static void
148enter_line_range PARAMS ((struct subfile *, unsigned, unsigned, CORE_ADDR,
149 unsigned *));
150
151static void
152aixcoff_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int));
153
154static void
155free_debugsection PARAMS ((void));
156
157static int
158init_debugsection PARAMS ((bfd *));
159
160static int
161init_stringtab PARAMS ((bfd *, long, struct objfile *));
162
163static void
164aixcoff_symfile_init PARAMS ((struct sym_fns *));
165
166static void
167aixcoff_new_init PARAMS ((void));
168
1ab3bf1b
JG
169static int
170init_lineno PARAMS ((bfd *, long, int));
171
172static void
173find_linenos PARAMS ((bfd *, sec_ptr, PTR));
174
175static int
176read_symbol_lineno PARAMS ((char *, int));
177
178static int
179read_symbol_nvalue PARAMS ((char *, int));
180
181static struct symbol *
182process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
183
184static void
185read_xcoff_symtab PARAMS ((struct objfile *, int));
186
187static void
188enter_line_range PARAMS ((struct subfile *, unsigned, unsigned, CORE_ADDR,
189 unsigned *));
190
191static void
192add_stab_to_list PARAMS ((char *, struct pending_stabs **));
193
194static void
195sort_syms PARAMS ((void));
196
197static int
198compare_symbols PARAMS ((const void *, const void *));
199
e38e0312
JG
200/* Call sort_syms to sort alphabetically
201 the symbols of each block of each symtab. */
202
203static int
1ab3bf1b
JG
204compare_symbols (s1p, s2p)
205 const PTR s1p;
206 const PTR s2p;
e38e0312
JG
207{
208 /* Names that are less should come first. */
1ab3bf1b
JG
209 register struct symbol **s1 = (struct symbol **) s1p;
210 register struct symbol **s2 = (struct symbol **) s2p;
e38e0312
JG
211 register int namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
212 if (namediff != 0)
213 return namediff;
214
215 /* For symbols of the same name, registers should come first. */
216 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
217 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
218}
219
220
221/* Sort a vector of symbols by their value. */
222
223static void
224sort_syms ()
225{
226 register struct symtab *s;
1ab3bf1b 227 register struct objfile *objfile;
e38e0312
JG
228 register int i, nbl;
229 register struct blockvector *bv;
230 register struct block *b;
231
1ab3bf1b 232 for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
e38e0312 233 {
1ab3bf1b
JG
234 for (s = objfile -> symtabs; s != NULL; s = s -> next)
235 {
236 bv = BLOCKVECTOR (s);
237 nbl = BLOCKVECTOR_NBLOCKS (bv);
238 for (i = 0; i < nbl; i++)
239 {
240 b = BLOCKVECTOR_BLOCK (bv, i);
241 if (BLOCK_SHOULD_SORT (b))
242 {
243 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
244 sizeof (struct symbol *), compare_symbols);
245 }
246 }
247 }
e38e0312 248 }
e38e0312
JG
249}
250
251
252/* add a given stab string into given stab vector. */
253
254static void
255add_stab_to_list (stabname, stabvector)
256char *stabname;
257struct pending_stabs **stabvector;
258{
259 if ( *stabvector == NULL) {
260 *stabvector = (struct pending_stabs *)
261 xmalloc (sizeof (struct pending_stabs) +
262 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
263 (*stabvector)->count = 0;
264 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
265 }
266 else if ((*stabvector)->count >= (*stabvector)->length) {
267 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
268 *stabvector = (struct pending_stabs *)
1ab3bf1b 269 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
e38e0312
JG
270 (*stabvector)->length * sizeof (char*));
271 }
272 (*stabvector)->stab [(*stabvector)->count++] = stabname;
273}
274
275
e38e0312
JG
276/* Enter a given range of lines into the line vector.
277 can be called in the following two ways:
278 enter_line_range (subfile, beginoffset, endoffset, 0, firstLine) or
279 enter_line_range (subfile, beginoffset, 0, endaddr, firstLine) */
280
281static void
282enter_line_range (subfile, beginoffset, endoffset, endaddr, firstLine)
283 struct subfile *subfile; /* which sub-file to put line#s in */
284 unsigned beginoffset, endoffset; /* offsets to line table */
285 CORE_ADDR endaddr;
286 unsigned *firstLine;
287{
288 char *pp, *limit;
289 CORE_ADDR addr;
290 struct internal_lineno lptr;
291 unsigned local_linesz = coff_data (symfile_bfd)->local_linesz;
292
293 pp = &linetab [beginoffset - linetab_offset];
294 limit = endoffset ? &linetab [endoffset - linetab_offset]
295 : &linetab [linetab_size -1];
296
297 while (pp <= limit) {
298
299 /* Swap and align this lineno entry into lptr. */
300 bfd_coff_swap_lineno_in (symfile_bfd, pp, &lptr);
301
302 /* find the address this line represents */
303 addr = lptr.l_lnno ?
304 lptr.l_addr.l_paddr : read_symbol_nvalue (symtbl, lptr.l_addr.l_symndx);
305
306 if (endaddr && addr >= endaddr)
307 return;
308
309 if (lptr.l_lnno == 0) {
310 *firstLine = read_symbol_lineno (symtbl, lptr.l_addr.l_symndx);
311 --(*firstLine);
312 }
313 else
314 record_line (subfile, *firstLine + lptr.l_lnno, addr);
315
316 pp += local_linesz;
317 }
318}
319
320
321/* Save the vital information for use when closing off the current file.
322 NAME is the file name the symbols came from, START_ADDR is the first
323 text address for the file, and SIZE is the number of bytes of text. */
324
325#define complete_symtab(name, start_addr) { \
326 last_source_file = savestring (name, strlen (name)); \
327 cur_src_start_addr = start_addr; \
328}
329
330
331/* Refill the symbol table input buffer
332 and set the variables that control fetching entries from it.
333 Reports an error if no data available.
334 This function can read past the end of the symbol table
335 (into the string table) but this does no harm. */
336
337/* Reading symbol table has to be fast! Keep the followings as macros, rather
338 than functions. */
339
1ab3bf1b 340#define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \
e38e0312
JG
341{ \
342 char *namestr; \
343 if (ALLOCED) \
344 namestr = (NAME) + 1; \
345 else { \
1ab3bf1b 346 namestr = obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
e38e0312
JG
347 (ALLOCED) = 1; \
348 } \
1ab3bf1b 349 prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \
e38e0312
JG
350 last_recorded_fun = (ADDR); \
351}
352
353
354
355/* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
356 nested. At any given time, a symbol can only be in one static block.
357 This is the base address of current static block, zero if non exists. */
358
359static int static_block_base = 0;
360
361/* true if space for symbol name has been allocated. */
362
363static int symname_alloced = 0;
364
365/* read the whole symbol table of a given bfd. */
366
1ab3bf1b 367static void
e38e0312
JG
368read_xcoff_symtab (objfile, nsyms)
369 struct objfile *objfile; /* Object file we're reading from */
370 int nsyms; /* # of symbols */
371{
372 bfd *abfd = objfile->obfd;
373 /* char *symtbl; */ /* Raw symbol table base */
374 char *raw_symbol; /* Pointer into raw seething symbol table */
375 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
376 struct internal_syment symbol[1];
377 union internal_auxent main_aux[1];
378 struct coff_symbol cs[1];
379 CORE_ADDR file_start_addr = 0;
380 CORE_ADDR file_end_addr = 0;
381
382 int next_file_symnum = -1;
383 int just_started = 1;
384 int depth = 0;
385 int val;
386 int fcn_first_line;
387 int fcn_last_line;
388 int fcn_start_addr;
389 long fcn_line_offset;
390 size_t size;
391
392 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
393 union internal_auxent fcn_aux_saved;
394 struct context_stack *new;
395
396 char *filestring = " _start_ "; /* Name of the current file. */
397 char *last_seen_csect;
398 int last_recorded_fun = 0; /* last recorded fun. value */
399
1ab3bf1b
JG
400 current_objfile = objfile;
401
e38e0312
JG
402 /* Get the appropriate COFF "constants" related to the file we're handling. */
403 N_TMASK = coff_data (abfd)->local_n_tmask;
404 N_BTSHFT = coff_data (abfd)->local_n_btshft;
405 local_symesz = coff_data (abfd)->local_symesz;
406
407 last_source_file = 0;
408 last_seen_csect = 0;
409 last_recorded_fun = 0;
410
411 start_symtab (filestring, (char *)NULL, file_start_addr);
412 symnum = 0;
413 first_object_file_end = 0;
414
415 /* Allocate space for the entire symbol table at once, and read it
416 all in. The bfd is already positioned at the beginning of
417 the symbol table. */
418
419 size = coff_data (abfd)->local_symesz * nsyms;
420 symtbl = xmalloc (size);
421
422 val = bfd_read (symtbl, size, 1, abfd);
423 if (val != size)
424 perror_with_name ("reading symbol table");
425
426 raw_symbol = symtbl;
427
428 while (symnum < nsyms) {
429
430 QUIT; /* make this command interruptable. */
431
432 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
433 /* read one symbol into `cs' structure. After processing the whole symbol
434 table, only string table will be kept in memory, symbol table and debug
435 section of aixcoff will be freed. Thus we can mark symbols with names
436 in string table as `alloced'. */
437 {
438 int ii;
439
440 /* Swap and align the symbol into a reasonable C structure. */
441 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
442
443 cs->c_symnum = symnum;
444 cs->c_nsyms = symbol->n_numaux;
445 if (symbol->n_zeroes) {
446 symname_alloced = 0;
447 /* We must use the original, unswapped, name here so the name field
448 pointed to by cs->c_name will persist throughout xcoffread. If
449 we use the new field, it gets overwritten for each symbol. */
450 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
451 } else if (symbol->n_sclass & 0x80) {
452 cs->c_name = debugsec + symbol->n_offset;
453 symname_alloced = 0;
454 } else { /* in string table */
455 cs->c_name = strtbl + (int)symbol->n_offset;
456 symname_alloced = 1;
457 }
458 cs->c_value = symbol->n_value;
459 cs->c_sclass = symbol->n_sclass & 0xff;
460 cs->c_secnum = symbol->n_scnum;
461 cs->c_type = (unsigned)symbol->n_type;
462
463 raw_symbol += coff_data (abfd)->local_symesz;
464 ++symnum;
465
466 raw_auxptr = raw_symbol; /* Save addr of first aux entry */
467
468 /* Skip all the auxents associated with this symbol. */
469 for (ii = symbol->n_numaux; ii; --ii ) {
470 raw_symbol += coff_data (abfd)->local_auxesz;
471 ++symnum;
472 }
473 }
474
475 /* if symbol name starts with ".$" or "$", ignore it. */
476 if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
477 continue;
478
479 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) {
480 if (last_source_file)
481 end_symtab (cur_src_end_addr, 1, 1, objfile);
482
483 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
484 cur_src_end_addr = first_object_file_end;
485 /* done with all files, everything from here on is globals */
486 }
487
488 /* if explicitly specified as a function, treat is as one. */
489 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) {
490 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
491 main_aux);
492 goto function_entry_point;
493 }
494
495 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1)
496 {
497 /* dealing with a symbol with a csect entry. */
498
499# define CSECT(PP) ((PP)->x_csect)
500# define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
501# define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
502# define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
503# define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
504
505 /* Convert the auxent to something we can access. */
506 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
507 main_aux);
508
509 switch (CSECT_SMTYP (main_aux)) {
510
511 case XTY_ER :
512 continue; /* ignore all external references. */
513
514 case XTY_SD : /* a section description. */
515 {
516 switch (CSECT_SCLAS (main_aux)) {
517
518 case XMC_PR : /* a `.text' csect. */
519 {
520
521 /* A program csect is seen.
522
523 We have to allocate one symbol table for each program csect. Normally
524 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
525 CU might include more than one prog csect, and they don't have to be
526 adjacent in terms of the space they occupy in memory. Thus, one single
527 CU might get fragmented in the memory and gdb's file start and end address
528 approach does not work! */
529
530 if (last_seen_csect) {
531 complete_symtab (filestring, file_start_addr);
532 cur_src_end_addr = file_end_addr;
533 end_symtab (file_end_addr, 1, 1, objfile);
534 start_symtab ((char *)NULL, (char *)NULL, (CORE_ADDR)0);
535 }
536
537 /* If this is the very first csect seen, basically `__start'. */
538 if (just_started) {
539 first_object_file_end = cs->c_value + CSECT_LEN (main_aux);
540 just_started = 0;
541 }
542
543 file_start_addr = cs->c_value;
544 file_end_addr = cs->c_value + CSECT_LEN (main_aux);
545
546 if (cs->c_name && cs->c_name[0] == '.') {
547 last_seen_csect = cs->c_name;
1ab3bf1b 548 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, symname_alloced);
e38e0312
JG
549 }
550 }
551 continue;
552
553 case XMC_RW :
554 break;
555
556 /* If the section is not a data description, ignore it. Note that
557 uninitialized data will show up as XTY_CM/XMC_RW pair. */
558
559 case XMC_TC0:
560#ifdef XCOFF_ADD_TOC_TO_LOADINFO
561 XCOFF_ADD_TOC_TO_LOADINFO (cs->c_value);
562#endif
563 /* fall down to default case. */
564
565 case XMC_TC : /* ignore toc entries */
566 default : /* any other XMC_XXX */
567 continue;
568 }
569 }
570 break; /* switch CSECT_SCLAS() */
571
572 case XTY_LD :
573
574 /* a function entry point. */
575 if (CSECT_SCLAS (main_aux) == XMC_PR) {
576
577function_entry_point:
578 if (cs->c_value != last_recorded_fun)
1ab3bf1b 579 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text,
e38e0312
JG
580 symname_alloced);
581
582 fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr;
583 fcn_start_addr = cs->c_value;
584
585 /* save the function header info, which will be used
586 when `.bf' is seen. */
587 fcn_cs_saved = *cs;
588 fcn_aux_saved = *main_aux;
589 continue;
590 }
591
592 /* shared library function entry point. */
593 else if (CSECT_SCLAS (main_aux) == XMC_GL) {
594 if (last_recorded_fun != cs->c_value)
1ab3bf1b 595 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text,
e38e0312
JG
596 symname_alloced);
597 continue;
598 }
599 break;
600
601 default : /* all other XTY_XXXs */
602 break;
603 } /* switch CSECT_SMTYP() */
604 }
605
606 switch (cs->c_sclass) {
607
608 case C_FILE:
609
610 /* c_value field contains symnum of next .file entry in table
611 or symnum of first global after last .file. */
612
613 next_file_symnum = cs->c_value;
614
615 /* complete symbol table for last object file containing
616 debugging information. */
617
618 /* Whether or not there was a csect in the previous file, we have
619 to call `end_symtab' and `start_symtab' to reset type_vector,
620 line_vector, etc. structures. */
621 complete_symtab (filestring, file_start_addr);
622 cur_src_end_addr = file_end_addr;
623 end_symtab (file_end_addr, 1, 1, objfile);
624 start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0);
625 last_seen_csect = 0;
626
627 /* reset file start and end addresses. A compilation unit with no text
628 (only data) should have zero file boundaries. */
629 file_start_addr = file_end_addr = 0;
630
631 filestring = cs->c_name;
632 break;
633
634
635 case C_FCN:
636 if (strcmp (cs->c_name, ".bf") == 0) {
637
638 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
639 main_aux);
640
641 within_function = 1;
642
643 /* value contains address of first non-init type code */
644 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
645 contains line number of '{' } */
646 fcn_first_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
647
648 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
649 Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */
650 /* mark_first_line (fcn_line_offset, cs->c_symnum); */
651
652 new = push_context (0, fcn_start_addr);
1ab3bf1b 653 new->name = process_xcoff_symbol (&fcn_cs_saved, objfile);
e38e0312
JG
654 }
655 else if (strcmp (cs->c_name, ".ef") == 0) {
656
657 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
658 main_aux);
659
660 /* the value of .ef is the address of epilogue code;
661 not useful for gdb */
662 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
663 contains number of lines to '}' */
664
665 fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
666#if 0
667 enter_linenos (fcn_line_offset, fcn_first_line,
668 fcn_first_line + fcn_last_line);
669#endif
670
671 new = pop_context ();
672 if (context_stack_depth != 0)
673 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
674 symnum);
675
676 finish_block (new->name, &local_symbols, new->old_blocks,
677 new->start_addr,
678 fcn_cs_saved.c_value +
1ab3bf1b 679 fcn_aux_saved.x_sym.x_misc.x_fsize, objfile);
e38e0312
JG
680 within_function = 0;
681 }
682 break;
683
684 case C_BSTAT : /* begin static block */
685 static_block_base = read_symbol_nvalue (symtbl, cs->c_value);
686 break;
687
688 case C_ESTAT : /* end of static block */
689 static_block_base = 0;
690 break;
691
692 case C_ARG : /* These are not implemented. */
693 case C_REGPARM :
694 case C_TPDEF :
695 case C_STRTAG :
696 case C_UNTAG :
697 case C_ENTAG :
698 printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
699 break;
700
701 case C_HIDEXT : /* ignore these.. */
702 case C_LABEL :
703 case C_NULL :
704 break;
705
706 case C_BINCL : /* beginning of include file */
707 push_subfile ();
708 start_subfile (cs->c_name, (char *)0);
709 fcn_first_line = cs->c_value; /* Offset to first lineno of file */
710 break;
711
712 case C_EINCL : /* end of include file */
713 fcn_last_line = cs->c_value; /* Offset to last line number */
714 { long dummy = 0;
715 enter_line_range (current_subfile, fcn_first_line, cs->c_value, 0,
1ab3bf1b 716 (unsigned *) &dummy);
e38e0312
JG
717 }
718 start_subfile (pop_subfile (), (char *)0);
719 break;
720
721 case C_BLOCK :
722 if (strcmp (cs->c_name, ".bb") == 0) {
723 depth++;
724 new = push_context (depth, cs->c_value);
725 }
726 else if (strcmp (cs->c_name, ".eb") == 0) {
727 new = pop_context ();
728 if (depth != new->depth)
729 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
730 symnum);
731
732 depth--;
733 if (local_symbols && context_stack_depth > 0) {
734 /* Make a block for the local symbols within. */
735 finish_block (new->name, &local_symbols, new->old_blocks,
1ab3bf1b 736 new->start_addr, cs->c_value, objfile);
e38e0312
JG
737 }
738 local_symbols = new->locals;
739 }
740 break;
741
742 default :
1ab3bf1b 743 (void) process_xcoff_symbol (cs, objfile);
e38e0312
JG
744 break;
745 }
746
747 } /* while */
748
749 if (last_source_file)
750 end_symtab (cur_src_end_addr, 1, 1, objfile);
751
752 free (symtbl);
1ab3bf1b 753 current_objfile = NULL;
e38e0312
JG
754}
755
756#define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
757 (SYMBOL2) = (struct symbol *) \
1ab3bf1b 758 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
e38e0312
JG
759 *(SYMBOL2) = *(SYMBOL1);
760
761
762#define SYMNAME_ALLOC(NAME, ALLOCED) \
1ab3bf1b 763 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
e38e0312
JG
764
765
766
767/* process one xcoff symbol. */
768
769static struct symbol *
1ab3bf1b 770process_xcoff_symbol (cs, objfile)
e38e0312 771 register struct coff_symbol *cs;
1ab3bf1b 772 struct objfile *objfile;
e38e0312
JG
773{
774 struct symbol onesymbol;
775 register struct symbol *sym = &onesymbol;
776 struct symbol *sym2 = NULL;
777 struct type *ttype;
778 char *name, *pp, *qq;
779
780 name = cs->c_name;
781 if (name[0] == '.')
782 ++name;
783
784 bzero (sym, sizeof (struct symbol));
785
786 /* default assumptions */
787 SYMBOL_VALUE (sym) = cs->c_value;
788 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
789
790 if (ISFCN (cs->c_type)) {
791
792 /* At this point, we don't know the type of the function and assume it
793 is int. This will be patched with the type from its stab entry later
794 on in patch_block_stabs () */
795
796 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1ab3bf1b 797 SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (current_objfile, FT_INTEGER));
e38e0312
JG
798
799 SYMBOL_CLASS (sym) = LOC_BLOCK;
800 SYMBOL_DUP (sym, sym2);
801
802 if (cs->c_sclass == C_EXT)
803 add_symbol_to_list (sym2, &global_symbols);
804 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
805 add_symbol_to_list (sym2, &file_symbols);
806 }
807
808 else {
809
810 /* in case we can't figure out the type, default is `int'. */
1ab3bf1b 811 SYMBOL_TYPE (sym) = lookup_fundamental_type (current_objfile, FT_INTEGER);
e38e0312
JG
812
813 switch (cs->c_sclass)
814 {
815 case C_FUN:
816 if (fcn_cs_saved.c_sclass == C_EXT)
817 add_stab_to_list (name, &global_stabs);
818 else
819 add_stab_to_list (name, &file_stabs);
820 break;
821
822 case C_DECL: /* a type decleration?? */
1ab3bf1b 823 qq = (char*) strchr (name, ':');
e38e0312
JG
824 if (!qq) /* skip if there is no ':' */
825 return NULL;
826
827 pp = qq + 2;
1ab3bf1b 828 ttype = SYMBOL_TYPE (sym) = read_type (&pp, objfile);
e38e0312
JG
829
830 /* read_type() will return null if type (or tag) definition was
831 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
832 there is no need to keep it in symbol table. */
833
834 if (!ttype || name == qq)
835 return NULL;
836
837 if (qq[1] == 'T')
838 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
839 else if (qq[1] == 't')
840 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
841 else {
842 printf ("ERROR: Unrecognized stab string.\n");
843 return NULL;
844 }
845
846 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1ab3bf1b 847 SYMBOL_NAME (sym) = obsavestring (name, qq-name, &objfile->symbol_obstack);
e38e0312
JG
848
849 if (SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE)
850 TYPE_NAME (ttype) = concat (
851 TYPE_CODE (ttype) == TYPE_CODE_UNION ? "union " :
852 TYPE_CODE (ttype) == TYPE_CODE_STRUCT? "struct " : "enum ",
58ae87f6 853 SYMBOL_NAME (sym), NULL);
e38e0312
JG
854
855 else if (!TYPE_NAME (ttype)) /* else, regular typedef. */
856 TYPE_NAME (ttype) = SYMBOL_NAME (sym);
857
858 SYMBOL_DUP (sym, sym2);
859 add_symbol_to_list
860 (sym2, within_function ? &local_symbols : &file_symbols);
861 break;
862
863 case C_GSYM:
864 add_stab_to_list (name, &global_stabs);
865 break;
866
867 case C_PSYM:
1ab3bf1b 868 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
e38e0312 869 return NULL;
1ab3bf1b 870 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
e38e0312
JG
871 SYMBOL_CLASS (sym) = LOC_ARG;
872 pp += 2;
1ab3bf1b 873 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
e38e0312
JG
874 SYMBOL_DUP (sym, sym2);
875 add_symbol_to_list (sym2, &local_symbols);
876 break;
877
878 case C_STSYM:
1ab3bf1b 879 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
e38e0312 880 return NULL;
1ab3bf1b 881 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
e38e0312
JG
882 SYMBOL_CLASS (sym) = LOC_STATIC;
883 SYMBOL_VALUE (sym) += static_block_base;
884 pp += 2;
1ab3bf1b 885 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
e38e0312
JG
886 SYMBOL_DUP (sym, sym2);
887 add_symbol_to_list
888 (sym2, within_function ? &local_symbols : &file_symbols);
889 break;
890
891 case C_LSYM:
1ab3bf1b 892 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
e38e0312 893 return NULL;
1ab3bf1b 894 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
e38e0312
JG
895 SYMBOL_CLASS (sym) = LOC_LOCAL;
896 pp += 1;
1ab3bf1b 897 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
e38e0312
JG
898 SYMBOL_DUP (sym, sym2);
899 add_symbol_to_list (sym2, &local_symbols);
900 break;
901
902 case C_AUTO:
903 SYMBOL_CLASS (sym) = LOC_LOCAL;
904 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
905 SYMBOL_DUP (sym, sym2);
906 add_symbol_to_list (sym2, &local_symbols);
907 break;
908
909 case C_EXT:
910 SYMBOL_CLASS (sym) = LOC_STATIC;
911 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
912 SYMBOL_DUP (sym, sym2);
913 add_symbol_to_list (sym2, &global_symbols);
914 break;
915
916 case C_STAT:
917 SYMBOL_CLASS (sym) = LOC_STATIC;
918 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
919 SYMBOL_DUP (sym, sym2);
920 add_symbol_to_list
921 (sym2, within_function ? &local_symbols : &file_symbols);
922 break;
923
924 case C_REG:
925 printf ("ERROR! C_REG is not fully implemented!\n");
926 SYMBOL_CLASS (sym) = LOC_REGISTER;
927 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
928 SYMBOL_DUP (sym, sym2);
929 add_symbol_to_list (sym2, &local_symbols);
930 break;
931
932 case C_RSYM:
1ab3bf1b 933 pp = (char*) strchr (name, ':');
e38e0312
JG
934 SYMBOL_CLASS (sym) = LOC_REGISTER;
935 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (cs->c_value);
936 if (pp) {
1ab3bf1b 937 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
e38e0312
JG
938 pp += 2;
939 if (*pp)
1ab3bf1b 940 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
e38e0312
JG
941 }
942 else
943 /* else this is not a stab entry, suppose the type is either
944 `int' or `float', depending on the register class. */
945
1ab3bf1b
JG
946 SYMBOL_TYPE (sym) = (SYMBOL_VALUE (sym) < 32)
947 ? lookup_fundamental_type (current_objfile, FT_INTEGER)
948 : lookup_fundamental_type (current_objfile, FT_FLOAT);
e38e0312
JG
949
950 SYMBOL_DUP (sym, sym2);
951 add_symbol_to_list (sym2, &local_symbols);
952 break;
953
954 default :
955 printf ("ERROR: Unexpected storage class: %d.\n", cs->c_sclass);
956 return NULL;
957 }
958 }
959 return sym2;
960}
961
962
963static int
964read_symbol_nvalue (symtable, symno)
965 char *symtable;
966 int symno;
967{
968 struct internal_syment symbol[1];
969
970 bfd_coff_swap_sym_in (symfile_bfd, symtable + (symno*local_symesz), symbol);
971 return symbol->n_value;
972}
973
974
975static int
976read_symbol_lineno (symtable, symno)
977 char *symtable;
978 int symno;
979{
980 struct internal_syment symbol[1];
981 union internal_auxent main_aux[1];
982
983 int ii;
984
985 for (ii = 0; ii < 50; ii++) {
986 bfd_coff_swap_sym_in (symfile_bfd,
987 symtable + (symno*local_symesz), symbol);
988 if (symbol->n_sclass == C_FCN && 0 == strcmp (symbol->n_name, ".bf"))
989 goto gotit;
6b5b330b 990 symno += symbol->n_numaux+1;
e38e0312
JG
991 }
992
993 printf ("GDB Error: `.bf' not found.\n");
994 return 0;
995
996gotit:
997 /* take aux entry and return its lineno */
998 symno++;
999 bfd_coff_swap_aux_in (symfile_bfd, symtable+(symno*local_symesz),
1000 symbol->n_type, symbol->n_sclass, main_aux);
1001
1002 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1003}
1004
1005/* Support for line number handling */
1006
1007/* This function is called for every section; it finds the outer limits
1008 * of the line table (minimum and maximum file offset) so that the
1009 * mainline code can read the whole thing for efficiency.
1010 */
1011static void
1012find_linenos(abfd, asect, vpinfo)
1013bfd *abfd;
1014sec_ptr asect;
1ab3bf1b 1015PTR vpinfo;
e38e0312
JG
1016{
1017 struct coff_symfile_info *info;
1018 int size, count;
1019 file_ptr offset, maxoff;
1020
1021 count = asect->lineno_count;
1022
1023 if (count == 0)
1024 return;
1025
1026 size = count * coff_data (symfile_bfd)->local_linesz;
1027 info = (struct coff_symfile_info *)vpinfo;
1028 offset = asect->line_filepos;
1029 maxoff = offset + size;
1030
1031 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1032 info->min_lineno_offset = offset;
1033
1034 if (maxoff > info->max_lineno_offset)
1035 info->max_lineno_offset = maxoff;
1036}
1037
1038
1039/* Read in all the line numbers for fast lookups later. Leave them in
1040 external (unswapped) format in memory; we'll swap them as we enter
1041 them into GDB's data structures. */
1042
1043static int
1044init_lineno (abfd, offset, size)
1045 bfd *abfd;
1046 long offset;
1047 int size;
1048{
1049 int val;
1050
1051 if (bfd_seek(abfd, offset, 0) < 0)
1052 return -1;
1053
1054 linetab = (char *) xmalloc(size);
1055
1056 val = bfd_read(linetab, 1, size, abfd);
1057 if (val != size)
1058 return -1;
1059
1060 linetab_offset = offset;
1061 linetab_size = size;
1ab3bf1b 1062 make_cleanup (free, linetab); /* Be sure it gets de-allocated. */
e38e0312
JG
1063 return 0;
1064}
93fe4e33 1065\f
e38e0312
JG
1066/* dbx allows the text of a symbol name to be continued into the
1067 next symbol name! When such a continuation is encountered
1068 (a \ at the end of the text of a name)
1069 call this function to get the continuation. */
1070/* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1071 for aixcoff. */
1072
1d4c28c5 1073#undef next_symbol_text
e38e0312
JG
1074#define next_symbol_text() \
1075 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1076
1077
1078/* xlc/dbx combination uses a set of builtin types, starting from -1. return
1079 the proper type node fora given builtin type #. */
1080
1081struct type *
1082builtin_type (pp)
1083char **pp;
1084{
1085 int typenums[2];
1086
1087 if (**pp != '-') {
1088 printf ("ERROR!, unknown built-in type!\n");
1089 return NULL;
1090 }
1091 *pp += 1;
1092 read_type_number (pp, typenums);
1093
1094 /* default types are defined in dbxstclass.h. */
1095 switch ( typenums[1] ) {
1096 case 1:
1ab3bf1b 1097 return lookup_fundamental_type (current_objfile, FT_INTEGER);
e38e0312 1098 case 2:
1ab3bf1b 1099 return lookup_fundamental_type (current_objfile, FT_CHAR);
e38e0312 1100 case 3:
1ab3bf1b 1101 return lookup_fundamental_type (current_objfile, FT_SHORT);
e38e0312 1102 case 4:
1ab3bf1b 1103 return lookup_fundamental_type (current_objfile, FT_LONG);
e38e0312 1104 case 5:
1ab3bf1b 1105 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
e38e0312 1106 case 6:
1ab3bf1b 1107 return lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR);
e38e0312 1108 case 7:
1ab3bf1b 1109 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
e38e0312 1110 case 8:
1ab3bf1b 1111 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
e38e0312 1112 case 9:
1ab3bf1b 1113 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
e38e0312 1114 case 10:
1ab3bf1b 1115 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
e38e0312 1116 case 11:
1ab3bf1b 1117 return lookup_fundamental_type (current_objfile, FT_VOID);
e38e0312 1118 case 12:
1ab3bf1b 1119 return lookup_fundamental_type (current_objfile, FT_FLOAT);
e38e0312 1120 case 13:
1ab3bf1b 1121 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
e38e0312 1122 case 14:
1ab3bf1b 1123 return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
e38e0312 1124 case 15:
1ab3bf1b
JG
1125 /* requires a builtin `integer' */
1126 return lookup_fundamental_type (current_objfile, FT_INTEGER);
e38e0312 1127 case 16:
1ab3bf1b 1128 return lookup_fundamental_type (current_objfile, FT_BOOLEAN);
e38e0312 1129 case 17:
1ab3bf1b
JG
1130 /* requires builtin `short real' */
1131 return lookup_fundamental_type (current_objfile, FT_FLOAT);
e38e0312 1132 case 18:
1ab3bf1b
JG
1133 /* requires builtin `real' */
1134 return lookup_fundamental_type (current_objfile, FT_FLOAT);
e38e0312
JG
1135 default :
1136 printf ("ERROR! Unknown builtin type -%d\n", typenums[1]);
1137 return NULL;
1138 }
1139}
1140
1ab3bf1b
JG
1141#if 0 /* Seems to be unused, don't bother converting from old misc function
1142 vector usage to new minimal symbol tables. FIXME: Delete this? */
1143
e38e0312
JG
1144/* if we now nothing about a function but its address, make a function symbol
1145 out of it with the limited knowladge you have. This will be used when
1146 somebody refers to a function, which doesn't exist in the symbol table,
1ab3bf1b 1147 but is in the minimal symbol table. */
e38e0312
JG
1148
1149struct symbol *
1ab3bf1b 1150build_function_symbol (ind, objfile)
e38e0312 1151 int ind;
1ab3bf1b 1152 struct objfile *objfile;
e38e0312
JG
1153{
1154 struct symbol *sym =
1ab3bf1b 1155 (struct symbol *) obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
e38e0312
JG
1156 SYMBOL_NAME (sym) = misc_function_vector[ind].name;
1157 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
1158 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1159 SYMBOL_CLASS (sym) = LOC_BLOCK;
1ab3bf1b 1160 SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (current_objfile, FT_INTEGER));
e38e0312 1161 SYMBOL_BLOCK_VALUE (sym) = (struct block *)
1ab3bf1b 1162 obstack_alloc (&objfile->symbol_obstack, sizeof (struct block));
e38e0312
JG
1163 BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) = misc_function_vector[ind].address;
1164 return sym;
1165}
1166
1ab3bf1b 1167#endif
e38e0312 1168
1ab3bf1b 1169static void
e38e0312
JG
1170aixcoff_new_init ()
1171{
1172 /* Nothin' to do. */
1173}
1174
1ab3bf1b 1175static void
e38e0312
JG
1176aixcoff_symfile_init (sf)
1177struct sym_fns *sf;
1178{
1179 bfd *abfd = sf->sym_bfd;
1180
1181 /* Allocate struct to keep track of the symfile */
1182 /* FIXME memory leak */
1183 sf->sym_private = xmalloc(sizeof (struct coff_symfile_info));
1184
1185 /*
1186 * Save startup file's range of PC addresses to help
1187 * blockframe.c decide where the bottom of the stack is.
1188 */
1189 if (bfd_get_file_flags(abfd) & EXEC_P) {
1190 entry_point = bfd_get_start_address(abfd);
1191 } else {
1192 entry_point = ~0;
1193 /* set the startup file to be an empty range. */
1194 startup_file_start = 0;
1195 startup_file_end = 0;
1196 }
1197}
1198
1199
1200static int
1ab3bf1b 1201init_stringtab(abfd, offset, objfile)
e38e0312
JG
1202 bfd *abfd;
1203 long offset;
1ab3bf1b 1204 struct objfile *objfile;
e38e0312
JG
1205{
1206 long length;
1207 int val;
1208 unsigned char lengthbuf[4];
1209
1210 if (bfd_seek(abfd, offset, 0) < 0)
1211 return -1;
1212
1213 val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
1214 length = bfd_h_get_32(abfd, lengthbuf);
1215
1216 /* If no string table is needed, then the file may end immediately
1217 after the symbols. Just return with `strtbl' set to null. */
1218
1219 if (val != sizeof length || length < sizeof length)
1220 return 0;
1221
1222 /* Allocate string table from symbol_obstack. We will need this table
1223 as long as we have its symbol table around. */
1224
1ab3bf1b 1225 strtbl = (char*) obstack_alloc (&objfile->symbol_obstack, length);
e38e0312
JG
1226 if (strtbl == NULL)
1227 return -1;
1228
1229 bcopy(&length, strtbl, sizeof length);
1230 if (length == sizeof length)
1231 return 0;
1232
1233 val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd);
1234
1235 if (val != length - sizeof length || strtbl[length - 1] != '\0')
1236 return -1;
1237
1238 return 0;
1239}
1240
1241static int
1242init_debugsection(abfd)
1243 bfd *abfd;
1244{
1245 register sec_ptr secp;
1246 bfd_size_type length;
1247
1248 if (debugsec) {
1249 free(debugsec);
1250 debugsec = NULL;
1251 }
1252
1253 secp = bfd_get_section_by_name(abfd, ".debug");
1254 if (!secp)
1255 return 0;
1256
1257 if (!(length = bfd_section_size(abfd, secp)))
1258 return 0;
1259
1ab3bf1b 1260 debugsec = (char *) xmalloc ((unsigned)length);
e38e0312
JG
1261 if (debugsec == NULL)
1262 return -1;
1263
1264 if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) {
1265 printf ("Can't read .debug section from symbol file\n");
1266 return -1;
1267 }
1268 return 0;
1269}
1270
1271static void
1272free_debugsection()
1273{
1274 if (debugsec)
1275 free(debugsec);
1276 debugsec = NULL;
1277}
1278
1279
1280/* aixcoff version of symbol file read. */
1281
1ab3bf1b 1282static void
e38e0312
JG
1283aixcoff_symfile_read (sf, addr, mainline)
1284 struct sym_fns *sf;
1285 CORE_ADDR addr;
1286 int mainline;
1287{
1288 int num_symbols; /* # of symbols */
1289 int symtab_offset; /* symbol table and */
1290 int stringtab_offset; /* string table file offsets */
1291 int val;
1292 bfd *abfd;
1293 struct coff_symfile_info *info = (void*) sf->sym_private;
1294 char *name;
1295
1296 symfile_bfd = abfd = sf->objfile->obfd;
1297 name = sf->objfile->name;
1298
1299 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
1300 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
1301 stringtab_offset = symtab_offset +
1302 num_symbols * coff_data(abfd)->local_symesz;
1303
1304 info->min_lineno_offset = 0;
1305 info->max_lineno_offset = 0;
1306 bfd_map_over_sections (abfd, find_linenos, info);
1307
1308 /* FIXME! This stuff should move into symfile_init */
1309 if (info->min_lineno_offset != 0
1310 && info->max_lineno_offset > info->min_lineno_offset) {
1311
1312 /* only read in the line # table if one exists */
1313 val = init_lineno(abfd, info->min_lineno_offset,
1314 info->max_lineno_offset - info->min_lineno_offset);
1315
1316 if (val < 0)
1317 error("\"%s\": error reading line numbers\n", name);
1318 }
1319
1ab3bf1b 1320 val = init_stringtab(abfd, stringtab_offset, sf->objfile);
e38e0312
JG
1321 if (val < 0) {
1322 error ("\"%s\": can't get string table", name);
1323 }
1324
1325 if (init_debugsection(abfd) < 0) {
1326 error ("Error reading .debug section of `%s'\n", name);
1327 }
1328
1329 /* Position to read the symbol table. Do not read it all at once. */
1330 val = bfd_seek(abfd, (long)symtab_offset, 0);
1331 if (val < 0)
1332 perror_with_name(name);
1333
1334 if (bfd_tell(abfd) != symtab_offset)
1335 fatal("bfd? BFD!");
1336
1ab3bf1b
JG
1337 init_minimal_symbol_collection ();
1338 make_cleanup (discard_minimal_symbols, 0);
e38e0312
JG
1339
1340#ifdef XCOFF_INIT_LOADINFO
1341 if (mainline)
1342 XCOFF_INIT_LOADINFO ();
1343#endif
1344
1345 /* Now that the executable file is positioned at symbol table,
1346 process it and define symbols accordingly. */
1347
1348 read_xcoff_symtab(sf->objfile, num_symbols);
1349
1ab3bf1b 1350 make_cleanup (free_debugsection, 0);
e38e0312
JG
1351
1352 /* Sort symbols alphabetically within each block. */
1353 sort_syms ();
1354
1ab3bf1b
JG
1355 /* Install any minimal symbols that have been collected as the current
1356 minimal symbols for this objfile. */
1357
021959e2 1358 install_minimal_symbols (sf -> objfile);
e38e0312
JG
1359
1360 /* Make a default for file to list. */
1361 select_source_symtab (0);
1362}
1363
1364/* Register our ability to parse symbols for aixcoff BFD files. */
1365
1366static struct sym_fns aixcoff_sym_fns =
1367{
1368 "aixcoff-rs6000", 15,
1369 aixcoff_new_init, aixcoff_symfile_init,
1370 aixcoff_symfile_read,
1371};
1372
1373void
1374_initialize_xcoffread ()
1375{
1376 add_symtab_fns(&aixcoff_sym_fns);
1377}
This page took 0.118167 seconds and 4 git commands to generate.