Commit | Line | Data |
---|---|---|
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 | ||
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" | |
e38e0312 | 24 | |
1eeba686 | 25 | #ifdef IBM6000_HOST |
818de002 PB |
26 | /* Native only: Need struct tbtable in <sys/debug.h>. */ |
27 | ||
e38e0312 JG |
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> | |
5e4d4b0f | 37 | #ifndef NO_SYS_FILE |
e38e0312 | 38 | #include <sys/file.h> |
5e4d4b0f | 39 | #endif |
e38e0312 | 40 | #include <sys/stat.h> |
818de002 | 41 | #include <sys/debug.h> |
e38e0312 JG |
42 | |
43 | #include "symtab.h" | |
1ab3bf1b | 44 | #include "gdbtypes.h" |
e38e0312 | 45 | #include "symfile.h" |
5e2e79f8 | 46 | #include "objfiles.h" |
e38e0312 | 47 | #include "buildsym.h" |
d07734e3 | 48 | #include "stabsread.h" |
2670f34d | 49 | #include "gdb-stabs.h" |
e38e0312 | 50 | |
f5f0679a | 51 | #include "coff/internal.h" /* FIXME, internal data from BFD */ |
e38e0312 | 52 | #include "libcoff.h" /* FIXME, internal data from BFD */ |
f5f0679a | 53 | #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */ |
e38e0312 | 54 | |
1eeba686 PB |
55 | |
56 | /* Define this if you want gdb use the old xcoff symbol processing. This | |
57 | way it won't use common `define_symbol()' function and Sun dbx stab | |
58 | string grammar. And likely it won't be able to do G++ debugging. */ | |
59 | ||
60 | /* #define NO_DEFINE_SYMBOL 1 */ | |
61 | ||
62 | /* Define this if you want gdb to ignore typdef stabs. This was needed for | |
63 | one of Transarc, to reduce the size of the symbol table. Types won't be | |
64 | recognized, but tag names will be. */ | |
65 | ||
554d1be4 | 66 | /* #define NO_TYPEDEFS 1 */ |
1eeba686 | 67 | |
e38e0312 JG |
68 | /* Simplified internal version of coff symbol table information */ |
69 | ||
70 | struct coff_symbol { | |
71 | char *c_name; | |
72 | int c_symnum; /* symbol number of this entry */ | |
73 | int c_nsyms; /* 0 if syment only, 1 if syment + auxent */ | |
74 | long c_value; | |
75 | int c_sclass; | |
76 | int c_secnum; | |
77 | unsigned int c_type; | |
78 | }; | |
79 | ||
80 | /* The COFF line table, in raw form. */ | |
81 | static char *linetab = NULL; /* Its actual contents */ | |
82 | static long linetab_offset; /* Its offset in the file */ | |
83 | static unsigned long linetab_size; /* Its size */ | |
84 | ||
85 | /* last function's saved coff symbol `cs' */ | |
86 | ||
87 | static struct coff_symbol fcn_cs_saved; | |
88 | ||
89 | static bfd *symfile_bfd; | |
90 | ||
91 | /* Core address of start and end of text of current source file. | |
92 | This is calculated from the first function seen after a C_FILE | |
93 | symbol. */ | |
94 | ||
818de002 | 95 | |
e38e0312 JG |
96 | static CORE_ADDR cur_src_end_addr; |
97 | ||
98 | /* Core address of the end of the first object file. */ | |
99 | ||
100 | static CORE_ADDR first_object_file_end; | |
101 | ||
102 | /* pointer to the string table */ | |
103 | static char *strtbl; | |
104 | ||
105 | /* length of the string table */ | |
106 | static int strtbl_len; | |
107 | ||
108 | /* pointer to debug section */ | |
109 | static char *debugsec; | |
110 | ||
111 | /* pointer to the a.out symbol table */ | |
112 | static char *symtbl; | |
113 | ||
114 | /* initial symbol-table-debug-string vector length */ | |
115 | ||
116 | #define INITIAL_STABVECTOR_LENGTH 40 | |
117 | ||
e38e0312 JG |
118 | /* Nonzero if within a function (so symbols should be local, |
119 | if nothing says specifically). */ | |
120 | ||
121 | int within_function; | |
122 | ||
123 | /* Local variables that hold the shift and mask values for the | |
124 | COFF file that we are currently reading. These come back to us | |
125 | from BFD, and are referenced by their macro names, as well as | |
126 | internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF | |
127 | macros from ../internalcoff.h . */ | |
128 | ||
129 | static unsigned local_n_btshft; | |
130 | static unsigned local_n_tmask; | |
131 | ||
132 | #undef N_BTSHFT | |
133 | #define N_BTSHFT local_n_btshft | |
134 | #undef N_TMASK | |
135 | #define N_TMASK local_n_tmask | |
136 | ||
137 | /* Local variables that hold the sizes in the file of various COFF structures. | |
138 | (We only need to know this to read them from the file -- BFD will then | |
139 | translate the data in them, into `internal_xxx' structs in the right | |
140 | byte order, alignment, etc.) */ | |
141 | ||
142 | static unsigned local_symesz; | |
143 | ||
818de002 | 144 | |
e38e0312 JG |
145 | /* coff_symfile_init() |
146 | is the coff-specific initialization routine for reading symbols. | |
147 | It is passed a struct sym_fns which contains, among other things, | |
148 | the BFD for the file whose symbols are being read, and a slot for | |
149 | a pointer to "private data" which we fill with cookies and other | |
150 | treats for coff_symfile_read(). | |
151 | ||
152 | We will only be called if this is a COFF or COFF-like file. | |
153 | BFD handles figuring out the format of the file, and code in symtab.c | |
154 | uses BFD's determination to vector to us. | |
155 | ||
156 | The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */ | |
157 | ||
158 | struct coff_symfile_info { | |
159 | file_ptr min_lineno_offset; /* Where in file lowest line#s are */ | |
160 | file_ptr max_lineno_offset; /* 1+last byte of line#s in file */ | |
161 | }; | |
162 | ||
163 | ||
1ab3bf1b | 164 | static void |
818de002 PB |
165 | enter_line_range PARAMS ((struct subfile *, unsigned, unsigned, |
166 | CORE_ADDR, CORE_ADDR, unsigned *)); | |
1ab3bf1b | 167 | |
1ab3bf1b JG |
168 | static void |
169 | free_debugsection PARAMS ((void)); | |
170 | ||
171 | static int | |
172 | init_debugsection PARAMS ((bfd *)); | |
173 | ||
174 | static int | |
175 | init_stringtab PARAMS ((bfd *, long, struct objfile *)); | |
176 | ||
177 | static void | |
80d68b1d FF |
178 | aixcoff_symfile_init PARAMS ((struct objfile *)); |
179 | ||
180 | static void | |
181 | aixcoff_new_init PARAMS ((struct objfile *)); | |
182 | ||
930acbe5 SG |
183 | struct section_offset; |
184 | ||
80d68b1d | 185 | static void |
2670f34d | 186 | aixcoff_symfile_read PARAMS ((struct objfile *, struct section_offset *, int)); |
1ab3bf1b JG |
187 | |
188 | static void | |
80d68b1d | 189 | aixcoff_symfile_finish PARAMS ((struct objfile *)); |
1ab3bf1b | 190 | |
fe0b60b2 | 191 | static struct section_offsets * |
2670f34d JG |
192 | aixcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR)); |
193 | ||
1ab3bf1b JG |
194 | static int |
195 | init_lineno PARAMS ((bfd *, long, int)); | |
196 | ||
197 | static void | |
198 | find_linenos PARAMS ((bfd *, sec_ptr, PTR)); | |
199 | ||
200 | static int | |
201 | read_symbol_lineno PARAMS ((char *, int)); | |
202 | ||
203 | static int | |
204 | read_symbol_nvalue PARAMS ((char *, int)); | |
205 | ||
206 | static struct symbol * | |
207 | process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *)); | |
208 | ||
209 | static void | |
210 | read_xcoff_symtab PARAMS ((struct objfile *, int)); | |
211 | ||
1ab3bf1b JG |
212 | static void |
213 | add_stab_to_list PARAMS ((char *, struct pending_stabs **)); | |
214 | ||
215 | static void | |
216 | sort_syms PARAMS ((void)); | |
217 | ||
218 | static int | |
219 | compare_symbols PARAMS ((const void *, const void *)); | |
220 | ||
e38e0312 JG |
221 | /* Call sort_syms to sort alphabetically |
222 | the symbols of each block of each symtab. */ | |
223 | ||
224 | static int | |
1ab3bf1b JG |
225 | compare_symbols (s1p, s2p) |
226 | const PTR s1p; | |
227 | const PTR s2p; | |
e38e0312 JG |
228 | { |
229 | /* Names that are less should come first. */ | |
1ab3bf1b JG |
230 | register struct symbol **s1 = (struct symbol **) s1p; |
231 | register struct symbol **s2 = (struct symbol **) s2p; | |
e38e0312 JG |
232 | register int namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2)); |
233 | if (namediff != 0) | |
234 | return namediff; | |
235 | ||
236 | /* For symbols of the same name, registers should come first. */ | |
237 | return ((SYMBOL_CLASS (*s2) == LOC_REGISTER) | |
238 | - (SYMBOL_CLASS (*s1) == LOC_REGISTER)); | |
239 | } | |
240 | ||
241 | ||
242 | /* Sort a vector of symbols by their value. */ | |
243 | ||
244 | static void | |
245 | sort_syms () | |
246 | { | |
247 | register struct symtab *s; | |
1ab3bf1b | 248 | register struct objfile *objfile; |
e38e0312 JG |
249 | register int i, nbl; |
250 | register struct blockvector *bv; | |
251 | register struct block *b; | |
252 | ||
1ab3bf1b | 253 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
e38e0312 | 254 | { |
1ab3bf1b JG |
255 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
256 | { | |
257 | bv = BLOCKVECTOR (s); | |
258 | nbl = BLOCKVECTOR_NBLOCKS (bv); | |
259 | for (i = 0; i < nbl; i++) | |
260 | { | |
261 | b = BLOCKVECTOR_BLOCK (bv, i); | |
262 | if (BLOCK_SHOULD_SORT (b)) | |
263 | { | |
264 | qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), | |
265 | sizeof (struct symbol *), compare_symbols); | |
266 | } | |
267 | } | |
268 | } | |
e38e0312 | 269 | } |
e38e0312 JG |
270 | } |
271 | ||
272 | ||
273 | /* add a given stab string into given stab vector. */ | |
274 | ||
275 | static void | |
276 | add_stab_to_list (stabname, stabvector) | |
277 | char *stabname; | |
278 | struct pending_stabs **stabvector; | |
279 | { | |
280 | if ( *stabvector == NULL) { | |
281 | *stabvector = (struct pending_stabs *) | |
282 | xmalloc (sizeof (struct pending_stabs) + | |
283 | INITIAL_STABVECTOR_LENGTH * sizeof (char*)); | |
284 | (*stabvector)->count = 0; | |
285 | (*stabvector)->length = INITIAL_STABVECTOR_LENGTH; | |
286 | } | |
287 | else if ((*stabvector)->count >= (*stabvector)->length) { | |
288 | (*stabvector)->length += INITIAL_STABVECTOR_LENGTH; | |
289 | *stabvector = (struct pending_stabs *) | |
1ab3bf1b | 290 | xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) + |
e38e0312 JG |
291 | (*stabvector)->length * sizeof (char*)); |
292 | } | |
293 | (*stabvector)->stab [(*stabvector)->count++] = stabname; | |
294 | } | |
295 | ||
296 | ||
818de002 PB |
297 | #if 0 |
298 | /* for all the stabs in a given stab vector, build appropriate types | |
299 | and fix their symbols in given symbol vector. */ | |
300 | ||
301 | void | |
302 | patch_block_stabs (symbols, stabs) | |
303 | struct pending *symbols; | |
304 | struct pending_stabs *stabs; | |
305 | { | |
306 | int ii; | |
307 | ||
308 | if (!stabs) | |
309 | return; | |
310 | ||
311 | /* for all the stab entries, find their corresponding symbols and | |
312 | patch their types! */ | |
313 | ||
314 | for (ii=0; ii < stabs->count; ++ii) { | |
315 | char *name = stabs->stab[ii]; | |
316 | char *pp = (char*) index (name, ':'); | |
317 | struct symbol *sym = find_symbol_in_list (symbols, name, pp-name); | |
318 | if (!sym) { | |
319 | ; | |
84ffdec2 | 320 | /* printf ("ERROR! stab symbol not found!\n"); */ /* FIXME */ |
818de002 PB |
321 | /* The above is a false alarm. There are cases the we can have |
322 | a stab, without its symbol. xlc generates this for the extern | |
323 | definitions in inner blocks. */ | |
324 | } | |
325 | else { | |
326 | pp += 2; | |
327 | ||
328 | if (*(pp-1) == 'F' || *(pp-1) == 'f') | |
329 | SYMBOL_TYPE (sym) = lookup_function_type (read_type (&pp)); | |
330 | else | |
331 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); | |
332 | } | |
333 | } | |
334 | } | |
335 | #endif | |
336 | ||
337 | ||
338 | /* compare line table entry addresses. */ | |
339 | ||
340 | static int | |
341 | compare_lte (lte1, lte2) | |
342 | struct linetable_entry *lte1, *lte2; | |
343 | { | |
344 | return lte1->pc - lte2->pc; | |
345 | } | |
346 | ||
347 | /* Give a line table with function entries are marked, arrange its functions | |
348 | in assending order and strip off function entry markers and return it in | |
349 | a newly created table. If the old one is good enough, return the old one. */ | |
350 | ||
351 | static struct linetable * | |
352 | arrange_linetable (oldLineTb) | |
353 | struct linetable *oldLineTb; /* old linetable */ | |
354 | { | |
355 | int ii, jj, | |
356 | newline, /* new line count */ | |
357 | function_count; /* # of functions */ | |
358 | ||
359 | struct linetable_entry *fentry; /* function entry vector */ | |
360 | int fentry_size; /* # of function entries */ | |
361 | struct linetable *newLineTb; /* new line table */ | |
362 | ||
363 | #define NUM_OF_FUNCTIONS 20 | |
364 | ||
365 | fentry_size = NUM_OF_FUNCTIONS; | |
366 | fentry = (struct linetable_entry*) | |
367 | malloc (fentry_size * sizeof (struct linetable_entry)); | |
368 | ||
369 | for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) { | |
370 | ||
371 | if (oldLineTb->item[ii].line == 0) { /* function entry found. */ | |
372 | ||
373 | if (function_count >= fentry_size) { /* make sure you have room. */ | |
374 | fentry_size *= 2; | |
375 | fentry = (struct linetable_entry*) | |
376 | realloc (fentry, fentry_size * sizeof (struct linetable_entry)); | |
377 | } | |
378 | fentry[function_count].line = ii; | |
379 | fentry[function_count].pc = oldLineTb->item[ii].pc; | |
380 | ++function_count; | |
381 | } | |
382 | } | |
383 | ||
384 | if (function_count == 0) { | |
385 | free (fentry); | |
386 | return oldLineTb; | |
387 | } | |
388 | else if (function_count > 1) | |
389 | qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte); | |
390 | ||
391 | /* allocate a new line table. */ | |
392 | newLineTb = (struct linetable*) malloc (sizeof (struct linetable) + | |
393 | (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry)); | |
394 | ||
395 | /* if line table does not start with a function beginning, copy up until | |
396 | a function begin. */ | |
397 | ||
398 | newline = 0; | |
399 | if (oldLineTb->item[0].line != 0) | |
400 | for (newline=0; | |
401 | newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline) | |
402 | newLineTb->item[newline] = oldLineTb->item[newline]; | |
403 | ||
404 | /* Now copy function lines one by one. */ | |
405 | ||
406 | for (ii=0; ii < function_count; ++ii) { | |
407 | for (jj = fentry[ii].line + 1; | |
408 | jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0; | |
409 | ++jj, ++newline) | |
410 | newLineTb->item[newline] = oldLineTb->item[jj]; | |
411 | } | |
412 | free (fentry); | |
413 | newLineTb->nitems = oldLineTb->nitems - function_count; | |
414 | return newLineTb; | |
415 | } | |
416 | ||
417 | ||
418 | ||
419 | /* We try to detect the beginning of a compilation unit. That info will | |
420 | be used as an entry in line number recording routines (enter_line_range) */ | |
421 | ||
422 | static unsigned first_fun_line_offset; | |
423 | static unsigned first_fun_bf; | |
424 | ||
425 | #define mark_first_line(OFFSET, SYMNUM) \ | |
426 | if (!first_fun_line_offset) { \ | |
427 | first_fun_line_offset = OFFSET; \ | |
428 | first_fun_bf = SYMNUM; \ | |
429 | } | |
430 | ||
431 | ||
432 | /* include file support: C_BINCL/C_EINCL pairs will be kept in the | |
433 | following `IncludeChain'. At the end of each symtab (end_symtab), | |
434 | we will determine if we should create additional symtab's to | |
435 | represent if (the include files. */ | |
436 | ||
437 | ||
438 | typedef struct _inclTable { | |
439 | char *name; /* include filename */ | |
440 | int begin, end; /* offsets to the line table */ | |
441 | struct subfile *subfile; | |
442 | unsigned funStartLine; /* start line # of its function */ | |
443 | } InclTable; | |
444 | ||
445 | #define INITIAL_INCLUDE_TABLE_LENGTH 20 | |
446 | static InclTable *inclTable; /* global include table */ | |
447 | static int inclIndx; /* last entry to table */ | |
448 | static int inclLength; /* table length */ | |
449 | static int inclDepth; /* nested include depth */ | |
450 | ||
451 | ||
452 | static void | |
453 | record_include_begin (cs) | |
454 | struct coff_symbol *cs; | |
455 | { | |
6c6afbb9 | 456 | /* In aixcoff, we assume include files cannot be nested (not in .c files |
818de002 PB |
457 | of course, but in corresponding .s files.) */ |
458 | ||
459 | if (inclDepth) | |
460 | fatal ("aix internal: pending include file exists."); | |
461 | ||
462 | ++inclDepth; | |
463 | ||
464 | /* allocate an include file, or make room for the new entry */ | |
465 | if (inclLength == 0) { | |
466 | inclTable = (InclTable*) | |
467 | xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH); | |
468 | bzero (inclTable, sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH); | |
469 | inclLength = INITIAL_INCLUDE_TABLE_LENGTH; | |
470 | inclIndx = 0; | |
471 | } | |
472 | else if (inclIndx >= inclLength) { | |
473 | inclLength += INITIAL_INCLUDE_TABLE_LENGTH; | |
474 | inclTable = (InclTable*) | |
475 | xrealloc (inclTable, sizeof (InclTable) * inclLength); | |
476 | bzero (inclTable+inclLength-INITIAL_INCLUDE_TABLE_LENGTH, | |
477 | sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH); | |
478 | } | |
479 | ||
480 | inclTable [inclIndx].name = cs->c_name; | |
481 | inclTable [inclIndx].begin = cs->c_value; | |
482 | } | |
483 | ||
484 | ||
485 | static void | |
486 | record_include_end (cs) | |
487 | struct coff_symbol *cs; | |
488 | { | |
489 | InclTable *pTbl; | |
490 | ||
491 | if (inclDepth == 0) | |
492 | fatal ("aix internal: Mismatch C_BINCL/C_EINCL pair found."); | |
493 | ||
494 | pTbl = &inclTable [inclIndx]; | |
495 | pTbl->end = cs->c_value; | |
496 | ||
497 | --inclDepth; | |
498 | ++inclIndx; | |
499 | } | |
500 | ||
501 | ||
818de002 PB |
502 | /* given the start and end addresses of a compilation unit (or a csect, at times) |
503 | process its lines and create appropriate line vectors. */ | |
504 | ||
505 | static void | |
506 | process_linenos (start, end) | |
507 | CORE_ADDR start, end; | |
508 | { | |
509 | char *pp; | |
510 | int offset, ii; | |
511 | ||
512 | struct subfile main_subfile; /* subfile structure for the main | |
513 | compilation unit. */ | |
514 | ||
515 | /* in the main source file, any time we see a function entry, we reset | |
516 | this variable to function's absolute starting line number. All the | |
517 | following line numbers in the function are relative to this, and | |
518 | we record absolute line numbers in record_line(). */ | |
519 | ||
520 | int main_source_baseline = 0; | |
521 | ||
522 | ||
523 | unsigned *firstLine; | |
524 | CORE_ADDR addr; | |
525 | ||
526 | if (!(offset = first_fun_line_offset)) | |
527 | goto return_after_cleanup; | |
528 | ||
529 | bzero (&main_subfile, sizeof (main_subfile)); | |
530 | first_fun_line_offset = 0; | |
531 | ||
532 | if (inclIndx == 0) | |
556f3d90 PB |
533 | /* All source lines were in the main source file. None in include files. */ |
534 | ||
818de002 PB |
535 | enter_line_range (&main_subfile, offset, 0, start, end, |
536 | &main_source_baseline); | |
537 | ||
538 | /* else, there was source with line numbers in include files */ | |
539 | else { | |
540 | ||
541 | main_source_baseline = 0; | |
542 | for (ii=0; ii < inclIndx; ++ii) { | |
543 | ||
544 | struct subfile *tmpSubfile; | |
545 | ||
546 | /* if there is main file source before include file, enter it. */ | |
547 | if (offset < inclTable[ii].begin) { | |
548 | enter_line_range | |
549 | (&main_subfile, offset, inclTable[ii].begin - LINESZ, start, 0, | |
550 | &main_source_baseline); | |
551 | } | |
552 | ||
553 | /* Have a new subfile for the include file */ | |
554 | ||
555 | tmpSubfile = inclTable[ii].subfile = (struct subfile*) | |
556 | xmalloc (sizeof (struct subfile)); | |
557 | ||
558 | bzero (tmpSubfile, sizeof (struct subfile)); | |
559 | firstLine = &(inclTable[ii].funStartLine); | |
560 | ||
561 | /* enter include file's lines now. */ | |
562 | enter_line_range (tmpSubfile, inclTable[ii].begin, | |
563 | inclTable[ii].end, start, 0, firstLine); | |
564 | ||
565 | offset = inclTable[ii].end + LINESZ; | |
566 | } | |
567 | ||
568 | /* all the include files' line have been processed at this point. Now, | |
569 | enter remaining lines of the main file, if any left. */ | |
570 | if (offset < (linetab_offset + linetab_size + 1 - LINESZ)) { | |
571 | enter_line_range (&main_subfile, offset, 0, start, end, | |
572 | &main_source_baseline); | |
573 | } | |
574 | } | |
575 | ||
576 | /* Process main file's line numbers. */ | |
577 | if (main_subfile.line_vector) { | |
578 | struct linetable *lineTb, *lv; | |
579 | ||
580 | lv = main_subfile.line_vector; | |
581 | ||
582 | /* Line numbers are not necessarily ordered. xlc compilation will | |
583 | put static function to the end. */ | |
584 | ||
585 | lineTb = arrange_linetable (lv); | |
586 | if (lv == lineTb) { | |
587 | current_subfile->line_vector = (struct linetable *) | |
588 | xrealloc (lv, (sizeof (struct linetable) | |
589 | + lv->nitems * sizeof (struct linetable_entry))); | |
590 | ||
591 | } | |
592 | else { | |
593 | free (lv); | |
594 | current_subfile->line_vector = lineTb; | |
595 | } | |
596 | ||
597 | current_subfile->line_vector_length = | |
598 | current_subfile->line_vector->nitems; | |
556f3d90 | 599 | } |
818de002 PB |
600 | |
601 | /* Now, process included files' line numbers. */ | |
602 | ||
603 | for (ii=0; ii < inclIndx; ++ii) { | |
604 | ||
605 | if ( (inclTable[ii].subfile)->line_vector) { /* Useless if!!! FIXMEmgo */ | |
606 | struct linetable *lineTb, *lv; | |
607 | ||
608 | lv = (inclTable[ii].subfile)->line_vector; | |
609 | ||
610 | /* Line numbers are not necessarily ordered. xlc compilation will | |
611 | put static function to the end. */ | |
612 | ||
613 | lineTb = arrange_linetable (lv); | |
614 | ||
615 | push_subfile (); | |
616 | ||
617 | /* For the same include file, we might want to have more than one subfile. | |
618 | This happens if we have something like: | |
619 | ||
620 | ...... | |
621 | #include "foo.h" | |
622 | ...... | |
623 | #include "foo.h" | |
624 | ...... | |
625 | ||
626 | while foo.h including code in it. (stupid but possible) | |
627 | Since start_subfile() looks at the name and uses an existing one if finds, | |
628 | we need to provide a fake name and fool it. */ | |
629 | ||
630 | /* start_subfile (inclTable[ii].name, (char*)0); */ | |
631 | start_subfile (" ?", (char*)0); | |
632 | current_subfile->name = | |
633 | obsavestring (inclTable[ii].name, strlen (inclTable[ii].name), | |
634 | ¤t_objfile->symbol_obstack); | |
635 | ||
636 | if (lv == lineTb) { | |
637 | current_subfile->line_vector = (struct linetable *) | |
638 | xrealloc (lv, (sizeof (struct linetable) | |
639 | + lv->nitems * sizeof (struct linetable_entry))); | |
640 | ||
641 | } | |
642 | else { | |
643 | free (lv); | |
644 | current_subfile->line_vector = lineTb; | |
645 | } | |
646 | ||
647 | current_subfile->line_vector_length = | |
648 | current_subfile->line_vector->nitems; | |
649 | start_subfile (pop_subfile (), (char*)0); | |
650 | } | |
651 | } | |
818de002 PB |
652 | |
653 | return_after_cleanup: | |
654 | ||
655 | /* We don't want to keep alloc/free'ing the global include file table. */ | |
656 | inclIndx = 0; | |
657 | ||
658 | /* start with a fresh subfile structure for the next file. */ | |
659 | bzero (&main_subfile, sizeof (struct subfile)); | |
660 | } | |
661 | ||
662 | void | |
663 | aix_process_linenos () | |
664 | { | |
665 | /* process line numbers and enter them into line vector */ | |
666 | process_linenos (last_source_start_addr, cur_src_end_addr); | |
667 | } | |
668 | ||
669 | ||
e38e0312 JG |
670 | /* Enter a given range of lines into the line vector. |
671 | can be called in the following two ways: | |
818de002 PB |
672 | enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or |
673 | enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine) */ | |
e38e0312 JG |
674 | |
675 | static void | |
818de002 PB |
676 | enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr, firstLine) |
677 | struct subfile *subfile; | |
e38e0312 | 678 | unsigned beginoffset, endoffset; /* offsets to line table */ |
818de002 | 679 | CORE_ADDR startaddr, endaddr; |
e38e0312 JG |
680 | unsigned *firstLine; |
681 | { | |
682 | char *pp, *limit; | |
683 | CORE_ADDR addr; | |
818de002 PB |
684 | |
685 | /* Do Byte swapping, if needed. FIXME! */ | |
686 | #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno) | |
687 | #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr) | |
688 | #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx) | |
e38e0312 JG |
689 | |
690 | pp = &linetab [beginoffset - linetab_offset]; | |
691 | limit = endoffset ? &linetab [endoffset - linetab_offset] | |
692 | : &linetab [linetab_size -1]; | |
693 | ||
694 | while (pp <= limit) { | |
695 | ||
e38e0312 | 696 | /* find the address this line represents */ |
818de002 PB |
697 | addr = P_LINENO(pp) ? |
698 | P_LINEADDR(pp) : read_symbol_nvalue (symtbl, P_LINESYM(pp)); | |
e38e0312 | 699 | |
818de002 | 700 | if (addr < startaddr || (endaddr && addr > endaddr)) |
e38e0312 JG |
701 | return; |
702 | ||
818de002 PB |
703 | if (P_LINENO(pp) == 0) { |
704 | *firstLine = read_symbol_lineno (symtbl, P_LINESYM(pp)); | |
705 | record_line (subfile, 0, addr); | |
e38e0312 JG |
706 | --(*firstLine); |
707 | } | |
708 | else | |
818de002 PB |
709 | record_line (subfile, *firstLine + P_LINENO(pp), addr); |
710 | ||
711 | pp += LINESZ; | |
712 | } | |
713 | } | |
714 | ||
715 | typedef struct { | |
716 | int fsize; /* file size */ | |
717 | int fixedparms; /* number of fixed parms */ | |
718 | int floatparms; /* number of float parms */ | |
719 | unsigned int parminfo; /* parameter info. | |
720 | See /usr/include/sys/debug.h | |
721 | tbtable_ext.parminfo */ | |
722 | int framesize; /* function frame size */ | |
723 | } TracebackInfo; | |
724 | ||
725 | ||
726 | /* Given a function symbol, return its traceback information. */ | |
727 | ||
728 | TracebackInfo * | |
729 | retrieve_tracebackinfo (abfd, textsec, cs) | |
730 | bfd *abfd; | |
731 | sec_ptr textsec; | |
732 | struct coff_symbol *cs; | |
733 | { | |
734 | #define TBTABLE_BUFSIZ 2000 | |
735 | #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a | |
736 | traceback table. */ | |
737 | ||
738 | static TracebackInfo tbInfo; | |
739 | struct tbtable *ptb; | |
740 | ||
741 | static char buffer [TBTABLE_BUFSIZ]; | |
742 | ||
743 | int *pinsn; | |
744 | int bytesread=0; /* total # of bytes read so far */ | |
745 | int bufferbytes; /* number of bytes in the buffer */ | |
746 | ||
747 | int functionstart = cs->c_value - textsec->vma; | |
748 | ||
749 | bzero (&tbInfo, sizeof (tbInfo)); | |
750 | ||
751 | /* keep reading blocks of data from the text section, until finding a zero | |
752 | word and a traceback table. */ | |
753 | ||
556f3d90 | 754 | while ( |
818de002 PB |
755 | bufferbytes = ( |
756 | (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread)) ? | |
556f3d90 PB |
757 | TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread)) |
758 | ||
759 | && bfd_get_section_contents (abfd, textsec, buffer, | |
760 | (file_ptr)(functionstart + bytesread), bufferbytes)) | |
818de002 PB |
761 | { |
762 | bytesread += bufferbytes; | |
763 | pinsn = (int*) buffer; | |
764 | ||
765 | /* if this is the first time we filled the buffer, retrieve function | |
766 | framesize info. */ | |
767 | ||
768 | if (bytesread == bufferbytes) { | |
769 | ||
770 | /* skip over unrelated instructions */ | |
771 | ||
772 | if (*pinsn == 0x7c0802a6) /* mflr r0 */ | |
773 | ++pinsn; | |
774 | if ((*pinsn & 0xfc00003e) == 0x7c000026) /* mfcr Rx */ | |
775 | ++pinsn; | |
776 | if ((*pinsn & 0xfc000000) == 0x48000000) /* bl foo, save fprs */ | |
777 | ++pinsn; | |
778 | if ((*pinsn & 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */ | |
779 | ++pinsn; | |
780 | ||
781 | do { | |
782 | int tmp = (*pinsn >> 16) & 0xffff; | |
783 | ||
784 | if (tmp == 0x9421) { /* stu r1, NUM(r1) */ | |
785 | tbInfo.framesize = 0x10000 - (*pinsn & 0xffff); | |
786 | break; | |
787 | } | |
788 | else if ((*pinsn == 0x93e1fffc) || /* st r31,-4(r1) */ | |
789 | (tmp == 0x9001)) /* st r0, NUM(r1) */ | |
790 | ; | |
791 | /* else, could not find a frame size. */ | |
792 | else | |
793 | return NULL; | |
794 | ||
795 | } while (++pinsn && *pinsn); | |
796 | ||
797 | if (!tbInfo.framesize) | |
798 | return NULL; | |
799 | } | |
800 | ||
801 | /* look for a zero word. */ | |
802 | ||
803 | while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int)))) | |
804 | ++pinsn; | |
805 | ||
806 | if (pinsn >= (int*)(buffer + bufferbytes)) | |
807 | continue; | |
e38e0312 | 808 | |
818de002 PB |
809 | if (*pinsn == 0) { |
810 | ||
811 | /* function size is the amount of bytes we have skipped so far. */ | |
812 | tbInfo.fsize = bytesread - (buffer + bufferbytes - (char*)pinsn); | |
813 | ||
814 | ++pinsn; | |
815 | ||
816 | /* if we don't have the whole traceback table in the buffer, re-read | |
817 | the whole thing. */ | |
818 | ||
819 | if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) { | |
820 | ||
821 | /* In case if we are *very* close to the end of the text section | |
822 | and cannot read properly from that point on, abort by returning | |
823 | NULL. | |
824 | Handle this case more graciously -- FIXME */ | |
825 | ||
826 | if (!bfd_get_section_contents ( | |
827 | abfd, textsec, buffer, | |
828 | (file_ptr)(functionstart + | |
829 | bytesread - (buffer + bufferbytes - (char*)pinsn)),MIN_TBTABSIZ)) | |
830 | { printf ("Abnormal return!..\n"); return NULL; } | |
831 | ||
832 | ptb = (struct tbtable *)buffer; | |
833 | } | |
834 | else | |
835 | ptb = (struct tbtable *)pinsn; | |
836 | ||
837 | tbInfo.fixedparms = ptb->tb.fixedparms; | |
838 | tbInfo.floatparms = ptb->tb.floatparms; | |
839 | tbInfo.parminfo = ptb->tb_ext.parminfo; | |
840 | return &tbInfo; | |
841 | } | |
842 | } | |
843 | return NULL; | |
844 | } | |
845 | ||
846 | #if 0 | |
847 | /* Given a function symbol, return a pointer to its traceback table. */ | |
848 | ||
849 | struct tbtable * | |
850 | retrieve_traceback (abfd, textsec, cs, size) | |
851 | bfd *abfd; | |
852 | sec_ptr textsec; | |
853 | struct coff_symbol *cs; | |
854 | int *size; /* return function size */ | |
855 | { | |
856 | #define TBTABLE_BUFSIZ 2000 | |
857 | #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a | |
858 | traceback table. */ | |
859 | ||
860 | static char buffer [TBTABLE_BUFSIZ]; | |
861 | ||
862 | int *pinsn; | |
863 | int bytesread=0; /* total # of bytes read so far */ | |
864 | int bufferbytes; /* number of bytes in the buffer */ | |
865 | ||
866 | int functionstart = cs->c_value - textsec->filepos + textsec->vma; | |
867 | *size = 0; | |
868 | ||
869 | /* keep reading blocks of data from the text section, until finding a zero | |
870 | word and a traceback table. */ | |
871 | ||
872 | while (bfd_get_section_contents (abfd, textsec, buffer, | |
873 | (file_ptr)(functionstart + bytesread), | |
874 | bufferbytes = ( | |
875 | (TBTABLE_BUFSIZ < (textsec->size - functionstart - bytesread)) ? | |
876 | TBTABLE_BUFSIZ : (textsec->size - functionstart - bytesread)))) | |
877 | { | |
878 | bytesread += bufferbytes; | |
879 | pinsn = (int*) buffer; | |
880 | ||
881 | /* look for a zero word. */ | |
882 | ||
883 | while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int)))) | |
884 | ++pinsn; | |
885 | ||
886 | if (pinsn >= (int*)(buffer + bufferbytes)) | |
887 | continue; | |
888 | ||
889 | if (*pinsn == 0) { | |
890 | ||
891 | /* function size is the amount of bytes we have skipped so far. */ | |
892 | *size = bytesread - (buffer + bufferbytes - pinsn); | |
893 | ||
894 | ++pinsn; | |
895 | ||
896 | /* if we don't have the whole traceback table in the buffer, re-read | |
897 | the whole thing. */ | |
898 | ||
899 | if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) { | |
900 | ||
901 | /* In case if we are *very* close to the end of the text section | |
902 | and cannot read properly from that point on, abort for now. | |
903 | Handle this case more graciously -- FIXME */ | |
904 | ||
905 | if (!bfd_get_section_contents ( | |
906 | abfd, textsec, buffer, | |
907 | (file_ptr)(functionstart + | |
908 | bytesread - (buffer + bufferbytes - pinsn)),MIN_TBTABSIZ)) | |
909 | /* abort (); */ { printf ("abort!!!\n"); return NULL; } | |
910 | ||
911 | return (struct tbtable *)buffer; | |
912 | } | |
913 | else | |
914 | return (struct tbtable *)pinsn; | |
915 | } | |
e38e0312 | 916 | } |
818de002 | 917 | return NULL; |
e38e0312 | 918 | } |
818de002 PB |
919 | #endif /* 0 */ |
920 | ||
921 | ||
e38e0312 JG |
922 | |
923 | ||
924 | /* Save the vital information for use when closing off the current file. | |
925 | NAME is the file name the symbols came from, START_ADDR is the first | |
926 | text address for the file, and SIZE is the number of bytes of text. */ | |
927 | ||
928 | #define complete_symtab(name, start_addr) { \ | |
929 | last_source_file = savestring (name, strlen (name)); \ | |
818de002 | 930 | last_source_start_addr = start_addr; \ |
e38e0312 JG |
931 | } |
932 | ||
933 | ||
934 | /* Refill the symbol table input buffer | |
935 | and set the variables that control fetching entries from it. | |
936 | Reports an error if no data available. | |
937 | This function can read past the end of the symbol table | |
938 | (into the string table) but this does no harm. */ | |
939 | ||
940 | /* Reading symbol table has to be fast! Keep the followings as macros, rather | |
941 | than functions. */ | |
942 | ||
1ab3bf1b | 943 | #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \ |
e38e0312 JG |
944 | { \ |
945 | char *namestr; \ | |
946 | if (ALLOCED) \ | |
947 | namestr = (NAME) + 1; \ | |
948 | else { \ | |
1eeba686 PB |
949 | (NAME) = namestr = \ |
950 | obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \ | |
e38e0312 JG |
951 | (ALLOCED) = 1; \ |
952 | } \ | |
1ab3bf1b | 953 | prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \ |
818de002 | 954 | misc_func_recorded = 1; \ |
e38e0312 JG |
955 | } |
956 | ||
957 | ||
818de002 PB |
958 | /* A parameter template, used by ADD_PARM_TO_PENDING. */ |
959 | ||
960 | static struct symbol parmsym = { /* default parameter symbol */ | |
961 | "", /* name */ | |
962 | VAR_NAMESPACE, /* namespace */ | |
963 | LOC_ARG, /* class */ | |
964 | NULL, /* type */ | |
965 | 0, /* line number */ | |
966 | 0, /* value */ | |
967 | }; | |
968 | ||
969 | /* Add a parameter to a given pending symbol list. */ | |
970 | ||
971 | #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \ | |
972 | { \ | |
973 | PARM = (struct symbol *) \ | |
974 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \ | |
975 | *(PARM) = parmsym; \ | |
976 | SYMBOL_TYPE (PARM) = PTYPE; \ | |
977 | SYMBOL_VALUE (PARM) = VALUE; \ | |
978 | add_symbol_to_list (PARM, &PENDING_SYMBOLS); \ | |
979 | } | |
980 | ||
e38e0312 JG |
981 | |
982 | /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be | |
983 | nested. At any given time, a symbol can only be in one static block. | |
984 | This is the base address of current static block, zero if non exists. */ | |
985 | ||
986 | static int static_block_base = 0; | |
987 | ||
988 | /* true if space for symbol name has been allocated. */ | |
989 | ||
990 | static int symname_alloced = 0; | |
991 | ||
992 | /* read the whole symbol table of a given bfd. */ | |
993 | ||
1ab3bf1b | 994 | static void |
e38e0312 JG |
995 | read_xcoff_symtab (objfile, nsyms) |
996 | struct objfile *objfile; /* Object file we're reading from */ | |
997 | int nsyms; /* # of symbols */ | |
998 | { | |
999 | bfd *abfd = objfile->obfd; | |
e38e0312 JG |
1000 | char *raw_symbol; /* Pointer into raw seething symbol table */ |
1001 | char *raw_auxptr; /* Pointer to first raw aux entry for sym */ | |
818de002 PB |
1002 | sec_ptr textsec; /* Pointer to text section */ |
1003 | TracebackInfo *ptb; /* Pointer to traceback table */ | |
1004 | ||
e38e0312 JG |
1005 | struct internal_syment symbol[1]; |
1006 | union internal_auxent main_aux[1]; | |
1007 | struct coff_symbol cs[1]; | |
1008 | CORE_ADDR file_start_addr = 0; | |
1009 | CORE_ADDR file_end_addr = 0; | |
1010 | ||
1011 | int next_file_symnum = -1; | |
1012 | int just_started = 1; | |
1013 | int depth = 0; | |
556f3d90 | 1014 | int toc_offset = 0; /* toc offset value in data section. */ |
e38e0312 | 1015 | int val; |
e38e0312 JG |
1016 | int fcn_last_line; |
1017 | int fcn_start_addr; | |
1018 | long fcn_line_offset; | |
1019 | size_t size; | |
1020 | ||
1eeba686 PB |
1021 | struct coff_symbol fcn_stab_saved; |
1022 | ||
e38e0312 JG |
1023 | /* fcn_cs_saved is global because process_xcoff_symbol needs it. */ |
1024 | union internal_auxent fcn_aux_saved; | |
818de002 | 1025 | struct type *fcn_type_saved = NULL; |
e38e0312 JG |
1026 | struct context_stack *new; |
1027 | ||
1028 | char *filestring = " _start_ "; /* Name of the current file. */ | |
818de002 PB |
1029 | |
1030 | char *last_csect_name; /* last seen csect's name and value */ | |
1031 | CORE_ADDR last_csect_val; | |
1032 | int misc_func_recorded; /* true if any misc. function */ | |
e38e0312 | 1033 | |
1ab3bf1b JG |
1034 | current_objfile = objfile; |
1035 | ||
e38e0312 JG |
1036 | /* Get the appropriate COFF "constants" related to the file we're handling. */ |
1037 | N_TMASK = coff_data (abfd)->local_n_tmask; | |
1038 | N_BTSHFT = coff_data (abfd)->local_n_btshft; | |
1039 | local_symesz = coff_data (abfd)->local_symesz; | |
1040 | ||
d07734e3 | 1041 | last_source_file = NULL; |
818de002 PB |
1042 | last_csect_name = 0; |
1043 | last_csect_val = 0; | |
1044 | misc_func_recorded = 0; | |
e38e0312 | 1045 | |
d07734e3 | 1046 | start_stabs (); |
e38e0312 JG |
1047 | start_symtab (filestring, (char *)NULL, file_start_addr); |
1048 | symnum = 0; | |
1049 | first_object_file_end = 0; | |
1050 | ||
1051 | /* Allocate space for the entire symbol table at once, and read it | |
1052 | all in. The bfd is already positioned at the beginning of | |
1053 | the symbol table. */ | |
1054 | ||
1055 | size = coff_data (abfd)->local_symesz * nsyms; | |
1056 | symtbl = xmalloc (size); | |
1057 | ||
1058 | val = bfd_read (symtbl, size, 1, abfd); | |
1059 | if (val != size) | |
1060 | perror_with_name ("reading symbol table"); | |
1061 | ||
1062 | raw_symbol = symtbl; | |
1063 | ||
818de002 PB |
1064 | textsec = bfd_get_section_by_name (abfd, ".text"); |
1065 | if (!textsec) { | |
1066 | printf ("Unable to locate text section!\n"); | |
1067 | } | |
1068 | ||
e38e0312 JG |
1069 | while (symnum < nsyms) { |
1070 | ||
1071 | QUIT; /* make this command interruptable. */ | |
1072 | ||
1073 | /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */ | |
1074 | /* read one symbol into `cs' structure. After processing the whole symbol | |
1075 | table, only string table will be kept in memory, symbol table and debug | |
1076 | section of aixcoff will be freed. Thus we can mark symbols with names | |
1077 | in string table as `alloced'. */ | |
1078 | { | |
1079 | int ii; | |
1080 | ||
1081 | /* Swap and align the symbol into a reasonable C structure. */ | |
1082 | bfd_coff_swap_sym_in (abfd, raw_symbol, symbol); | |
1083 | ||
1084 | cs->c_symnum = symnum; | |
1085 | cs->c_nsyms = symbol->n_numaux; | |
1086 | if (symbol->n_zeroes) { | |
1087 | symname_alloced = 0; | |
1088 | /* We must use the original, unswapped, name here so the name field | |
1089 | pointed to by cs->c_name will persist throughout xcoffread. If | |
1090 | we use the new field, it gets overwritten for each symbol. */ | |
1091 | cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name; | |
1092 | } else if (symbol->n_sclass & 0x80) { | |
1093 | cs->c_name = debugsec + symbol->n_offset; | |
1094 | symname_alloced = 0; | |
1095 | } else { /* in string table */ | |
1096 | cs->c_name = strtbl + (int)symbol->n_offset; | |
1097 | symname_alloced = 1; | |
1098 | } | |
1099 | cs->c_value = symbol->n_value; | |
2795260c JG |
1100 | /* n_sclass is signed (FIXME), so we had better not mask off any |
1101 | high bits it contains, since the values we will be comparing | |
1102 | it to are also signed (FIXME). Defined in <coff/internal.h>. | |
1103 | At this point (3Jun92, gnu@cygnus.com) I think the fix is to | |
1104 | make the fields and values unsigned chars, but changing the next | |
1105 | line is a simple patch late in the release cycle, for now. */ | |
1106 | cs->c_sclass = symbol->n_sclass /* & 0xff */; | |
e38e0312 JG |
1107 | cs->c_secnum = symbol->n_scnum; |
1108 | cs->c_type = (unsigned)symbol->n_type; | |
1109 | ||
1110 | raw_symbol += coff_data (abfd)->local_symesz; | |
1111 | ++symnum; | |
1112 | ||
1113 | raw_auxptr = raw_symbol; /* Save addr of first aux entry */ | |
1114 | ||
1115 | /* Skip all the auxents associated with this symbol. */ | |
1116 | for (ii = symbol->n_numaux; ii; --ii ) { | |
1117 | raw_symbol += coff_data (abfd)->local_auxesz; | |
1118 | ++symnum; | |
1119 | } | |
1120 | } | |
1121 | ||
1122 | /* if symbol name starts with ".$" or "$", ignore it. */ | |
1123 | if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.')) | |
1124 | continue; | |
1125 | ||
1126 | if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) { | |
1127 | if (last_source_file) | |
d07734e3 FF |
1128 | { |
1129 | end_symtab (cur_src_end_addr, 1, 0, objfile); | |
1130 | end_stabs (); | |
1131 | } | |
e38e0312 | 1132 | |
d07734e3 | 1133 | start_stabs (); |
e38e0312 JG |
1134 | start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0); |
1135 | cur_src_end_addr = first_object_file_end; | |
1136 | /* done with all files, everything from here on is globals */ | |
1137 | } | |
1138 | ||
1139 | /* if explicitly specified as a function, treat is as one. */ | |
1140 | if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) { | |
1141 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
1142 | main_aux); | |
1143 | goto function_entry_point; | |
1144 | } | |
1145 | ||
1146 | if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1) | |
1147 | { | |
1148 | /* dealing with a symbol with a csect entry. */ | |
1149 | ||
1150 | # define CSECT(PP) ((PP)->x_csect) | |
1151 | # define CSECT_LEN(PP) (CSECT(PP).x_scnlen) | |
1152 | # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp)) | |
1153 | # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp)) | |
1154 | # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas) | |
1155 | ||
1156 | /* Convert the auxent to something we can access. */ | |
1157 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
1158 | main_aux); | |
1159 | ||
1160 | switch (CSECT_SMTYP (main_aux)) { | |
1161 | ||
1162 | case XTY_ER : | |
1163 | continue; /* ignore all external references. */ | |
1164 | ||
1165 | case XTY_SD : /* a section description. */ | |
1166 | { | |
1167 | switch (CSECT_SCLAS (main_aux)) { | |
1168 | ||
1169 | case XMC_PR : /* a `.text' csect. */ | |
1170 | { | |
1171 | ||
1172 | /* A program csect is seen. | |
1173 | ||
1174 | We have to allocate one symbol table for each program csect. Normally | |
1175 | gdb prefers one symtab for each compilation unit (CU). In case of AIX, one | |
1176 | CU might include more than one prog csect, and they don't have to be | |
1177 | adjacent in terms of the space they occupy in memory. Thus, one single | |
1178 | CU might get fragmented in the memory and gdb's file start and end address | |
1179 | approach does not work! */ | |
1180 | ||
818de002 PB |
1181 | if (last_csect_name) { |
1182 | ||
1183 | /* if no misc. function recorded in the last seen csect, enter | |
1184 | it as a function. This will take care of functions like | |
1185 | strcmp() compiled by xlc. */ | |
1186 | ||
1187 | if (!misc_func_recorded) { | |
1188 | int alloced = 0; | |
1189 | RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val, | |
1190 | mst_text, alloced); | |
1191 | } | |
1192 | ||
1193 | ||
e38e0312 JG |
1194 | complete_symtab (filestring, file_start_addr); |
1195 | cur_src_end_addr = file_end_addr; | |
818de002 | 1196 | end_symtab (file_end_addr, 1, 0, objfile); |
d07734e3 FF |
1197 | end_stabs (); |
1198 | start_stabs (); | |
e38e0312 JG |
1199 | start_symtab ((char *)NULL, (char *)NULL, (CORE_ADDR)0); |
1200 | } | |
1201 | ||
1202 | /* If this is the very first csect seen, basically `__start'. */ | |
1203 | if (just_started) { | |
1204 | first_object_file_end = cs->c_value + CSECT_LEN (main_aux); | |
1205 | just_started = 0; | |
1206 | } | |
1207 | ||
1208 | file_start_addr = cs->c_value; | |
1209 | file_end_addr = cs->c_value + CSECT_LEN (main_aux); | |
1210 | ||
1211 | if (cs->c_name && cs->c_name[0] == '.') { | |
818de002 PB |
1212 | last_csect_name = cs->c_name; |
1213 | last_csect_val = cs->c_value; | |
e38e0312 JG |
1214 | } |
1215 | } | |
818de002 | 1216 | misc_func_recorded = 0; |
e38e0312 JG |
1217 | continue; |
1218 | ||
1219 | case XMC_RW : | |
1220 | break; | |
1221 | ||
1222 | /* If the section is not a data description, ignore it. Note that | |
1223 | uninitialized data will show up as XTY_CM/XMC_RW pair. */ | |
1224 | ||
1225 | case XMC_TC0: | |
556f3d90 PB |
1226 | if (toc_offset) |
1227 | warning ("More than one xmc_tc0 symbol found."); | |
1228 | toc_offset = cs->c_value; | |
1229 | continue; | |
e38e0312 JG |
1230 | |
1231 | case XMC_TC : /* ignore toc entries */ | |
1232 | default : /* any other XMC_XXX */ | |
1233 | continue; | |
1234 | } | |
1235 | } | |
1236 | break; /* switch CSECT_SCLAS() */ | |
1237 | ||
1238 | case XTY_LD : | |
1239 | ||
1240 | /* a function entry point. */ | |
1241 | if (CSECT_SCLAS (main_aux) == XMC_PR) { | |
1242 | ||
1243 | function_entry_point: | |
818de002 PB |
1244 | RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, |
1245 | symname_alloced); | |
e38e0312 JG |
1246 | |
1247 | fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr; | |
1248 | fcn_start_addr = cs->c_value; | |
1249 | ||
1250 | /* save the function header info, which will be used | |
1251 | when `.bf' is seen. */ | |
1252 | fcn_cs_saved = *cs; | |
1253 | fcn_aux_saved = *main_aux; | |
818de002 PB |
1254 | |
1255 | ||
1256 | ptb = NULL; | |
1257 | ||
1258 | /* If function has two auxent, then debugging information is | |
1259 | already available for it. Process traceback table for | |
1260 | functions with only one auxent. */ | |
1261 | ||
1262 | if (cs->c_nsyms == 1) | |
1263 | ptb = retrieve_tracebackinfo (abfd, textsec, cs); | |
1264 | ||
1265 | else if (cs->c_nsyms != 2) | |
1266 | abort (); | |
1267 | ||
1268 | /* If there is traceback info, create and add parameters for it. */ | |
1269 | ||
1270 | if (ptb && (ptb->fixedparms || ptb->floatparms)) { | |
1271 | ||
1272 | int parmcnt = ptb->fixedparms + ptb->floatparms; | |
1273 | char *parmcode = (char*) &ptb->parminfo; | |
1274 | int parmvalue = ptb->framesize + 0x18; /* sizeof(LINK AREA) == 0x18 */ | |
1275 | unsigned int ii, mask; | |
1276 | ||
1277 | for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii) { | |
1278 | struct symbol *parm; | |
1279 | ||
1280 | if (ptb->parminfo & mask) { /* float or double */ | |
1281 | mask = mask >> 1; | |
1282 | if (ptb->parminfo & mask) { /* double parm */ | |
1283 | ADD_PARM_TO_PENDING | |
1284 | (parm, parmvalue, builtin_type_double, local_symbols); | |
1285 | parmvalue += sizeof (double); | |
1286 | } | |
1287 | else { /* float parm */ | |
1288 | ADD_PARM_TO_PENDING | |
1289 | (parm, parmvalue, builtin_type_float, local_symbols); | |
1290 | parmvalue += sizeof (float); | |
1291 | } | |
1292 | } | |
6c6afbb9 PB |
1293 | else { /* fixed parm, use (int*) for hex rep. */ |
1294 | ADD_PARM_TO_PENDING (parm, parmvalue, | |
1295 | lookup_pointer_type (builtin_type_int), | |
1296 | local_symbols); | |
818de002 PB |
1297 | parmvalue += sizeof (int); |
1298 | } | |
1299 | mask = mask >> 1; | |
1300 | } | |
1301 | ||
1302 | /* Fake this as a function. Needed in process_xcoff_symbol() */ | |
1303 | cs->c_type = 32; | |
1304 | ||
1305 | finish_block(process_xcoff_symbol (cs, objfile), &local_symbols, | |
1306 | pending_blocks, cs->c_value, | |
1307 | cs->c_value + ptb->fsize, objfile); | |
1308 | } | |
e38e0312 JG |
1309 | continue; |
1310 | } | |
818de002 | 1311 | /* shared library function trampoline code entry point. */ |
e38e0312 | 1312 | else if (CSECT_SCLAS (main_aux) == XMC_GL) { |
507e4004 PB |
1313 | |
1314 | /* record trampoline code entries as mst_unknown symbol. When we | |
1315 | lookup mst symbols, we will choose mst_text over mst_unknown. */ | |
1316 | ||
1eeba686 PB |
1317 | #if 1 |
1318 | /* After the implementation of incremental loading of shared | |
1319 | libraries, we don't want to access trampoline entries. This | |
1320 | approach has a consequence of the necessity to bring the whole | |
1321 | shared library at first, in order do anything with it (putting | |
1322 | breakpoints, using malloc, etc). On the other side, this is | |
1323 | consistient with gdb's behaviour on a SUN platform. */ | |
1324 | ||
1325 | /* Trying to prefer *real* function entry over its trampoline, | |
1326 | by assigning `mst_unknown' type to trampoline entries fails. | |
1327 | Gdb treats those entries as chars. FIXME. */ | |
1328 | ||
1329 | /* Recording this entry is necessary. Single stepping relies on | |
1330 | this vector to get an idea about function address boundaries. */ | |
1331 | ||
1332 | prim_record_minimal_symbol (0, cs->c_value, mst_unknown); | |
1333 | #else | |
1334 | ||
1335 | /* record trampoline code entries as mst_unknown symbol. When we | |
1336 | lookup mst symbols, we will choose mst_text over mst_unknown. */ | |
1337 | ||
507e4004 | 1338 | RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_unknown, |
818de002 | 1339 | symname_alloced); |
1eeba686 | 1340 | #endif |
e38e0312 JG |
1341 | continue; |
1342 | } | |
1343 | break; | |
1344 | ||
1345 | default : /* all other XTY_XXXs */ | |
1346 | break; | |
818de002 | 1347 | } /* switch CSECT_SMTYP() */ } |
e38e0312 JG |
1348 | |
1349 | switch (cs->c_sclass) { | |
1350 | ||
1351 | case C_FILE: | |
1352 | ||
818de002 PB |
1353 | /* see if the last csect needs to be recorded. */ |
1354 | ||
1355 | if (last_csect_name && !misc_func_recorded) { | |
1356 | ||
1357 | /* if no misc. function recorded in the last seen csect, enter | |
1358 | it as a function. This will take care of functions like | |
1359 | strcmp() compiled by xlc. */ | |
1360 | ||
1361 | int alloced = 0; | |
1362 | RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val, | |
1363 | mst_text, alloced); | |
1364 | } | |
1365 | ||
e38e0312 JG |
1366 | /* c_value field contains symnum of next .file entry in table |
1367 | or symnum of first global after last .file. */ | |
1368 | ||
1369 | next_file_symnum = cs->c_value; | |
1370 | ||
1371 | /* complete symbol table for last object file containing | |
1372 | debugging information. */ | |
1373 | ||
d07734e3 FF |
1374 | /* Whether or not there was a csect in the previous file, we have to call |
1375 | `end_stabs' and `start_stabs' to reset type_vector, | |
e38e0312 | 1376 | line_vector, etc. structures. */ |
818de002 | 1377 | |
e38e0312 JG |
1378 | complete_symtab (filestring, file_start_addr); |
1379 | cur_src_end_addr = file_end_addr; | |
818de002 | 1380 | end_symtab (file_end_addr, 1, 0, objfile); |
d07734e3 FF |
1381 | end_stabs (); |
1382 | start_stabs (); | |
e38e0312 | 1383 | start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0); |
818de002 | 1384 | last_csect_name = 0; |
e38e0312 JG |
1385 | |
1386 | /* reset file start and end addresses. A compilation unit with no text | |
1387 | (only data) should have zero file boundaries. */ | |
1388 | file_start_addr = file_end_addr = 0; | |
1389 | ||
1390 | filestring = cs->c_name; | |
1391 | break; | |
1392 | ||
1393 | ||
818de002 PB |
1394 | case C_FUN: |
1395 | ||
1eeba686 | 1396 | #ifdef NO_DEFINE_SYMBOL |
818de002 PB |
1397 | /* For a function stab, just save its type in `fcn_type_saved', and leave |
1398 | it for the `.bf' processing. */ | |
1399 | { | |
1400 | char *pp = (char*) index (cs->c_name, ':'); | |
1401 | ||
1402 | if (!pp || ( *(pp+1) != 'F' && *(pp+1) != 'f')) | |
1403 | fatal ("Unrecognized stab"); | |
1404 | pp += 2; | |
1405 | ||
1406 | if (fcn_type_saved) | |
1407 | fatal ("Unprocessed function type"); | |
1408 | ||
1409 | fcn_type_saved = lookup_function_type (read_type (&pp, objfile)); | |
1410 | } | |
1eeba686 PB |
1411 | #else |
1412 | fcn_stab_saved = *cs; | |
1413 | #endif | |
818de002 PB |
1414 | break; |
1415 | ||
1416 | ||
e38e0312 JG |
1417 | case C_FCN: |
1418 | if (strcmp (cs->c_name, ".bf") == 0) { | |
1419 | ||
1420 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
1421 | main_aux); | |
1422 | ||
1423 | within_function = 1; | |
1424 | ||
e38e0312 JG |
1425 | /* Linenos are now processed on a file-by-file, not fn-by-fn, basis. |
1426 | Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */ | |
818de002 PB |
1427 | |
1428 | /* Two reasons: | |
1429 | ||
1430 | 1) xlc (IBM's native c compiler) postpones static function code | |
1431 | emission to the end of a compilation unit. This way it can | |
1432 | determine if those functions (statics) are needed or not, and | |
1433 | can do some garbage collection (I think). This makes line | |
1434 | numbers and corresponding addresses unordered, and we end up | |
1435 | with a line table like: | |
1436 | ||
1437 | ||
1438 | lineno addr | |
1439 | foo() 10 0x100 | |
1440 | 20 0x200 | |
1441 | 30 0x300 | |
1442 | ||
1443 | foo3() 70 0x400 | |
1444 | 80 0x500 | |
1445 | 90 0x600 | |
1446 | ||
1447 | static foo2() | |
1448 | 40 0x700 | |
1449 | 50 0x800 | |
1450 | 60 0x900 | |
1451 | ||
1452 | and that breaks gdb's binary search on line numbers, if the | |
1453 | above table is not sorted on line numbers. And that sort | |
1454 | should be on function based, since gcc can emit line numbers | |
1455 | like: | |
1456 | ||
1457 | 10 0x100 - for the init/test part of a for stmt. | |
1458 | 20 0x200 | |
1459 | 30 0x300 | |
1460 | 10 0x400 - for the increment part of a for stmt. | |
1461 | ||
1462 | arrange_linenos() will do this sorting. | |
1463 | ||
1464 | ||
1465 | 2) aix symbol table might look like: | |
1466 | ||
1467 | c_file // beginning of a new file | |
1468 | .bi // beginning of include file | |
1469 | .ei // end of include file | |
1470 | .bi | |
1471 | .ei | |
1472 | ||
1473 | basically, .bi/.ei pairs do not necessarily encapsulate | |
1474 | their scope. They need to be recorded, and processed later | |
1475 | on when we come the end of the compilation unit. | |
1476 | Include table (inclTable) and process_linenos() handle | |
1477 | that. | |
1478 | */ | |
1479 | mark_first_line (fcn_line_offset, cs->c_symnum); | |
e38e0312 JG |
1480 | |
1481 | new = push_context (0, fcn_start_addr); | |
1eeba686 PB |
1482 | |
1483 | #ifdef NO_DEFINE_SYMBOL | |
1ab3bf1b | 1484 | new->name = process_xcoff_symbol (&fcn_cs_saved, objfile); |
818de002 PB |
1485 | |
1486 | /* Between a function symbol and `.bf', there always will be a function | |
1487 | stab. We save function type when processing that stab. */ | |
1488 | ||
2b5a8d9c PB |
1489 | if (fcn_type_saved == NULL) { |
1490 | printf ("Unknown function type: symbol 0x%x\n", cs->c_symnum); | |
1491 | SYMBOL_TYPE (new->name) = lookup_function_type (builtin_type_int); | |
1492 | } | |
1493 | else { | |
1494 | SYMBOL_TYPE (new->name) = fcn_type_saved; | |
1495 | fcn_type_saved = NULL; | |
1496 | } | |
1eeba686 PB |
1497 | #else |
1498 | new->name = define_symbol | |
1499 | (fcn_cs_saved.c_value, fcn_stab_saved.c_name, 0, 0, objfile); | |
1500 | #endif | |
e38e0312 JG |
1501 | } |
1502 | else if (strcmp (cs->c_name, ".ef") == 0) { | |
1503 | ||
1504 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
1505 | main_aux); | |
1506 | ||
1507 | /* the value of .ef is the address of epilogue code; | |
1508 | not useful for gdb */ | |
1509 | /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno | |
1510 | contains number of lines to '}' */ | |
1511 | ||
1512 | fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno; | |
e38e0312 JG |
1513 | new = pop_context (); |
1514 | if (context_stack_depth != 0) | |
1515 | error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.", | |
1516 | symnum); | |
1517 | ||
1518 | finish_block (new->name, &local_symbols, new->old_blocks, | |
1519 | new->start_addr, | |
1520 | fcn_cs_saved.c_value + | |
1ab3bf1b | 1521 | fcn_aux_saved.x_sym.x_misc.x_fsize, objfile); |
e38e0312 JG |
1522 | within_function = 0; |
1523 | } | |
1524 | break; | |
1525 | ||
1526 | case C_BSTAT : /* begin static block */ | |
1527 | static_block_base = read_symbol_nvalue (symtbl, cs->c_value); | |
1528 | break; | |
1529 | ||
1530 | case C_ESTAT : /* end of static block */ | |
1531 | static_block_base = 0; | |
1532 | break; | |
1533 | ||
1534 | case C_ARG : /* These are not implemented. */ | |
1535 | case C_REGPARM : | |
1536 | case C_TPDEF : | |
1537 | case C_STRTAG : | |
1538 | case C_UNTAG : | |
1539 | case C_ENTAG : | |
1540 | printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass); | |
1541 | break; | |
1542 | ||
1543 | case C_HIDEXT : /* ignore these.. */ | |
1544 | case C_LABEL : | |
1545 | case C_NULL : | |
1546 | break; | |
1547 | ||
1548 | case C_BINCL : /* beginning of include file */ | |
818de002 PB |
1549 | |
1550 | /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted | |
1551 | order. Thus, when wee see them, we might not know enough info | |
1552 | to process them. Thus, we'll be saving them into a table | |
1553 | (inclTable) and postpone their processing. */ | |
1554 | ||
1555 | record_include_begin (cs); | |
e38e0312 JG |
1556 | break; |
1557 | ||
1558 | case C_EINCL : /* end of include file */ | |
818de002 PB |
1559 | /* see the comment after case C_BINCL. */ |
1560 | record_include_end (cs); | |
e38e0312 JG |
1561 | break; |
1562 | ||
1563 | case C_BLOCK : | |
1564 | if (strcmp (cs->c_name, ".bb") == 0) { | |
1565 | depth++; | |
1566 | new = push_context (depth, cs->c_value); | |
1567 | } | |
1568 | else if (strcmp (cs->c_name, ".eb") == 0) { | |
1569 | new = pop_context (); | |
1570 | if (depth != new->depth) | |
1571 | error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.", | |
1572 | symnum); | |
1573 | ||
1574 | depth--; | |
1575 | if (local_symbols && context_stack_depth > 0) { | |
1576 | /* Make a block for the local symbols within. */ | |
1577 | finish_block (new->name, &local_symbols, new->old_blocks, | |
1ab3bf1b | 1578 | new->start_addr, cs->c_value, objfile); |
e38e0312 JG |
1579 | } |
1580 | local_symbols = new->locals; | |
1581 | } | |
1582 | break; | |
1583 | ||
1584 | default : | |
4ed3a9ea | 1585 | process_xcoff_symbol (cs, objfile); |
e38e0312 JG |
1586 | break; |
1587 | } | |
1588 | ||
1589 | } /* while */ | |
1590 | ||
1591 | if (last_source_file) | |
d07734e3 FF |
1592 | { |
1593 | end_symtab (cur_src_end_addr, 1, 0, objfile); | |
1594 | end_stabs (); | |
1595 | } | |
e38e0312 JG |
1596 | |
1597 | free (symtbl); | |
1ab3bf1b | 1598 | current_objfile = NULL; |
556f3d90 PB |
1599 | |
1600 | /* Record the toc offset value of this symbol table into ldinfo structure. | |
1601 | If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain | |
1602 | this information would be file auxiliary header. */ | |
1603 | ||
1604 | xcoff_add_toc_to_loadinfo (toc_offset); | |
e38e0312 JG |
1605 | } |
1606 | ||
1607 | #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \ | |
1608 | (SYMBOL2) = (struct symbol *) \ | |
1ab3bf1b | 1609 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \ |
e38e0312 JG |
1610 | *(SYMBOL2) = *(SYMBOL1); |
1611 | ||
1612 | ||
1613 | #define SYMNAME_ALLOC(NAME, ALLOCED) \ | |
1ab3bf1b | 1614 | (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME)); |
e38e0312 JG |
1615 | |
1616 | ||
e38e0312 JG |
1617 | /* process one xcoff symbol. */ |
1618 | ||
1619 | static struct symbol * | |
1ab3bf1b | 1620 | process_xcoff_symbol (cs, objfile) |
e38e0312 | 1621 | register struct coff_symbol *cs; |
1ab3bf1b | 1622 | struct objfile *objfile; |
e38e0312 JG |
1623 | { |
1624 | struct symbol onesymbol; | |
1625 | register struct symbol *sym = &onesymbol; | |
1626 | struct symbol *sym2 = NULL; | |
1627 | struct type *ttype; | |
1628 | char *name, *pp, *qq; | |
818de002 | 1629 | int struct_and_type_combined; |
6c6afbb9 | 1630 | int nameless; |
e38e0312 JG |
1631 | |
1632 | name = cs->c_name; | |
1633 | if (name[0] == '.') | |
1634 | ++name; | |
1635 | ||
1636 | bzero (sym, sizeof (struct symbol)); | |
1637 | ||
1638 | /* default assumptions */ | |
1639 | SYMBOL_VALUE (sym) = cs->c_value; | |
1640 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1641 | ||
1642 | if (ISFCN (cs->c_type)) { | |
1643 | ||
1644 | /* At this point, we don't know the type of the function and assume it | |
1645 | is int. This will be patched with the type from its stab entry later | |
1646 | on in patch_block_stabs () */ | |
1647 | ||
1648 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
818de002 | 1649 | SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (objfile, FT_INTEGER)); |
e38e0312 JG |
1650 | |
1651 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
1652 | SYMBOL_DUP (sym, sym2); | |
1653 | ||
1654 | if (cs->c_sclass == C_EXT) | |
1655 | add_symbol_to_list (sym2, &global_symbols); | |
1656 | else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT) | |
1657 | add_symbol_to_list (sym2, &file_symbols); | |
1658 | } | |
1659 | ||
1660 | else { | |
1661 | ||
1662 | /* in case we can't figure out the type, default is `int'. */ | |
818de002 | 1663 | SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, FT_INTEGER); |
e38e0312 JG |
1664 | |
1665 | switch (cs->c_sclass) | |
1666 | { | |
818de002 | 1667 | #if 0 |
e38e0312 JG |
1668 | case C_FUN: |
1669 | if (fcn_cs_saved.c_sclass == C_EXT) | |
1670 | add_stab_to_list (name, &global_stabs); | |
1671 | else | |
1672 | add_stab_to_list (name, &file_stabs); | |
1673 | break; | |
818de002 | 1674 | #endif |
e38e0312 JG |
1675 | |
1676 | case C_DECL: /* a type decleration?? */ | |
1eeba686 PB |
1677 | |
1678 | #if defined(NO_TYPEDEFS) || defined(NO_DEFINE_SYMBOL) | |
1ab3bf1b | 1679 | qq = (char*) strchr (name, ':'); |
e38e0312 JG |
1680 | if (!qq) /* skip if there is no ':' */ |
1681 | return NULL; | |
1682 | ||
6c6afbb9 PB |
1683 | nameless = (qq == name); |
1684 | ||
818de002 PB |
1685 | struct_and_type_combined = (qq[1] == 'T' && qq[2] == 't'); |
1686 | pp = qq + (struct_and_type_combined ? 3 : 2); | |
2b5a8d9c PB |
1687 | |
1688 | ||
1689 | /* To handle GNU C++ typename abbreviation, we need to be able to fill | |
1690 | in a type's name as soon as space for that type is allocated. */ | |
1691 | ||
1692 | if (struct_and_type_combined && name != qq) { | |
1693 | ||
1694 | int typenums[2]; | |
1695 | struct type *tmp_type; | |
1696 | char *tmp_pp = pp; | |
1697 | ||
1698 | read_type_number (&tmp_pp, typenums); | |
507e4004 | 1699 | tmp_type = dbx_alloc_type (typenums, objfile); |
2b5a8d9c | 1700 | |
6c6afbb9 | 1701 | if (tmp_type && !TYPE_NAME (tmp_type) && !nameless) |
2b5a8d9c | 1702 | TYPE_NAME (tmp_type) = SYMBOL_NAME (sym) = |
507e4004 PB |
1703 | obsavestring (name, qq-name, |
1704 | &objfile->symbol_obstack); | |
2b5a8d9c | 1705 | } |
1eeba686 PB |
1706 | ttype = SYMBOL_TYPE (sym) = read_type (&pp); |
1707 | ||
1708 | /* if there is no name for this typedef, you don't have to keep its | |
1709 | symbol, since nobody could ask for it. Otherwise, build a symbol | |
1710 | and add it into symbol_list. */ | |
1711 | ||
1712 | if (nameless) | |
1713 | return; | |
1714 | ||
1715 | #ifdef NO_TYPEDEFS | |
1716 | /* Transarc wants to eliminate type definitions from the symbol table. | |
1717 | Limited debugging capabilities, but faster symbol table processing | |
1718 | and less memory usage. Note that tag definitions (starting with | |
1719 | 'T') will remain intact. */ | |
1720 | ||
1721 | if (qq[1] != 'T' && (!TYPE_NAME (ttype) || *(TYPE_NAME (ttype)) == '\0')) { | |
1722 | ||
1723 | if (SYMBOL_NAME (sym)) | |
1724 | TYPE_NAME (ttype) = SYMBOL_NAME (sym); | |
1725 | else | |
1726 | TYPE_NAME (ttype) = obsavestring (name, qq-name); | |
1727 | ||
1728 | return; | |
1729 | } | |
1730 | ||
1731 | #endif /* !NO_TYPEDEFS */ | |
e38e0312 JG |
1732 | |
1733 | /* read_type() will return null if type (or tag) definition was | |
1734 | unnnecessarily duplicated. Also, if the symbol doesn't have a name, | |
1735 | there is no need to keep it in symbol table. */ | |
2b5a8d9c | 1736 | /* The above argument no longer valid. read_type() never returns NULL. */ |
e38e0312 | 1737 | |
6c6afbb9 | 1738 | if (!ttype) |
e38e0312 JG |
1739 | return NULL; |
1740 | ||
6c6afbb9 PB |
1741 | /* if there is no name for this typedef, you don't have to keep its |
1742 | symbol, since nobody could ask for it. Otherwise, build a symbol | |
1743 | and add it into symbol_list. */ | |
1744 | ||
1eeba686 | 1745 | if (qq[1] == 'T') |
6c6afbb9 | 1746 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; |
1eeba686 | 1747 | else if (qq[1] == 't') |
6c6afbb9 | 1748 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
1eeba686 PB |
1749 | else { |
1750 | warning ("Unrecognized stab string.\n"); | |
6c6afbb9 | 1751 | return NULL; |
1eeba686 | 1752 | } |
6c6afbb9 | 1753 | |
1eeba686 PB |
1754 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
1755 | if (!SYMBOL_NAME (sym)) | |
1756 | SYMBOL_NAME (sym) = obsavestring (name, qq-name); | |
6c6afbb9 | 1757 | |
1eeba686 PB |
1758 | SYMBOL_DUP (sym, sym2); |
1759 | add_symbol_to_list | |
6c6afbb9 PB |
1760 | (sym2, within_function ? &local_symbols : &file_symbols); |
1761 | ||
1eeba686 PB |
1762 | /* For a combination of struct and type, add one more symbol |
1763 | for the type. */ | |
e38e0312 | 1764 | |
1eeba686 | 1765 | if (struct_and_type_combined) { |
6c6afbb9 PB |
1766 | SYMBOL_DUP (sym, sym2); |
1767 | SYMBOL_NAMESPACE (sym2) = VAR_NAMESPACE; | |
1768 | add_symbol_to_list | |
1769 | (sym2, within_function ? &local_symbols : &file_symbols); | |
1eeba686 | 1770 | } |
e38e0312 | 1771 | |
1eeba686 | 1772 | /* assign a name to the type node. */ |
6c6afbb9 | 1773 | |
1eeba686 | 1774 | if (!TYPE_NAME (ttype) || *(TYPE_NAME (ttype)) == '\0') { |
6c6afbb9 PB |
1775 | if (struct_and_type_combined) |
1776 | TYPE_NAME (ttype) = SYMBOL_NAME (sym); | |
6c6afbb9 | 1777 | else if (qq[1] == 'T') /* struct namespace */ |
e38e0312 JG |
1778 | TYPE_NAME (ttype) = concat ( |
1779 | TYPE_CODE (ttype) == TYPE_CODE_UNION ? "union " : | |
1780 | TYPE_CODE (ttype) == TYPE_CODE_STRUCT? "struct " : "enum ", | |
58ae87f6 | 1781 | SYMBOL_NAME (sym), NULL); |
818de002 | 1782 | } |
e38e0312 JG |
1783 | break; |
1784 | ||
1eeba686 PB |
1785 | #else /* !NO_DEFINE_SYMBOL */ |
1786 | return define_symbol (cs->c_value, cs->c_name, 0, 0, objfile); | |
1787 | #endif | |
1788 | ||
e38e0312 JG |
1789 | case C_GSYM: |
1790 | add_stab_to_list (name, &global_stabs); | |
1791 | break; | |
1792 | ||
1793 | case C_PSYM: | |
818de002 | 1794 | case C_RPSYM: |
1eeba686 PB |
1795 | |
1796 | #ifdef NO_DEFINE_SYMBOL | |
1ab3bf1b | 1797 | if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL) |
e38e0312 | 1798 | return NULL; |
1ab3bf1b | 1799 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
818de002 | 1800 | SYMBOL_CLASS (sym) = (cs->c_sclass == C_PSYM) ? LOC_ARG : LOC_REGPARM; |
e38e0312 | 1801 | pp += 2; |
1ab3bf1b | 1802 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
1803 | SYMBOL_DUP (sym, sym2); |
1804 | add_symbol_to_list (sym2, &local_symbols); | |
1805 | break; | |
1eeba686 PB |
1806 | #else |
1807 | sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile); | |
1808 | SYMBOL_CLASS (sym) = (cs->c_sclass == C_PSYM) ? LOC_ARG : LOC_REGPARM; | |
1809 | return sym; | |
1810 | #endif | |
e38e0312 JG |
1811 | |
1812 | case C_STSYM: | |
1eeba686 PB |
1813 | |
1814 | #ifdef NO_DEFINE_SYMBOL | |
1ab3bf1b | 1815 | if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL) |
e38e0312 | 1816 | return NULL; |
1ab3bf1b | 1817 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
e38e0312 JG |
1818 | SYMBOL_CLASS (sym) = LOC_STATIC; |
1819 | SYMBOL_VALUE (sym) += static_block_base; | |
1820 | pp += 2; | |
1ab3bf1b | 1821 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
1822 | SYMBOL_DUP (sym, sym2); |
1823 | add_symbol_to_list | |
1824 | (sym2, within_function ? &local_symbols : &file_symbols); | |
1825 | break; | |
1eeba686 PB |
1826 | #else |
1827 | /* If we are going to use Sun dbx's define_symbol(), we need to | |
1828 | massage our stab string a little. Change 'V' type to 'S' to be | |
1829 | comparible with Sun. */ | |
1830 | ||
1831 | if (*name == ':' || (pp = (char *) index (name, ':')) == NULL) | |
1832 | return NULL; | |
1833 | ||
1834 | ++pp; | |
1835 | if (*pp == 'V') *pp = 'S'; | |
1836 | sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile); | |
1837 | SYMBOL_VALUE (sym) += static_block_base; | |
1838 | return sym; | |
1839 | #endif | |
e38e0312 JG |
1840 | |
1841 | case C_LSYM: | |
1ab3bf1b | 1842 | if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL) |
e38e0312 | 1843 | return NULL; |
1ab3bf1b | 1844 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
e38e0312 JG |
1845 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
1846 | pp += 1; | |
1ab3bf1b | 1847 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
1848 | SYMBOL_DUP (sym, sym2); |
1849 | add_symbol_to_list (sym2, &local_symbols); | |
1850 | break; | |
1851 | ||
1852 | case C_AUTO: | |
1853 | SYMBOL_CLASS (sym) = LOC_LOCAL; | |
1854 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
1855 | SYMBOL_DUP (sym, sym2); | |
1856 | add_symbol_to_list (sym2, &local_symbols); | |
1857 | break; | |
1858 | ||
1859 | case C_EXT: | |
1860 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
1861 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
1862 | SYMBOL_DUP (sym, sym2); | |
1863 | add_symbol_to_list (sym2, &global_symbols); | |
1864 | break; | |
1865 | ||
1866 | case C_STAT: | |
1867 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
1868 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
1869 | SYMBOL_DUP (sym, sym2); | |
1870 | add_symbol_to_list | |
1871 | (sym2, within_function ? &local_symbols : &file_symbols); | |
1872 | break; | |
1873 | ||
1874 | case C_REG: | |
1875 | printf ("ERROR! C_REG is not fully implemented!\n"); | |
1876 | SYMBOL_CLASS (sym) = LOC_REGISTER; | |
1877 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
1878 | SYMBOL_DUP (sym, sym2); | |
1879 | add_symbol_to_list (sym2, &local_symbols); | |
1880 | break; | |
1881 | ||
1882 | case C_RSYM: | |
1eeba686 PB |
1883 | |
1884 | #ifdef NO_DEFINE_SYMBOL | |
1ab3bf1b | 1885 | pp = (char*) strchr (name, ':'); |
e38e0312 JG |
1886 | SYMBOL_CLASS (sym) = LOC_REGISTER; |
1887 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (cs->c_value); | |
1888 | if (pp) { | |
1ab3bf1b | 1889 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
e38e0312 JG |
1890 | pp += 2; |
1891 | if (*pp) | |
1ab3bf1b | 1892 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
1893 | } |
1894 | else | |
1895 | /* else this is not a stab entry, suppose the type is either | |
1896 | `int' or `float', depending on the register class. */ | |
1897 | ||
1ab3bf1b | 1898 | SYMBOL_TYPE (sym) = (SYMBOL_VALUE (sym) < 32) |
818de002 PB |
1899 | ? lookup_fundamental_type (objfile, FT_INTEGER) |
1900 | : lookup_fundamental_type (objfile, FT_FLOAT); | |
e38e0312 JG |
1901 | |
1902 | SYMBOL_DUP (sym, sym2); | |
1903 | add_symbol_to_list (sym2, &local_symbols); | |
1904 | break; | |
1eeba686 PB |
1905 | #else |
1906 | if (pp) { | |
1907 | sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile); | |
1908 | return sym; | |
1909 | } | |
1910 | else { | |
1911 | warning ("A non-stab C_RSYM needs special handling."); | |
1912 | return NULL; | |
1913 | } | |
1914 | #endif | |
e38e0312 JG |
1915 | |
1916 | default : | |
1eeba686 | 1917 | warning ("Unexpected storage class: %d.", cs->c_sclass); |
e38e0312 JG |
1918 | return NULL; |
1919 | } | |
1920 | } | |
1921 | return sym2; | |
1922 | } | |
1923 | ||
1924 | ||
1925 | static int | |
1926 | read_symbol_nvalue (symtable, symno) | |
1927 | char *symtable; | |
1928 | int symno; | |
1929 | { | |
1930 | struct internal_syment symbol[1]; | |
1931 | ||
1932 | bfd_coff_swap_sym_in (symfile_bfd, symtable + (symno*local_symesz), symbol); | |
1933 | return symbol->n_value; | |
1934 | } | |
1935 | ||
1936 | ||
1937 | static int | |
1938 | read_symbol_lineno (symtable, symno) | |
1939 | char *symtable; | |
1940 | int symno; | |
1941 | { | |
1942 | struct internal_syment symbol[1]; | |
1943 | union internal_auxent main_aux[1]; | |
1944 | ||
1945 | int ii; | |
1946 | ||
1947 | for (ii = 0; ii < 50; ii++) { | |
1948 | bfd_coff_swap_sym_in (symfile_bfd, | |
1949 | symtable + (symno*local_symesz), symbol); | |
1950 | if (symbol->n_sclass == C_FCN && 0 == strcmp (symbol->n_name, ".bf")) | |
1951 | goto gotit; | |
6b5b330b | 1952 | symno += symbol->n_numaux+1; |
e38e0312 JG |
1953 | } |
1954 | ||
1955 | printf ("GDB Error: `.bf' not found.\n"); | |
1956 | return 0; | |
1957 | ||
1958 | gotit: | |
1959 | /* take aux entry and return its lineno */ | |
1960 | symno++; | |
1961 | bfd_coff_swap_aux_in (symfile_bfd, symtable+(symno*local_symesz), | |
1962 | symbol->n_type, symbol->n_sclass, main_aux); | |
1963 | ||
1964 | return main_aux->x_sym.x_misc.x_lnsz.x_lnno; | |
1965 | } | |
1966 | ||
1967 | /* Support for line number handling */ | |
1968 | ||
1969 | /* This function is called for every section; it finds the outer limits | |
1970 | * of the line table (minimum and maximum file offset) so that the | |
1971 | * mainline code can read the whole thing for efficiency. | |
1972 | */ | |
1973 | static void | |
1974 | find_linenos(abfd, asect, vpinfo) | |
1975 | bfd *abfd; | |
1976 | sec_ptr asect; | |
1ab3bf1b | 1977 | PTR vpinfo; |
e38e0312 JG |
1978 | { |
1979 | struct coff_symfile_info *info; | |
1980 | int size, count; | |
1981 | file_ptr offset, maxoff; | |
1982 | ||
1983 | count = asect->lineno_count; | |
1984 | ||
818de002 | 1985 | if (strcmp (asect->name, ".text") || count == 0) |
e38e0312 JG |
1986 | return; |
1987 | ||
1988 | size = count * coff_data (symfile_bfd)->local_linesz; | |
1989 | info = (struct coff_symfile_info *)vpinfo; | |
1990 | offset = asect->line_filepos; | |
1991 | maxoff = offset + size; | |
1992 | ||
1993 | if (offset < info->min_lineno_offset || info->min_lineno_offset == 0) | |
1994 | info->min_lineno_offset = offset; | |
1995 | ||
1996 | if (maxoff > info->max_lineno_offset) | |
1997 | info->max_lineno_offset = maxoff; | |
1998 | } | |
1999 | ||
2000 | ||
2001 | /* Read in all the line numbers for fast lookups later. Leave them in | |
2002 | external (unswapped) format in memory; we'll swap them as we enter | |
2003 | them into GDB's data structures. */ | |
2004 | ||
2005 | static int | |
2006 | init_lineno (abfd, offset, size) | |
2007 | bfd *abfd; | |
2008 | long offset; | |
2009 | int size; | |
2010 | { | |
2011 | int val; | |
2012 | ||
2013 | if (bfd_seek(abfd, offset, 0) < 0) | |
2014 | return -1; | |
2015 | ||
2016 | linetab = (char *) xmalloc(size); | |
2017 | ||
2018 | val = bfd_read(linetab, 1, size, abfd); | |
2019 | if (val != size) | |
2020 | return -1; | |
2021 | ||
2022 | linetab_offset = offset; | |
2023 | linetab_size = size; | |
1ab3bf1b | 2024 | make_cleanup (free, linetab); /* Be sure it gets de-allocated. */ |
e38e0312 JG |
2025 | return 0; |
2026 | } | |
93fe4e33 | 2027 | \f |
e38e0312 JG |
2028 | /* dbx allows the text of a symbol name to be continued into the |
2029 | next symbol name! When such a continuation is encountered | |
2030 | (a \ at the end of the text of a name) | |
2031 | call this function to get the continuation. */ | |
2032 | /* So far, I haven't seen this happenning xlc output. I doubt we'll need this | |
2033 | for aixcoff. */ | |
2034 | ||
1d4c28c5 | 2035 | #undef next_symbol_text |
e38e0312 JG |
2036 | #define next_symbol_text() \ |
2037 | printf ("Gdb Error: symbol names on multiple lines not implemented.\n") | |
2038 | ||
2039 | ||
2040 | /* xlc/dbx combination uses a set of builtin types, starting from -1. return | |
2041 | the proper type node fora given builtin type #. */ | |
2042 | ||
2043 | struct type * | |
2044 | builtin_type (pp) | |
2045 | char **pp; | |
2046 | { | |
2047 | int typenums[2]; | |
2048 | ||
2049 | if (**pp != '-') { | |
2050 | printf ("ERROR!, unknown built-in type!\n"); | |
2051 | return NULL; | |
2052 | } | |
2053 | *pp += 1; | |
2054 | read_type_number (pp, typenums); | |
2055 | ||
2056 | /* default types are defined in dbxstclass.h. */ | |
2057 | switch ( typenums[1] ) { | |
2058 | case 1: | |
1ab3bf1b | 2059 | return lookup_fundamental_type (current_objfile, FT_INTEGER); |
e38e0312 | 2060 | case 2: |
1ab3bf1b | 2061 | return lookup_fundamental_type (current_objfile, FT_CHAR); |
e38e0312 | 2062 | case 3: |
1ab3bf1b | 2063 | return lookup_fundamental_type (current_objfile, FT_SHORT); |
e38e0312 | 2064 | case 4: |
1ab3bf1b | 2065 | return lookup_fundamental_type (current_objfile, FT_LONG); |
e38e0312 | 2066 | case 5: |
1ab3bf1b | 2067 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR); |
e38e0312 | 2068 | case 6: |
1ab3bf1b | 2069 | return lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR); |
e38e0312 | 2070 | case 7: |
1ab3bf1b | 2071 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT); |
e38e0312 | 2072 | case 8: |
1ab3bf1b | 2073 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); |
e38e0312 | 2074 | case 9: |
1ab3bf1b | 2075 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); |
e38e0312 | 2076 | case 10: |
1ab3bf1b | 2077 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG); |
e38e0312 | 2078 | case 11: |
1ab3bf1b | 2079 | return lookup_fundamental_type (current_objfile, FT_VOID); |
e38e0312 | 2080 | case 12: |
1ab3bf1b | 2081 | return lookup_fundamental_type (current_objfile, FT_FLOAT); |
e38e0312 | 2082 | case 13: |
1ab3bf1b | 2083 | return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT); |
e38e0312 | 2084 | case 14: |
1ab3bf1b | 2085 | return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT); |
e38e0312 | 2086 | case 15: |
1ab3bf1b JG |
2087 | /* requires a builtin `integer' */ |
2088 | return lookup_fundamental_type (current_objfile, FT_INTEGER); | |
e38e0312 | 2089 | case 16: |
1ab3bf1b | 2090 | return lookup_fundamental_type (current_objfile, FT_BOOLEAN); |
e38e0312 | 2091 | case 17: |
1ab3bf1b JG |
2092 | /* requires builtin `short real' */ |
2093 | return lookup_fundamental_type (current_objfile, FT_FLOAT); | |
e38e0312 | 2094 | case 18: |
1ab3bf1b JG |
2095 | /* requires builtin `real' */ |
2096 | return lookup_fundamental_type (current_objfile, FT_FLOAT); | |
e38e0312 JG |
2097 | default : |
2098 | printf ("ERROR! Unknown builtin type -%d\n", typenums[1]); | |
2099 | return NULL; | |
2100 | } | |
2101 | } | |
2102 | ||
1ab3bf1b JG |
2103 | #if 0 /* Seems to be unused, don't bother converting from old misc function |
2104 | vector usage to new minimal symbol tables. FIXME: Delete this? */ | |
2105 | ||
e38e0312 JG |
2106 | /* if we now nothing about a function but its address, make a function symbol |
2107 | out of it with the limited knowladge you have. This will be used when | |
2108 | somebody refers to a function, which doesn't exist in the symbol table, | |
1ab3bf1b | 2109 | but is in the minimal symbol table. */ |
e38e0312 JG |
2110 | |
2111 | struct symbol * | |
1ab3bf1b | 2112 | build_function_symbol (ind, objfile) |
e38e0312 | 2113 | int ind; |
1ab3bf1b | 2114 | struct objfile *objfile; |
e38e0312 JG |
2115 | { |
2116 | struct symbol *sym = | |
1ab3bf1b | 2117 | (struct symbol *) obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); |
e38e0312 JG |
2118 | SYMBOL_NAME (sym) = misc_function_vector[ind].name; |
2119 | /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */ | |
2120 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
2121 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
1ab3bf1b | 2122 | SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (current_objfile, FT_INTEGER)); |
e38e0312 | 2123 | SYMBOL_BLOCK_VALUE (sym) = (struct block *) |
1ab3bf1b | 2124 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct block)); |
e38e0312 JG |
2125 | BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) = misc_function_vector[ind].address; |
2126 | return sym; | |
2127 | } | |
2128 | ||
1ab3bf1b | 2129 | #endif |
e38e0312 | 2130 | |
1ab3bf1b | 2131 | static void |
80d68b1d FF |
2132 | aixcoff_new_init (objfile) |
2133 | struct objfile *objfile; | |
e38e0312 | 2134 | { |
e38e0312 JG |
2135 | } |
2136 | ||
1ab3bf1b | 2137 | static void |
80d68b1d FF |
2138 | aixcoff_symfile_init (objfile) |
2139 | struct objfile *objfile; | |
e38e0312 | 2140 | { |
80d68b1d | 2141 | bfd *abfd = objfile->obfd; |
e38e0312 JG |
2142 | |
2143 | /* Allocate struct to keep track of the symfile */ | |
80d68b1d FF |
2144 | objfile -> sym_private = xmmalloc (objfile -> md, |
2145 | sizeof (struct coff_symfile_info)); | |
5e2e79f8 | 2146 | init_entry_point_info (objfile); |
e38e0312 JG |
2147 | } |
2148 | ||
80d68b1d FF |
2149 | /* Perform any local cleanups required when we are done with a particular |
2150 | objfile. I.E, we are in the process of discarding all symbol information | |
2151 | for an objfile, freeing up all memory held for it, and unlinking the | |
2152 | objfile struct from the global list of known objfiles. */ | |
2153 | ||
2154 | static void | |
2155 | aixcoff_symfile_finish (objfile) | |
2156 | struct objfile *objfile; | |
2157 | { | |
2158 | if (objfile -> sym_private != NULL) | |
2159 | { | |
2160 | mfree (objfile -> md, objfile -> sym_private); | |
2161 | } | |
2162 | ||
2163 | /* Start with a fresh include table for the next objfile. */ | |
2164 | ||
2165 | if (inclTable) | |
2166 | { | |
2167 | free (inclTable); | |
2168 | inclTable = NULL; | |
2169 | } | |
2170 | inclIndx = inclLength = inclDepth = 0; | |
2171 | } | |
2172 | ||
e38e0312 JG |
2173 | |
2174 | static int | |
1ab3bf1b | 2175 | init_stringtab(abfd, offset, objfile) |
e38e0312 JG |
2176 | bfd *abfd; |
2177 | long offset; | |
1ab3bf1b | 2178 | struct objfile *objfile; |
e38e0312 JG |
2179 | { |
2180 | long length; | |
2181 | int val; | |
2182 | unsigned char lengthbuf[4]; | |
2183 | ||
2184 | if (bfd_seek(abfd, offset, 0) < 0) | |
2185 | return -1; | |
2186 | ||
2187 | val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd); | |
2188 | length = bfd_h_get_32(abfd, lengthbuf); | |
2189 | ||
2190 | /* If no string table is needed, then the file may end immediately | |
2191 | after the symbols. Just return with `strtbl' set to null. */ | |
2192 | ||
2193 | if (val != sizeof length || length < sizeof length) | |
2194 | return 0; | |
2195 | ||
2196 | /* Allocate string table from symbol_obstack. We will need this table | |
2197 | as long as we have its symbol table around. */ | |
2198 | ||
1ab3bf1b | 2199 | strtbl = (char*) obstack_alloc (&objfile->symbol_obstack, length); |
e38e0312 JG |
2200 | if (strtbl == NULL) |
2201 | return -1; | |
2202 | ||
2203 | bcopy(&length, strtbl, sizeof length); | |
2204 | if (length == sizeof length) | |
2205 | return 0; | |
2206 | ||
2207 | val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd); | |
2208 | ||
2209 | if (val != length - sizeof length || strtbl[length - 1] != '\0') | |
2210 | return -1; | |
2211 | ||
2212 | return 0; | |
2213 | } | |
2214 | ||
2215 | static int | |
2216 | init_debugsection(abfd) | |
2217 | bfd *abfd; | |
2218 | { | |
2219 | register sec_ptr secp; | |
2220 | bfd_size_type length; | |
2221 | ||
2222 | if (debugsec) { | |
2223 | free(debugsec); | |
2224 | debugsec = NULL; | |
2225 | } | |
2226 | ||
2227 | secp = bfd_get_section_by_name(abfd, ".debug"); | |
2228 | if (!secp) | |
2229 | return 0; | |
2230 | ||
2231 | if (!(length = bfd_section_size(abfd, secp))) | |
2232 | return 0; | |
2233 | ||
1ab3bf1b | 2234 | debugsec = (char *) xmalloc ((unsigned)length); |
e38e0312 JG |
2235 | if (debugsec == NULL) |
2236 | return -1; | |
2237 | ||
2238 | if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) { | |
2239 | printf ("Can't read .debug section from symbol file\n"); | |
2240 | return -1; | |
2241 | } | |
2242 | return 0; | |
2243 | } | |
2244 | ||
2245 | static void | |
2246 | free_debugsection() | |
2247 | { | |
2248 | if (debugsec) | |
2249 | free(debugsec); | |
2250 | debugsec = NULL; | |
2251 | } | |
2252 | ||
2253 | ||
2254 | /* aixcoff version of symbol file read. */ | |
2255 | ||
1ab3bf1b | 2256 | static void |
2670f34d | 2257 | aixcoff_symfile_read (objfile, section_offset, mainline) |
80d68b1d | 2258 | struct objfile *objfile; |
2670f34d | 2259 | struct section_offset *section_offset; |
e38e0312 JG |
2260 | int mainline; |
2261 | { | |
2262 | int num_symbols; /* # of symbols */ | |
2263 | int symtab_offset; /* symbol table and */ | |
2264 | int stringtab_offset; /* string table file offsets */ | |
2265 | int val; | |
2266 | bfd *abfd; | |
80d68b1d | 2267 | struct coff_symfile_info *info; |
e38e0312 JG |
2268 | char *name; |
2269 | ||
80d68b1d FF |
2270 | info = (struct coff_symfile_info *) objfile -> sym_private; |
2271 | symfile_bfd = abfd = objfile->obfd; | |
2272 | name = objfile->name; | |
e38e0312 JG |
2273 | |
2274 | num_symbols = bfd_get_symcount (abfd); /* # of symbols */ | |
2275 | symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */ | |
2276 | stringtab_offset = symtab_offset + | |
2277 | num_symbols * coff_data(abfd)->local_symesz; | |
2278 | ||
2279 | info->min_lineno_offset = 0; | |
2280 | info->max_lineno_offset = 0; | |
2281 | bfd_map_over_sections (abfd, find_linenos, info); | |
2282 | ||
2283 | /* FIXME! This stuff should move into symfile_init */ | |
2284 | if (info->min_lineno_offset != 0 | |
2285 | && info->max_lineno_offset > info->min_lineno_offset) { | |
2286 | ||
2287 | /* only read in the line # table if one exists */ | |
2288 | val = init_lineno(abfd, info->min_lineno_offset, | |
2289 | info->max_lineno_offset - info->min_lineno_offset); | |
2290 | ||
2291 | if (val < 0) | |
2292 | error("\"%s\": error reading line numbers\n", name); | |
2293 | } | |
2294 | ||
80d68b1d | 2295 | val = init_stringtab(abfd, stringtab_offset, objfile); |
e38e0312 JG |
2296 | if (val < 0) { |
2297 | error ("\"%s\": can't get string table", name); | |
2298 | } | |
2299 | ||
2300 | if (init_debugsection(abfd) < 0) { | |
2301 | error ("Error reading .debug section of `%s'\n", name); | |
2302 | } | |
2303 | ||
2304 | /* Position to read the symbol table. Do not read it all at once. */ | |
2305 | val = bfd_seek(abfd, (long)symtab_offset, 0); | |
2306 | if (val < 0) | |
2307 | perror_with_name(name); | |
2308 | ||
2309 | if (bfd_tell(abfd) != symtab_offset) | |
2310 | fatal("bfd? BFD!"); | |
2311 | ||
1ab3bf1b JG |
2312 | init_minimal_symbol_collection (); |
2313 | make_cleanup (discard_minimal_symbols, 0); | |
e38e0312 | 2314 | |
556f3d90 | 2315 | /* Initialize load info structure. */ |
e38e0312 | 2316 | if (mainline) |
556f3d90 | 2317 | xcoff_init_loadinfo (); |
e38e0312 JG |
2318 | |
2319 | /* Now that the executable file is positioned at symbol table, | |
2320 | process it and define symbols accordingly. */ | |
2321 | ||
80d68b1d | 2322 | read_xcoff_symtab(objfile, num_symbols); |
e38e0312 | 2323 | |
1eeba686 PB |
2324 | /* Free debug section. */ |
2325 | free_debugsection (); | |
e38e0312 JG |
2326 | |
2327 | /* Sort symbols alphabetically within each block. */ | |
2328 | sort_syms (); | |
2329 | ||
1ab3bf1b JG |
2330 | /* Install any minimal symbols that have been collected as the current |
2331 | minimal symbols for this objfile. */ | |
2332 | ||
80d68b1d | 2333 | install_minimal_symbols (objfile); |
e38e0312 JG |
2334 | |
2335 | /* Make a default for file to list. */ | |
2336 | select_source_symtab (0); | |
2337 | } | |
2338 | ||
2670f34d JG |
2339 | /* XCOFF-specific parsing routine for section offsets. |
2340 | Plain and simple for now. */ | |
2341 | ||
2342 | static | |
2343 | struct section_offsets * | |
2344 | aixcoff_symfile_offsets (objfile, addr) | |
2345 | struct objfile *objfile; | |
2346 | CORE_ADDR addr; | |
2347 | { | |
2348 | struct section_offsets *section_offsets; | |
2349 | int i; | |
2350 | ||
2351 | section_offsets = (struct section_offsets *) | |
2352 | obstack_alloc (&objfile -> psymbol_obstack, | |
2353 | sizeof (struct section_offsets) + | |
2354 | sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1)); | |
2355 | ||
2356 | for (i = 0; i < SECT_OFF_MAX; i++) | |
2357 | ANOFFSET (section_offsets, i) = addr; | |
2358 | ||
2359 | return section_offsets; | |
2360 | } | |
e38e0312 JG |
2361 | /* Register our ability to parse symbols for aixcoff BFD files. */ |
2362 | ||
2363 | static struct sym_fns aixcoff_sym_fns = | |
2364 | { | |
80d68b1d FF |
2365 | "aixcoff-rs6000", /* sym_name: name or name prefix of BFD target type */ |
2366 | 15, /* sym_namelen: number of significant sym_name chars */ | |
2367 | aixcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */ | |
2368 | aixcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
2369 | aixcoff_symfile_read, /* sym_read: read a symbol file into symtab */ | |
2370 | aixcoff_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
2670f34d | 2371 | aixcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */ |
80d68b1d | 2372 | NULL /* next: pointer to next struct sym_fns */ |
e38e0312 JG |
2373 | }; |
2374 | ||
2375 | void | |
2376 | _initialize_xcoffread () | |
2377 | { | |
2378 | add_symtab_fns(&aixcoff_sym_fns); | |
2379 | } | |
6c6afbb9 | 2380 | |
1eeba686 | 2381 | #else /* IBM6000_HOST */ |
818de002 | 2382 | struct type * |
84ffdec2 JG |
2383 | builtin_type (ignore) |
2384 | char **ignore; | |
818de002 | 2385 | { |
84ffdec2 | 2386 | fatal ("GDB internal eror: builtin_type called on non-RS/6000!"); |
818de002 | 2387 | } |
1eeba686 | 2388 | #endif /* IBM6000_HOST */ |