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