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