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