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