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