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