Commit | Line | Data |
---|---|---|
9b280a7f | 1 | /* Read AIX xcoff symbol tables and convert to internal format, for GDB. |
d1f14b46 | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 |
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 | |
6c9638b4 | 21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
e38e0312 | 22 | |
df1e1074 PS |
23 | /* RS/6000 and PowerPC only: |
24 | Needs xcoff_add_toc_to_loadinfo and xcoff_init_loadinfo in | |
25 | rs6000-tdep.c from target. | |
26 | However, if you define FAKING_RS6000, then this code will link with | |
27 | any target. */ | |
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> | |
2b576293 | 35 | #include "gdb_string.h" |
e38e0312 | 36 | |
e38e0312 | 37 | #include <sys/param.h> |
5e4d4b0f | 38 | #ifndef NO_SYS_FILE |
e38e0312 | 39 | #include <sys/file.h> |
5e4d4b0f | 40 | #endif |
2b576293 | 41 | #include "gdb_stat.h" |
e38e0312 | 42 | |
a367db89 | 43 | #include "coff/internal.h" |
27ad511f | 44 | #include "libcoff.h" /* FIXME, internal data from BFD */ |
a367db89 | 45 | #include "coff/rs6000.h" |
27ad511f | 46 | |
e38e0312 | 47 | #include "symtab.h" |
1ab3bf1b | 48 | #include "gdbtypes.h" |
e38e0312 | 49 | #include "symfile.h" |
5e2e79f8 | 50 | #include "objfiles.h" |
e38e0312 | 51 | #include "buildsym.h" |
d07734e3 | 52 | #include "stabsread.h" |
df1e1074 PS |
53 | #include "expression.h" |
54 | #include "language.h" /* Needed inside partial-stab.h */ | |
dd469789 | 55 | #include "complaints.h" |
e38e0312 | 56 | |
a81ce07d JK |
57 | #include "gdb-stabs.h" |
58 | ||
73262420 | 59 | /* For interface with stabsread.c. */ |
c41e08c4 | 60 | #include "aout/stab_gnu.h" |
1eeba686 | 61 | |
a367db89 JK |
62 | /* For interface with partial-stab.h. */ |
63 | #define N_UNDF 0 /* Undefined symbol */ | |
64 | #undef N_ABS | |
65 | #define N_ABS 2 | |
66 | #define N_TEXT 4 /* Text sym -- defined at offset in text seg */ | |
67 | #define N_DATA 6 /* Data sym -- defined at offset in data seg */ | |
68 | #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */ | |
69 | #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */ | |
70 | #define N_FN 0x1f /* File name of .o file */ | |
71 | #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */ | |
72 | /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT, | |
73 | N_DATA, or N_BSS. When the low-order bit of other types is set, | |
74 | (e.g. N_WARNING versus N_FN), they are two different types. */ | |
75 | #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */ | |
76 | #define N_INDR 0x0a | |
77 | ||
78 | /* The following symbols refer to set elements. | |
79 | All the N_SET[ATDB] symbols with the same name form one set. | |
80 | Space is allocated for the set in the text section, and each set | |
81 | elements value is stored into one word of the space. | |
82 | The first word of the space is the length of the set (number of elements). | |
83 | ||
84 | The address of the set is made into an N_SETV symbol | |
85 | whose name is the same as the name of the set. | |
86 | This symbol acts like a N_DATA global symbol | |
87 | in that it can satisfy undefined external references. */ | |
88 | ||
89 | /* These appear as input to LD, in a .o file. */ | |
90 | #define N_SETA 0x14 /* Absolute set element symbol */ | |
91 | #define N_SETT 0x16 /* Text set element symbol */ | |
92 | #define N_SETD 0x18 /* Data set element symbol */ | |
93 | #define N_SETB 0x1A /* Bss set element symbol */ | |
94 | ||
95 | /* This is output from LD. */ | |
96 | #define N_SETV 0x1C /* Pointer to set vector in data area. */ | |
97 | \f | |
bbb053fd JK |
98 | /* We put a pointer to this structure in the read_symtab_private field |
99 | of the psymtab. */ | |
a367db89 JK |
100 | |
101 | struct symloc { | |
102 | ||
103 | /* First symbol number for this file. */ | |
104 | ||
105 | int first_symnum; | |
106 | ||
107 | /* Number of symbols in the section of the symbol table devoted to | |
108 | this file's symbols (actually, the section bracketed may contain | |
109 | more than just this file's symbols). If numsyms is 0, the only | |
110 | reason for this thing's existence is the dependency list. Nothing | |
111 | else will happen when it is read in. */ | |
112 | ||
113 | int numsyms; | |
114 | ||
115 | /* Position of the start of the line number information for this psymtab. */ | |
116 | unsigned int lineno_off; | |
117 | }; | |
118 | ||
119 | /* Remember what we deduced to be the source language of this psymtab. */ | |
120 | ||
121 | static enum language psymtab_language = language_unknown; | |
122 | ||
123 | \f | |
e38e0312 JG |
124 | /* Simplified internal version of coff symbol table information */ |
125 | ||
126 | struct coff_symbol { | |
127 | char *c_name; | |
128 | int c_symnum; /* symbol number of this entry */ | |
d4a0983a | 129 | int c_naux; /* 0 if syment only, 1 if syment + auxent */ |
e38e0312 | 130 | long c_value; |
ef5b809c | 131 | unsigned char c_sclass; |
e38e0312 JG |
132 | int c_secnum; |
133 | unsigned int c_type; | |
134 | }; | |
135 | ||
e38e0312 JG |
136 | /* last function's saved coff symbol `cs' */ |
137 | ||
138 | static struct coff_symbol fcn_cs_saved; | |
139 | ||
140 | static bfd *symfile_bfd; | |
141 | ||
142 | /* Core address of start and end of text of current source file. | |
143 | This is calculated from the first function seen after a C_FILE | |
144 | symbol. */ | |
145 | ||
818de002 | 146 | |
e38e0312 JG |
147 | static CORE_ADDR cur_src_end_addr; |
148 | ||
149 | /* Core address of the end of the first object file. */ | |
150 | ||
151 | static CORE_ADDR first_object_file_end; | |
152 | ||
e38e0312 JG |
153 | /* initial symbol-table-debug-string vector length */ |
154 | ||
155 | #define INITIAL_STABVECTOR_LENGTH 40 | |
156 | ||
e38e0312 JG |
157 | /* Nonzero if within a function (so symbols should be local, |
158 | if nothing says specifically). */ | |
159 | ||
160 | int within_function; | |
161 | ||
a367db89 JK |
162 | /* Size of a COFF symbol. I think it is always 18, so I'm not sure |
163 | there is any reason not to just use a #define, but might as well | |
164 | ask BFD for the size and store it here, I guess. */ | |
e38e0312 JG |
165 | |
166 | static unsigned local_symesz; | |
167 | ||
e38e0312 JG |
168 | struct coff_symfile_info { |
169 | file_ptr min_lineno_offset; /* Where in file lowest line#s are */ | |
170 | file_ptr max_lineno_offset; /* 1+last byte of line#s in file */ | |
a367db89 JK |
171 | |
172 | /* Pointer to the string table. */ | |
173 | char *strtbl; | |
174 | ||
175 | /* Pointer to debug section. */ | |
176 | char *debugsec; | |
177 | ||
178 | /* Pointer to the a.out symbol table. */ | |
179 | char *symtbl; | |
180 | ||
181 | /* Number of symbols in symtbl. */ | |
182 | int symtbl_num_syms; | |
e38e0312 JG |
183 | }; |
184 | ||
dd469789 JG |
185 | static struct complaint storclass_complaint = |
186 | {"Unexpected storage class: %d", 0, 0}; | |
187 | ||
188 | static struct complaint bf_notfound_complaint = | |
189 | {"line numbers off, `.bf' symbol not found", 0, 0}; | |
e38e0312 | 190 | |
df1e1074 PS |
191 | static struct complaint ef_complaint = |
192 | {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0}; | |
193 | ||
194 | static struct complaint eb_complaint = | |
195 | {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0}; | |
f8203ed0 | 196 | |
1ab3bf1b | 197 | static void |
818de002 PB |
198 | enter_line_range PARAMS ((struct subfile *, unsigned, unsigned, |
199 | CORE_ADDR, CORE_ADDR, unsigned *)); | |
1ab3bf1b | 200 | |
1ab3bf1b | 201 | static void |
d5931d79 | 202 | init_stringtab PARAMS ((bfd *, file_ptr, struct objfile *)); |
1ab3bf1b JG |
203 | |
204 | static void | |
9b280a7f | 205 | xcoff_symfile_init PARAMS ((struct objfile *)); |
80d68b1d FF |
206 | |
207 | static void | |
9b280a7f | 208 | xcoff_new_init PARAMS ((struct objfile *)); |
80d68b1d | 209 | |
1ab3bf1b | 210 | static void |
9b280a7f | 211 | xcoff_symfile_finish PARAMS ((struct objfile *)); |
1ab3bf1b | 212 | |
fe0b60b2 | 213 | static struct section_offsets * |
9b280a7f | 214 | xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR)); |
2670f34d | 215 | |
1ab3bf1b JG |
216 | static void |
217 | find_linenos PARAMS ((bfd *, sec_ptr, PTR)); | |
218 | ||
e8abe489 | 219 | static char * |
a367db89 | 220 | coff_getfilename PARAMS ((union internal_auxent *, struct objfile *)); |
e8abe489 | 221 | |
3c02636b JK |
222 | static void |
223 | read_symbol PARAMS ((struct internal_syment *, int)); | |
224 | ||
1ab3bf1b | 225 | static int |
c84a96d7 | 226 | read_symbol_lineno PARAMS ((int)); |
1ab3bf1b JG |
227 | |
228 | static int | |
c84a96d7 | 229 | read_symbol_nvalue PARAMS ((int)); |
1ab3bf1b JG |
230 | |
231 | static struct symbol * | |
232 | process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *)); | |
233 | ||
234 | static void | |
a367db89 | 235 | read_xcoff_symtab PARAMS ((struct partial_symtab *)); |
1ab3bf1b | 236 | |
1ab3bf1b JG |
237 | static void |
238 | add_stab_to_list PARAMS ((char *, struct pending_stabs **)); | |
239 | ||
a81ce07d | 240 | \f |
a367db89 JK |
241 | /* Translate from a COFF section number (target_index) to a SECT_OFF_* |
242 | code. */ | |
243 | static int secnum_to_section PARAMS ((int, struct objfile *)); | |
a81ce07d JK |
244 | |
245 | struct find_targ_sec_arg { | |
246 | int targ_index; | |
247 | int *resultp; | |
248 | }; | |
249 | ||
250 | static void find_targ_sec PARAMS ((bfd *, asection *, void *)); | |
251 | ||
252 | static void find_targ_sec (abfd, sect, obj) | |
253 | bfd *abfd; | |
254 | asection *sect; | |
255 | PTR obj; | |
256 | { | |
257 | struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj; | |
258 | if (sect->target_index == args->targ_index) | |
259 | { | |
260 | /* This is the section. Figure out what SECT_OFF_* code it is. */ | |
261 | if (bfd_get_section_flags (abfd, sect) & SEC_CODE) | |
262 | *args->resultp = SECT_OFF_TEXT; | |
263 | else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD) | |
264 | *args->resultp = SECT_OFF_DATA; | |
265 | else | |
266 | *args->resultp = SECT_OFF_BSS; | |
267 | } | |
268 | } | |
269 | ||
270 | /* Return the section number (SECT_OFF_*) that CS points to. */ | |
271 | static int | |
a367db89 JK |
272 | secnum_to_section (secnum, objfile) |
273 | int secnum; | |
a81ce07d JK |
274 | struct objfile *objfile; |
275 | { | |
276 | int off = SECT_OFF_TEXT; | |
277 | struct find_targ_sec_arg args; | |
a367db89 | 278 | args.targ_index = secnum; |
a81ce07d JK |
279 | args.resultp = &off; |
280 | bfd_map_over_sections (objfile->obfd, find_targ_sec, &args); | |
281 | return off; | |
282 | } | |
a81ce07d | 283 | \f |
e38e0312 JG |
284 | /* add a given stab string into given stab vector. */ |
285 | ||
286 | static void | |
287 | add_stab_to_list (stabname, stabvector) | |
288 | char *stabname; | |
289 | struct pending_stabs **stabvector; | |
290 | { | |
291 | if ( *stabvector == NULL) { | |
292 | *stabvector = (struct pending_stabs *) | |
293 | xmalloc (sizeof (struct pending_stabs) + | |
294 | INITIAL_STABVECTOR_LENGTH * sizeof (char*)); | |
295 | (*stabvector)->count = 0; | |
296 | (*stabvector)->length = INITIAL_STABVECTOR_LENGTH; | |
297 | } | |
298 | else if ((*stabvector)->count >= (*stabvector)->length) { | |
299 | (*stabvector)->length += INITIAL_STABVECTOR_LENGTH; | |
300 | *stabvector = (struct pending_stabs *) | |
1ab3bf1b | 301 | xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) + |
e38e0312 JG |
302 | (*stabvector)->length * sizeof (char*)); |
303 | } | |
304 | (*stabvector)->stab [(*stabvector)->count++] = stabname; | |
305 | } | |
194d98c6 JK |
306 | \f |
307 | /* Linenos are processed on a file-by-file basis. | |
308 | ||
309 | Two reasons: | |
310 | ||
311 | 1) xlc (IBM's native c compiler) postpones static function code | |
312 | emission to the end of a compilation unit. This way it can | |
313 | determine if those functions (statics) are needed or not, and | |
314 | can do some garbage collection (I think). This makes line | |
315 | numbers and corresponding addresses unordered, and we end up | |
316 | with a line table like: | |
317 | ||
318 | ||
319 | lineno addr | |
320 | foo() 10 0x100 | |
321 | 20 0x200 | |
322 | 30 0x300 | |
323 | ||
324 | foo3() 70 0x400 | |
325 | 80 0x500 | |
326 | 90 0x600 | |
327 | ||
328 | static foo2() | |
329 | 40 0x700 | |
330 | 50 0x800 | |
331 | 60 0x900 | |
332 | ||
333 | and that breaks gdb's binary search on line numbers, if the | |
334 | above table is not sorted on line numbers. And that sort | |
335 | should be on function based, since gcc can emit line numbers | |
336 | like: | |
337 | ||
338 | 10 0x100 - for the init/test part of a for stmt. | |
339 | 20 0x200 | |
340 | 30 0x300 | |
341 | 10 0x400 - for the increment part of a for stmt. | |
e38e0312 | 342 | |
194d98c6 | 343 | arrange_linetable() will do this sorting. |
e38e0312 | 344 | |
194d98c6 | 345 | 2) aix symbol table might look like: |
818de002 | 346 | |
194d98c6 JK |
347 | c_file // beginning of a new file |
348 | .bi // beginning of include file | |
349 | .ei // end of include file | |
350 | .bi | |
351 | .ei | |
818de002 | 352 | |
194d98c6 JK |
353 | basically, .bi/.ei pairs do not necessarily encapsulate |
354 | their scope. They need to be recorded, and processed later | |
355 | on when we come the end of the compilation unit. | |
356 | Include table (inclTable) and process_linenos() handle | |
357 | that. */ | |
818de002 PB |
358 | |
359 | /* compare line table entry addresses. */ | |
360 | ||
194d98c6 | 361 | static int |
818de002 | 362 | compare_lte (lte1, lte2) |
194d98c6 | 363 | struct linetable_entry *lte1, *lte2; |
818de002 PB |
364 | { |
365 | return lte1->pc - lte2->pc; | |
366 | } | |
367 | ||
368 | /* Give a line table with function entries are marked, arrange its functions | |
369 | in assending order and strip off function entry markers and return it in | |
370 | a newly created table. If the old one is good enough, return the old one. */ | |
c438b3af JK |
371 | /* FIXME: I think all this stuff can be replaced by just passing |
372 | sort_linevec = 1 to end_symtab. */ | |
818de002 PB |
373 | |
374 | static struct linetable * | |
375 | arrange_linetable (oldLineTb) | |
a367db89 | 376 | struct linetable *oldLineTb; /* old linetable */ |
818de002 PB |
377 | { |
378 | int ii, jj, | |
379 | newline, /* new line count */ | |
380 | function_count; /* # of functions */ | |
381 | ||
382 | struct linetable_entry *fentry; /* function entry vector */ | |
383 | int fentry_size; /* # of function entries */ | |
384 | struct linetable *newLineTb; /* new line table */ | |
385 | ||
386 | #define NUM_OF_FUNCTIONS 20 | |
387 | ||
388 | fentry_size = NUM_OF_FUNCTIONS; | |
389 | fentry = (struct linetable_entry*) | |
ecfd2b60 | 390 | xmalloc (fentry_size * sizeof (struct linetable_entry)); |
818de002 PB |
391 | |
392 | for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) { | |
393 | ||
394 | if (oldLineTb->item[ii].line == 0) { /* function entry found. */ | |
395 | ||
396 | if (function_count >= fentry_size) { /* make sure you have room. */ | |
397 | fentry_size *= 2; | |
398 | fentry = (struct linetable_entry*) | |
ecfd2b60 | 399 | xrealloc (fentry, fentry_size * sizeof (struct linetable_entry)); |
818de002 PB |
400 | } |
401 | fentry[function_count].line = ii; | |
402 | fentry[function_count].pc = oldLineTb->item[ii].pc; | |
403 | ++function_count; | |
404 | } | |
405 | } | |
406 | ||
407 | if (function_count == 0) { | |
408 | free (fentry); | |
409 | return oldLineTb; | |
410 | } | |
411 | else if (function_count > 1) | |
412 | qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte); | |
413 | ||
414 | /* allocate a new line table. */ | |
ecfd2b60 JK |
415 | newLineTb = (struct linetable *) |
416 | xmalloc | |
417 | (sizeof (struct linetable) + | |
418 | (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry)); | |
818de002 PB |
419 | |
420 | /* if line table does not start with a function beginning, copy up until | |
421 | a function begin. */ | |
422 | ||
423 | newline = 0; | |
424 | if (oldLineTb->item[0].line != 0) | |
425 | for (newline=0; | |
426 | newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline) | |
427 | newLineTb->item[newline] = oldLineTb->item[newline]; | |
428 | ||
429 | /* Now copy function lines one by one. */ | |
430 | ||
431 | for (ii=0; ii < function_count; ++ii) { | |
432 | for (jj = fentry[ii].line + 1; | |
433 | jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0; | |
434 | ++jj, ++newline) | |
435 | newLineTb->item[newline] = oldLineTb->item[jj]; | |
436 | } | |
437 | free (fentry); | |
438 | newLineTb->nitems = oldLineTb->nitems - function_count; | |
439 | return newLineTb; | |
440 | } | |
441 | ||
818de002 PB |
442 | /* include file support: C_BINCL/C_EINCL pairs will be kept in the |
443 | following `IncludeChain'. At the end of each symtab (end_symtab), | |
444 | we will determine if we should create additional symtab's to | |
445 | represent if (the include files. */ | |
446 | ||
447 | ||
448 | typedef struct _inclTable { | |
449 | char *name; /* include filename */ | |
2aefe6e4 JK |
450 | |
451 | /* Offsets to the line table. end points to the last entry which is | |
452 | part of this include file. */ | |
453 | int begin, end; | |
454 | ||
818de002 PB |
455 | struct subfile *subfile; |
456 | unsigned funStartLine; /* start line # of its function */ | |
457 | } InclTable; | |
458 | ||
459 | #define INITIAL_INCLUDE_TABLE_LENGTH 20 | |
460 | static InclTable *inclTable; /* global include table */ | |
461 | static int inclIndx; /* last entry to table */ | |
462 | static int inclLength; /* table length */ | |
463 | static int inclDepth; /* nested include depth */ | |
464 | ||
7f4c8595 | 465 | static void allocate_include_entry PARAMS ((void)); |
818de002 PB |
466 | |
467 | static void | |
468 | record_include_begin (cs) | |
469 | struct coff_symbol *cs; | |
470 | { | |
818de002 | 471 | if (inclDepth) |
486b440e JK |
472 | { |
473 | /* In xcoff, we assume include files cannot be nested (not in .c files | |
474 | of course, but in corresponding .s files.). */ | |
475 | ||
67240bb8 JK |
476 | /* This can happen with old versions of GCC. |
477 | GCC 2.3.3-930426 does not exhibit this on a test case which | |
478 | a user said produced the message for him. */ | |
b646b438 | 479 | static struct complaint msg = {"Nested C_BINCL symbols", 0, 0}; |
486b440e JK |
480 | complain (&msg); |
481 | } | |
818de002 PB |
482 | ++inclDepth; |
483 | ||
7f4c8595 | 484 | allocate_include_entry (); |
818de002 PB |
485 | |
486 | inclTable [inclIndx].name = cs->c_name; | |
487 | inclTable [inclIndx].begin = cs->c_value; | |
488 | } | |
489 | ||
818de002 PB |
490 | static void |
491 | record_include_end (cs) | |
492 | struct coff_symbol *cs; | |
493 | { | |
494 | InclTable *pTbl; | |
495 | ||
496 | if (inclDepth == 0) | |
486b440e | 497 | { |
b646b438 | 498 | static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0}; |
486b440e JK |
499 | complain (&msg); |
500 | } | |
818de002 | 501 | |
7f4c8595 SS |
502 | allocate_include_entry (); |
503 | ||
818de002 PB |
504 | pTbl = &inclTable [inclIndx]; |
505 | pTbl->end = cs->c_value; | |
506 | ||
507 | --inclDepth; | |
508 | ++inclIndx; | |
509 | } | |
510 | ||
7f4c8595 SS |
511 | static void |
512 | allocate_include_entry () | |
513 | { | |
514 | if (inclTable == NULL) | |
515 | { | |
516 | inclTable = (InclTable *) | |
517 | xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH); | |
518 | memset (inclTable, | |
519 | '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH); | |
520 | inclLength = INITIAL_INCLUDE_TABLE_LENGTH; | |
521 | inclIndx = 0; | |
522 | } | |
523 | else if (inclIndx >= inclLength) | |
524 | { | |
525 | inclLength += INITIAL_INCLUDE_TABLE_LENGTH; | |
526 | inclTable = (InclTable *) | |
527 | xrealloc (inclTable, sizeof (InclTable) * inclLength); | |
528 | memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH, | |
529 | '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH); | |
530 | } | |
531 | } | |
818de002 | 532 | |
a367db89 JK |
533 | /* Global variable to pass the psymtab down to all the routines involved |
534 | in psymtab to symtab processing. */ | |
535 | static struct partial_symtab *this_symtab_psymtab; | |
536 | ||
7f4c8595 SS |
537 | /* given the start and end addresses of a compilation unit (or a csect, |
538 | at times) process its lines and create appropriate line vectors. */ | |
818de002 PB |
539 | |
540 | static void | |
541 | process_linenos (start, end) | |
a367db89 | 542 | CORE_ADDR start, end; |
818de002 | 543 | { |
818de002 | 544 | int offset, ii; |
a367db89 JK |
545 | file_ptr max_offset = |
546 | ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private) | |
547 | ->max_lineno_offset; | |
818de002 | 548 | |
5cba5d26 JK |
549 | /* subfile structure for the main compilation unit. */ |
550 | struct subfile main_subfile; | |
818de002 | 551 | |
5cba5d26 JK |
552 | /* In the main source file, any time we see a function entry, we |
553 | reset this variable to function's absolute starting line number. | |
554 | All the following line numbers in the function are relative to | |
555 | this, and we record absolute line numbers in record_line(). */ | |
818de002 | 556 | |
df1e1074 | 557 | unsigned int main_source_baseline = 0; |
818de002 | 558 | |
818de002 | 559 | unsigned *firstLine; |
818de002 | 560 | |
a367db89 JK |
561 | offset = |
562 | ((struct symloc *)this_symtab_psymtab->read_symtab_private)->lineno_off; | |
563 | if (offset == 0) | |
818de002 PB |
564 | goto return_after_cleanup; |
565 | ||
4ed97c9a | 566 | memset (&main_subfile, '\0', sizeof (main_subfile)); |
818de002 PB |
567 | |
568 | if (inclIndx == 0) | |
556f3d90 PB |
569 | /* All source lines were in the main source file. None in include files. */ |
570 | ||
818de002 PB |
571 | enter_line_range (&main_subfile, offset, 0, start, end, |
572 | &main_source_baseline); | |
573 | ||
5cba5d26 JK |
574 | else |
575 | { | |
576 | /* There was source with line numbers in include files. */ | |
577 | main_source_baseline = 0; | |
578 | for (ii=0; ii < inclIndx; ++ii) | |
579 | { | |
580 | struct subfile *tmpSubfile; | |
818de002 | 581 | |
5cba5d26 JK |
582 | /* If there is main file source before include file, enter it. */ |
583 | if (offset < inclTable[ii].begin) | |
584 | { | |
585 | enter_line_range | |
586 | (&main_subfile, offset, inclTable[ii].begin - LINESZ, | |
587 | start, 0, &main_source_baseline); | |
588 | } | |
818de002 | 589 | |
5cba5d26 | 590 | /* Have a new subfile for the include file. */ |
818de002 | 591 | |
5cba5d26 JK |
592 | tmpSubfile = inclTable[ii].subfile = |
593 | (struct subfile *) xmalloc (sizeof (struct subfile)); | |
818de002 | 594 | |
5cba5d26 JK |
595 | memset (tmpSubfile, '\0', sizeof (struct subfile)); |
596 | firstLine = &(inclTable[ii].funStartLine); | |
818de002 | 597 | |
5cba5d26 JK |
598 | /* Enter include file's lines now. */ |
599 | enter_line_range (tmpSubfile, inclTable[ii].begin, | |
600 | inclTable[ii].end, start, 0, firstLine); | |
818de002 | 601 | |
d2fee216 | 602 | if (offset <= inclTable[ii].end) |
fc564b18 | 603 | offset = inclTable[ii].end + LINESZ; |
5cba5d26 | 604 | } |
818de002 | 605 | |
5cba5d26 JK |
606 | /* All the include files' line have been processed at this point. Now, |
607 | enter remaining lines of the main file, if any left. */ | |
a367db89 | 608 | if (offset < max_offset + 1 - LINESZ) |
5cba5d26 JK |
609 | { |
610 | enter_line_range (&main_subfile, offset, 0, start, end, | |
611 | &main_source_baseline); | |
612 | } | |
818de002 PB |
613 | } |
614 | ||
5cba5d26 JK |
615 | /* Process main file's line numbers. */ |
616 | if (main_subfile.line_vector) | |
617 | { | |
618 | struct linetable *lineTb, *lv; | |
818de002 | 619 | |
5cba5d26 | 620 | lv = main_subfile.line_vector; |
818de002 | 621 | |
5cba5d26 JK |
622 | /* Line numbers are not necessarily ordered. xlc compilation will |
623 | put static function to the end. */ | |
818de002 | 624 | |
5cba5d26 JK |
625 | lineTb = arrange_linetable (lv); |
626 | if (lv == lineTb) | |
627 | { | |
628 | current_subfile->line_vector = (struct linetable *) | |
629 | xrealloc (lv, (sizeof (struct linetable) | |
630 | + lv->nitems * sizeof (struct linetable_entry))); | |
631 | } | |
632 | else | |
633 | { | |
634 | free (lv); | |
635 | current_subfile->line_vector = lineTb; | |
636 | } | |
818de002 | 637 | |
5cba5d26 JK |
638 | current_subfile->line_vector_length = |
639 | current_subfile->line_vector->nitems; | |
818de002 | 640 | } |
818de002 | 641 | |
5cba5d26 | 642 | /* Now, process included files' line numbers. */ |
818de002 | 643 | |
5cba5d26 JK |
644 | for (ii=0; ii < inclIndx; ++ii) |
645 | { | |
646 | if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */ | |
647 | { | |
648 | struct linetable *lineTb, *lv; | |
818de002 | 649 | |
5cba5d26 | 650 | lv = (inclTable[ii].subfile)->line_vector; |
818de002 | 651 | |
5cba5d26 JK |
652 | /* Line numbers are not necessarily ordered. xlc compilation will |
653 | put static function to the end. */ | |
818de002 | 654 | |
5cba5d26 | 655 | lineTb = arrange_linetable (lv); |
818de002 | 656 | |
5cba5d26 | 657 | push_subfile (); |
818de002 | 658 | |
5cba5d26 JK |
659 | /* For the same include file, we might want to have more than one |
660 | subfile. This happens if we have something like: | |
818de002 | 661 | |
818de002 PB |
662 | ...... |
663 | #include "foo.h" | |
664 | ...... | |
665 | #include "foo.h" | |
666 | ...... | |
667 | ||
5cba5d26 JK |
668 | while foo.h including code in it. (stupid but possible) |
669 | Since start_subfile() looks at the name and uses an | |
670 | existing one if finds, we need to provide a fake name and | |
671 | fool it. */ | |
672 | ||
673 | #if 0 | |
674 | start_subfile (inclTable[ii].name, (char*)0); | |
675 | #else | |
676 | { | |
677 | /* Pick a fake name that will produce the same results as this | |
678 | one when passed to deduce_language_from_filename. Kludge on | |
679 | top of kludge. */ | |
680 | char *fakename = strrchr (inclTable[ii].name, '.'); | |
681 | if (fakename == NULL) | |
682 | fakename = " ?"; | |
683 | start_subfile (fakename, (char*)0); | |
684 | free (current_subfile->name); | |
685 | } | |
686 | current_subfile->name = strdup (inclTable[ii].name); | |
687 | #endif | |
818de002 | 688 | |
5cba5d26 JK |
689 | if (lv == lineTb) |
690 | { | |
691 | current_subfile->line_vector = | |
692 | (struct linetable *) xrealloc | |
693 | (lv, (sizeof (struct linetable) | |
818de002 PB |
694 | + lv->nitems * sizeof (struct linetable_entry))); |
695 | ||
5cba5d26 JK |
696 | } |
697 | else | |
698 | { | |
699 | free (lv); | |
700 | current_subfile->line_vector = lineTb; | |
701 | } | |
818de002 | 702 | |
5cba5d26 JK |
703 | current_subfile->line_vector_length = |
704 | current_subfile->line_vector->nitems; | |
705 | start_subfile (pop_subfile (), (char*)0); | |
706 | } | |
818de002 | 707 | } |
818de002 | 708 | |
5cba5d26 | 709 | return_after_cleanup: |
818de002 | 710 | |
5cba5d26 | 711 | /* We don't want to keep alloc/free'ing the global include file table. */ |
818de002 PB |
712 | inclIndx = 0; |
713 | ||
5cba5d26 | 714 | /* Start with a fresh subfile structure for the next file. */ |
4ed97c9a | 715 | memset (&main_subfile, '\0', sizeof (struct subfile)); |
818de002 PB |
716 | } |
717 | ||
718 | void | |
719 | aix_process_linenos () | |
720 | { | |
721 | /* process line numbers and enter them into line vector */ | |
722 | process_linenos (last_source_start_addr, cur_src_end_addr); | |
723 | } | |
724 | ||
725 | ||
e38e0312 JG |
726 | /* Enter a given range of lines into the line vector. |
727 | can be called in the following two ways: | |
818de002 | 728 | enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or |
2aefe6e4 JK |
729 | enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine) |
730 | ||
731 | endoffset points to the last line table entry that we should pay | |
732 | attention to. */ | |
e38e0312 JG |
733 | |
734 | static void | |
a367db89 JK |
735 | enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr, |
736 | firstLine) | |
737 | struct subfile *subfile; | |
738 | unsigned beginoffset, endoffset; /* offsets to line table */ | |
739 | CORE_ADDR startaddr, endaddr; | |
740 | unsigned *firstLine; | |
e38e0312 | 741 | { |
a367db89 JK |
742 | unsigned int curoffset; |
743 | CORE_ADDR addr; | |
744 | struct external_lineno ext_lnno; | |
745 | struct internal_lineno int_lnno; | |
746 | unsigned int limit_offset; | |
747 | bfd *abfd; | |
818de002 | 748 | |
a367db89 JK |
749 | if (endoffset == 0 && startaddr == 0 && endaddr == 0) |
750 | return; | |
751 | curoffset = beginoffset; | |
752 | limit_offset = | |
753 | ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private) | |
754 | ->max_lineno_offset; | |
e38e0312 | 755 | |
a367db89 | 756 | if (endoffset != 0) |
2aefe6e4 | 757 | { |
a367db89 JK |
758 | if (endoffset >= limit_offset) |
759 | { | |
760 | static struct complaint msg = | |
761 | {"Bad line table offset in C_EINCL directive", 0, 0}; | |
762 | complain (&msg); | |
763 | return; | |
764 | } | |
765 | limit_offset = endoffset; | |
2aefe6e4 | 766 | } |
a367db89 JK |
767 | else |
768 | limit_offset -= 1; | |
769 | abfd = this_symtab_psymtab->objfile->obfd; | |
e38e0312 | 770 | |
a367db89 JK |
771 | while (curoffset <= limit_offset) |
772 | { | |
773 | bfd_seek (abfd, curoffset, SEEK_SET); | |
774 | bfd_read (&ext_lnno, sizeof (struct external_lineno), 1, abfd); | |
775 | bfd_coff_swap_lineno_in (abfd, &ext_lnno, &int_lnno); | |
e38e0312 | 776 | |
a367db89 JK |
777 | /* Find the address this line represents. */ |
778 | addr = (int_lnno.l_lnno | |
779 | ? int_lnno.l_addr.l_paddr | |
780 | : read_symbol_nvalue (int_lnno.l_addr.l_symndx)); | |
781 | addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets, | |
782 | SECT_OFF_TEXT); | |
e38e0312 | 783 | |
a367db89 JK |
784 | if (addr < startaddr || (endaddr && addr >= endaddr)) |
785 | return; | |
e38e0312 | 786 | |
a367db89 JK |
787 | if (int_lnno.l_lnno == 0) |
788 | { | |
789 | *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx); | |
790 | record_line (subfile, 0, addr); | |
791 | --(*firstLine); | |
792 | } | |
793 | else | |
794 | record_line (subfile, *firstLine + int_lnno.l_lnno, addr); | |
795 | curoffset += LINESZ; | |
e38e0312 | 796 | } |
818de002 PB |
797 | } |
798 | ||
818de002 | 799 | |
e38e0312 JG |
800 | /* Save the vital information for use when closing off the current file. |
801 | NAME is the file name the symbols came from, START_ADDR is the first | |
802 | text address for the file, and SIZE is the number of bytes of text. */ | |
803 | ||
804 | #define complete_symtab(name, start_addr) { \ | |
805 | last_source_file = savestring (name, strlen (name)); \ | |
818de002 | 806 | last_source_start_addr = start_addr; \ |
e38e0312 JG |
807 | } |
808 | ||
809 | ||
810 | /* Refill the symbol table input buffer | |
811 | and set the variables that control fetching entries from it. | |
812 | Reports an error if no data available. | |
813 | This function can read past the end of the symbol table | |
814 | (into the string table) but this does no harm. */ | |
815 | ||
816 | /* Reading symbol table has to be fast! Keep the followings as macros, rather | |
817 | than functions. */ | |
818 | ||
a367db89 | 819 | #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \ |
e38e0312 JG |
820 | { \ |
821 | char *namestr; \ | |
a81ce07d JK |
822 | namestr = (NAME); \ |
823 | if (namestr[0] == '.') ++namestr; \ | |
3c02636b | 824 | prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \ |
8d60affd | 825 | (char *)NULL, (SECTION), (OBJFILE)); \ |
818de002 | 826 | misc_func_recorded = 1; \ |
e38e0312 JG |
827 | } |
828 | ||
829 | ||
9b280a7f | 830 | /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be |
e38e0312 JG |
831 | nested. At any given time, a symbol can only be in one static block. |
832 | This is the base address of current static block, zero if non exists. */ | |
833 | ||
834 | static int static_block_base = 0; | |
835 | ||
3c02636b JK |
836 | /* Section number for the current static block. */ |
837 | ||
838 | static int static_block_section = -1; | |
839 | ||
e38e0312 JG |
840 | /* true if space for symbol name has been allocated. */ |
841 | ||
842 | static int symname_alloced = 0; | |
843 | ||
34d265dc JK |
844 | /* Next symbol to read. Pointer into raw seething symbol table. */ |
845 | ||
846 | static char *raw_symbol; | |
847 | ||
848 | /* This is the function which stabsread.c calls to get symbol | |
849 | continuations. */ | |
850 | static char * | |
2dd30c72 FF |
851 | xcoff_next_symbol_text (objfile) |
852 | struct objfile *objfile; | |
34d265dc JK |
853 | { |
854 | struct internal_syment symbol; | |
855 | static struct complaint msg = | |
856 | {"Unexpected symbol continuation", 0, 0}; | |
963dbabe | 857 | char *retval; |
2dd30c72 FF |
858 | /* FIXME: is this the same as the passed arg? */ |
859 | objfile = this_symtab_psymtab->objfile; | |
34d265dc | 860 | |
a367db89 | 861 | bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol); |
afbdbbd7 | 862 | if (symbol.n_zeroes) |
963dbabe JK |
863 | { |
864 | complain (&msg); | |
865 | ||
866 | /* Return something which points to '\0' and hope the symbol reading | |
867 | code does something reasonable. */ | |
868 | retval = ""; | |
869 | } | |
afbdbbd7 | 870 | else if (symbol.n_sclass & 0x80) |
963dbabe | 871 | { |
a367db89 JK |
872 | retval = |
873 | ((struct coff_symfile_info *)objfile->sym_private)->debugsec | |
874 | + symbol.n_offset; | |
875 | raw_symbol += | |
876 | coff_data (objfile->obfd)->local_symesz; | |
963dbabe JK |
877 | ++symnum; |
878 | } | |
34d265dc | 879 | else |
963dbabe JK |
880 | { |
881 | complain (&msg); | |
882 | ||
883 | /* Return something which points to '\0' and hope the symbol reading | |
884 | code does something reasonable. */ | |
885 | retval = ""; | |
886 | } | |
887 | return retval; | |
34d265dc JK |
888 | } |
889 | ||
a367db89 | 890 | /* Read symbols for a given partial symbol table. */ |
e38e0312 | 891 | |
1ab3bf1b | 892 | static void |
a367db89 JK |
893 | read_xcoff_symtab (pst) |
894 | struct partial_symtab *pst; | |
e38e0312 | 895 | { |
a367db89 | 896 | struct objfile *objfile = pst->objfile; |
e38e0312 | 897 | bfd *abfd = objfile->obfd; |
e38e0312 | 898 | char *raw_auxptr; /* Pointer to first raw aux entry for sym */ |
a367db89 JK |
899 | char *strtbl = ((struct coff_symfile_info *)objfile->sym_private)->strtbl; |
900 | char *debugsec = | |
901 | ((struct coff_symfile_info *)objfile->sym_private)->debugsec; | |
818de002 | 902 | |
e38e0312 | 903 | struct internal_syment symbol[1]; |
6657a0c7 | 904 | union internal_auxent main_aux; |
e38e0312 JG |
905 | struct coff_symbol cs[1]; |
906 | CORE_ADDR file_start_addr = 0; | |
907 | CORE_ADDR file_end_addr = 0; | |
908 | ||
909 | int next_file_symnum = -1; | |
a367db89 | 910 | unsigned int max_symnum; |
e38e0312 JG |
911 | int just_started = 1; |
912 | int depth = 0; | |
df1e1074 | 913 | int fcn_start_addr = 0; |
e38e0312 | 914 | |
1eeba686 PB |
915 | struct coff_symbol fcn_stab_saved; |
916 | ||
e38e0312 JG |
917 | /* fcn_cs_saved is global because process_xcoff_symbol needs it. */ |
918 | union internal_auxent fcn_aux_saved; | |
919 | struct context_stack *new; | |
920 | ||
921 | char *filestring = " _start_ "; /* Name of the current file. */ | |
818de002 PB |
922 | |
923 | char *last_csect_name; /* last seen csect's name and value */ | |
924 | CORE_ADDR last_csect_val; | |
3c02636b | 925 | int last_csect_sec; |
e38e0312 | 926 | |
a367db89 | 927 | this_symtab_psymtab = pst; |
1ab3bf1b | 928 | |
a81ce07d JK |
929 | /* Get the appropriate COFF "constants" related to the file we're |
930 | handling. */ | |
e38e0312 JG |
931 | local_symesz = coff_data (abfd)->local_symesz; |
932 | ||
d07734e3 | 933 | last_source_file = NULL; |
818de002 PB |
934 | last_csect_name = 0; |
935 | last_csect_val = 0; | |
e38e0312 | 936 | |
d07734e3 | 937 | start_stabs (); |
e38e0312 | 938 | start_symtab (filestring, (char *)NULL, file_start_addr); |
a367db89 JK |
939 | symnum = ((struct symloc *)pst->read_symtab_private)->first_symnum; |
940 | max_symnum = | |
941 | symnum + ((struct symloc *)pst->read_symtab_private)->numsyms; | |
e38e0312 JG |
942 | first_object_file_end = 0; |
943 | ||
a367db89 JK |
944 | raw_symbol = |
945 | ((struct coff_symfile_info *) objfile->sym_private)->symtbl | |
946 | + symnum * local_symesz; | |
34d265dc | 947 | |
a367db89 | 948 | while (symnum < max_symnum) |
a81ce07d | 949 | { |
e38e0312 | 950 | |
a81ce07d | 951 | QUIT; /* make this command interruptable. */ |
e38e0312 | 952 | |
a81ce07d JK |
953 | /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */ |
954 | /* read one symbol into `cs' structure. After processing the | |
955 | whole symbol table, only string table will be kept in memory, | |
956 | symbol table and debug section of xcoff will be freed. Thus | |
957 | we can mark symbols with names in string table as | |
958 | `alloced'. */ | |
959 | { | |
960 | int ii; | |
961 | ||
962 | /* Swap and align the symbol into a reasonable C structure. */ | |
963 | bfd_coff_swap_sym_in (abfd, raw_symbol, symbol); | |
964 | ||
965 | cs->c_symnum = symnum; | |
966 | cs->c_naux = symbol->n_numaux; | |
967 | if (symbol->n_zeroes) | |
786757a9 | 968 | { |
a81ce07d JK |
969 | symname_alloced = 0; |
970 | /* We must use the original, unswapped, name here so the name field | |
971 | pointed to by cs->c_name will persist throughout xcoffread. If | |
972 | we use the new field, it gets overwritten for each symbol. */ | |
973 | cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name; | |
974 | /* If it's exactly E_SYMNMLEN characters long it isn't | |
975 | '\0'-terminated. */ | |
976 | if (cs->c_name[E_SYMNMLEN - 1] != '\0') | |
977 | { | |
978 | char *p; | |
979 | p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1); | |
980 | strncpy (p, cs->c_name, E_SYMNMLEN); | |
981 | p[E_SYMNMLEN] = '\0'; | |
982 | cs->c_name = p; | |
983 | symname_alloced = 1; | |
984 | } | |
985 | } | |
986 | else if (symbol->n_sclass & 0x80) | |
987 | { | |
988 | cs->c_name = debugsec + symbol->n_offset; | |
989 | symname_alloced = 0; | |
990 | } | |
991 | else | |
992 | { | |
993 | /* in string table */ | |
994 | cs->c_name = strtbl + (int)symbol->n_offset; | |
786757a9 JK |
995 | symname_alloced = 1; |
996 | } | |
a81ce07d JK |
997 | cs->c_value = symbol->n_value; |
998 | cs->c_sclass = symbol->n_sclass; | |
999 | cs->c_secnum = symbol->n_scnum; | |
1000 | cs->c_type = (unsigned)symbol->n_type; | |
e38e0312 | 1001 | |
a81ce07d JK |
1002 | raw_symbol += coff_data (abfd)->local_symesz; |
1003 | ++symnum; | |
e38e0312 | 1004 | |
a81ce07d JK |
1005 | /* Save addr of first aux entry. */ |
1006 | raw_auxptr = raw_symbol; | |
e38e0312 | 1007 | |
a81ce07d JK |
1008 | /* Skip all the auxents associated with this symbol. */ |
1009 | for (ii = symbol->n_numaux; ii; --ii) | |
1010 | { | |
1011 | raw_symbol += coff_data (abfd)->local_auxesz; | |
1012 | ++symnum; | |
1013 | } | |
e38e0312 | 1014 | } |
e38e0312 | 1015 | |
a81ce07d JK |
1016 | /* if symbol name starts with ".$" or "$", ignore it. */ |
1017 | if (cs->c_name[0] == '$' | |
1018 | || (cs->c_name[1] == '$' && cs->c_name[0] == '.')) | |
1019 | continue; | |
e38e0312 | 1020 | |
a81ce07d | 1021 | if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) |
d07734e3 | 1022 | { |
a81ce07d JK |
1023 | if (last_source_file) |
1024 | { | |
a367db89 JK |
1025 | pst->symtab = |
1026 | end_symtab (cur_src_end_addr, 1, 0, objfile, SECT_OFF_TEXT); | |
a81ce07d JK |
1027 | end_stabs (); |
1028 | } | |
e38e0312 | 1029 | |
a81ce07d JK |
1030 | start_stabs (); |
1031 | start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0); | |
1032 | cur_src_end_addr = first_object_file_end; | |
1033 | /* done with all files, everything from here on is globals */ | |
1034 | } | |
e38e0312 | 1035 | |
a81ce07d JK |
1036 | /* if explicitly specified as a function, treat is as one. */ |
1037 | if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) | |
1038 | { | |
1039 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
1040 | 0, cs->c_naux, &main_aux); | |
1041 | goto function_entry_point; | |
1042 | } | |
e38e0312 | 1043 | |
a81ce07d JK |
1044 | if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) |
1045 | && cs->c_naux == 1) | |
1046 | { | |
1047 | /* Dealing with a symbol with a csect entry. */ | |
e38e0312 | 1048 | |
a81ce07d JK |
1049 | #define CSECT(PP) ((PP)->x_csect) |
1050 | #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l) | |
1051 | #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp)) | |
1052 | #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp)) | |
1053 | #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas) | |
e38e0312 | 1054 | |
a81ce07d JK |
1055 | /* Convert the auxent to something we can access. */ |
1056 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
1057 | 0, cs->c_naux, &main_aux); | |
e38e0312 | 1058 | |
a81ce07d JK |
1059 | switch (CSECT_SMTYP (&main_aux)) |
1060 | { | |
e38e0312 | 1061 | |
a81ce07d JK |
1062 | case XTY_ER: |
1063 | /* Ignore all external references. */ | |
1064 | continue; | |
e38e0312 | 1065 | |
a81ce07d JK |
1066 | case XTY_SD: |
1067 | /* A section description. */ | |
e38e0312 | 1068 | { |
a81ce07d JK |
1069 | switch (CSECT_SCLAS (&main_aux)) |
1070 | { | |
1071 | ||
1072 | case XMC_PR: | |
1073 | { | |
1074 | ||
1075 | /* A program csect is seen. We have to allocate one | |
1076 | symbol table for each program csect. Normally gdb | |
1077 | prefers one symtab for each source file. In case | |
1078 | of AIX, one source file might include more than one | |
1079 | [PR] csect, and they don't have to be adjacent in | |
1080 | terms of the space they occupy in memory. Thus, one | |
1081 | single source file might get fragmented in the | |
1082 | memory and gdb's file start and end address | |
1083 | approach does not work! GCC (and I think xlc) seem | |
1084 | to put all the code in the unnamed program csect. */ | |
1085 | ||
1086 | if (last_csect_name) | |
1087 | { | |
a81ce07d JK |
1088 | complete_symtab (filestring, file_start_addr); |
1089 | cur_src_end_addr = file_end_addr; | |
1090 | end_symtab (file_end_addr, 1, 0, objfile, | |
e2adc41a | 1091 | SECT_OFF_TEXT); |
a81ce07d JK |
1092 | end_stabs (); |
1093 | start_stabs (); | |
1094 | /* Give all csects for this source file the same | |
1095 | name. */ | |
1096 | start_symtab (filestring, NULL, (CORE_ADDR)0); | |
1097 | } | |
1098 | ||
1099 | /* If this is the very first csect seen, | |
1100 | basically `__start'. */ | |
1101 | if (just_started) | |
1102 | { | |
1103 | first_object_file_end | |
1104 | = cs->c_value + CSECT_LEN (&main_aux); | |
1105 | just_started = 0; | |
1106 | } | |
1107 | ||
a367db89 JK |
1108 | file_start_addr = |
1109 | cs->c_value + ANOFFSET (objfile->section_offsets, | |
1110 | SECT_OFF_TEXT); | |
1111 | file_end_addr = file_start_addr + CSECT_LEN (&main_aux); | |
a81ce07d JK |
1112 | |
1113 | if (cs->c_name && cs->c_name[0] == '.') | |
1114 | { | |
1115 | last_csect_name = cs->c_name; | |
1116 | last_csect_val = cs->c_value; | |
a367db89 | 1117 | last_csect_sec = secnum_to_section (cs->c_secnum, objfile); |
a81ce07d JK |
1118 | } |
1119 | } | |
a81ce07d JK |
1120 | continue; |
1121 | ||
df1e1074 PS |
1122 | /* All other symbols are put into the minimal symbol |
1123 | table only. */ | |
a81ce07d | 1124 | |
df1e1074 PS |
1125 | case XMC_RW: |
1126 | continue; | |
a81ce07d JK |
1127 | |
1128 | case XMC_TC0: | |
a81ce07d JK |
1129 | continue; |
1130 | ||
1131 | case XMC_TC: | |
a367db89 | 1132 | continue; |
e38e0312 | 1133 | |
a81ce07d JK |
1134 | default: |
1135 | /* Ignore the symbol. */ | |
1136 | continue; | |
818de002 | 1137 | } |
e38e0312 | 1138 | } |
e38e0312 JG |
1139 | break; |
1140 | ||
a81ce07d JK |
1141 | case XTY_LD: |
1142 | ||
1143 | switch (CSECT_SCLAS (&main_aux)) | |
1144 | { | |
1145 | case XMC_PR: | |
1146 | /* a function entry point. */ | |
1147 | function_entry_point: | |
a81ce07d | 1148 | |
a81ce07d JK |
1149 | fcn_start_addr = cs->c_value; |
1150 | ||
1151 | /* save the function header info, which will be used | |
1152 | when `.bf' is seen. */ | |
1153 | fcn_cs_saved = *cs; | |
1154 | fcn_aux_saved = main_aux; | |
a81ce07d JK |
1155 | continue; |
1156 | ||
1157 | case XMC_GL: | |
1158 | /* shared library function trampoline code entry point. */ | |
a81ce07d JK |
1159 | continue; |
1160 | ||
1161 | case XMC_DS: | |
1162 | /* The symbols often have the same names as debug symbols for | |
1163 | functions, and confuse lookup_symbol. */ | |
1164 | continue; | |
1165 | ||
1166 | default: | |
1167 | /* xlc puts each variable in a separate csect, so we get | |
1168 | an XTY_SD for each variable. But gcc puts several | |
1169 | variables in a csect, so that each variable only gets | |
df1e1074 PS |
1170 | an XTY_LD. This will typically be XMC_RW; I suspect |
1171 | XMC_RO and XMC_BS might be possible too. | |
1172 | These variables are put in the minimal symbol table | |
1173 | only. */ | |
1174 | continue; | |
a81ce07d | 1175 | } |
df1e1074 PS |
1176 | break; |
1177 | ||
1178 | case XTY_CM: | |
1179 | /* Common symbols are put into the minimal symbol table only. */ | |
1180 | continue; | |
e38e0312 | 1181 | |
a81ce07d JK |
1182 | default: |
1183 | break; | |
e38e0312 | 1184 | } |
a81ce07d | 1185 | } |
e38e0312 | 1186 | |
a81ce07d JK |
1187 | switch (cs->c_sclass) |
1188 | { | |
e38e0312 | 1189 | |
a81ce07d | 1190 | case C_FILE: |
818de002 | 1191 | |
a81ce07d JK |
1192 | /* c_value field contains symnum of next .file entry in table |
1193 | or symnum of first global after last .file. */ | |
818de002 | 1194 | |
a81ce07d | 1195 | next_file_symnum = cs->c_value; |
818de002 | 1196 | |
a81ce07d JK |
1197 | /* Complete symbol table for last object file containing |
1198 | debugging information. */ | |
818de002 | 1199 | |
a81ce07d JK |
1200 | /* Whether or not there was a csect in the previous file, we |
1201 | have to call `end_stabs' and `start_stabs' to reset | |
1202 | type_vector, line_vector, etc. structures. */ | |
818de002 | 1203 | |
a81ce07d JK |
1204 | complete_symtab (filestring, file_start_addr); |
1205 | cur_src_end_addr = file_end_addr; | |
e2adc41a | 1206 | end_symtab (file_end_addr, 1, 0, objfile, SECT_OFF_TEXT); |
a81ce07d | 1207 | end_stabs (); |
818de002 | 1208 | |
a81ce07d JK |
1209 | /* XCOFF, according to the AIX 3.2 documentation, puts the filename |
1210 | in cs->c_name. But xlc 1.3.0.2 has decided to do things the | |
1211 | standard COFF way and put it in the auxent. We use the auxent if | |
1212 | the symbol is ".file" and an auxent exists, otherwise use the symbol | |
1213 | itself. Simple enough. */ | |
1214 | if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0) | |
1215 | { | |
1216 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
1217 | 0, cs->c_naux, &main_aux); | |
a367db89 | 1218 | filestring = coff_getfilename (&main_aux, objfile); |
818de002 | 1219 | } |
a81ce07d JK |
1220 | else |
1221 | filestring = cs->c_name; | |
d4cedfe4 | 1222 | |
a81ce07d JK |
1223 | start_stabs (); |
1224 | start_symtab (filestring, (char *)NULL, (CORE_ADDR)0); | |
1225 | last_csect_name = 0; | |
507e4004 | 1226 | |
a81ce07d JK |
1227 | /* reset file start and end addresses. A compilation unit with no text |
1228 | (only data) should have zero file boundaries. */ | |
1229 | file_start_addr = file_end_addr = 0; | |
e38e0312 | 1230 | break; |
e38e0312 | 1231 | |
a81ce07d JK |
1232 | case C_FUN: |
1233 | fcn_stab_saved = *cs; | |
1234 | break; | |
e38e0312 | 1235 | |
a81ce07d JK |
1236 | case C_FCN: |
1237 | if (STREQ (cs->c_name, ".bf")) | |
1238 | { | |
a367db89 JK |
1239 | CORE_ADDR off = ANOFFSET (objfile->section_offsets, |
1240 | SECT_OFF_TEXT); | |
a81ce07d JK |
1241 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, |
1242 | 0, cs->c_naux, &main_aux); | |
818de002 | 1243 | |
a81ce07d | 1244 | within_function = 1; |
818de002 | 1245 | |
a367db89 | 1246 | new = push_context (0, fcn_start_addr + off); |
e38e0312 | 1247 | |
a81ce07d | 1248 | new->name = define_symbol |
a367db89 JK |
1249 | (fcn_cs_saved.c_value + off, |
1250 | fcn_stab_saved.c_name, 0, 0, objfile); | |
a81ce07d | 1251 | if (new->name != NULL) |
a367db89 | 1252 | SYMBOL_SECTION (new->name) = SECT_OFF_TEXT; |
a81ce07d JK |
1253 | } |
1254 | else if (STREQ (cs->c_name, ".ef")) | |
1255 | { | |
e38e0312 | 1256 | |
a81ce07d JK |
1257 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, |
1258 | 0, cs->c_naux, &main_aux); | |
1259 | ||
1260 | /* The value of .ef is the address of epilogue code; | |
1261 | not useful for gdb. */ | |
1262 | /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno | |
1263 | contains number of lines to '}' */ | |
1264 | ||
df1e1074 PS |
1265 | if (context_stack_depth <= 0) |
1266 | { /* We attempted to pop an empty context stack */ | |
1267 | complain (&ef_complaint, cs->c_symnum); | |
1268 | within_function = 0; | |
1269 | break; | |
1270 | } | |
a81ce07d | 1271 | new = pop_context (); |
f8203ed0 JK |
1272 | /* Stack must be empty now. */ |
1273 | if (context_stack_depth > 0 || new == NULL) | |
1274 | { | |
1275 | complain (&ef_complaint, cs->c_symnum); | |
1276 | within_function = 0; | |
1277 | break; | |
1278 | } | |
a81ce07d JK |
1279 | |
1280 | finish_block (new->name, &local_symbols, new->old_blocks, | |
1281 | new->start_addr, | |
a367db89 JK |
1282 | (fcn_cs_saved.c_value |
1283 | + fcn_aux_saved.x_sym.x_misc.x_fsize | |
1284 | + ANOFFSET (objfile->section_offsets, | |
1285 | SECT_OFF_TEXT)), | |
1286 | objfile); | |
a81ce07d JK |
1287 | within_function = 0; |
1288 | } | |
1289 | break; | |
818de002 | 1290 | |
a81ce07d JK |
1291 | case C_BSTAT: |
1292 | /* Begin static block. */ | |
1293 | { | |
1294 | struct internal_syment symbol; | |
af8b7906 | 1295 | |
a81ce07d JK |
1296 | read_symbol (&symbol, cs->c_value); |
1297 | static_block_base = symbol.n_value; | |
a367db89 JK |
1298 | static_block_section = |
1299 | secnum_to_section (symbol.n_scnum, objfile); | |
a81ce07d JK |
1300 | } |
1301 | break; | |
af8b7906 | 1302 | |
a81ce07d JK |
1303 | case C_ESTAT: |
1304 | /* End of static block. */ | |
1305 | static_block_base = 0; | |
1306 | static_block_section = -1; | |
1307 | break; | |
e38e0312 | 1308 | |
a81ce07d JK |
1309 | case C_ARG: |
1310 | case C_REGPARM: | |
f8203ed0 | 1311 | case C_REG: |
a81ce07d JK |
1312 | case C_TPDEF: |
1313 | case C_STRTAG: | |
1314 | case C_UNTAG: | |
1315 | case C_ENTAG: | |
f8203ed0 JK |
1316 | { |
1317 | static struct complaint msg = | |
1318 | {"Unrecognized storage class %d.", 0, 0}; | |
1319 | complain (&msg, cs->c_sclass); | |
1320 | } | |
a81ce07d | 1321 | break; |
e38e0312 | 1322 | |
a81ce07d JK |
1323 | case C_LABEL: |
1324 | case C_NULL: | |
1325 | /* Ignore these. */ | |
1326 | break; | |
e38e0312 | 1327 | |
a81ce07d | 1328 | case C_HIDEXT: |
df1e1074 | 1329 | case C_STAT: |
a81ce07d | 1330 | break; |
e38e0312 | 1331 | |
a81ce07d JK |
1332 | case C_BINCL: |
1333 | /* beginning of include file */ | |
1334 | /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted | |
1335 | order. Thus, when wee see them, we might not know enough info | |
1336 | to process them. Thus, we'll be saving them into a table | |
1337 | (inclTable) and postpone their processing. */ | |
e38e0312 | 1338 | |
a81ce07d JK |
1339 | record_include_begin (cs); |
1340 | break; | |
e38e0312 | 1341 | |
a81ce07d JK |
1342 | case C_EINCL: |
1343 | /* End of include file. */ | |
1344 | /* See the comment after case C_BINCL. */ | |
1345 | record_include_end (cs); | |
1346 | break; | |
1eeba686 | 1347 | |
a81ce07d JK |
1348 | case C_BLOCK: |
1349 | if (STREQ (cs->c_name, ".bb")) | |
1350 | { | |
1351 | depth++; | |
a367db89 JK |
1352 | new = push_context (depth, |
1353 | (cs->c_value | |
1354 | + ANOFFSET (objfile->section_offsets, | |
1355 | SECT_OFF_TEXT))); | |
a81ce07d JK |
1356 | } |
1357 | else if (STREQ (cs->c_name, ".eb")) | |
1358 | { | |
df1e1074 PS |
1359 | if (context_stack_depth <= 0) |
1360 | { /* We attempted to pop an empty context stack */ | |
1361 | complain (&eb_complaint, cs->c_symnum); | |
1362 | break; | |
1363 | } | |
a81ce07d | 1364 | new = pop_context (); |
f8203ed0 JK |
1365 | if (depth-- != new->depth) |
1366 | { | |
df1e1074 | 1367 | complain (&eb_complaint, cs->c_symnum); |
f8203ed0 JK |
1368 | break; |
1369 | } | |
a81ce07d JK |
1370 | if (local_symbols && context_stack_depth > 0) |
1371 | { | |
1372 | /* Make a block for the local symbols within. */ | |
1373 | finish_block (new->name, &local_symbols, new->old_blocks, | |
a367db89 JK |
1374 | new->start_addr, |
1375 | (cs->c_value | |
1376 | + ANOFFSET (objfile->section_offsets, | |
1377 | SECT_OFF_TEXT)), | |
1378 | objfile); | |
a81ce07d JK |
1379 | } |
1380 | local_symbols = new->locals; | |
1381 | } | |
1382 | break; | |
e38e0312 | 1383 | |
a81ce07d JK |
1384 | default: |
1385 | process_xcoff_symbol (cs, objfile); | |
1386 | break; | |
e38e0312 | 1387 | } |
e38e0312 JG |
1388 | } |
1389 | ||
e38e0312 | 1390 | if (last_source_file) |
d07734e3 | 1391 | { |
a367db89 JK |
1392 | struct symtab *s; |
1393 | ||
1394 | complete_symtab (filestring, file_start_addr); | |
1395 | cur_src_end_addr = file_end_addr; | |
1396 | s = end_symtab (file_end_addr, 1, 0, objfile, SECT_OFF_TEXT); | |
1397 | /* When reading symbols for the last C_FILE of the objfile, try | |
1398 | to make sure that we set pst->symtab to the symtab for the | |
1399 | file, not to the _globals_ symtab. I'm not sure whether this | |
1400 | actually works right or when/if it comes up. */ | |
1401 | if (pst->symtab == NULL) | |
1402 | pst->symtab = s; | |
d07734e3 FF |
1403 | end_stabs (); |
1404 | } | |
e38e0312 JG |
1405 | } |
1406 | ||
1407 | #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \ | |
1408 | (SYMBOL2) = (struct symbol *) \ | |
1ab3bf1b | 1409 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \ |
e38e0312 JG |
1410 | *(SYMBOL2) = *(SYMBOL1); |
1411 | ||
1412 | ||
1413 | #define SYMNAME_ALLOC(NAME, ALLOCED) \ | |
1ab3bf1b | 1414 | (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME)); |
e38e0312 JG |
1415 | |
1416 | ||
a81ce07d JK |
1417 | static struct type *func_symbol_type; |
1418 | static struct type *var_symbol_type; | |
1419 | ||
e38e0312 JG |
1420 | /* process one xcoff symbol. */ |
1421 | ||
1422 | static struct symbol * | |
1ab3bf1b | 1423 | process_xcoff_symbol (cs, objfile) |
e38e0312 | 1424 | register struct coff_symbol *cs; |
1ab3bf1b | 1425 | struct objfile *objfile; |
e38e0312 JG |
1426 | { |
1427 | struct symbol onesymbol; | |
1428 | register struct symbol *sym = &onesymbol; | |
1429 | struct symbol *sym2 = NULL; | |
df1e1074 | 1430 | char *name, *pp; |
e38e0312 | 1431 | |
a367db89 JK |
1432 | int sec; |
1433 | CORE_ADDR off; | |
1434 | ||
1435 | if (cs->c_secnum < 0) | |
1436 | { | |
1437 | /* The value is a register number, offset within a frame, etc., | |
1438 | and does not get relocated. */ | |
1439 | off = 0; | |
1440 | sec = -1; | |
1441 | } | |
1442 | else | |
1443 | { | |
1444 | sec = secnum_to_section (cs->c_secnum, objfile); | |
1445 | off = ANOFFSET (objfile->section_offsets, sec); | |
1446 | } | |
1447 | ||
e38e0312 JG |
1448 | name = cs->c_name; |
1449 | if (name[0] == '.') | |
1450 | ++name; | |
1451 | ||
4ed97c9a | 1452 | memset (sym, '\0', sizeof (struct symbol)); |
e38e0312 JG |
1453 | |
1454 | /* default assumptions */ | |
a367db89 | 1455 | SYMBOL_VALUE (sym) = cs->c_value + off; |
e38e0312 | 1456 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
a367db89 | 1457 | SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile); |
e38e0312 | 1458 | |
a81ce07d JK |
1459 | if (ISFCN (cs->c_type)) |
1460 | { | |
1461 | /* At this point, we don't know the type of the function. This | |
1462 | will be patched with the type from its stab entry later on in | |
1463 | patch_block_stabs (), unless the file was compiled without -g. */ | |
e38e0312 | 1464 | |
a81ce07d JK |
1465 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); |
1466 | SYMBOL_TYPE (sym) = func_symbol_type; | |
e38e0312 | 1467 | |
a81ce07d JK |
1468 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
1469 | SYMBOL_DUP (sym, sym2); | |
e38e0312 | 1470 | |
a81ce07d JK |
1471 | if (cs->c_sclass == C_EXT) |
1472 | add_symbol_to_list (sym2, &global_symbols); | |
1473 | else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT) | |
1474 | add_symbol_to_list (sym2, &file_symbols); | |
1475 | } | |
1476 | else | |
e38e0312 | 1477 | { |
a81ce07d JK |
1478 | /* In case we can't figure out the type, provide default. */ |
1479 | SYMBOL_TYPE (sym) = var_symbol_type; | |
1480 | ||
1481 | switch (cs->c_sclass) | |
1482 | { | |
818de002 | 1483 | #if 0 |
df1e1074 PS |
1484 | /* The values of functions and global symbols are now resolved |
1485 | via the global_sym_chain in stabsread.c. */ | |
a81ce07d JK |
1486 | case C_FUN: |
1487 | if (fcn_cs_saved.c_sclass == C_EXT) | |
1488 | add_stab_to_list (name, &global_stabs); | |
1489 | else | |
1490 | add_stab_to_list (name, &file_stabs); | |
1491 | break; | |
e38e0312 | 1492 | |
a81ce07d JK |
1493 | case C_GSYM: |
1494 | add_stab_to_list (name, &global_stabs); | |
1495 | break; | |
df1e1074 | 1496 | #endif |
e38e0312 | 1497 | |
a81ce07d JK |
1498 | case C_BCOMM: |
1499 | common_block_start (cs->c_name, objfile); | |
1500 | break; | |
9438d642 | 1501 | |
a81ce07d JK |
1502 | case C_ECOMM: |
1503 | common_block_end (objfile); | |
1504 | break; | |
9438d642 | 1505 | |
a81ce07d JK |
1506 | default: |
1507 | complain (&storclass_complaint, cs->c_sclass); | |
1508 | /* FALLTHROUGH */ | |
9438d642 | 1509 | |
a81ce07d JK |
1510 | case C_DECL: |
1511 | case C_PSYM: | |
1512 | case C_RPSYM: | |
1513 | case C_ECOML: | |
a367db89 JK |
1514 | case C_LSYM: |
1515 | case C_RSYM: | |
df1e1074 | 1516 | case C_GSYM: |
1eeba686 | 1517 | |
a367db89 JK |
1518 | { |
1519 | sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile); | |
1520 | if (sym != NULL) | |
1521 | { | |
1522 | SYMBOL_SECTION (sym) = sec; | |
1523 | } | |
1524 | return sym; | |
1525 | } | |
e38e0312 | 1526 | |
a81ce07d | 1527 | case C_STSYM: |
1eeba686 | 1528 | |
a81ce07d JK |
1529 | /* For xlc (not GCC), the 'V' symbol descriptor is used for |
1530 | all statics and we need to distinguish file-scope versus | |
1531 | function-scope using within_function. We do this by | |
1532 | changing the string we pass to define_symbol to use 'S' | |
1533 | where we need to, which is not necessarily super-clean, | |
1534 | but seems workable enough. */ | |
91cc45da | 1535 | |
a81ce07d JK |
1536 | if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL) |
1537 | return NULL; | |
91cc45da | 1538 | |
a81ce07d JK |
1539 | ++pp; |
1540 | if (*pp == 'V' && !within_function) | |
1541 | *pp = 'S'; | |
a367db89 JK |
1542 | sym = define_symbol ((cs->c_value |
1543 | + ANOFFSET (objfile->section_offsets, | |
1544 | static_block_section)), | |
1545 | cs->c_name, 0, 0, objfile); | |
a81ce07d JK |
1546 | if (sym != NULL) |
1547 | { | |
1548 | SYMBOL_VALUE (sym) += static_block_base; | |
1549 | SYMBOL_SECTION (sym) = static_block_section; | |
1550 | } | |
1551 | return sym; | |
e38e0312 | 1552 | |
1eeba686 | 1553 | } |
e38e0312 | 1554 | } |
e38e0312 JG |
1555 | return sym2; |
1556 | } | |
1557 | ||
e8abe489 PS |
1558 | /* Extract the file name from the aux entry of a C_FILE symbol. Return |
1559 | only the last component of the name. Result is in static storage and | |
1560 | is only good for temporary use. */ | |
1561 | ||
1562 | static char * | |
a367db89 JK |
1563 | coff_getfilename (aux_entry, objfile) |
1564 | union internal_auxent *aux_entry; | |
1565 | struct objfile *objfile; | |
e8abe489 PS |
1566 | { |
1567 | static char buffer[BUFSIZ]; | |
1568 | register char *temp; | |
1569 | char *result; | |
1570 | ||
1571 | if (aux_entry->x_file.x_n.x_zeroes == 0) | |
a367db89 JK |
1572 | strcpy (buffer, |
1573 | ((struct coff_symfile_info *)objfile->sym_private)->strtbl | |
1574 | + aux_entry->x_file.x_n.x_offset); | |
e8abe489 PS |
1575 | else |
1576 | { | |
1577 | strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN); | |
1578 | buffer[FILNMLEN] = '\0'; | |
1579 | } | |
1580 | result = buffer; | |
1581 | ||
1582 | /* FIXME: We should not be throwing away the information about what | |
1583 | directory. It should go into dirname of the symtab, or some such | |
1584 | place. */ | |
1585 | if ((temp = strrchr (result, '/')) != NULL) | |
1586 | result = temp + 1; | |
1587 | return (result); | |
1588 | } | |
1589 | ||
3c02636b JK |
1590 | /* Set *SYMBOL to symbol number symno in symtbl. */ |
1591 | static void | |
1592 | read_symbol (symbol, symno) | |
1593 | struct internal_syment *symbol; | |
e38e0312 JG |
1594 | int symno; |
1595 | { | |
a367db89 JK |
1596 | int nsyms = |
1597 | ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private) | |
1598 | ->symtbl_num_syms; | |
1599 | char *stbl = | |
1600 | ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private) | |
1601 | ->symtbl; | |
1602 | if (symno < 0 || symno >= nsyms) | |
c84a96d7 | 1603 | { |
b646b438 | 1604 | static struct complaint msg = |
c84a96d7 JK |
1605 | {"Invalid symbol offset", 0, 0}; |
1606 | complain (&msg); | |
3c02636b JK |
1607 | symbol->n_value = 0; |
1608 | symbol->n_scnum = -1; | |
1609 | return; | |
c84a96d7 | 1610 | } |
a367db89 JK |
1611 | bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd, |
1612 | stbl + (symno*local_symesz), | |
1613 | symbol); | |
3c02636b JK |
1614 | } |
1615 | ||
1616 | /* Get value corresponding to symbol number symno in symtbl. */ | |
1617 | ||
1618 | static int | |
1619 | read_symbol_nvalue (symno) | |
1620 | int symno; | |
1621 | { | |
1622 | struct internal_syment symbol[1]; | |
1623 | ||
1624 | read_symbol (symbol, symno); | |
e38e0312 JG |
1625 | return symbol->n_value; |
1626 | } | |
1627 | ||
1628 | ||
c84a96d7 JK |
1629 | /* Find the address of the function corresponding to symno, where |
1630 | symno is the symbol pointed to by the linetable. */ | |
1631 | ||
e38e0312 | 1632 | static int |
c84a96d7 | 1633 | read_symbol_lineno (symno) |
a367db89 | 1634 | int symno; |
e38e0312 | 1635 | { |
a367db89 JK |
1636 | int nsyms = |
1637 | ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private) | |
1638 | ->symtbl_num_syms; | |
1639 | char *stbl = | |
1640 | ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private) | |
1641 | ->symtbl; | |
e38e0312 JG |
1642 | struct internal_syment symbol[1]; |
1643 | union internal_auxent main_aux[1]; | |
1644 | ||
a367db89 JK |
1645 | if (symno < 0) |
1646 | { | |
1647 | complain (&bf_notfound_complaint); | |
1648 | return 0; | |
1649 | } | |
1650 | ||
c84a96d7 JK |
1651 | /* Note that just searching for a short distance (e.g. 50 symbols) |
1652 | is not enough, at least in the following case. | |
1653 | ||
1654 | .extern foo | |
1655 | [many .stabx entries] | |
1656 | [a few functions, referring to foo] | |
1657 | .globl foo | |
1658 | .bf | |
e38e0312 | 1659 | |
c84a96d7 JK |
1660 | What happens here is that the assembler moves the .stabx entries |
1661 | to right before the ".bf" for foo, but the symbol for "foo" is before | |
1662 | all the stabx entries. See PR gdb/2222. */ | |
a367db89 JK |
1663 | |
1664 | /* Maintaining a table of .bf entries might be preferable to this search. | |
1665 | If I understand things correctly it would need to be done only for | |
1666 | the duration of a single psymtab to symtab conversion. */ | |
1667 | while (symno < nsyms) | |
1668 | { | |
1669 | bfd_coff_swap_sym_in (symfile_bfd, | |
1670 | stbl + (symno * local_symesz), symbol); | |
1671 | if (symbol->n_sclass == C_FCN && STREQ (symbol->n_name, ".bf")) | |
1672 | goto gotit; | |
1673 | symno += symbol->n_numaux + 1; | |
1674 | } | |
e38e0312 | 1675 | |
e9916390 | 1676 | complain (&bf_notfound_complaint); |
e38e0312 JG |
1677 | return 0; |
1678 | ||
1679 | gotit: | |
1680 | /* take aux entry and return its lineno */ | |
1681 | symno++; | |
a367db89 JK |
1682 | bfd_coff_swap_aux_in (this_symtab_psymtab->objfile->obfd, |
1683 | stbl + symno * local_symesz, | |
bf8d9d28 ILT |
1684 | symbol->n_type, symbol->n_sclass, |
1685 | 0, symbol->n_numaux, main_aux); | |
e38e0312 JG |
1686 | |
1687 | return main_aux->x_sym.x_misc.x_lnsz.x_lnno; | |
1688 | } | |
1689 | ||
1690 | /* Support for line number handling */ | |
1691 | ||
1692 | /* This function is called for every section; it finds the outer limits | |
1693 | * of the line table (minimum and maximum file offset) so that the | |
1694 | * mainline code can read the whole thing for efficiency. | |
1695 | */ | |
1696 | static void | |
a367db89 JK |
1697 | find_linenos (abfd, asect, vpinfo) |
1698 | bfd *abfd; | |
1699 | sec_ptr asect; | |
1700 | PTR vpinfo; | |
e38e0312 JG |
1701 | { |
1702 | struct coff_symfile_info *info; | |
1703 | int size, count; | |
1704 | file_ptr offset, maxoff; | |
1705 | ||
1706 | count = asect->lineno_count; | |
1707 | ||
2e4964ad | 1708 | if (!STREQ (asect->name, ".text") || count == 0) |
e38e0312 JG |
1709 | return; |
1710 | ||
a367db89 JK |
1711 | size = count * coff_data (abfd)->local_linesz; |
1712 | info = (struct coff_symfile_info *)vpinfo; | |
e38e0312 JG |
1713 | offset = asect->line_filepos; |
1714 | maxoff = offset + size; | |
1715 | ||
1716 | if (offset < info->min_lineno_offset || info->min_lineno_offset == 0) | |
1717 | info->min_lineno_offset = offset; | |
1718 | ||
1719 | if (maxoff > info->max_lineno_offset) | |
1720 | info->max_lineno_offset = maxoff; | |
1721 | } | |
a367db89 JK |
1722 | \f |
1723 | static void xcoff_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *)); | |
e38e0312 | 1724 | |
a367db89 JK |
1725 | static void |
1726 | xcoff_psymtab_to_symtab_1 (pst) | |
1727 | struct partial_symtab *pst; | |
e38e0312 | 1728 | { |
a367db89 JK |
1729 | struct cleanup *old_chain; |
1730 | int i; | |
1731 | ||
1732 | if (!pst) | |
1733 | return; | |
1734 | ||
1735 | if (pst->readin) | |
1736 | { | |
1737 | fprintf_unfiltered | |
1738 | (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
1739 | pst->filename); | |
1740 | return; | |
1741 | } | |
e38e0312 | 1742 | |
a367db89 JK |
1743 | /* Read in all partial symtabs on which this one is dependent */ |
1744 | for (i = 0; i < pst->number_of_dependencies; i++) | |
1745 | if (!pst->dependencies[i]->readin) | |
1746 | { | |
1747 | /* Inform about additional files that need to be read in. */ | |
1748 | if (info_verbose) | |
1749 | { | |
1750 | fputs_filtered (" ", gdb_stdout); | |
1751 | wrap_here (""); | |
1752 | fputs_filtered ("and ", gdb_stdout); | |
1753 | wrap_here (""); | |
1754 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
1755 | wrap_here (""); /* Flush output */ | |
1756 | gdb_flush (gdb_stdout); | |
1757 | } | |
1758 | xcoff_psymtab_to_symtab_1 (pst->dependencies[i]); | |
1759 | } | |
0eb22669 | 1760 | |
a367db89 JK |
1761 | if (((struct symloc *)pst->read_symtab_private)->numsyms != 0) |
1762 | { | |
1763 | /* Init stuff necessary for reading in symbols. */ | |
1764 | stabsread_init (); | |
1765 | buildsym_init (); | |
1766 | old_chain = make_cleanup (really_free_pendings, 0); | |
e38e0312 | 1767 | |
a367db89 JK |
1768 | read_xcoff_symtab (pst); |
1769 | sort_symtab_syms (pst->symtab); | |
e38e0312 | 1770 | |
a367db89 JK |
1771 | do_cleanups (old_chain); |
1772 | } | |
e38e0312 | 1773 | |
a367db89 | 1774 | pst->readin = 1; |
e38e0312 | 1775 | } |
0eb22669 | 1776 | |
a367db89 JK |
1777 | static void xcoff_psymtab_to_symtab PARAMS ((struct partial_symtab *)); |
1778 | ||
1779 | /* Read in all of the symbols for a given psymtab for real. | |
1780 | Be verbose about it if the user wants that. */ | |
1781 | ||
0eb22669 | 1782 | static void |
a367db89 JK |
1783 | xcoff_psymtab_to_symtab (pst) |
1784 | struct partial_symtab *pst; | |
0eb22669 | 1785 | { |
a367db89 JK |
1786 | bfd *sym_bfd; |
1787 | ||
1788 | if (!pst) | |
1789 | return; | |
1790 | ||
1791 | if (pst->readin) | |
1792 | { | |
1793 | fprintf_unfiltered | |
1794 | (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
1795 | pst->filename); | |
1796 | return; | |
1797 | } | |
1798 | ||
1799 | if (((struct symloc *)pst->read_symtab_private)->numsyms != 0 | |
1800 | || pst->number_of_dependencies) | |
1801 | { | |
1802 | /* Print the message now, before reading the string table, | |
1803 | to avoid disconcerting pauses. */ | |
1804 | if (info_verbose) | |
1805 | { | |
1806 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
1807 | gdb_flush (gdb_stdout); | |
1808 | } | |
1809 | ||
1810 | sym_bfd = pst->objfile->obfd; | |
1811 | ||
1812 | next_symbol_text_func = xcoff_next_symbol_text; | |
1813 | ||
1814 | xcoff_psymtab_to_symtab_1 (pst); | |
1815 | ||
1816 | /* Match with global symbols. This only needs to be done once, | |
1817 | after all of the symtabs and dependencies have been read in. */ | |
1818 | scan_file_globals (pst->objfile); | |
1819 | ||
1820 | /* Finish up the debug error message. */ | |
1821 | if (info_verbose) | |
1822 | printf_filtered ("done.\n"); | |
1823 | } | |
1824 | } | |
93fe4e33 | 1825 | \f |
1ab3bf1b | 1826 | static void |
9b280a7f | 1827 | xcoff_new_init (objfile) |
80d68b1d | 1828 | struct objfile *objfile; |
e38e0312 | 1829 | { |
df1e1074 PS |
1830 | stabsread_new_init (); |
1831 | buildsym_new_init (); | |
e38e0312 JG |
1832 | } |
1833 | ||
a367db89 | 1834 | /* Do initialization in preparation for reading symbols from OBJFILE. |
dd469789 JG |
1835 | |
1836 | We will only be called if this is an XCOFF or XCOFF-like file. | |
1837 | BFD handles figuring out the format of the file, and code in symfile.c | |
a367db89 | 1838 | uses BFD's determination to vector to us. */ |
dd469789 | 1839 | |
1ab3bf1b | 1840 | static void |
9b280a7f | 1841 | xcoff_symfile_init (objfile) |
a367db89 | 1842 | struct objfile *objfile; |
e38e0312 | 1843 | { |
e38e0312 | 1844 | /* Allocate struct to keep track of the symfile */ |
80d68b1d FF |
1845 | objfile -> sym_private = xmmalloc (objfile -> md, |
1846 | sizeof (struct coff_symfile_info)); | |
5e2e79f8 | 1847 | init_entry_point_info (objfile); |
e38e0312 JG |
1848 | } |
1849 | ||
80d68b1d FF |
1850 | /* Perform any local cleanups required when we are done with a particular |
1851 | objfile. I.E, we are in the process of discarding all symbol information | |
1852 | for an objfile, freeing up all memory held for it, and unlinking the | |
1853 | objfile struct from the global list of known objfiles. */ | |
1854 | ||
1855 | static void | |
9b280a7f | 1856 | xcoff_symfile_finish (objfile) |
80d68b1d FF |
1857 | struct objfile *objfile; |
1858 | { | |
1859 | if (objfile -> sym_private != NULL) | |
1860 | { | |
1861 | mfree (objfile -> md, objfile -> sym_private); | |
1862 | } | |
1863 | ||
a367db89 | 1864 | /* Start with a fresh include table for the next objfile. */ |
80d68b1d FF |
1865 | if (inclTable) |
1866 | { | |
1867 | free (inclTable); | |
1868 | inclTable = NULL; | |
1869 | } | |
1870 | inclIndx = inclLength = inclDepth = 0; | |
1871 | } | |
1872 | ||
e38e0312 | 1873 | |
a367db89 JK |
1874 | static void |
1875 | init_stringtab (abfd, offset, objfile) | |
e38e0312 | 1876 | bfd *abfd; |
d5931d79 | 1877 | file_ptr offset; |
1ab3bf1b | 1878 | struct objfile *objfile; |
e38e0312 JG |
1879 | { |
1880 | long length; | |
1881 | int val; | |
1882 | unsigned char lengthbuf[4]; | |
a367db89 | 1883 | char *strtbl; |
e38e0312 | 1884 | |
a367db89 | 1885 | ((struct coff_symfile_info *)objfile->sym_private)->strtbl = NULL; |
e38e0312 | 1886 | |
987622b5 | 1887 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
a367db89 JK |
1888 | error ("cannot seek to string table in %s: %s", |
1889 | bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); | |
1890 | ||
1891 | val = bfd_read ((char *)lengthbuf, 1, sizeof lengthbuf, abfd); | |
1892 | length = bfd_h_get_32 (abfd, lengthbuf); | |
e38e0312 JG |
1893 | |
1894 | /* If no string table is needed, then the file may end immediately | |
a367db89 | 1895 | after the symbols. Just return with `strtbl' set to NULL. */ |
e38e0312 | 1896 | |
a367db89 JK |
1897 | if (val != sizeof lengthbuf || length < sizeof lengthbuf) |
1898 | return; | |
e38e0312 JG |
1899 | |
1900 | /* Allocate string table from symbol_obstack. We will need this table | |
1901 | as long as we have its symbol table around. */ | |
1902 | ||
a367db89 JK |
1903 | strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length); |
1904 | ((struct coff_symfile_info *)objfile->sym_private)->strtbl = strtbl; | |
e38e0312 | 1905 | |
df1e1074 PS |
1906 | /* Copy length buffer, the first byte is usually zero and is |
1907 | used for stabs with a name length of zero. */ | |
1908 | memcpy (strtbl, lengthbuf, sizeof lengthbuf); | |
a367db89 JK |
1909 | if (length == sizeof lengthbuf) |
1910 | return; | |
e38e0312 | 1911 | |
a367db89 JK |
1912 | val = bfd_read (strtbl + sizeof lengthbuf, 1, length - sizeof lengthbuf, |
1913 | abfd); | |
e38e0312 | 1914 | |
a367db89 JK |
1915 | if (val != length - sizeof lengthbuf) |
1916 | error ("cannot read string table from %s: %s", | |
1917 | bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); | |
1918 | if (strtbl[length - 1] != '\0') | |
1919 | error ("bad symbol file: string table does not end with null character"); | |
e38e0312 | 1920 | |
a367db89 | 1921 | return; |
e38e0312 | 1922 | } |
a367db89 JK |
1923 | \f |
1924 | /* If we have not yet seen a function for this psymtab, this is 0. If we | |
1925 | have seen one, it is the offset in the line numbers of the line numbers | |
1926 | for the psymtab. */ | |
1927 | static unsigned int first_fun_line_offset; | |
e38e0312 | 1928 | |
a367db89 JK |
1929 | static struct partial_symtab *xcoff_start_psymtab |
1930 | PARAMS ((struct objfile *, struct section_offsets *, char *, int, | |
1931 | struct partial_symbol *, struct partial_symbol *)); | |
1932 | ||
1933 | /* Allocate and partially fill a partial symtab. It will be | |
1934 | completely filled at the end of the symbol list. | |
1935 | ||
1936 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
1937 | is the address relative to which its symbols are (incremental) or 0 | |
1938 | (normal). */ | |
1939 | ||
1940 | static struct partial_symtab * | |
1941 | xcoff_start_psymtab (objfile, section_offsets, | |
1942 | filename, first_symnum, global_syms, static_syms) | |
1943 | struct objfile *objfile; | |
1944 | struct section_offsets *section_offsets; | |
1945 | char *filename; | |
1946 | int first_symnum; | |
1947 | struct partial_symbol *global_syms; | |
1948 | struct partial_symbol *static_syms; | |
e38e0312 | 1949 | { |
a367db89 JK |
1950 | struct partial_symtab *result = |
1951 | start_psymtab_common (objfile, section_offsets, | |
1952 | filename, | |
1953 | /* We fill in textlow later. */ | |
1954 | 0, | |
1955 | global_syms, static_syms); | |
1956 | ||
1957 | result->read_symtab_private = (char *) | |
1958 | obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc)); | |
1959 | ((struct symloc *)result->read_symtab_private)->first_symnum = first_symnum; | |
1960 | result->read_symtab = xcoff_psymtab_to_symtab; | |
1961 | ||
1962 | /* Deduce the source language from the filename for this psymtab. */ | |
1963 | psymtab_language = deduce_language_from_filename (filename); | |
1964 | ||
1965 | return result; | |
1966 | } | |
e38e0312 | 1967 | |
a367db89 JK |
1968 | static struct partial_symtab *xcoff_end_psymtab |
1969 | PARAMS ((struct partial_symtab *, char **, int, int, | |
1970 | struct partial_symtab **, int)); | |
e38e0312 | 1971 | |
a367db89 JK |
1972 | /* Close off the current usage of PST. |
1973 | Returns PST, or NULL if the partial symtab was empty and thrown away. | |
e38e0312 | 1974 | |
a367db89 | 1975 | CAPPING_SYMBOL_NUMBER is the end of pst (exclusive). |
e38e0312 | 1976 | |
a367db89 JK |
1977 | INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES |
1978 | are the information for includes and dependencies. */ | |
e38e0312 | 1979 | |
a367db89 JK |
1980 | static struct partial_symtab * |
1981 | xcoff_end_psymtab (pst, include_list, num_includes, capping_symbol_number, | |
1982 | dependency_list, number_dependencies) | |
1983 | struct partial_symtab *pst; | |
1984 | char **include_list; | |
1985 | int num_includes; | |
1986 | int capping_symbol_number; | |
1987 | struct partial_symtab **dependency_list; | |
1988 | int number_dependencies; | |
1989 | { | |
1990 | int i; | |
1991 | struct objfile *objfile = pst -> objfile; | |
1992 | ||
1993 | if (capping_symbol_number != -1) | |
1994 | ((struct symloc *)pst->read_symtab_private)->numsyms = | |
1995 | capping_symbol_number | |
1996 | - ((struct symloc *)pst->read_symtab_private)->first_symnum; | |
1997 | ((struct symloc *)pst->read_symtab_private)->lineno_off = | |
1998 | first_fun_line_offset; | |
1999 | first_fun_line_offset = 0; | |
2000 | pst->n_global_syms = | |
2001 | objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset); | |
2002 | pst->n_static_syms = | |
2003 | objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset); | |
2004 | ||
2005 | pst->number_of_dependencies = number_dependencies; | |
2006 | if (number_dependencies) | |
2007 | { | |
2008 | pst->dependencies = (struct partial_symtab **) | |
2009 | obstack_alloc (&objfile->psymbol_obstack, | |
2010 | number_dependencies * sizeof (struct partial_symtab *)); | |
2011 | memcpy (pst->dependencies, dependency_list, | |
2012 | number_dependencies * sizeof (struct partial_symtab *)); | |
2013 | } | |
2014 | else | |
2015 | pst->dependencies = 0; | |
2016 | ||
2017 | for (i = 0; i < num_includes; i++) | |
2018 | { | |
2019 | struct partial_symtab *subpst = | |
2020 | allocate_psymtab (include_list[i], objfile); | |
2021 | ||
2022 | subpst->section_offsets = pst->section_offsets; | |
2023 | subpst->read_symtab_private = | |
2024 | (char *) obstack_alloc (&objfile->psymbol_obstack, | |
2025 | sizeof (struct symloc)); | |
2026 | ((struct symloc *)subpst->read_symtab_private)->first_symnum = 0; | |
2027 | ((struct symloc *)subpst->read_symtab_private)->numsyms = 0; | |
2028 | subpst->textlow = 0; | |
2029 | subpst->texthigh = 0; | |
2030 | ||
2031 | /* We could save slight bits of space by only making one of these, | |
2032 | shared by the entire set of include files. FIXME-someday. */ | |
2033 | subpst->dependencies = (struct partial_symtab **) | |
2034 | obstack_alloc (&objfile->psymbol_obstack, | |
2035 | sizeof (struct partial_symtab *)); | |
2036 | subpst->dependencies[0] = pst; | |
2037 | subpst->number_of_dependencies = 1; | |
2038 | ||
2039 | subpst->globals_offset = | |
2040 | subpst->n_global_syms = | |
2041 | subpst->statics_offset = | |
2042 | subpst->n_static_syms = 0; | |
2043 | ||
2044 | subpst->readin = 0; | |
2045 | subpst->symtab = 0; | |
2046 | subpst->read_symtab = pst->read_symtab; | |
2047 | } | |
2048 | ||
2049 | sort_pst_symbols (pst); | |
2050 | ||
2051 | /* If there is already a psymtab or symtab for a file of this name, | |
2052 | remove it. (If there is a symtab, more drastic things also | |
2053 | happen.) This happens in VxWorks. */ | |
2054 | free_named_symtabs (pst->filename); | |
2055 | ||
2056 | if (num_includes == 0 | |
2057 | && number_dependencies == 0 | |
2058 | && pst->n_global_syms == 0 | |
2059 | && pst->n_static_syms == 0) | |
2060 | { | |
2061 | /* Throw away this psymtab, it's empty. We can't deallocate it, since | |
2062 | it is on the obstack, but we can forget to chain it on the list. */ | |
2063 | /* Empty psymtabs happen as a result of header files which don't have | |
df1e1074 | 2064 | any symbols in them. There can be a lot of them. */ |
a367db89 JK |
2065 | struct partial_symtab *prev_pst; |
2066 | ||
2067 | /* First, snip it out of the psymtab chain */ | |
2068 | ||
2069 | if (pst->objfile->psymtabs == pst) | |
2070 | pst->objfile->psymtabs = pst->next; | |
2071 | else | |
2072 | for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next) | |
2073 | if (prev_pst->next == pst) | |
2074 | prev_pst->next = pst->next; | |
2075 | ||
2076 | /* Next, put it on a free list for recycling */ | |
2077 | ||
2078 | pst->next = pst->objfile->free_psymtabs; | |
2079 | pst->objfile->free_psymtabs = pst; | |
2080 | ||
2081 | /* Indicate that psymtab was thrown away. */ | |
2082 | pst = (struct partial_symtab *)NULL; | |
2083 | } | |
2084 | return pst; | |
2085 | } | |
2086 | ||
2087 | static void swap_sym PARAMS ((struct internal_syment *, | |
2088 | union internal_auxent *, char **, char **, | |
2089 | unsigned int *, | |
2090 | struct objfile *)); | |
2091 | ||
2092 | /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in | |
2093 | *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over | |
2094 | the symbol and its auxents. */ | |
2095 | ||
2096 | static void | |
2097 | swap_sym (symbol, aux, name, raw, symnump, objfile) | |
2098 | struct internal_syment *symbol; | |
2099 | union internal_auxent *aux; | |
2100 | char **name; | |
2101 | char **raw; | |
2102 | unsigned int *symnump; | |
2103 | struct objfile *objfile; | |
2104 | { | |
2105 | bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol); | |
2106 | if (symbol->n_zeroes) | |
2107 | { | |
2108 | /* If it's exactly E_SYMNMLEN characters long it isn't | |
2109 | '\0'-terminated. */ | |
2110 | if (symbol->n_name[E_SYMNMLEN - 1] != '\0') | |
2111 | { | |
2112 | /* FIXME: wastes memory for symbols which we don't end up putting | |
2113 | into the minimal symbols. */ | |
2114 | char *p; | |
2115 | p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1); | |
2116 | strncpy (p, symbol->n_name, E_SYMNMLEN); | |
2117 | p[E_SYMNMLEN] = '\0'; | |
2118 | *name = p; | |
2119 | } | |
2120 | else | |
2121 | /* Point to the unswapped name as that persists as long as the | |
2122 | objfile does. */ | |
2123 | *name = ((struct external_syment *)*raw)->e.e_name; | |
2124 | } | |
2125 | else if (symbol->n_sclass & 0x80) | |
2126 | { | |
2127 | *name = ((struct coff_symfile_info *)objfile->sym_private)->debugsec | |
2128 | + symbol->n_offset; | |
2129 | } | |
2130 | else | |
2131 | { | |
2132 | *name = ((struct coff_symfile_info *)objfile->sym_private)->strtbl | |
2133 | + symbol->n_offset; | |
2134 | } | |
2135 | ++*symnump; | |
2136 | *raw += coff_data (objfile->obfd)->local_symesz; | |
2137 | if (symbol->n_numaux > 0) | |
2138 | { | |
2139 | bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type, | |
2140 | symbol->n_sclass, 0, symbol->n_numaux, aux); | |
2141 | ||
2142 | *symnump += symbol->n_numaux; | |
2143 | *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux; | |
2144 | } | |
e38e0312 JG |
2145 | } |
2146 | ||
2147 | static void | |
a367db89 JK |
2148 | scan_xcoff_symtab (section_offsets, objfile) |
2149 | struct section_offsets *section_offsets; | |
2150 | struct objfile *objfile; | |
e38e0312 | 2151 | { |
a367db89 | 2152 | int toc_offset = 0; /* toc offset value in data section. */ |
df1e1074 | 2153 | char *filestring = NULL; |
a367db89 JK |
2154 | |
2155 | char *namestring; | |
a367db89 | 2156 | int past_first_source_file = 0; |
a367db89 JK |
2157 | bfd *abfd; |
2158 | unsigned int nsyms; | |
2159 | ||
2160 | /* Current partial symtab */ | |
2161 | struct partial_symtab *pst; | |
2162 | ||
2163 | /* List of current psymtab's include files */ | |
2164 | char **psymtab_include_list; | |
2165 | int includes_allocated; | |
2166 | int includes_used; | |
2167 | ||
2168 | /* Index within current psymtab dependency list */ | |
2169 | struct partial_symtab **dependency_list; | |
2170 | int dependencies_used, dependencies_allocated; | |
2171 | ||
2172 | char *sraw_symbol; | |
2173 | struct internal_syment symbol; | |
2174 | union internal_auxent main_aux; | |
2175 | unsigned int ssymnum; | |
2176 | ||
2177 | char *last_csect_name = NULL; /* last seen csect's name and value */ | |
df1e1074 PS |
2178 | CORE_ADDR last_csect_val = 0; |
2179 | int last_csect_sec = 0; | |
2180 | int misc_func_recorded = 0; /* true if any misc. function */ | |
a367db89 JK |
2181 | |
2182 | pst = (struct partial_symtab *) 0; | |
2183 | ||
2184 | includes_allocated = 30; | |
2185 | includes_used = 0; | |
2186 | psymtab_include_list = (char **) alloca (includes_allocated * | |
2187 | sizeof (char *)); | |
2188 | ||
2189 | dependencies_allocated = 30; | |
2190 | dependencies_used = 0; | |
2191 | dependency_list = | |
2192 | (struct partial_symtab **) alloca (dependencies_allocated * | |
2193 | sizeof (struct partial_symtab *)); | |
2194 | ||
2195 | last_source_file = NULL; | |
2196 | ||
2197 | abfd = objfile->obfd; | |
2198 | ||
2199 | sraw_symbol = ((struct coff_symfile_info *)objfile->sym_private)->symtbl; | |
2200 | nsyms = ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms; | |
2201 | ssymnum = 0; | |
2202 | while (ssymnum < nsyms) | |
2203 | { | |
df1e1074 | 2204 | int sclass = ((struct external_syment *)sraw_symbol)->e_sclass[0] & 0xff; |
a367db89 JK |
2205 | /* This is the type we pass to partial-stab.h. A less kludgy solution |
2206 | would be to break out partial-stab.h into its various parts--shuffle | |
2207 | off the DBXREAD_ONLY stuff to dbxread.c, and make separate | |
2208 | pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */ | |
2209 | int stype; | |
2210 | ||
2211 | QUIT; | |
2212 | ||
2213 | switch (sclass) | |
2214 | { | |
2215 | case C_EXT: | |
2216 | case C_HIDEXT: | |
2217 | { | |
2218 | /* The CSECT auxent--always the last auxent. */ | |
2219 | union internal_auxent csect_aux; | |
2220 | unsigned int symnum_before = ssymnum; | |
2221 | ||
2222 | swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol, | |
2223 | &ssymnum, objfile); | |
2224 | if (symbol.n_numaux > 1) | |
2225 | { | |
2226 | bfd_coff_swap_aux_in | |
2227 | (objfile->obfd, | |
2228 | sraw_symbol - coff_data(abfd)->local_symesz, | |
2229 | symbol.n_type, | |
2230 | symbol.n_sclass, | |
2231 | symbol.n_numaux - 1, | |
2232 | symbol.n_numaux, | |
2233 | &csect_aux); | |
2234 | } | |
2235 | else | |
2236 | csect_aux = main_aux; | |
2237 | ||
df1e1074 PS |
2238 | /* If symbol name starts with ".$" or "$", ignore it. */ |
2239 | if (namestring[0] == '$' | |
2240 | || (namestring[0] == '.' && namestring[1] == '$')) | |
2241 | break; | |
2242 | ||
a367db89 JK |
2243 | switch (csect_aux.x_csect.x_smtyp & 0x7) |
2244 | { | |
2245 | case XTY_SD: | |
2246 | switch (csect_aux.x_csect.x_smclas) | |
2247 | { | |
2248 | case XMC_PR: | |
2249 | if (last_csect_name) | |
2250 | { | |
2251 | /* If no misc. function recorded in the last | |
2252 | seen csect, enter it as a function. This | |
2253 | will take care of functions like strcmp() | |
2254 | compiled by xlc. */ | |
2255 | ||
2256 | if (!misc_func_recorded) | |
2257 | { | |
2258 | RECORD_MINIMAL_SYMBOL | |
2259 | (last_csect_name, last_csect_val, | |
2260 | mst_text, last_csect_sec, | |
2261 | objfile); | |
2262 | } | |
2263 | ||
2264 | if (pst != NULL) | |
2265 | { | |
2266 | /* We have to allocate one psymtab for | |
2267 | each program csect, because their text | |
2268 | sections need not be adjacent. */ | |
2269 | xcoff_end_psymtab | |
2270 | (pst, psymtab_include_list, | |
2271 | includes_used, | |
2272 | symnum_before, | |
2273 | dependency_list, dependencies_used); | |
2274 | includes_used = 0; | |
2275 | dependencies_used = 0; | |
2276 | /* Give all psymtabs for this source file the same | |
2277 | name. */ | |
2278 | pst = xcoff_start_psymtab | |
2279 | (objfile, section_offsets, | |
2280 | filestring, | |
2281 | symnum_before, | |
2282 | objfile->global_psymbols.next, | |
2283 | objfile->static_psymbols.next); | |
2284 | } | |
2285 | } | |
2286 | if (namestring && namestring[0] == '.') | |
2287 | { | |
2288 | last_csect_name = namestring; | |
2289 | last_csect_val = symbol.n_value; | |
2290 | last_csect_sec = | |
2291 | secnum_to_section (symbol.n_scnum, objfile); | |
2292 | } | |
2293 | if (pst != NULL) | |
2294 | { | |
2295 | CORE_ADDR highval = | |
2296 | symbol.n_value + csect_aux.x_csect.x_scnlen.l; | |
2297 | if (highval > pst->texthigh) | |
2298 | pst->texthigh = highval; | |
2299 | if (pst->textlow == 0 || symbol.n_value < pst->textlow) | |
2300 | pst->textlow = symbol.n_value; | |
2301 | } | |
2302 | misc_func_recorded = 0; | |
2303 | break; | |
df1e1074 | 2304 | |
a367db89 | 2305 | case XMC_RW: |
df1e1074 PS |
2306 | /* Data variables are recorded in the minimal symbol |
2307 | table, except for section symbols. */ | |
2308 | if (*namestring != '.') | |
2309 | prim_record_minimal_symbol_and_info | |
2310 | (namestring, symbol.n_value, | |
2311 | sclass == C_HIDEXT ? mst_file_data : mst_data, | |
2312 | NULL, secnum_to_section (symbol.n_scnum, objfile), | |
2313 | objfile); | |
a367db89 | 2314 | break; |
df1e1074 | 2315 | |
a367db89 JK |
2316 | case XMC_TC0: |
2317 | if (toc_offset) | |
2318 | warning ("More than one XMC_TC0 symbol found."); | |
2319 | toc_offset = symbol.n_value; | |
2320 | break; | |
df1e1074 | 2321 | |
a367db89 JK |
2322 | case XMC_TC: |
2323 | /* These symbols tell us where the TOC entry for a | |
2324 | variable is, not the variable itself. */ | |
2325 | break; | |
df1e1074 | 2326 | |
a367db89 JK |
2327 | default: |
2328 | break; | |
2329 | } | |
2330 | break; | |
2331 | ||
2332 | case XTY_LD: | |
2333 | switch (csect_aux.x_csect.x_smclas) | |
2334 | { | |
2335 | case XMC_PR: | |
df1e1074 PS |
2336 | /* A function entry point. */ |
2337 | ||
2338 | if (first_fun_line_offset == 0 && symbol.n_numaux > 1) | |
2339 | first_fun_line_offset = | |
2340 | main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr; | |
2341 | RECORD_MINIMAL_SYMBOL | |
2342 | (namestring, symbol.n_value, | |
2343 | sclass == C_HIDEXT ? mst_file_text : mst_text, | |
2344 | secnum_to_section (symbol.n_scnum, objfile), | |
2345 | objfile); | |
a367db89 | 2346 | break; |
df1e1074 | 2347 | |
a367db89 JK |
2348 | case XMC_GL: |
2349 | /* shared library function trampoline code entry | |
2350 | point. */ | |
2351 | ||
2352 | /* record trampoline code entries as | |
2353 | mst_solib_trampoline symbol. When we lookup mst | |
2354 | symbols, we will choose mst_text over | |
2355 | mst_solib_trampoline. */ | |
2356 | RECORD_MINIMAL_SYMBOL | |
2357 | (namestring, symbol.n_value, | |
2358 | mst_solib_trampoline, | |
2359 | secnum_to_section (symbol.n_scnum, objfile), | |
2360 | objfile); | |
2361 | break; | |
2362 | ||
2363 | case XMC_DS: | |
2364 | /* The symbols often have the same names as | |
2365 | debug symbols for functions, and confuse | |
2366 | lookup_symbol. */ | |
2367 | break; | |
2368 | ||
2369 | default: | |
2370 | ||
2371 | /* xlc puts each variable in a separate csect, | |
2372 | so we get an XTY_SD for each variable. But | |
2373 | gcc puts several variables in a csect, so | |
2374 | that each variable only gets an XTY_LD. We | |
2375 | still need to record them. This will | |
2376 | typically be XMC_RW; I suspect XMC_RO and | |
2377 | XMC_BS might be possible too. */ | |
df1e1074 PS |
2378 | if (*namestring != '.') |
2379 | prim_record_minimal_symbol_and_info | |
2380 | (namestring, symbol.n_value, | |
2381 | sclass == C_HIDEXT ? mst_file_data : mst_data, | |
2382 | NULL, secnum_to_section (symbol.n_scnum, objfile), | |
2383 | objfile); | |
2384 | break; | |
2385 | } | |
2386 | break; | |
a367db89 | 2387 | |
df1e1074 PS |
2388 | case XTY_CM: |
2389 | switch (csect_aux.x_csect.x_smclas) | |
2390 | { | |
2391 | case XMC_RW: | |
2392 | case XMC_BS: | |
2393 | /* Common variables are recorded in the minimal symbol | |
2394 | table, except for section symbols. */ | |
2395 | if (*namestring != '.') | |
2396 | prim_record_minimal_symbol_and_info | |
2397 | (namestring, symbol.n_value, | |
2398 | sclass == C_HIDEXT ? mst_file_bss : mst_bss, | |
2399 | NULL, secnum_to_section (symbol.n_scnum, objfile), | |
2400 | objfile); | |
a367db89 JK |
2401 | break; |
2402 | } | |
df1e1074 PS |
2403 | break; |
2404 | ||
a367db89 JK |
2405 | default: |
2406 | break; | |
2407 | } | |
2408 | } | |
2409 | break; | |
2410 | case C_FILE: | |
2411 | { | |
2412 | unsigned int symnum_before; | |
2413 | ||
2414 | symnum_before = ssymnum; | |
2415 | swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol, | |
2416 | &ssymnum, objfile); | |
2417 | ||
2418 | /* See if the last csect needs to be recorded. */ | |
2419 | ||
2420 | if (last_csect_name && !misc_func_recorded) | |
2421 | { | |
2422 | ||
2423 | /* If no misc. function recorded in the last seen csect, enter | |
2424 | it as a function. This will take care of functions like | |
2425 | strcmp() compiled by xlc. */ | |
2426 | ||
2427 | RECORD_MINIMAL_SYMBOL | |
2428 | (last_csect_name, last_csect_val, | |
2429 | mst_text, last_csect_sec, objfile); | |
2430 | } | |
2431 | ||
2432 | if (pst) | |
2433 | { | |
2434 | xcoff_end_psymtab (pst, psymtab_include_list, includes_used, | |
2435 | symnum_before, | |
2436 | dependency_list, dependencies_used); | |
2437 | includes_used = 0; | |
2438 | dependencies_used = 0; | |
2439 | } | |
2440 | first_fun_line_offset = 0; | |
2441 | ||
2442 | /* XCOFF, according to the AIX 3.2 documentation, puts the | |
2443 | filename in cs->c_name. But xlc 1.3.0.2 has decided to | |
2444 | do things the standard COFF way and put it in the auxent. | |
2445 | We use the auxent if the symbol is ".file" and an auxent | |
2446 | exists, otherwise use the symbol itself. */ | |
2447 | if (!strcmp (namestring, ".file") && symbol.n_numaux > 0) | |
2448 | { | |
2449 | filestring = coff_getfilename (&main_aux, objfile); | |
2450 | } | |
2451 | else | |
2452 | filestring = namestring; | |
2453 | ||
2454 | pst = xcoff_start_psymtab (objfile, section_offsets, | |
2455 | filestring, | |
2456 | symnum_before, | |
2457 | objfile->global_psymbols.next, | |
2458 | objfile->static_psymbols.next); | |
2459 | last_csect_name = NULL; | |
2460 | } | |
2461 | break; | |
2462 | ||
2463 | default: | |
2464 | { | |
2465 | static struct complaint msg = | |
2466 | {"Storage class %d not recognized during scan", 0, 0}; | |
2467 | complain (&msg, sclass); | |
2468 | } | |
2469 | /* FALLTHROUGH */ | |
2470 | ||
2471 | /* C_FCN is .bf and .ef symbols. I think it is sufficient | |
2472 | to handle only the C_FUN and C_EXT. */ | |
2473 | case C_FCN: | |
2474 | ||
2475 | case C_BSTAT: | |
2476 | case C_ESTAT: | |
2477 | case C_ARG: | |
2478 | case C_REGPARM: | |
2479 | case C_REG: | |
2480 | case C_TPDEF: | |
2481 | case C_STRTAG: | |
2482 | case C_UNTAG: | |
2483 | case C_ENTAG: | |
2484 | case C_LABEL: | |
2485 | case C_NULL: | |
2486 | ||
2487 | /* C_EINCL means we are switching back to the main file. But there | |
2488 | is no reason to care; the only thing we want to know about | |
2489 | includes is the names of all the included (.h) files. */ | |
2490 | case C_EINCL: | |
2491 | ||
2492 | case C_BLOCK: | |
2493 | ||
2494 | /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be | |
2495 | used instead. */ | |
2496 | case C_STAT: | |
2497 | ||
2498 | /* I don't think the name of the common block (as opposed to the | |
2499 | variables within it) is something which is user visible | |
2500 | currently. */ | |
2501 | case C_BCOMM: | |
2502 | case C_ECOMM: | |
2503 | ||
2504 | case C_PSYM: | |
2505 | case C_RPSYM: | |
2506 | ||
2507 | /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL | |
2508 | so C_LSYM would appear to be only for locals. */ | |
2509 | case C_LSYM: | |
2510 | ||
2511 | case C_AUTO: | |
2512 | case C_RSYM: | |
2513 | { | |
2514 | /* We probably could save a few instructions by assuming that | |
2515 | C_LSYM, C_PSYM, etc., never have auxents. */ | |
2516 | int naux1 = | |
2517 | ((struct external_syment *)sraw_symbol)->e_numaux[0] + 1; | |
2518 | ssymnum += naux1; | |
2519 | sraw_symbol += sizeof (struct external_syment) * naux1; | |
2520 | } | |
2521 | break; | |
2522 | ||
2523 | case C_BINCL: | |
2524 | stype = N_SOL; | |
2525 | goto pstab; | |
2526 | ||
2527 | case C_FUN: | |
2528 | /* The value of the C_FUN is not the address of the function (it | |
2529 | appears to be the address before linking), but as long as it | |
2530 | is smaller than the actual address, then find_pc_partial_function | |
2531 | will use the minimal symbols instead. I hope. */ | |
2532 | ||
2533 | case C_GSYM: | |
2534 | case C_ECOML: | |
2535 | case C_DECL: | |
2536 | case C_STSYM: | |
2537 | stype = N_LSYM; | |
2538 | pstab:; | |
2539 | swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol, | |
2540 | &ssymnum, objfile); | |
2541 | #define CUR_SYMBOL_TYPE stype | |
2542 | #define CUR_SYMBOL_VALUE symbol.n_value | |
2543 | ||
2544 | /* START_PSYMTAB and END_PSYMTAB are never used, because they are only | |
2545 | called from DBXREAD_ONLY or N_SO code. Likewise for the symnum | |
2546 | variable. */ | |
2547 | #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0 | |
2548 | #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\ | |
2549 | do {} while (0) | |
2550 | /* We have already set the namestring. */ | |
df1e1074 | 2551 | #define SET_NAMESTRING() /* */ |
a367db89 JK |
2552 | |
2553 | #include "partial-stab.h" | |
2554 | } | |
2555 | } | |
a367db89 JK |
2556 | |
2557 | if (pst) | |
2558 | { | |
2559 | xcoff_end_psymtab (pst, psymtab_include_list, includes_used, | |
2560 | ssymnum, | |
2561 | dependency_list, dependencies_used); | |
2562 | } | |
2563 | ||
2564 | /* Record the toc offset value of this symbol table into ldinfo structure. | |
2565 | If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain | |
2566 | this information would be file auxiliary header. */ | |
2567 | ||
2568 | #ifndef FAKING_RS6000 | |
2569 | xcoff_add_toc_to_loadinfo (toc_offset); | |
2570 | #endif | |
e38e0312 JG |
2571 | } |
2572 | ||
a367db89 JK |
2573 | /* Scan and build partial symbols for a symbol file. |
2574 | We have been initialized by a call to dbx_symfile_init, which | |
2575 | put all the relevant info into a "struct dbx_symfile_info", | |
2576 | hung off the objfile structure. | |
e38e0312 | 2577 | |
a367db89 JK |
2578 | SECTION_OFFSETS contains offsets relative to which the symbols in the |
2579 | various sections are (depending where the sections were actually loaded). | |
2580 | MAINLINE is true if we are reading the main symbol | |
2581 | table (as opposed to a shared lib or dynamically loaded file). */ | |
e38e0312 | 2582 | |
1ab3bf1b | 2583 | static void |
a367db89 JK |
2584 | xcoff_initial_scan (objfile, section_offsets, mainline) |
2585 | struct objfile *objfile; | |
2586 | struct section_offsets *section_offsets; | |
2587 | int mainline; /* FIXME comments above */ | |
e38e0312 | 2588 | { |
a367db89 JK |
2589 | bfd *abfd; |
2590 | int val; | |
2591 | struct cleanup *back_to; | |
d5931d79 JG |
2592 | int num_symbols; /* # of symbols */ |
2593 | file_ptr symtab_offset; /* symbol table and */ | |
2594 | file_ptr stringtab_offset; /* string table file offsets */ | |
80d68b1d | 2595 | struct coff_symfile_info *info; |
e38e0312 | 2596 | char *name; |
a367db89 JK |
2597 | unsigned int size; |
2598 | ||
2599 | #ifndef FAKING_RS6000 | |
2600 | /* Initialize load info structure. */ | |
2601 | if (mainline) | |
2602 | xcoff_init_loadinfo (); | |
2603 | #endif | |
e38e0312 | 2604 | |
80d68b1d FF |
2605 | info = (struct coff_symfile_info *) objfile -> sym_private; |
2606 | symfile_bfd = abfd = objfile->obfd; | |
2607 | name = objfile->name; | |
e38e0312 JG |
2608 | |
2609 | num_symbols = bfd_get_symcount (abfd); /* # of symbols */ | |
2610 | symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */ | |
2611 | stringtab_offset = symtab_offset + | |
2612 | num_symbols * coff_data(abfd)->local_symesz; | |
2613 | ||
2614 | info->min_lineno_offset = 0; | |
2615 | info->max_lineno_offset = 0; | |
2616 | bfd_map_over_sections (abfd, find_linenos, info); | |
2617 | ||
9d61147e JK |
2618 | if (num_symbols > 0) |
2619 | { | |
a367db89 JK |
2620 | /* Read the string table. */ |
2621 | init_stringtab (abfd, stringtab_offset, objfile); | |
e38e0312 | 2622 | |
a367db89 JK |
2623 | /* Read the .debug section, if present. */ |
2624 | { | |
2625 | sec_ptr secp; | |
2626 | bfd_size_type length; | |
2627 | char *debugsec = NULL; | |
2628 | ||
2629 | secp = bfd_get_section_by_name (abfd, ".debug"); | |
2630 | if (secp) | |
2631 | { | |
2632 | length = bfd_section_size (abfd, secp); | |
2633 | if (length) | |
2634 | { | |
2635 | debugsec = | |
2636 | (char *) obstack_alloc (&objfile->symbol_obstack, length); | |
2637 | ||
2638 | if (!bfd_get_section_contents (abfd, secp, debugsec, | |
2639 | (file_ptr) 0, length)) | |
2640 | { | |
2641 | error ("Error reading .debug section of `%s': %s", | |
2642 | name, bfd_errmsg (bfd_get_error ())); | |
2643 | } | |
2644 | } | |
2645 | } | |
2646 | ((struct coff_symfile_info *)objfile->sym_private)->debugsec = | |
2647 | debugsec; | |
9d61147e JK |
2648 | } |
2649 | } | |
e38e0312 | 2650 | |
a367db89 JK |
2651 | /* Read the symbols. We keep them in core because we will want to |
2652 | access them randomly in read_symbol*. */ | |
987622b5 | 2653 | val = bfd_seek (abfd, symtab_offset, SEEK_SET); |
e38e0312 | 2654 | if (val < 0) |
a367db89 JK |
2655 | error ("Error reading symbols from %s: %s", |
2656 | name, bfd_errmsg (bfd_get_error ())); | |
2657 | size = coff_data (abfd)->local_symesz * num_symbols; | |
2658 | ((struct coff_symfile_info *)objfile->sym_private)->symtbl = | |
2659 | obstack_alloc (&objfile->symbol_obstack, size); | |
2660 | ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms = | |
2661 | num_symbols; | |
2662 | ||
2663 | val = bfd_read (((struct coff_symfile_info *)objfile->sym_private)->symtbl, | |
2664 | size, 1, abfd); | |
2665 | if (val != size) | |
2666 | perror_with_name ("reading symbol table"); | |
2667 | ||
2668 | /* If we are reinitializing, or if we have never loaded syms yet, init */ | |
2669 | if (mainline | |
2670 | || objfile->global_psymbols.size == 0 | |
2671 | || objfile->static_psymbols.size == 0) | |
2672 | /* I'm not sure how how good num_symbols is; the rule of thumb in | |
2673 | init_psymbol_list was developed for a.out. On the one hand, | |
2674 | num_symbols includes auxents. On the other hand, it doesn't | |
2675 | include N_SLINE. */ | |
2676 | init_psymbol_list (objfile, num_symbols); | |
e38e0312 | 2677 | |
a367db89 JK |
2678 | pending_blocks = 0; |
2679 | back_to = make_cleanup (really_free_pendings, 0); | |
e38e0312 | 2680 | |
1ab3bf1b JG |
2681 | init_minimal_symbol_collection (); |
2682 | make_cleanup (discard_minimal_symbols, 0); | |
e38e0312 | 2683 | |
a367db89 JK |
2684 | /* Now that the symbol table data of the executable file are all in core, |
2685 | process them and define symbols accordingly. */ | |
e38e0312 | 2686 | |
a367db89 | 2687 | scan_xcoff_symtab (section_offsets, objfile); |
e38e0312 | 2688 | |
1ab3bf1b JG |
2689 | /* Install any minimal symbols that have been collected as the current |
2690 | minimal symbols for this objfile. */ | |
2691 | ||
80d68b1d | 2692 | install_minimal_symbols (objfile); |
0eb22669 PS |
2693 | |
2694 | do_cleanups (back_to); | |
e38e0312 | 2695 | } |
a367db89 | 2696 | \f |
e2adc41a | 2697 | static struct section_offsets * |
9b280a7f | 2698 | xcoff_symfile_offsets (objfile, addr) |
2670f34d JG |
2699 | struct objfile *objfile; |
2700 | CORE_ADDR addr; | |
2701 | { | |
2702 | struct section_offsets *section_offsets; | |
2703 | int i; | |
3c02636b | 2704 | |
e2adc41a | 2705 | objfile->num_sections = SECT_OFF_MAX; |
2670f34d | 2706 | section_offsets = (struct section_offsets *) |
3c02636b JK |
2707 | obstack_alloc |
2708 | (&objfile -> psymbol_obstack, | |
2709 | sizeof (struct section_offsets) | |
e2adc41a | 2710 | + sizeof (section_offsets->offsets) * objfile->num_sections); |
2670f34d | 2711 | |
1d7e34e1 JK |
2712 | /* syms_from_objfile kindly subtracts from addr the bfd_section_vma |
2713 | of the .text section. This strikes me as wrong--whether the | |
2714 | offset to be applied to symbol reading is relative to the start | |
2715 | address of the section depends on the symbol format. In any | |
2716 | event, this whole "addr" concept is pretty broken (it doesn't | |
2717 | handle any section but .text sensibly), so just ignore the addr | |
a367db89 JK |
2718 | parameter and use 0. rs6000-nat.c will set the correct section |
2719 | offsets via objfile_relocate. */ | |
e2adc41a | 2720 | for (i = 0; i < objfile->num_sections; ++i) |
38fb211b | 2721 | ANOFFSET (section_offsets, i) = 0; |
e2adc41a | 2722 | |
2670f34d JG |
2723 | return section_offsets; |
2724 | } | |
0eed42de JK |
2725 | |
2726 | /* Register our ability to parse symbols for xcoff BFD files. */ | |
e38e0312 | 2727 | |
9b280a7f | 2728 | static struct sym_fns xcoff_sym_fns = |
e38e0312 | 2729 | { |
0eed42de JK |
2730 | |
2731 | /* Because the bfd uses coff_flavour, we need to specially kludge | |
e2adc41a JK |
2732 | the flavour. It is possible that coff and xcoff should be merged as |
2733 | they do have fundamental similarities (for example, the extra storage | |
2734 | classes used for stabs could presumably be recognized in any COFF file). | |
2735 | However, in addition to obvious things like all the csect hair, there are | |
2736 | some subtler differences between xcoffread.c and coffread.c, notably | |
2737 | the fact that coffread.c has no need to read in all the symbols, but | |
2738 | xcoffread.c reads all the symbols and does in fact randomly access them | |
a367db89 | 2739 | (in C_BSTAT and line number processing). */ |
0eed42de | 2740 | |
52912aac | 2741 | (enum bfd_flavour)-1, |
0eed42de | 2742 | |
9b280a7f JG |
2743 | xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */ |
2744 | xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
a367db89 | 2745 | xcoff_initial_scan, /* sym_read: read a symbol file into symtab */ |
9b280a7f JG |
2746 | xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */ |
2747 | xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */ | |
80d68b1d | 2748 | NULL /* next: pointer to next struct sym_fns */ |
e38e0312 JG |
2749 | }; |
2750 | ||
2751 | void | |
2752 | _initialize_xcoffread () | |
2753 | { | |
9b280a7f | 2754 | add_symtab_fns(&xcoff_sym_fns); |
e5eeaaf8 | 2755 | |
a81ce07d JK |
2756 | func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0, |
2757 | "<function, no debug info>", NULL); | |
2758 | TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int; | |
2759 | var_symbol_type = | |
2760 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0, | |
2761 | "<variable, no debug info>", NULL); | |
e38e0312 | 2762 | } |