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