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