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