GDB (API)
|
00001 /* Read dbx symbol tables and convert to internal format, for GDB. 00002 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00003 00004 This file is part of GDB. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00018 00019 /* This module provides three functions: dbx_symfile_init, 00020 which initializes to read a symbol file; dbx_new_init, which 00021 discards existing cached information when all symbols are being 00022 discarded; and dbx_symfile_read, which reads a symbol table 00023 from a file. 00024 00025 dbx_symfile_read only does the minimum work necessary for letting the 00026 user "name" things symbolically; it does not read the entire symtab. 00027 Instead, it reads the external and static symbols and puts them in partial 00028 symbol tables. When more extensive information is requested of a 00029 file, the corresponding partial symbol table is mutated into a full 00030 fledged symbol table by going back and reading the symbols 00031 for real. dbx_psymtab_to_symtab() is the function that does this */ 00032 00033 #include "defs.h" 00034 #include "gdb_string.h" 00035 00036 #if defined(__CYGNUSCLIB__) 00037 #include <sys/types.h> 00038 #include <fcntl.h> 00039 #endif 00040 00041 #include "gdb_obstack.h" 00042 #include "gdb_stat.h" 00043 #include "symtab.h" 00044 #include "breakpoint.h" 00045 #include "target.h" 00046 #include "gdbcore.h" /* for bfd stuff */ 00047 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ 00048 #include "filenames.h" 00049 #include "objfiles.h" 00050 #include "buildsym.h" 00051 #include "stabsread.h" 00052 #include "gdb-stabs.h" 00053 #include "demangle.h" 00054 #include "complaints.h" 00055 #include "cp-abi.h" 00056 #include "cp-support.h" 00057 #include "psympriv.h" 00058 #include "block.h" 00059 00060 #include "gdb_assert.h" 00061 #include "gdb_string.h" 00062 00063 #include "aout/aout64.h" 00064 #include "aout/stab_gnu.h" /* We always use GNU stabs, not 00065 native, now. */ 00066 00067 00068 /* Key for dbx-associated data. */ 00069 00070 const struct objfile_data *dbx_objfile_data_key; 00071 00072 /* We put a pointer to this structure in the read_symtab_private field 00073 of the psymtab. */ 00074 00075 struct symloc 00076 { 00077 /* Offset within the file symbol table of first local symbol for this 00078 file. */ 00079 00080 int ldsymoff; 00081 00082 /* Length (in bytes) of the section of the symbol table devoted to 00083 this file's symbols (actually, the section bracketed may contain 00084 more than just this file's symbols). If ldsymlen is 0, the only 00085 reason for this thing's existence is the dependency list. Nothing 00086 else will happen when it is read in. */ 00087 00088 int ldsymlen; 00089 00090 /* The size of each symbol in the symbol file (in external form). */ 00091 00092 int symbol_size; 00093 00094 /* Further information needed to locate the symbols if they are in 00095 an ELF file. */ 00096 00097 int symbol_offset; 00098 int string_offset; 00099 int file_string_offset; 00100 }; 00101 00102 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff) 00103 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen) 00104 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private)) 00105 #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size) 00106 #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset) 00107 #define STRING_OFFSET(p) (SYMLOC(p)->string_offset) 00108 #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset) 00109 00110 00111 /* The objfile we are currently reading. */ 00112 00113 static struct objfile *dbxread_objfile; 00114 00115 /* Remember what we deduced to be the source language of this psymtab. */ 00116 00117 static enum language psymtab_language = language_unknown; 00118 00119 /* The BFD for this file -- implicit parameter to next_symbol_text. */ 00120 00121 static bfd *symfile_bfd; 00122 00123 /* The size of each symbol in the symbol file (in external form). 00124 This is set by dbx_symfile_read when building psymtabs, and by 00125 dbx_psymtab_to_symtab when building symtabs. */ 00126 00127 static unsigned symbol_size; 00128 00129 /* This is the offset of the symbol table in the executable file. */ 00130 00131 static unsigned symbol_table_offset; 00132 00133 /* This is the offset of the string table in the executable file. */ 00134 00135 static unsigned string_table_offset; 00136 00137 /* For elf+stab executables, the n_strx field is not a simple index 00138 into the string table. Instead, each .o file has a base offset in 00139 the string table, and the associated symbols contain offsets from 00140 this base. The following two variables contain the base offset for 00141 the current and next .o files. */ 00142 00143 static unsigned int file_string_table_offset; 00144 static unsigned int next_file_string_table_offset; 00145 00146 /* .o and NLM files contain unrelocated addresses which are based at 00147 0. When non-zero, this flag disables some of the special cases for 00148 Solaris elf+stab text addresses at location 0. */ 00149 00150 static int symfile_relocatable = 0; 00151 00152 /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are 00153 relative to the function start address. */ 00154 00155 static int block_address_function_relative = 0; 00156 00157 /* The lowest text address we have yet encountered. This is needed 00158 because in an a.out file, there is no header field which tells us 00159 what address the program is actually going to be loaded at, so we 00160 need to make guesses based on the symbols (which *are* relocated to 00161 reflect the address it will be loaded at). */ 00162 00163 static CORE_ADDR lowest_text_address; 00164 00165 /* Non-zero if there is any line number info in the objfile. Prevents 00166 end_psymtab from discarding an otherwise empty psymtab. */ 00167 00168 static int has_line_numbers; 00169 00170 /* Complaints about the symbols we have encountered. */ 00171 00172 static void 00173 unknown_symtype_complaint (const char *arg1) 00174 { 00175 complaint (&symfile_complaints, _("unknown symbol type %s"), arg1); 00176 } 00177 00178 static void 00179 lbrac_mismatch_complaint (int arg1) 00180 { 00181 complaint (&symfile_complaints, 00182 _("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1); 00183 } 00184 00185 static void 00186 repeated_header_complaint (const char *arg1, int arg2) 00187 { 00188 complaint (&symfile_complaints, 00189 _("\"repeated\" header file %s not " 00190 "previously seen, at symtab pos %d"), 00191 arg1, arg2); 00192 } 00193 00194 /* find_text_range --- find start and end of loadable code sections 00195 00196 The find_text_range function finds the shortest address range that 00197 encloses all sections containing executable code, and stores it in 00198 objfile's text_addr and text_size members. 00199 00200 dbx_symfile_read will use this to finish off the partial symbol 00201 table, in some cases. */ 00202 00203 static void 00204 find_text_range (bfd * sym_bfd, struct objfile *objfile) 00205 { 00206 asection *sec; 00207 int found_any = 0; 00208 CORE_ADDR start = 0; 00209 CORE_ADDR end = 0; 00210 00211 for (sec = sym_bfd->sections; sec; sec = sec->next) 00212 if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE) 00213 { 00214 CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec); 00215 CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec); 00216 00217 if (found_any) 00218 { 00219 if (sec_start < start) 00220 start = sec_start; 00221 if (sec_end > end) 00222 end = sec_end; 00223 } 00224 else 00225 { 00226 start = sec_start; 00227 end = sec_end; 00228 } 00229 00230 found_any = 1; 00231 } 00232 00233 if (!found_any) 00234 error (_("Can't find any code sections in symbol file")); 00235 00236 DBX_TEXT_ADDR (objfile) = start; 00237 DBX_TEXT_SIZE (objfile) = end - start; 00238 } 00239 00240 00241 00242 /* During initial symbol readin, we need to have a structure to keep 00243 track of which psymtabs have which bincls in them. This structure 00244 is used during readin to setup the list of dependencies within each 00245 partial symbol table. */ 00246 00247 struct header_file_location 00248 { 00249 char *name; /* Name of header file */ 00250 int instance; /* See above */ 00251 struct partial_symtab *pst; /* Partial symtab that has the 00252 BINCL/EINCL defs for this file. */ 00253 }; 00254 00255 /* The actual list and controling variables. */ 00256 static struct header_file_location *bincl_list, *next_bincl; 00257 static int bincls_allocated; 00258 00259 /* Local function prototypes. */ 00260 00261 extern void _initialize_dbxread (void); 00262 00263 static void read_ofile_symtab (struct objfile *, struct partial_symtab *); 00264 00265 static void dbx_read_symtab (struct partial_symtab *self, 00266 struct objfile *objfile); 00267 00268 static void dbx_psymtab_to_symtab_1 (struct objfile *, struct partial_symtab *); 00269 00270 static void read_dbx_dynamic_symtab (struct objfile *objfile); 00271 00272 static void read_dbx_symtab (struct objfile *); 00273 00274 static void free_bincl_list (struct objfile *); 00275 00276 static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int); 00277 00278 static void add_bincl_to_list (struct partial_symtab *, char *, int); 00279 00280 static void init_bincl_list (int, struct objfile *); 00281 00282 static char *dbx_next_symbol_text (struct objfile *); 00283 00284 static void fill_symbuf (bfd *); 00285 00286 static void dbx_symfile_init (struct objfile *); 00287 00288 static void dbx_new_init (struct objfile *); 00289 00290 static void dbx_symfile_read (struct objfile *, int); 00291 00292 static void dbx_symfile_finish (struct objfile *); 00293 00294 static void record_minimal_symbol (const char *, CORE_ADDR, int, 00295 struct objfile *); 00296 00297 static void add_new_header_file (char *, int); 00298 00299 static void add_old_header_file (char *, int); 00300 00301 static void add_this_object_header_file (int); 00302 00303 static struct partial_symtab *start_psymtab (struct objfile *, char *, 00304 CORE_ADDR, int, 00305 struct partial_symbol **, 00306 struct partial_symbol **); 00307 00308 /* Free up old header file tables. */ 00309 00310 void 00311 free_header_files (void) 00312 { 00313 if (this_object_header_files) 00314 { 00315 xfree (this_object_header_files); 00316 this_object_header_files = NULL; 00317 } 00318 n_allocated_this_object_header_files = 0; 00319 } 00320 00321 /* Allocate new header file tables. */ 00322 00323 void 00324 init_header_files (void) 00325 { 00326 n_allocated_this_object_header_files = 10; 00327 this_object_header_files = (int *) xmalloc (10 * sizeof (int)); 00328 } 00329 00330 /* Add header file number I for this object file 00331 at the next successive FILENUM. */ 00332 00333 static void 00334 add_this_object_header_file (int i) 00335 { 00336 if (n_this_object_header_files == n_allocated_this_object_header_files) 00337 { 00338 n_allocated_this_object_header_files *= 2; 00339 this_object_header_files 00340 = (int *) xrealloc ((char *) this_object_header_files, 00341 n_allocated_this_object_header_files * sizeof (int)); 00342 } 00343 00344 this_object_header_files[n_this_object_header_files++] = i; 00345 } 00346 00347 /* Add to this file an "old" header file, one already seen in 00348 a previous object file. NAME is the header file's name. 00349 INSTANCE is its instance code, to select among multiple 00350 symbol tables for the same header file. */ 00351 00352 static void 00353 add_old_header_file (char *name, int instance) 00354 { 00355 struct header_file *p = HEADER_FILES (dbxread_objfile); 00356 int i; 00357 00358 for (i = 0; i < N_HEADER_FILES (dbxread_objfile); i++) 00359 if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance) 00360 { 00361 add_this_object_header_file (i); 00362 return; 00363 } 00364 repeated_header_complaint (name, symnum); 00365 } 00366 00367 /* Add to this file a "new" header file: definitions for its types follow. 00368 NAME is the header file's name. 00369 Most often this happens only once for each distinct header file, 00370 but not necessarily. If it happens more than once, INSTANCE has 00371 a different value each time, and references to the header file 00372 use INSTANCE values to select among them. 00373 00374 dbx output contains "begin" and "end" markers for each new header file, 00375 but at this level we just need to know which files there have been; 00376 so we record the file when its "begin" is seen and ignore the "end". */ 00377 00378 static void 00379 add_new_header_file (char *name, int instance) 00380 { 00381 int i; 00382 struct header_file *hfile; 00383 00384 /* Make sure there is room for one more header file. */ 00385 00386 i = N_ALLOCATED_HEADER_FILES (dbxread_objfile); 00387 00388 if (N_HEADER_FILES (dbxread_objfile) == i) 00389 { 00390 if (i == 0) 00391 { 00392 N_ALLOCATED_HEADER_FILES (dbxread_objfile) = 10; 00393 HEADER_FILES (dbxread_objfile) = (struct header_file *) 00394 xmalloc (10 * sizeof (struct header_file)); 00395 } 00396 else 00397 { 00398 i *= 2; 00399 N_ALLOCATED_HEADER_FILES (dbxread_objfile) = i; 00400 HEADER_FILES (dbxread_objfile) = (struct header_file *) 00401 xrealloc ((char *) HEADER_FILES (dbxread_objfile), 00402 (i * sizeof (struct header_file))); 00403 } 00404 } 00405 00406 /* Create an entry for this header file. */ 00407 00408 i = N_HEADER_FILES (dbxread_objfile)++; 00409 hfile = HEADER_FILES (dbxread_objfile) + i; 00410 hfile->name = xstrdup (name); 00411 hfile->instance = instance; 00412 hfile->length = 10; 00413 hfile->vector 00414 = (struct type **) xmalloc (10 * sizeof (struct type *)); 00415 memset (hfile->vector, 0, 10 * sizeof (struct type *)); 00416 00417 add_this_object_header_file (i); 00418 } 00419 00420 #if 0 00421 static struct type ** 00422 explicit_lookup_type (int real_filenum, int index) 00423 { 00424 struct header_file *f = &HEADER_FILES (dbxread_objfile)[real_filenum]; 00425 00426 if (index >= f->length) 00427 { 00428 f->length *= 2; 00429 f->vector = (struct type **) 00430 xrealloc (f->vector, f->length * sizeof (struct type *)); 00431 memset (&f->vector[f->length / 2], 00432 '\0', f->length * sizeof (struct type *) / 2); 00433 } 00434 return &f->vector[index]; 00435 } 00436 #endif 00437 00438 static void 00439 record_minimal_symbol (const char *name, CORE_ADDR address, int type, 00440 struct objfile *objfile) 00441 { 00442 enum minimal_symbol_type ms_type; 00443 int section; 00444 00445 switch (type) 00446 { 00447 case N_TEXT | N_EXT: 00448 ms_type = mst_text; 00449 section = SECT_OFF_TEXT (objfile); 00450 break; 00451 case N_DATA | N_EXT: 00452 ms_type = mst_data; 00453 section = SECT_OFF_DATA (objfile); 00454 break; 00455 case N_BSS | N_EXT: 00456 ms_type = mst_bss; 00457 section = SECT_OFF_BSS (objfile); 00458 break; 00459 case N_ABS | N_EXT: 00460 ms_type = mst_abs; 00461 section = -1; 00462 break; 00463 #ifdef N_SETV 00464 case N_SETV | N_EXT: 00465 ms_type = mst_data; 00466 section = SECT_OFF_DATA (objfile); 00467 break; 00468 case N_SETV: 00469 /* I don't think this type actually exists; since a N_SETV is the result 00470 of going over many .o files, it doesn't make sense to have one 00471 file local. */ 00472 ms_type = mst_file_data; 00473 section = SECT_OFF_DATA (objfile); 00474 break; 00475 #endif 00476 case N_TEXT: 00477 case N_NBTEXT: 00478 case N_FN: 00479 case N_FN_SEQ: 00480 ms_type = mst_file_text; 00481 section = SECT_OFF_TEXT (objfile); 00482 break; 00483 case N_DATA: 00484 ms_type = mst_file_data; 00485 00486 /* Check for __DYNAMIC, which is used by Sun shared libraries. 00487 Record it as global even if it's local, not global, so 00488 lookup_minimal_symbol can find it. We don't check symbol_leading_char 00489 because for SunOS4 it always is '_'. */ 00490 if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0) 00491 ms_type = mst_data; 00492 00493 /* Same with virtual function tables, both global and static. */ 00494 { 00495 const char *tempstring = name; 00496 00497 if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd)) 00498 ++tempstring; 00499 if (is_vtable_name (tempstring)) 00500 ms_type = mst_data; 00501 } 00502 section = SECT_OFF_DATA (objfile); 00503 break; 00504 case N_BSS: 00505 ms_type = mst_file_bss; 00506 section = SECT_OFF_BSS (objfile); 00507 break; 00508 default: 00509 ms_type = mst_unknown; 00510 section = -1; 00511 break; 00512 } 00513 00514 if ((ms_type == mst_file_text || ms_type == mst_text) 00515 && address < lowest_text_address) 00516 lowest_text_address = address; 00517 00518 prim_record_minimal_symbol_and_info 00519 (name, address, ms_type, section, objfile); 00520 } 00521 00522 /* Scan and build partial symbols for a symbol file. 00523 We have been initialized by a call to dbx_symfile_init, which 00524 put all the relevant info into a "struct dbx_symfile_info", 00525 hung off the objfile structure. */ 00526 00527 static void 00528 dbx_symfile_read (struct objfile *objfile, int symfile_flags) 00529 { 00530 bfd *sym_bfd; 00531 int val; 00532 struct cleanup *back_to; 00533 00534 sym_bfd = objfile->obfd; 00535 00536 /* .o and .nlm files are relocatables with text, data and bss segs based at 00537 0. This flag disables special (Solaris stabs-in-elf only) fixups for 00538 symbols with a value of 0. */ 00539 00540 symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC; 00541 00542 /* This is true for Solaris (and all other systems which put stabs 00543 in sections, hopefully, since it would be silly to do things 00544 differently from Solaris), and false for SunOS4 and other a.out 00545 file formats. */ 00546 block_address_function_relative = 00547 ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3)) 00548 || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3)) 00549 || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4)) 00550 || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2)) 00551 || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7)) 00552 || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3))); 00553 00554 val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET); 00555 if (val < 0) 00556 perror_with_name (objfile_name (objfile)); 00557 00558 /* Size the symbol table. */ 00559 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) 00560 init_psymbol_list (objfile, DBX_SYMCOUNT (objfile)); 00561 00562 symbol_size = DBX_SYMBOL_SIZE (objfile); 00563 symbol_table_offset = DBX_SYMTAB_OFFSET (objfile); 00564 00565 free_pending_blocks (); 00566 back_to = make_cleanup (really_free_pendings, 0); 00567 00568 init_minimal_symbol_collection (); 00569 make_cleanup_discard_minimal_symbols (); 00570 00571 /* Read stabs data from executable file and define symbols. */ 00572 00573 read_dbx_symtab (objfile); 00574 00575 /* Add the dynamic symbols. */ 00576 00577 read_dbx_dynamic_symtab (objfile); 00578 00579 /* Install any minimal symbols that have been collected as the current 00580 minimal symbols for this objfile. */ 00581 00582 install_minimal_symbols (objfile); 00583 00584 do_cleanups (back_to); 00585 } 00586 00587 /* Initialize anything that needs initializing when a completely new 00588 symbol file is specified (not just adding some symbols from another 00589 file, e.g. a shared library). */ 00590 00591 static void 00592 dbx_new_init (struct objfile *ignore) 00593 { 00594 stabsread_new_init (); 00595 buildsym_new_init (); 00596 init_header_files (); 00597 } 00598 00599 00600 /* dbx_symfile_init () 00601 is the dbx-specific initialization routine for reading symbols. 00602 It is passed a struct objfile which contains, among other things, 00603 the BFD for the file whose symbols are being read, and a slot for a pointer 00604 to "private data" which we fill with goodies. 00605 00606 We read the string table into malloc'd space and stash a pointer to it. 00607 00608 Since BFD doesn't know how to read debug symbols in a format-independent 00609 way (and may never do so...), we have to do it ourselves. We will never 00610 be called unless this is an a.out (or very similar) file. 00611 FIXME, there should be a cleaner peephole into the BFD environment here. */ 00612 00613 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */ 00614 00615 static void 00616 dbx_symfile_init (struct objfile *objfile) 00617 { 00618 int val; 00619 bfd *sym_bfd = objfile->obfd; 00620 char *name = bfd_get_filename (sym_bfd); 00621 asection *text_sect; 00622 unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE]; 00623 struct dbx_symfile_info *dbx; 00624 00625 /* Allocate struct to keep track of the symfile. */ 00626 dbx = XCNEW (struct dbx_symfile_info); 00627 set_objfile_data (objfile, dbx_objfile_data_key, dbx); 00628 00629 DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text"); 00630 DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data"); 00631 DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss"); 00632 00633 /* FIXME POKING INSIDE BFD DATA STRUCTURES. */ 00634 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd)) 00635 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd)) 00636 00637 /* FIXME POKING INSIDE BFD DATA STRUCTURES. */ 00638 00639 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL; 00640 00641 text_sect = bfd_get_section_by_name (sym_bfd, ".text"); 00642 if (!text_sect) 00643 error (_("Can't find .text section in symbol file")); 00644 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); 00645 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); 00646 00647 DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd); 00648 DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd); 00649 DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET; 00650 00651 /* Read the string table and stash it away in the objfile_obstack. 00652 When we blow away the objfile the string table goes away as well. 00653 Note that gdb used to use the results of attempting to malloc the 00654 string table, based on the size it read, as a form of sanity check 00655 for botched byte swapping, on the theory that a byte swapped string 00656 table size would be so totally bogus that the malloc would fail. Now 00657 that we put in on the objfile_obstack, we can't do this since gdb gets 00658 a fatal error (out of virtual memory) if the size is bogus. We can 00659 however at least check to see if the size is less than the size of 00660 the size field itself, or larger than the size of the entire file. 00661 Note that all valid string tables have a size greater than zero, since 00662 the bytes used to hold the size are included in the count. */ 00663 00664 if (STRING_TABLE_OFFSET == 0) 00665 { 00666 /* It appears that with the existing bfd code, STRING_TABLE_OFFSET 00667 will never be zero, even when there is no string table. This 00668 would appear to be a bug in bfd. */ 00669 DBX_STRINGTAB_SIZE (objfile) = 0; 00670 DBX_STRINGTAB (objfile) = NULL; 00671 } 00672 else 00673 { 00674 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET); 00675 if (val < 0) 00676 perror_with_name (name); 00677 00678 memset (size_temp, 0, sizeof (size_temp)); 00679 val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd); 00680 if (val < 0) 00681 { 00682 perror_with_name (name); 00683 } 00684 else if (val == 0) 00685 { 00686 /* With the existing bfd code, STRING_TABLE_OFFSET will be set to 00687 EOF if there is no string table, and attempting to read the size 00688 from EOF will read zero bytes. */ 00689 DBX_STRINGTAB_SIZE (objfile) = 0; 00690 DBX_STRINGTAB (objfile) = NULL; 00691 } 00692 else 00693 { 00694 /* Read some data that would appear to be the string table size. 00695 If there really is a string table, then it is probably the right 00696 size. Byteswap if necessary and validate the size. Note that 00697 the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some 00698 random data that happened to be at STRING_TABLE_OFFSET, because 00699 bfd can't tell us there is no string table, the sanity checks may 00700 or may not catch this. */ 00701 DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp); 00702 00703 if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp) 00704 || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd)) 00705 error (_("ridiculous string table size (%d bytes)."), 00706 DBX_STRINGTAB_SIZE (objfile)); 00707 00708 DBX_STRINGTAB (objfile) = 00709 (char *) obstack_alloc (&objfile->objfile_obstack, 00710 DBX_STRINGTAB_SIZE (objfile)); 00711 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile)); 00712 00713 /* Now read in the string table in one big gulp. */ 00714 00715 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET); 00716 if (val < 0) 00717 perror_with_name (name); 00718 val = bfd_bread (DBX_STRINGTAB (objfile), 00719 DBX_STRINGTAB_SIZE (objfile), 00720 sym_bfd); 00721 if (val != DBX_STRINGTAB_SIZE (objfile)) 00722 perror_with_name (name); 00723 } 00724 } 00725 } 00726 00727 /* Perform any local cleanups required when we are done with a particular 00728 objfile. I.E, we are in the process of discarding all symbol information 00729 for an objfile, freeing up all memory held for it, and unlinking the 00730 objfile struct from the global list of known objfiles. */ 00731 00732 static void 00733 dbx_symfile_finish (struct objfile *objfile) 00734 { 00735 free_header_files (); 00736 } 00737 00738 static void 00739 dbx_free_symfile_info (struct objfile *objfile, void *arg) 00740 { 00741 struct dbx_symfile_info *dbx = arg; 00742 00743 if (dbx->header_files != NULL) 00744 { 00745 int i = dbx->n_header_files; 00746 struct header_file *hfiles = dbx->header_files; 00747 00748 while (--i >= 0) 00749 { 00750 xfree (hfiles[i].name); 00751 xfree (hfiles[i].vector); 00752 } 00753 xfree (hfiles); 00754 } 00755 00756 xfree (dbx); 00757 } 00758 00759 00760 00761 /* Buffer for reading the symbol table entries. */ 00762 static struct external_nlist symbuf[4096]; 00763 static int symbuf_idx; 00764 static int symbuf_end; 00765 00766 /* Name of last function encountered. Used in Solaris to approximate 00767 object file boundaries. */ 00768 static char *last_function_name; 00769 00770 /* The address in memory of the string table of the object file we are 00771 reading (which might not be the "main" object file, but might be a 00772 shared library or some other dynamically loaded thing). This is 00773 set by read_dbx_symtab when building psymtabs, and by 00774 read_ofile_symtab when building symtabs, and is used only by 00775 next_symbol_text. FIXME: If that is true, we don't need it when 00776 building psymtabs, right? */ 00777 static char *stringtab_global; 00778 00779 /* These variables are used to control fill_symbuf when the stabs 00780 symbols are not contiguous (as may be the case when a COFF file is 00781 linked using --split-by-reloc). */ 00782 static struct stab_section_list *symbuf_sections; 00783 static unsigned int symbuf_left; 00784 static unsigned int symbuf_read; 00785 00786 /* This variable stores a global stabs buffer, if we read stabs into 00787 memory in one chunk in order to process relocations. */ 00788 static bfd_byte *stabs_data; 00789 00790 /* Refill the symbol table input buffer 00791 and set the variables that control fetching entries from it. 00792 Reports an error if no data available. 00793 This function can read past the end of the symbol table 00794 (into the string table) but this does no harm. */ 00795 00796 static void 00797 fill_symbuf (bfd *sym_bfd) 00798 { 00799 unsigned int count; 00800 int nbytes; 00801 00802 if (stabs_data) 00803 { 00804 nbytes = sizeof (symbuf); 00805 if (nbytes > symbuf_left) 00806 nbytes = symbuf_left; 00807 memcpy (symbuf, stabs_data + symbuf_read, nbytes); 00808 } 00809 else if (symbuf_sections == NULL) 00810 { 00811 count = sizeof (symbuf); 00812 nbytes = bfd_bread (symbuf, count, sym_bfd); 00813 } 00814 else 00815 { 00816 if (symbuf_left <= 0) 00817 { 00818 file_ptr filepos = symbuf_sections->section->filepos; 00819 00820 if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0) 00821 perror_with_name (bfd_get_filename (sym_bfd)); 00822 symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section); 00823 symbol_table_offset = filepos - symbuf_read; 00824 symbuf_sections = symbuf_sections->next; 00825 } 00826 00827 count = symbuf_left; 00828 if (count > sizeof (symbuf)) 00829 count = sizeof (symbuf); 00830 nbytes = bfd_bread (symbuf, count, sym_bfd); 00831 } 00832 00833 if (nbytes < 0) 00834 perror_with_name (bfd_get_filename (sym_bfd)); 00835 else if (nbytes == 0) 00836 error (_("Premature end of file reading symbol table")); 00837 symbuf_end = nbytes / symbol_size; 00838 symbuf_idx = 0; 00839 symbuf_left -= nbytes; 00840 symbuf_read += nbytes; 00841 } 00842 00843 static void 00844 stabs_seek (int sym_offset) 00845 { 00846 if (stabs_data) 00847 { 00848 symbuf_read += sym_offset; 00849 symbuf_left -= sym_offset; 00850 } 00851 else 00852 bfd_seek (symfile_bfd, sym_offset, SEEK_CUR); 00853 } 00854 00855 #define INTERNALIZE_SYMBOL(intern, extern, abfd) \ 00856 { \ 00857 (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \ 00858 (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \ 00859 (intern).n_other = 0; \ 00860 (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \ 00861 if (bfd_get_sign_extend_vma (abfd)) \ 00862 (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \ 00863 else \ 00864 (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \ 00865 } 00866 00867 /* Invariant: The symbol pointed to by symbuf_idx is the first one 00868 that hasn't been swapped. Swap the symbol at the same time 00869 that symbuf_idx is incremented. */ 00870 00871 /* dbx allows the text of a symbol name to be continued into the 00872 next symbol name! When such a continuation is encountered 00873 (a \ at the end of the text of a name) 00874 call this function to get the continuation. */ 00875 00876 static char * 00877 dbx_next_symbol_text (struct objfile *objfile) 00878 { 00879 struct internal_nlist nlist; 00880 00881 if (symbuf_idx == symbuf_end) 00882 fill_symbuf (symfile_bfd); 00883 00884 symnum++; 00885 INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd); 00886 OBJSTAT (objfile, n_stabs++); 00887 00888 symbuf_idx++; 00889 00890 return nlist.n_strx + stringtab_global + file_string_table_offset; 00891 } 00892 00893 /* Initialize the list of bincls to contain none and have some 00894 allocated. */ 00895 00896 static void 00897 init_bincl_list (int number, struct objfile *objfile) 00898 { 00899 bincls_allocated = number; 00900 next_bincl = bincl_list = (struct header_file_location *) 00901 xmalloc (bincls_allocated * sizeof (struct header_file_location)); 00902 } 00903 00904 /* Add a bincl to the list. */ 00905 00906 static void 00907 add_bincl_to_list (struct partial_symtab *pst, char *name, int instance) 00908 { 00909 if (next_bincl >= bincl_list + bincls_allocated) 00910 { 00911 int offset = next_bincl - bincl_list; 00912 00913 bincls_allocated *= 2; 00914 bincl_list = (struct header_file_location *) 00915 xrealloc ((char *) bincl_list, 00916 bincls_allocated * sizeof (struct header_file_location)); 00917 next_bincl = bincl_list + offset; 00918 } 00919 next_bincl->pst = pst; 00920 next_bincl->instance = instance; 00921 next_bincl++->name = name; 00922 } 00923 00924 /* Given a name, value pair, find the corresponding 00925 bincl in the list. Return the partial symtab associated 00926 with that header_file_location. */ 00927 00928 static struct partial_symtab * 00929 find_corresponding_bincl_psymtab (char *name, int instance) 00930 { 00931 struct header_file_location *bincl; 00932 00933 for (bincl = bincl_list; bincl < next_bincl; bincl++) 00934 if (bincl->instance == instance 00935 && strcmp (name, bincl->name) == 0) 00936 return bincl->pst; 00937 00938 repeated_header_complaint (name, symnum); 00939 return (struct partial_symtab *) 0; 00940 } 00941 00942 /* Free the storage allocated for the bincl list. */ 00943 00944 static void 00945 free_bincl_list (struct objfile *objfile) 00946 { 00947 xfree (bincl_list); 00948 bincls_allocated = 0; 00949 } 00950 00951 static void 00952 do_free_bincl_list_cleanup (void *objfile) 00953 { 00954 free_bincl_list (objfile); 00955 } 00956 00957 static struct cleanup * 00958 make_cleanup_free_bincl_list (struct objfile *objfile) 00959 { 00960 return make_cleanup (do_free_bincl_list_cleanup, objfile); 00961 } 00962 00963 /* Set namestring based on nlist. If the string table index is invalid, 00964 give a fake name, and print a single error message per symbol file read, 00965 rather than abort the symbol reading or flood the user with messages. */ 00966 00967 static char * 00968 set_namestring (struct objfile *objfile, const struct internal_nlist *nlist) 00969 { 00970 char *namestring; 00971 00972 if (nlist->n_strx + file_string_table_offset 00973 >= DBX_STRINGTAB_SIZE (objfile) 00974 || nlist->n_strx + file_string_table_offset < nlist->n_strx) 00975 { 00976 complaint (&symfile_complaints, 00977 _("bad string table offset in symbol %d"), 00978 symnum); 00979 namestring = "<bad string table offset>"; 00980 } 00981 else 00982 namestring = (nlist->n_strx + file_string_table_offset 00983 + DBX_STRINGTAB (objfile)); 00984 return namestring; 00985 } 00986 00987 /* Scan a SunOs dynamic symbol table for symbols of interest and 00988 add them to the minimal symbol table. */ 00989 00990 static void 00991 read_dbx_dynamic_symtab (struct objfile *objfile) 00992 { 00993 bfd *abfd = objfile->obfd; 00994 struct cleanup *back_to; 00995 int counter; 00996 long dynsym_size; 00997 long dynsym_count; 00998 asymbol **dynsyms; 00999 asymbol **symptr; 01000 arelent **relptr; 01001 long dynrel_size; 01002 long dynrel_count; 01003 arelent **dynrels; 01004 CORE_ADDR sym_value; 01005 const char *name; 01006 01007 /* Check that the symbol file has dynamic symbols that we know about. 01008 bfd_arch_unknown can happen if we are reading a sun3 symbol file 01009 on a sun4 host (and vice versa) and bfd is not configured 01010 --with-target=all. This would trigger an assertion in bfd/sunos.c, 01011 so we ignore the dynamic symbols in this case. */ 01012 if (bfd_get_flavour (abfd) != bfd_target_aout_flavour 01013 || (bfd_get_file_flags (abfd) & DYNAMIC) == 0 01014 || bfd_get_arch (abfd) == bfd_arch_unknown) 01015 return; 01016 01017 dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd); 01018 if (dynsym_size < 0) 01019 return; 01020 01021 dynsyms = (asymbol **) xmalloc (dynsym_size); 01022 back_to = make_cleanup (xfree, dynsyms); 01023 01024 dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms); 01025 if (dynsym_count < 0) 01026 { 01027 do_cleanups (back_to); 01028 return; 01029 } 01030 01031 /* Enter dynamic symbols into the minimal symbol table 01032 if this is a stripped executable. */ 01033 if (bfd_get_symcount (abfd) <= 0) 01034 { 01035 symptr = dynsyms; 01036 for (counter = 0; counter < dynsym_count; counter++, symptr++) 01037 { 01038 asymbol *sym = *symptr; 01039 asection *sec; 01040 int type; 01041 01042 sec = bfd_get_section (sym); 01043 01044 /* BFD symbols are section relative. */ 01045 sym_value = sym->value + sec->vma; 01046 01047 if (bfd_get_section_flags (abfd, sec) & SEC_CODE) 01048 { 01049 sym_value += ANOFFSET (objfile->section_offsets, 01050 SECT_OFF_TEXT (objfile)); 01051 type = N_TEXT; 01052 } 01053 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA) 01054 { 01055 sym_value += ANOFFSET (objfile->section_offsets, 01056 SECT_OFF_DATA (objfile)); 01057 type = N_DATA; 01058 } 01059 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) 01060 { 01061 sym_value += ANOFFSET (objfile->section_offsets, 01062 SECT_OFF_BSS (objfile)); 01063 type = N_BSS; 01064 } 01065 else 01066 continue; 01067 01068 if (sym->flags & BSF_GLOBAL) 01069 type |= N_EXT; 01070 01071 record_minimal_symbol (bfd_asymbol_name (sym), sym_value, 01072 type, objfile); 01073 } 01074 } 01075 01076 /* Symbols from shared libraries have a dynamic relocation entry 01077 that points to the associated slot in the procedure linkage table. 01078 We make a mininal symbol table entry with type mst_solib_trampoline 01079 at the address in the procedure linkage table. */ 01080 dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd); 01081 if (dynrel_size < 0) 01082 { 01083 do_cleanups (back_to); 01084 return; 01085 } 01086 01087 dynrels = (arelent **) xmalloc (dynrel_size); 01088 make_cleanup (xfree, dynrels); 01089 01090 dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms); 01091 if (dynrel_count < 0) 01092 { 01093 do_cleanups (back_to); 01094 return; 01095 } 01096 01097 for (counter = 0, relptr = dynrels; 01098 counter < dynrel_count; 01099 counter++, relptr++) 01100 { 01101 arelent *rel = *relptr; 01102 CORE_ADDR address = 01103 rel->address + ANOFFSET (objfile->section_offsets, 01104 SECT_OFF_DATA (objfile)); 01105 01106 switch (bfd_get_arch (abfd)) 01107 { 01108 case bfd_arch_sparc: 01109 if (rel->howto->type != RELOC_JMP_SLOT) 01110 continue; 01111 break; 01112 case bfd_arch_m68k: 01113 /* `16' is the type BFD produces for a jump table relocation. */ 01114 if (rel->howto->type != 16) 01115 continue; 01116 01117 /* Adjust address in the jump table to point to 01118 the start of the bsr instruction. */ 01119 address -= 2; 01120 break; 01121 default: 01122 continue; 01123 } 01124 01125 name = bfd_asymbol_name (*rel->sym_ptr_ptr); 01126 prim_record_minimal_symbol (name, address, mst_solib_trampoline, 01127 objfile); 01128 } 01129 01130 do_cleanups (back_to); 01131 } 01132 01133 static CORE_ADDR 01134 find_stab_function_addr (char *namestring, const char *filename, 01135 struct objfile *objfile) 01136 { 01137 struct minimal_symbol *msym; 01138 char *p; 01139 int n; 01140 01141 p = strchr (namestring, ':'); 01142 if (p == NULL) 01143 p = namestring; 01144 n = p - namestring; 01145 p = alloca (n + 2); 01146 strncpy (p, namestring, n); 01147 p[n] = 0; 01148 01149 msym = lookup_minimal_symbol (p, filename, objfile); 01150 if (msym == NULL) 01151 { 01152 /* Sun Fortran appends an underscore to the minimal symbol name, 01153 try again with an appended underscore if the minimal symbol 01154 was not found. */ 01155 p[n] = '_'; 01156 p[n + 1] = 0; 01157 msym = lookup_minimal_symbol (p, filename, objfile); 01158 } 01159 01160 if (msym == NULL && filename != NULL) 01161 { 01162 /* Try again without the filename. */ 01163 p[n] = 0; 01164 msym = lookup_minimal_symbol (p, NULL, objfile); 01165 } 01166 if (msym == NULL && filename != NULL) 01167 { 01168 /* And try again for Sun Fortran, but without the filename. */ 01169 p[n] = '_'; 01170 p[n + 1] = 0; 01171 msym = lookup_minimal_symbol (p, NULL, objfile); 01172 } 01173 01174 return msym == NULL ? 0 : SYMBOL_VALUE_ADDRESS (msym); 01175 } 01176 01177 static void 01178 function_outside_compilation_unit_complaint (const char *arg1) 01179 { 01180 complaint (&symfile_complaints, 01181 _("function `%s' appears to be defined " 01182 "outside of all compilation units"), 01183 arg1); 01184 } 01185 01186 /* Setup partial_symtab's describing each source file for which 01187 debugging information is available. */ 01188 01189 static void 01190 read_dbx_symtab (struct objfile *objfile) 01191 { 01192 struct gdbarch *gdbarch = get_objfile_arch (objfile); 01193 struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch. */ 01194 struct internal_nlist nlist; 01195 CORE_ADDR text_addr; 01196 int text_size; 01197 char *sym_name; 01198 int sym_len; 01199 01200 char *namestring; 01201 int nsl; 01202 int past_first_source_file = 0; 01203 CORE_ADDR last_o_file_start = 0; 01204 CORE_ADDR last_function_start = 0; 01205 struct cleanup *back_to; 01206 bfd *abfd; 01207 int textlow_not_set; 01208 int data_sect_index; 01209 01210 /* Current partial symtab. */ 01211 struct partial_symtab *pst; 01212 01213 /* List of current psymtab's include files. */ 01214 const char **psymtab_include_list; 01215 int includes_allocated; 01216 int includes_used; 01217 01218 /* Index within current psymtab dependency list. */ 01219 struct partial_symtab **dependency_list; 01220 int dependencies_used, dependencies_allocated; 01221 01222 text_addr = DBX_TEXT_ADDR (objfile); 01223 text_size = DBX_TEXT_SIZE (objfile); 01224 01225 /* FIXME. We probably want to change stringtab_global rather than add this 01226 while processing every symbol entry. FIXME. */ 01227 file_string_table_offset = 0; 01228 next_file_string_table_offset = 0; 01229 01230 stringtab_global = DBX_STRINGTAB (objfile); 01231 01232 pst = (struct partial_symtab *) 0; 01233 01234 includes_allocated = 30; 01235 includes_used = 0; 01236 psymtab_include_list = (const char **) alloca (includes_allocated * 01237 sizeof (const char *)); 01238 01239 dependencies_allocated = 30; 01240 dependencies_used = 0; 01241 dependency_list = 01242 (struct partial_symtab **) alloca (dependencies_allocated * 01243 sizeof (struct partial_symtab *)); 01244 01245 /* Init bincl list */ 01246 init_bincl_list (20, objfile); 01247 back_to = make_cleanup_free_bincl_list (objfile); 01248 01249 set_last_source_file (NULL); 01250 01251 lowest_text_address = (CORE_ADDR) -1; 01252 01253 symfile_bfd = objfile->obfd; /* For next_text_symbol. */ 01254 abfd = objfile->obfd; 01255 symbuf_end = symbuf_idx = 0; 01256 next_symbol_text_func = dbx_next_symbol_text; 01257 textlow_not_set = 1; 01258 has_line_numbers = 0; 01259 01260 /* FIXME: jimb/2003-09-12: We don't apply the right section's offset 01261 to global and static variables. The stab for a global or static 01262 variable doesn't give us any indication of which section it's in, 01263 so we can't tell immediately which offset in 01264 objfile->section_offsets we should apply to the variable's 01265 address. 01266 01267 We could certainly find out which section contains the variable 01268 by looking up the variable's unrelocated address with 01269 find_pc_section, but that would be expensive; this is the 01270 function that constructs the partial symbol tables by examining 01271 every symbol in the entire executable, and it's 01272 performance-critical. So that expense would not be welcome. I'm 01273 not sure what to do about this at the moment. 01274 01275 What we have done for years is to simply assume that the .data 01276 section's offset is appropriate for all global and static 01277 variables. Recently, this was expanded to fall back to the .bss 01278 section's offset if there is no .data section, and then to the 01279 .rodata section's offset. */ 01280 data_sect_index = objfile->sect_index_data; 01281 if (data_sect_index == -1) 01282 data_sect_index = SECT_OFF_BSS (objfile); 01283 if (data_sect_index == -1) 01284 data_sect_index = SECT_OFF_RODATA (objfile); 01285 01286 /* If data_sect_index is still -1, that's okay. It's perfectly fine 01287 for the file to have no .data, no .bss, and no .text at all, if 01288 it also has no global or static variables. If it does, we will 01289 get an internal error from an ANOFFSET macro below when we try to 01290 use data_sect_index. */ 01291 01292 for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++) 01293 { 01294 /* Get the symbol for this run and pull out some info. */ 01295 QUIT; /* Allow this to be interruptable. */ 01296 if (symbuf_idx == symbuf_end) 01297 fill_symbuf (abfd); 01298 bufp = &symbuf[symbuf_idx++]; 01299 01300 /* 01301 * Special case to speed up readin. 01302 */ 01303 if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE) 01304 { 01305 has_line_numbers = 1; 01306 continue; 01307 } 01308 01309 INTERNALIZE_SYMBOL (nlist, bufp, abfd); 01310 OBJSTAT (objfile, n_stabs++); 01311 01312 /* Ok. There is a lot of code duplicated in the rest of this 01313 switch statement (for efficiency reasons). Since I don't 01314 like duplicating code, I will do my penance here, and 01315 describe the code which is duplicated: 01316 01317 *) The assignment to namestring. 01318 *) The call to strchr. 01319 *) The addition of a partial symbol the two partial 01320 symbol lists. This last is a large section of code, so 01321 I've imbedded it in the following macro. */ 01322 01323 switch (nlist.n_type) 01324 { 01325 /* 01326 * Standard, external, non-debugger, symbols 01327 */ 01328 01329 case N_TEXT | N_EXT: 01330 case N_NBTEXT | N_EXT: 01331 nlist.n_value += ANOFFSET (objfile->section_offsets, 01332 SECT_OFF_TEXT (objfile)); 01333 goto record_it; 01334 01335 case N_DATA | N_EXT: 01336 case N_NBDATA | N_EXT: 01337 nlist.n_value += ANOFFSET (objfile->section_offsets, 01338 SECT_OFF_DATA (objfile)); 01339 goto record_it; 01340 01341 case N_BSS: 01342 case N_BSS | N_EXT: 01343 case N_NBBSS | N_EXT: 01344 case N_SETV | N_EXT: /* FIXME, is this in BSS? */ 01345 nlist.n_value += ANOFFSET (objfile->section_offsets, 01346 SECT_OFF_BSS (objfile)); 01347 goto record_it; 01348 01349 case N_ABS | N_EXT: 01350 record_it: 01351 namestring = set_namestring (objfile, &nlist); 01352 01353 bss_ext_symbol: 01354 record_minimal_symbol (namestring, nlist.n_value, 01355 nlist.n_type, objfile); /* Always */ 01356 continue; 01357 01358 /* Standard, local, non-debugger, symbols. */ 01359 01360 case N_NBTEXT: 01361 01362 /* We need to be able to deal with both N_FN or N_TEXT, 01363 because we have no way of knowing whether the sys-supplied ld 01364 or GNU ld was used to make the executable. Sequents throw 01365 in another wrinkle -- they renumbered N_FN. */ 01366 01367 case N_FN: 01368 case N_FN_SEQ: 01369 case N_TEXT: 01370 nlist.n_value += ANOFFSET (objfile->section_offsets, 01371 SECT_OFF_TEXT (objfile)); 01372 namestring = set_namestring (objfile, &nlist); 01373 01374 if ((namestring[0] == '-' && namestring[1] == 'l') 01375 || (namestring[(nsl = strlen (namestring)) - 1] == 'o' 01376 && namestring[nsl - 2] == '.')) 01377 { 01378 if (past_first_source_file && pst 01379 /* The gould NP1 uses low values for .o and -l symbols 01380 which are not the address. */ 01381 && nlist.n_value >= pst->textlow) 01382 { 01383 end_psymtab (objfile, pst, psymtab_include_list, 01384 includes_used, symnum * symbol_size, 01385 nlist.n_value > pst->texthigh 01386 ? nlist.n_value : pst->texthigh, 01387 dependency_list, dependencies_used, 01388 textlow_not_set); 01389 pst = (struct partial_symtab *) 0; 01390 includes_used = 0; 01391 dependencies_used = 0; 01392 has_line_numbers = 0; 01393 } 01394 else 01395 past_first_source_file = 1; 01396 last_o_file_start = nlist.n_value; 01397 } 01398 else 01399 goto record_it; 01400 continue; 01401 01402 case N_DATA: 01403 nlist.n_value += ANOFFSET (objfile->section_offsets, 01404 SECT_OFF_DATA (objfile)); 01405 goto record_it; 01406 01407 case N_UNDF | N_EXT: 01408 /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol. 01409 We used to rely on the target to tell us whether it knows 01410 where the symbol has been relocated to, but none of the 01411 target implementations actually provided that operation. 01412 So we just ignore the symbol, the same way we would do if 01413 we had a target-side symbol lookup which returned no match. 01414 01415 All other symbols (with nlist.n_value == 0), are really 01416 undefined, and so we ignore them too. */ 01417 continue; 01418 01419 case N_UNDF: 01420 if (processing_acc_compilation && nlist.n_strx == 1) 01421 { 01422 /* Deal with relative offsets in the string table 01423 used in ELF+STAB under Solaris. If we want to use the 01424 n_strx field, which contains the name of the file, 01425 we must adjust file_string_table_offset *before* calling 01426 set_namestring(). */ 01427 past_first_source_file = 1; 01428 file_string_table_offset = next_file_string_table_offset; 01429 next_file_string_table_offset = 01430 file_string_table_offset + nlist.n_value; 01431 if (next_file_string_table_offset < file_string_table_offset) 01432 error (_("string table offset backs up at %d"), symnum); 01433 /* FIXME -- replace error() with complaint. */ 01434 continue; 01435 } 01436 continue; 01437 01438 /* Lots of symbol types we can just ignore. */ 01439 01440 case N_ABS: 01441 case N_NBDATA: 01442 case N_NBBSS: 01443 continue; 01444 01445 /* Keep going . . . */ 01446 01447 /* 01448 * Special symbol types for GNU 01449 */ 01450 case N_INDR: 01451 case N_INDR | N_EXT: 01452 case N_SETA: 01453 case N_SETA | N_EXT: 01454 case N_SETT: 01455 case N_SETT | N_EXT: 01456 case N_SETD: 01457 case N_SETD | N_EXT: 01458 case N_SETB: 01459 case N_SETB | N_EXT: 01460 case N_SETV: 01461 continue; 01462 01463 /* 01464 * Debugger symbols 01465 */ 01466 01467 case N_SO: 01468 { 01469 CORE_ADDR valu; 01470 static int prev_so_symnum = -10; 01471 static int first_so_symnum; 01472 const char *p; 01473 static char *dirname_nso; 01474 int prev_textlow_not_set; 01475 01476 valu = nlist.n_value + ANOFFSET (objfile->section_offsets, 01477 SECT_OFF_TEXT (objfile)); 01478 01479 prev_textlow_not_set = textlow_not_set; 01480 01481 /* A zero value is probably an indication for the SunPRO 3.0 01482 compiler. end_psymtab explicitly tests for zero, so 01483 don't relocate it. */ 01484 01485 if (nlist.n_value == 0 01486 && gdbarch_sofun_address_maybe_missing (gdbarch)) 01487 { 01488 textlow_not_set = 1; 01489 valu = 0; 01490 } 01491 else 01492 textlow_not_set = 0; 01493 01494 past_first_source_file = 1; 01495 01496 if (prev_so_symnum != symnum - 1) 01497 { /* Here if prev stab wasn't N_SO. */ 01498 first_so_symnum = symnum; 01499 01500 if (pst) 01501 { 01502 end_psymtab (objfile, pst, psymtab_include_list, 01503 includes_used, symnum * symbol_size, 01504 valu > pst->texthigh ? valu : pst->texthigh, 01505 dependency_list, dependencies_used, 01506 prev_textlow_not_set); 01507 pst = (struct partial_symtab *) 0; 01508 includes_used = 0; 01509 dependencies_used = 0; 01510 has_line_numbers = 0; 01511 } 01512 } 01513 01514 prev_so_symnum = symnum; 01515 01516 /* End the current partial symtab and start a new one. */ 01517 01518 namestring = set_namestring (objfile, &nlist); 01519 01520 /* Null name means end of .o file. Don't start a new one. */ 01521 if (*namestring == '\000') 01522 continue; 01523 01524 /* Some compilers (including gcc) emit a pair of initial N_SOs. 01525 The first one is a directory name; the second the file name. 01526 If pst exists, is empty, and has a filename ending in '/', 01527 we assume the previous N_SO was a directory name. */ 01528 01529 p = lbasename (namestring); 01530 if (p != namestring && *p == '\000') 01531 { 01532 /* Save the directory name SOs locally, then save it into 01533 the psymtab when it's created below. */ 01534 dirname_nso = namestring; 01535 continue; 01536 } 01537 01538 /* Some other compilers (C++ ones in particular) emit useless 01539 SOs for non-existant .c files. We ignore all subsequent SOs 01540 that immediately follow the first. */ 01541 01542 if (!pst) 01543 { 01544 pst = start_psymtab (objfile, 01545 namestring, valu, 01546 first_so_symnum * symbol_size, 01547 objfile->global_psymbols.next, 01548 objfile->static_psymbols.next); 01549 pst->dirname = dirname_nso; 01550 dirname_nso = NULL; 01551 } 01552 continue; 01553 } 01554 01555 case N_BINCL: 01556 { 01557 enum language tmp_language; 01558 01559 /* Add this bincl to the bincl_list for future EXCLs. No 01560 need to save the string; it'll be around until 01561 read_dbx_symtab function returns. */ 01562 01563 namestring = set_namestring (objfile, &nlist); 01564 tmp_language = deduce_language_from_filename (namestring); 01565 01566 /* Only change the psymtab's language if we've learned 01567 something useful (eg. tmp_language is not language_unknown). 01568 In addition, to match what start_subfile does, never change 01569 from C++ to C. */ 01570 if (tmp_language != language_unknown 01571 && (tmp_language != language_c 01572 || psymtab_language != language_cplus)) 01573 psymtab_language = tmp_language; 01574 01575 if (pst == NULL) 01576 { 01577 /* FIXME: we should not get here without a PST to work on. 01578 Attempt to recover. */ 01579 complaint (&symfile_complaints, 01580 _("N_BINCL %s not in entries for " 01581 "any file, at symtab pos %d"), 01582 namestring, symnum); 01583 continue; 01584 } 01585 add_bincl_to_list (pst, namestring, nlist.n_value); 01586 01587 /* Mark down an include file in the current psymtab. */ 01588 01589 goto record_include_file; 01590 } 01591 01592 case N_SOL: 01593 { 01594 enum language tmp_language; 01595 01596 /* Mark down an include file in the current psymtab. */ 01597 namestring = set_namestring (objfile, &nlist); 01598 tmp_language = deduce_language_from_filename (namestring); 01599 01600 /* Only change the psymtab's language if we've learned 01601 something useful (eg. tmp_language is not language_unknown). 01602 In addition, to match what start_subfile does, never change 01603 from C++ to C. */ 01604 if (tmp_language != language_unknown 01605 && (tmp_language != language_c 01606 || psymtab_language != language_cplus)) 01607 psymtab_language = tmp_language; 01608 01609 /* In C++, one may expect the same filename to come round many 01610 times, when code is coming alternately from the main file 01611 and from inline functions in other files. So I check to see 01612 if this is a file we've seen before -- either the main 01613 source file, or a previously included file. 01614 01615 This seems to be a lot of time to be spending on N_SOL, but 01616 things like "break c-exp.y:435" need to work (I 01617 suppose the psymtab_include_list could be hashed or put 01618 in a binary tree, if profiling shows this is a major hog). */ 01619 if (pst && filename_cmp (namestring, pst->filename) == 0) 01620 continue; 01621 { 01622 int i; 01623 01624 for (i = 0; i < includes_used; i++) 01625 if (filename_cmp (namestring, psymtab_include_list[i]) == 0) 01626 { 01627 i = -1; 01628 break; 01629 } 01630 if (i == -1) 01631 continue; 01632 } 01633 01634 record_include_file: 01635 01636 psymtab_include_list[includes_used++] = namestring; 01637 if (includes_used >= includes_allocated) 01638 { 01639 const char **orig = psymtab_include_list; 01640 01641 psymtab_include_list = (const char **) 01642 alloca ((includes_allocated *= 2) * sizeof (const char *)); 01643 memcpy (psymtab_include_list, orig, 01644 includes_used * sizeof (const char *)); 01645 } 01646 continue; 01647 } 01648 case N_LSYM: /* Typedef or automatic variable. */ 01649 case N_STSYM: /* Data seg var -- static. */ 01650 case N_LCSYM: /* BSS " */ 01651 case N_ROSYM: /* Read-only data seg var -- static. */ 01652 case N_NBSTS: /* Gould nobase. */ 01653 case N_NBLCS: /* symbols. */ 01654 case N_FUN: 01655 case N_GSYM: /* Global (extern) variable; can be 01656 data or bss (sigh FIXME). */ 01657 01658 /* Following may probably be ignored; I'll leave them here 01659 for now (until I do Pascal and Modula 2 extensions). */ 01660 01661 case N_PC: /* I may or may not need this; I 01662 suspect not. */ 01663 case N_M2C: /* I suspect that I can ignore this here. */ 01664 case N_SCOPE: /* Same. */ 01665 { 01666 char *p; 01667 01668 namestring = set_namestring (objfile, &nlist); 01669 01670 /* See if this is an end of function stab. */ 01671 if (pst && nlist.n_type == N_FUN && *namestring == '\000') 01672 { 01673 CORE_ADDR valu; 01674 01675 /* It's value is the size (in bytes) of the function for 01676 function relative stabs, or the address of the function's 01677 end for old style stabs. */ 01678 valu = nlist.n_value + last_function_start; 01679 if (pst->texthigh == 0 || valu > pst->texthigh) 01680 pst->texthigh = valu; 01681 break; 01682 } 01683 01684 p = (char *) strchr (namestring, ':'); 01685 if (!p) 01686 continue; /* Not a debugging symbol. */ 01687 01688 sym_len = 0; 01689 sym_name = NULL; /* pacify "gcc -Werror" */ 01690 if (psymtab_language == language_cplus) 01691 { 01692 char *new_name, *name = xmalloc (p - namestring + 1); 01693 memcpy (name, namestring, p - namestring); 01694 01695 name[p - namestring] = '\0'; 01696 new_name = cp_canonicalize_string (name); 01697 if (new_name != NULL) 01698 { 01699 sym_len = strlen (new_name); 01700 sym_name = obstack_copy0 (&objfile->objfile_obstack, 01701 new_name, sym_len); 01702 xfree (new_name); 01703 } 01704 xfree (name); 01705 } 01706 01707 if (sym_len == 0) 01708 { 01709 sym_name = namestring; 01710 sym_len = p - namestring; 01711 } 01712 01713 /* Main processing section for debugging symbols which 01714 the initial read through the symbol tables needs to worry 01715 about. If we reach this point, the symbol which we are 01716 considering is definitely one we are interested in. 01717 p must also contain the (valid) index into the namestring 01718 which indicates the debugging type symbol. */ 01719 01720 switch (p[1]) 01721 { 01722 case 'S': 01723 nlist.n_value += ANOFFSET (objfile->section_offsets, 01724 data_sect_index); 01725 01726 if (gdbarch_static_transform_name_p (gdbarch)) 01727 gdbarch_static_transform_name (gdbarch, namestring); 01728 01729 add_psymbol_to_list (sym_name, sym_len, 1, 01730 VAR_DOMAIN, LOC_STATIC, 01731 &objfile->static_psymbols, 01732 0, nlist.n_value, 01733 psymtab_language, objfile); 01734 continue; 01735 01736 case 'G': 01737 nlist.n_value += ANOFFSET (objfile->section_offsets, 01738 data_sect_index); 01739 /* The addresses in these entries are reported to be 01740 wrong. See the code that reads 'G's for symtabs. */ 01741 add_psymbol_to_list (sym_name, sym_len, 1, 01742 VAR_DOMAIN, LOC_STATIC, 01743 &objfile->global_psymbols, 01744 0, nlist.n_value, 01745 psymtab_language, objfile); 01746 continue; 01747 01748 case 'T': 01749 /* When a 'T' entry is defining an anonymous enum, it 01750 may have a name which is the empty string, or a 01751 single space. Since they're not really defining a 01752 symbol, those shouldn't go in the partial symbol 01753 table. We do pick up the elements of such enums at 01754 'check_enum:', below. */ 01755 if (p >= namestring + 2 01756 || (p == namestring + 1 01757 && namestring[0] != ' ')) 01758 { 01759 add_psymbol_to_list (sym_name, sym_len, 1, 01760 STRUCT_DOMAIN, LOC_TYPEDEF, 01761 &objfile->static_psymbols, 01762 nlist.n_value, 0, 01763 psymtab_language, objfile); 01764 if (p[2] == 't') 01765 { 01766 /* Also a typedef with the same name. */ 01767 add_psymbol_to_list (sym_name, sym_len, 1, 01768 VAR_DOMAIN, LOC_TYPEDEF, 01769 &objfile->static_psymbols, 01770 nlist.n_value, 0, 01771 psymtab_language, objfile); 01772 p += 1; 01773 } 01774 } 01775 goto check_enum; 01776 01777 case 't': 01778 if (p != namestring) /* a name is there, not just :T... */ 01779 { 01780 add_psymbol_to_list (sym_name, sym_len, 1, 01781 VAR_DOMAIN, LOC_TYPEDEF, 01782 &objfile->static_psymbols, 01783 nlist.n_value, 0, 01784 psymtab_language, objfile); 01785 } 01786 check_enum: 01787 /* If this is an enumerated type, we need to 01788 add all the enum constants to the partial symbol 01789 table. This does not cover enums without names, e.g. 01790 "enum {a, b} c;" in C, but fortunately those are 01791 rare. There is no way for GDB to find those from the 01792 enum type without spending too much time on it. Thus 01793 to solve this problem, the compiler needs to put out the 01794 enum in a nameless type. GCC2 does this. */ 01795 01796 /* We are looking for something of the form 01797 <name> ":" ("t" | "T") [<number> "="] "e" 01798 {<constant> ":" <value> ","} ";". */ 01799 01800 /* Skip over the colon and the 't' or 'T'. */ 01801 p += 2; 01802 /* This type may be given a number. Also, numbers can come 01803 in pairs like (0,26). Skip over it. */ 01804 while ((*p >= '0' && *p <= '9') 01805 || *p == '(' || *p == ',' || *p == ')' 01806 || *p == '=') 01807 p++; 01808 01809 if (*p++ == 'e') 01810 { 01811 /* The aix4 compiler emits extra crud before the members. */ 01812 if (*p == '-') 01813 { 01814 /* Skip over the type (?). */ 01815 while (*p != ':') 01816 p++; 01817 01818 /* Skip over the colon. */ 01819 p++; 01820 } 01821 01822 /* We have found an enumerated type. */ 01823 /* According to comments in read_enum_type 01824 a comma could end it instead of a semicolon. 01825 I don't know where that happens. 01826 Accept either. */ 01827 while (*p && *p != ';' && *p != ',') 01828 { 01829 char *q; 01830 01831 /* Check for and handle cretinous dbx symbol name 01832 continuation! */ 01833 if (*p == '\\' || (*p == '?' && p[1] == '\0')) 01834 p = next_symbol_text (objfile); 01835 01836 /* Point to the character after the name 01837 of the enum constant. */ 01838 for (q = p; *q && *q != ':'; q++) 01839 ; 01840 /* Note that the value doesn't matter for 01841 enum constants in psymtabs, just in symtabs. */ 01842 add_psymbol_to_list (p, q - p, 1, 01843 VAR_DOMAIN, LOC_CONST, 01844 &objfile->static_psymbols, 0, 01845 0, psymtab_language, objfile); 01846 /* Point past the name. */ 01847 p = q; 01848 /* Skip over the value. */ 01849 while (*p && *p != ',') 01850 p++; 01851 /* Advance past the comma. */ 01852 if (*p) 01853 p++; 01854 } 01855 } 01856 continue; 01857 01858 case 'c': 01859 /* Constant, e.g. from "const" in Pascal. */ 01860 add_psymbol_to_list (sym_name, sym_len, 1, 01861 VAR_DOMAIN, LOC_CONST, 01862 &objfile->static_psymbols, nlist.n_value, 01863 0, psymtab_language, objfile); 01864 continue; 01865 01866 case 'f': 01867 if (! pst) 01868 { 01869 int name_len = p - namestring; 01870 char *name = xmalloc (name_len + 1); 01871 01872 memcpy (name, namestring, name_len); 01873 name[name_len] = '\0'; 01874 function_outside_compilation_unit_complaint (name); 01875 xfree (name); 01876 } 01877 nlist.n_value += ANOFFSET (objfile->section_offsets, 01878 SECT_OFF_TEXT (objfile)); 01879 /* Kludges for ELF/STABS with Sun ACC. */ 01880 last_function_name = namestring; 01881 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit 01882 value for the bottom of the text seg in those cases. */ 01883 if (nlist.n_value == ANOFFSET (objfile->section_offsets, 01884 SECT_OFF_TEXT (objfile)) 01885 && gdbarch_sofun_address_maybe_missing (gdbarch)) 01886 { 01887 CORE_ADDR minsym_valu = 01888 find_stab_function_addr (namestring, 01889 pst ? pst->filename : NULL, 01890 objfile); 01891 01892 /* find_stab_function_addr will return 0 if the minimal 01893 symbol wasn't found. (Unfortunately, this might also 01894 be a valid address.) Anyway, if it *does* return 0, 01895 it is likely that the value was set correctly to begin 01896 with... */ 01897 if (minsym_valu != 0) 01898 nlist.n_value = minsym_valu; 01899 } 01900 if (pst && textlow_not_set 01901 && gdbarch_sofun_address_maybe_missing (gdbarch)) 01902 { 01903 pst->textlow = nlist.n_value; 01904 textlow_not_set = 0; 01905 } 01906 /* End kludge. */ 01907 01908 /* Keep track of the start of the last function so we 01909 can handle end of function symbols. */ 01910 last_function_start = nlist.n_value; 01911 01912 /* In reordered executables this function may lie outside 01913 the bounds created by N_SO symbols. If that's the case 01914 use the address of this function as the low bound for 01915 the partial symbol table. */ 01916 if (pst 01917 && (textlow_not_set 01918 || (nlist.n_value < pst->textlow 01919 && (nlist.n_value 01920 != ANOFFSET (objfile->section_offsets, 01921 SECT_OFF_TEXT (objfile)))))) 01922 { 01923 pst->textlow = nlist.n_value; 01924 textlow_not_set = 0; 01925 } 01926 add_psymbol_to_list (sym_name, sym_len, 1, 01927 VAR_DOMAIN, LOC_BLOCK, 01928 &objfile->static_psymbols, 01929 0, nlist.n_value, 01930 psymtab_language, objfile); 01931 continue; 01932 01933 /* Global functions were ignored here, but now they 01934 are put into the global psymtab like one would expect. 01935 They're also in the minimal symbol table. */ 01936 case 'F': 01937 if (! pst) 01938 { 01939 int name_len = p - namestring; 01940 char *name = xmalloc (name_len + 1); 01941 01942 memcpy (name, namestring, name_len); 01943 name[name_len] = '\0'; 01944 function_outside_compilation_unit_complaint (name); 01945 xfree (name); 01946 } 01947 nlist.n_value += ANOFFSET (objfile->section_offsets, 01948 SECT_OFF_TEXT (objfile)); 01949 /* Kludges for ELF/STABS with Sun ACC. */ 01950 last_function_name = namestring; 01951 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit 01952 value for the bottom of the text seg in those cases. */ 01953 if (nlist.n_value == ANOFFSET (objfile->section_offsets, 01954 SECT_OFF_TEXT (objfile)) 01955 && gdbarch_sofun_address_maybe_missing (gdbarch)) 01956 { 01957 CORE_ADDR minsym_valu = 01958 find_stab_function_addr (namestring, 01959 pst ? pst->filename : NULL, 01960 objfile); 01961 01962 /* find_stab_function_addr will return 0 if the minimal 01963 symbol wasn't found. (Unfortunately, this might also 01964 be a valid address.) Anyway, if it *does* return 0, 01965 it is likely that the value was set correctly to begin 01966 with... */ 01967 if (minsym_valu != 0) 01968 nlist.n_value = minsym_valu; 01969 } 01970 if (pst && textlow_not_set 01971 && gdbarch_sofun_address_maybe_missing (gdbarch)) 01972 { 01973 pst->textlow = nlist.n_value; 01974 textlow_not_set = 0; 01975 } 01976 /* End kludge. */ 01977 01978 /* Keep track of the start of the last function so we 01979 can handle end of function symbols. */ 01980 last_function_start = nlist.n_value; 01981 01982 /* In reordered executables this function may lie outside 01983 the bounds created by N_SO symbols. If that's the case 01984 use the address of this function as the low bound for 01985 the partial symbol table. */ 01986 if (pst 01987 && (textlow_not_set 01988 || (nlist.n_value < pst->textlow 01989 && (nlist.n_value 01990 != ANOFFSET (objfile->section_offsets, 01991 SECT_OFF_TEXT (objfile)))))) 01992 { 01993 pst->textlow = nlist.n_value; 01994 textlow_not_set = 0; 01995 } 01996 add_psymbol_to_list (sym_name, sym_len, 1, 01997 VAR_DOMAIN, LOC_BLOCK, 01998 &objfile->global_psymbols, 01999 0, nlist.n_value, 02000 psymtab_language, objfile); 02001 continue; 02002 02003 /* Two things show up here (hopefully); static symbols of 02004 local scope (static used inside braces) or extensions 02005 of structure symbols. We can ignore both. */ 02006 case 'V': 02007 case '(': 02008 case '0': 02009 case '1': 02010 case '2': 02011 case '3': 02012 case '4': 02013 case '5': 02014 case '6': 02015 case '7': 02016 case '8': 02017 case '9': 02018 case '-': 02019 case '#': /* For symbol identification (used in live ranges). */ 02020 continue; 02021 02022 case ':': 02023 /* It is a C++ nested symbol. We don't need to record it 02024 (I don't think); if we try to look up foo::bar::baz, 02025 then symbols for the symtab containing foo should get 02026 read in, I think. */ 02027 /* Someone says sun cc puts out symbols like 02028 /foo/baz/maclib::/usr/local/bin/maclib, 02029 which would get here with a symbol type of ':'. */ 02030 continue; 02031 02032 default: 02033 /* Unexpected symbol descriptor. The second and subsequent stabs 02034 of a continued stab can show up here. The question is 02035 whether they ever can mimic a normal stab--it would be 02036 nice if not, since we certainly don't want to spend the 02037 time searching to the end of every string looking for 02038 a backslash. */ 02039 02040 complaint (&symfile_complaints, 02041 _("unknown symbol descriptor `%c'"), 02042 p[1]); 02043 02044 /* Ignore it; perhaps it is an extension that we don't 02045 know about. */ 02046 continue; 02047 } 02048 } 02049 02050 case N_EXCL: 02051 02052 namestring = set_namestring (objfile, &nlist); 02053 02054 /* Find the corresponding bincl and mark that psymtab on the 02055 psymtab dependency list. */ 02056 { 02057 struct partial_symtab *needed_pst = 02058 find_corresponding_bincl_psymtab (namestring, nlist.n_value); 02059 02060 /* If this include file was defined earlier in this file, 02061 leave it alone. */ 02062 if (needed_pst == pst) 02063 continue; 02064 02065 if (needed_pst) 02066 { 02067 int i; 02068 int found = 0; 02069 02070 for (i = 0; i < dependencies_used; i++) 02071 if (dependency_list[i] == needed_pst) 02072 { 02073 found = 1; 02074 break; 02075 } 02076 02077 /* If it's already in the list, skip the rest. */ 02078 if (found) 02079 continue; 02080 02081 dependency_list[dependencies_used++] = needed_pst; 02082 if (dependencies_used >= dependencies_allocated) 02083 { 02084 struct partial_symtab **orig = dependency_list; 02085 02086 dependency_list = 02087 (struct partial_symtab **) 02088 alloca ((dependencies_allocated *= 2) 02089 * sizeof (struct partial_symtab *)); 02090 memcpy (dependency_list, orig, 02091 (dependencies_used 02092 * sizeof (struct partial_symtab *))); 02093 #ifdef DEBUG_INFO 02094 fprintf_unfiltered (gdb_stderr, 02095 "Had to reallocate " 02096 "dependency list.\n"); 02097 fprintf_unfiltered (gdb_stderr, 02098 "New dependencies allocated: %d\n", 02099 dependencies_allocated); 02100 #endif 02101 } 02102 } 02103 } 02104 continue; 02105 02106 case N_ENDM: 02107 /* Solaris 2 end of module, finish current partial symbol table. 02108 end_psymtab will set pst->texthigh to the proper value, which 02109 is necessary if a module compiled without debugging info 02110 follows this module. */ 02111 if (pst && gdbarch_sofun_address_maybe_missing (gdbarch)) 02112 { 02113 end_psymtab (objfile, pst, psymtab_include_list, includes_used, 02114 symnum * symbol_size, 02115 (CORE_ADDR) 0, dependency_list, 02116 dependencies_used, textlow_not_set); 02117 pst = (struct partial_symtab *) 0; 02118 includes_used = 0; 02119 dependencies_used = 0; 02120 has_line_numbers = 0; 02121 } 02122 continue; 02123 02124 case N_RBRAC: 02125 #ifdef HANDLE_RBRAC 02126 HANDLE_RBRAC (nlist.n_value); 02127 continue; 02128 #endif 02129 case N_EINCL: 02130 case N_DSLINE: 02131 case N_BSLINE: 02132 case N_SSYM: /* Claim: Structure or union element. 02133 Hopefully, I can ignore this. */ 02134 case N_ENTRY: /* Alternate entry point; can ignore. */ 02135 case N_MAIN: /* Can definitely ignore this. */ 02136 case N_CATCH: /* These are GNU C++ extensions */ 02137 case N_EHDECL: /* that can safely be ignored here. */ 02138 case N_LENG: 02139 case N_BCOMM: 02140 case N_ECOMM: 02141 case N_ECOML: 02142 case N_FNAME: 02143 case N_SLINE: 02144 case N_RSYM: 02145 case N_PSYM: 02146 case N_LBRAC: 02147 case N_NSYMS: /* Ultrix 4.0: symbol count */ 02148 case N_DEFD: /* GNU Modula-2 */ 02149 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */ 02150 02151 case N_OBJ: /* Useless types from Solaris. */ 02152 case N_OPT: 02153 case N_PATCH: 02154 /* These symbols aren't interesting; don't worry about them. */ 02155 continue; 02156 02157 default: 02158 /* If we haven't found it yet, ignore it. It's probably some 02159 new type we don't know about yet. */ 02160 unknown_symtype_complaint (hex_string (nlist.n_type)); 02161 continue; 02162 } 02163 } 02164 02165 /* If there's stuff to be cleaned up, clean it up. */ 02166 if (pst) 02167 { 02168 /* Don't set pst->texthigh lower than it already is. */ 02169 CORE_ADDR text_end = 02170 (lowest_text_address == (CORE_ADDR) -1 02171 ? (text_addr + ANOFFSET (objfile->section_offsets, 02172 SECT_OFF_TEXT (objfile))) 02173 : lowest_text_address) 02174 + text_size; 02175 02176 end_psymtab (objfile, pst, psymtab_include_list, includes_used, 02177 symnum * symbol_size, 02178 text_end > pst->texthigh ? text_end : pst->texthigh, 02179 dependency_list, dependencies_used, textlow_not_set); 02180 } 02181 02182 do_cleanups (back_to); 02183 } 02184 02185 /* Allocate and partially fill a partial symtab. It will be 02186 completely filled at the end of the symbol list. 02187 02188 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR 02189 is the address relative to which its symbols are (incremental) or 0 02190 (normal). */ 02191 02192 static struct partial_symtab * 02193 start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow, 02194 int ldsymoff, struct partial_symbol **global_syms, 02195 struct partial_symbol **static_syms) 02196 { 02197 struct partial_symtab *result = 02198 start_psymtab_common (objfile, objfile->section_offsets, 02199 filename, textlow, global_syms, static_syms); 02200 02201 result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack, 02202 sizeof (struct symloc)); 02203 LDSYMOFF (result) = ldsymoff; 02204 result->read_symtab = dbx_read_symtab; 02205 SYMBOL_SIZE (result) = symbol_size; 02206 SYMBOL_OFFSET (result) = symbol_table_offset; 02207 STRING_OFFSET (result) = string_table_offset; 02208 FILE_STRING_OFFSET (result) = file_string_table_offset; 02209 02210 #ifdef HAVE_ELF 02211 /* If we're handling an ELF file, drag some section-relocation info 02212 for this source file out of the ELF symbol table, to compensate for 02213 Sun brain death. This replaces the section_offsets in this psymtab, 02214 if successful. */ 02215 elfstab_offset_sections (objfile, result); 02216 #endif 02217 02218 /* Deduce the source language from the filename for this psymtab. */ 02219 psymtab_language = deduce_language_from_filename (filename); 02220 02221 return result; 02222 } 02223 02224 /* Close off the current usage of PST. 02225 Returns PST or NULL if the partial symtab was empty and thrown away. 02226 02227 FIXME: List variables and peculiarities of same. */ 02228 02229 struct partial_symtab * 02230 end_psymtab (struct objfile *objfile, struct partial_symtab *pst, 02231 const char **include_list, int num_includes, 02232 int capping_symbol_offset, CORE_ADDR capping_text, 02233 struct partial_symtab **dependency_list, int number_dependencies, 02234 int textlow_not_set) 02235 { 02236 int i; 02237 struct gdbarch *gdbarch = get_objfile_arch (objfile); 02238 02239 if (capping_symbol_offset != -1) 02240 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst); 02241 pst->texthigh = capping_text; 02242 02243 /* Under Solaris, the N_SO symbols always have a value of 0, 02244 instead of the usual address of the .o file. Therefore, 02245 we have to do some tricks to fill in texthigh and textlow. 02246 The first trick is: if we see a static 02247 or global function, and the textlow for the current pst 02248 is not set (ie: textlow_not_set), then we use that function's 02249 address for the textlow of the pst. */ 02250 02251 /* Now, to fill in texthigh, we remember the last function seen 02252 in the .o file. Also, there's a hack in 02253 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field 02254 to here via the misc_info field. Therefore, we can fill in 02255 a reliable texthigh by taking the address plus size of the 02256 last function in the file. */ 02257 02258 if (pst->texthigh == 0 && last_function_name 02259 && gdbarch_sofun_address_maybe_missing (gdbarch)) 02260 { 02261 char *p; 02262 int n; 02263 struct minimal_symbol *minsym; 02264 02265 p = strchr (last_function_name, ':'); 02266 if (p == NULL) 02267 p = last_function_name; 02268 n = p - last_function_name; 02269 p = alloca (n + 2); 02270 strncpy (p, last_function_name, n); 02271 p[n] = 0; 02272 02273 minsym = lookup_minimal_symbol (p, pst->filename, objfile); 02274 if (minsym == NULL) 02275 { 02276 /* Sun Fortran appends an underscore to the minimal symbol name, 02277 try again with an appended underscore if the minimal symbol 02278 was not found. */ 02279 p[n] = '_'; 02280 p[n + 1] = 0; 02281 minsym = lookup_minimal_symbol (p, pst->filename, objfile); 02282 } 02283 02284 if (minsym) 02285 pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + MSYMBOL_SIZE (minsym); 02286 02287 last_function_name = NULL; 02288 } 02289 02290 if (!gdbarch_sofun_address_maybe_missing (gdbarch)) 02291 ; 02292 /* This test will be true if the last .o file is only data. */ 02293 else if (textlow_not_set) 02294 pst->textlow = pst->texthigh; 02295 else 02296 { 02297 struct partial_symtab *p1; 02298 02299 /* If we know our own starting text address, then walk through all other 02300 psymtabs for this objfile, and if any didn't know their ending text 02301 address, set it to our starting address. Take care to not set our 02302 own ending address to our starting address, nor to set addresses on 02303 `dependency' files that have both textlow and texthigh zero. */ 02304 02305 ALL_OBJFILE_PSYMTABS (objfile, p1) 02306 { 02307 if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst) 02308 { 02309 p1->texthigh = pst->textlow; 02310 /* If this file has only data, then make textlow match 02311 texthigh. */ 02312 if (p1->textlow == 0) 02313 p1->textlow = p1->texthigh; 02314 } 02315 } 02316 } 02317 02318 /* End of kludge for patching Solaris textlow and texthigh. */ 02319 02320 pst->n_global_syms = 02321 objfile->global_psymbols.next - (objfile->global_psymbols.list 02322 + pst->globals_offset); 02323 pst->n_static_syms = 02324 objfile->static_psymbols.next - (objfile->static_psymbols.list 02325 + pst->statics_offset); 02326 02327 pst->number_of_dependencies = number_dependencies; 02328 if (number_dependencies) 02329 { 02330 pst->dependencies = (struct partial_symtab **) 02331 obstack_alloc (&objfile->objfile_obstack, 02332 number_dependencies * sizeof (struct partial_symtab *)); 02333 memcpy (pst->dependencies, dependency_list, 02334 number_dependencies * sizeof (struct partial_symtab *)); 02335 } 02336 else 02337 pst->dependencies = 0; 02338 02339 for (i = 0; i < num_includes; i++) 02340 { 02341 struct partial_symtab *subpst = 02342 allocate_psymtab (include_list[i], objfile); 02343 02344 /* Copy the sesction_offsets array from the main psymtab. */ 02345 subpst->section_offsets = pst->section_offsets; 02346 subpst->read_symtab_private = 02347 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc)); 02348 LDSYMOFF (subpst) = 02349 LDSYMLEN (subpst) = 02350 subpst->textlow = 02351 subpst->texthigh = 0; 02352 02353 /* We could save slight bits of space by only making one of these, 02354 shared by the entire set of include files. FIXME-someday. */ 02355 subpst->dependencies = (struct partial_symtab **) 02356 obstack_alloc (&objfile->objfile_obstack, 02357 sizeof (struct partial_symtab *)); 02358 subpst->dependencies[0] = pst; 02359 subpst->number_of_dependencies = 1; 02360 02361 subpst->globals_offset = 02362 subpst->n_global_syms = 02363 subpst->statics_offset = 02364 subpst->n_static_syms = 0; 02365 02366 subpst->readin = 0; 02367 subpst->symtab = 0; 02368 subpst->read_symtab = pst->read_symtab; 02369 } 02370 02371 sort_pst_symbols (objfile, pst); 02372 02373 if (num_includes == 0 02374 && number_dependencies == 0 02375 && pst->n_global_syms == 0 02376 && pst->n_static_syms == 0 02377 && has_line_numbers == 0) 02378 { 02379 /* Throw away this psymtab, it's empty. We can't deallocate it, since 02380 it is on the obstack, but we can forget to chain it on the list. */ 02381 /* Empty psymtabs happen as a result of header files which don't have 02382 any symbols in them. There can be a lot of them. But this check 02383 is wrong, in that a psymtab with N_SLINE entries but nothing else 02384 is not empty, but we don't realize that. Fixing that without slowing 02385 things down might be tricky. */ 02386 02387 discard_psymtab (objfile, pst); 02388 02389 /* Indicate that psymtab was thrown away. */ 02390 pst = (struct partial_symtab *) NULL; 02391 } 02392 return pst; 02393 } 02394 02395 static void 02396 dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst) 02397 { 02398 struct cleanup *old_chain; 02399 int i; 02400 02401 if (pst->readin) 02402 { 02403 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. " 02404 "Shouldn't happen.\n", 02405 pst->filename); 02406 return; 02407 } 02408 02409 /* Read in all partial symtabs on which this one is dependent. */ 02410 for (i = 0; i < pst->number_of_dependencies; i++) 02411 if (!pst->dependencies[i]->readin) 02412 { 02413 /* Inform about additional files that need to be read in. */ 02414 if (info_verbose) 02415 { 02416 fputs_filtered (" ", gdb_stdout); 02417 wrap_here (""); 02418 fputs_filtered ("and ", gdb_stdout); 02419 wrap_here (""); 02420 printf_filtered ("%s...", pst->dependencies[i]->filename); 02421 wrap_here (""); /* Flush output. */ 02422 gdb_flush (gdb_stdout); 02423 } 02424 dbx_psymtab_to_symtab_1 (objfile, pst->dependencies[i]); 02425 } 02426 02427 if (LDSYMLEN (pst)) /* Otherwise it's a dummy. */ 02428 { 02429 /* Init stuff necessary for reading in symbols */ 02430 stabsread_init (); 02431 buildsym_init (); 02432 old_chain = make_cleanup (really_free_pendings, 0); 02433 file_string_table_offset = FILE_STRING_OFFSET (pst); 02434 symbol_size = SYMBOL_SIZE (pst); 02435 02436 /* Read in this file's symbols. */ 02437 bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET); 02438 read_ofile_symtab (objfile, pst); 02439 02440 do_cleanups (old_chain); 02441 } 02442 02443 pst->readin = 1; 02444 } 02445 02446 /* Read in all of the symbols for a given psymtab for real. 02447 Be verbose about it if the user wants that. SELF is not NULL. */ 02448 02449 static void 02450 dbx_read_symtab (struct partial_symtab *self, struct objfile *objfile) 02451 { 02452 bfd *sym_bfd; 02453 02454 if (self->readin) 02455 { 02456 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. " 02457 "Shouldn't happen.\n", 02458 self->filename); 02459 return; 02460 } 02461 02462 if (LDSYMLEN (self) || self->number_of_dependencies) 02463 { 02464 struct cleanup *back_to; 02465 02466 /* Print the message now, before reading the string table, 02467 to avoid disconcerting pauses. */ 02468 if (info_verbose) 02469 { 02470 printf_filtered ("Reading in symbols for %s...", self->filename); 02471 gdb_flush (gdb_stdout); 02472 } 02473 02474 sym_bfd = objfile->obfd; 02475 02476 next_symbol_text_func = dbx_next_symbol_text; 02477 02478 back_to = make_cleanup (null_cleanup, NULL); 02479 02480 if (DBX_STAB_SECTION (objfile)) 02481 { 02482 stabs_data 02483 = symfile_relocate_debug_section (objfile, 02484 DBX_STAB_SECTION (objfile), 02485 NULL); 02486 02487 if (stabs_data) 02488 make_cleanup (free_current_contents, (void *) &stabs_data); 02489 } 02490 02491 dbx_psymtab_to_symtab_1 (objfile, self); 02492 02493 do_cleanups (back_to); 02494 02495 /* Match with global symbols. This only needs to be done once, 02496 after all of the symtabs and dependencies have been read in. */ 02497 scan_file_globals (objfile); 02498 02499 /* Finish up the debug error message. */ 02500 if (info_verbose) 02501 printf_filtered ("done.\n"); 02502 } 02503 } 02504 02505 /* Read in a defined section of a specific object file's symbols. */ 02506 02507 static void 02508 read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst) 02509 { 02510 char *namestring; 02511 struct external_nlist *bufp; 02512 struct internal_nlist nlist; 02513 unsigned char type; 02514 unsigned max_symnum; 02515 bfd *abfd; 02516 int sym_offset; /* Offset to start of symbols to read */ 02517 int sym_size; /* Size of symbols to read */ 02518 CORE_ADDR text_offset; /* Start of text segment for symbols */ 02519 int text_size; /* Size of text segment for symbols */ 02520 struct section_offsets *section_offsets; 02521 02522 sym_offset = LDSYMOFF (pst); 02523 sym_size = LDSYMLEN (pst); 02524 text_offset = pst->textlow; 02525 text_size = pst->texthigh - pst->textlow; 02526 /* This cannot be simply objfile->section_offsets because of 02527 elfstab_offset_sections() which initializes the psymtab section 02528 offsets information in a special way, and that is different from 02529 objfile->section_offsets. */ 02530 section_offsets = pst->section_offsets; 02531 02532 dbxread_objfile = objfile; 02533 02534 stringtab_global = DBX_STRINGTAB (objfile); 02535 set_last_source_file (NULL); 02536 02537 abfd = objfile->obfd; 02538 symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol. */ 02539 symbuf_end = symbuf_idx = 0; 02540 symbuf_read = 0; 02541 symbuf_left = sym_offset + sym_size; 02542 02543 /* It is necessary to actually read one symbol *before* the start 02544 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL 02545 occurs before the N_SO symbol. 02546 02547 Detecting this in read_dbx_symtab 02548 would slow down initial readin, so we look for it here instead. */ 02549 if (!processing_acc_compilation && sym_offset >= (int) symbol_size) 02550 { 02551 stabs_seek (sym_offset - symbol_size); 02552 fill_symbuf (abfd); 02553 bufp = &symbuf[symbuf_idx++]; 02554 INTERNALIZE_SYMBOL (nlist, bufp, abfd); 02555 OBJSTAT (objfile, n_stabs++); 02556 02557 namestring = set_namestring (objfile, &nlist); 02558 02559 processing_gcc_compilation = 0; 02560 if (nlist.n_type == N_TEXT) 02561 { 02562 const char *tempstring = namestring; 02563 02564 if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0) 02565 processing_gcc_compilation = 1; 02566 else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0) 02567 processing_gcc_compilation = 2; 02568 if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd)) 02569 ++tempstring; 02570 if (strncmp (tempstring, "__gnu_compiled", 14) == 0) 02571 processing_gcc_compilation = 2; 02572 } 02573 } 02574 else 02575 { 02576 /* The N_SO starting this symtab is the first symbol, so we 02577 better not check the symbol before it. I'm not this can 02578 happen, but it doesn't hurt to check for it. */ 02579 stabs_seek (sym_offset); 02580 processing_gcc_compilation = 0; 02581 } 02582 02583 if (symbuf_idx == symbuf_end) 02584 fill_symbuf (abfd); 02585 bufp = &symbuf[symbuf_idx]; 02586 if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO) 02587 error (_("First symbol in segment of executable not a source symbol")); 02588 02589 max_symnum = sym_size / symbol_size; 02590 02591 for (symnum = 0; 02592 symnum < max_symnum; 02593 symnum++) 02594 { 02595 QUIT; /* Allow this to be interruptable. */ 02596 if (symbuf_idx == symbuf_end) 02597 fill_symbuf (abfd); 02598 bufp = &symbuf[symbuf_idx++]; 02599 INTERNALIZE_SYMBOL (nlist, bufp, abfd); 02600 OBJSTAT (objfile, n_stabs++); 02601 02602 type = bfd_h_get_8 (abfd, bufp->e_type); 02603 02604 namestring = set_namestring (objfile, &nlist); 02605 02606 if (type & N_STAB) 02607 { 02608 if (sizeof (nlist.n_value) > 4 02609 /* We are a 64-bit debugger debugging a 32-bit program. */ 02610 && (type == N_LSYM || type == N_PSYM)) 02611 /* We have to be careful with the n_value in the case of N_LSYM 02612 and N_PSYM entries, because they are signed offsets from frame 02613 pointer, but we actually read them as unsigned 32-bit values. 02614 This is not a problem for 32-bit debuggers, for which negative 02615 values end up being interpreted correctly (as negative 02616 offsets) due to integer overflow. 02617 But we need to sign-extend the value for 64-bit debuggers, 02618 or we'll end up interpreting negative values as very large 02619 positive offsets. */ 02620 nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000; 02621 process_one_symbol (type, nlist.n_desc, nlist.n_value, 02622 namestring, section_offsets, objfile); 02623 } 02624 /* We skip checking for a new .o or -l file; that should never 02625 happen in this routine. */ 02626 else if (type == N_TEXT) 02627 { 02628 /* I don't think this code will ever be executed, because 02629 the GCC_COMPILED_FLAG_SYMBOL usually is right before 02630 the N_SO symbol which starts this source file. 02631 However, there is no reason not to accept 02632 the GCC_COMPILED_FLAG_SYMBOL anywhere. */ 02633 02634 if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0) 02635 processing_gcc_compilation = 1; 02636 else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0) 02637 processing_gcc_compilation = 2; 02638 } 02639 else if (type & N_EXT || type == (unsigned char) N_TEXT 02640 || type == (unsigned char) N_NBTEXT) 02641 { 02642 /* Global symbol: see if we came across a dbx defintion for 02643 a corresponding symbol. If so, store the value. Remove 02644 syms from the chain when their values are stored, but 02645 search the whole chain, as there may be several syms from 02646 different files with the same name. */ 02647 /* This is probably not true. Since the files will be read 02648 in one at a time, each reference to a global symbol will 02649 be satisfied in each file as it appears. So we skip this 02650 section. */ 02651 ; 02652 } 02653 } 02654 02655 /* In a Solaris elf file, this variable, which comes from the 02656 value of the N_SO symbol, will still be 0. Luckily, text_offset, 02657 which comes from pst->textlow is correct. */ 02658 if (last_source_start_addr == 0) 02659 last_source_start_addr = text_offset; 02660 02661 /* In reordered executables last_source_start_addr may not be the 02662 lower bound for this symtab, instead use text_offset which comes 02663 from pst->textlow which is correct. */ 02664 if (last_source_start_addr > text_offset) 02665 last_source_start_addr = text_offset; 02666 02667 pst->symtab = end_symtab (text_offset + text_size, objfile, 02668 SECT_OFF_TEXT (objfile)); 02669 02670 end_stabs (); 02671 02672 dbxread_objfile = NULL; 02673 } 02674 02675 02676 /* Record the namespace that the function defined by SYMBOL was 02677 defined in, if necessary. BLOCK is the associated block; use 02678 OBSTACK for allocation. */ 02679 02680 static void 02681 cp_set_block_scope (const struct symbol *symbol, 02682 struct block *block, 02683 struct obstack *obstack) 02684 { 02685 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) 02686 { 02687 /* Try to figure out the appropriate namespace from the 02688 demangled name. */ 02689 02690 /* FIXME: carlton/2003-04-15: If the function in question is 02691 a method of a class, the name will actually include the 02692 name of the class as well. This should be harmless, but 02693 is a little unfortunate. */ 02694 02695 const char *name = SYMBOL_DEMANGLED_NAME (symbol); 02696 unsigned int prefix_len = cp_entire_prefix_len (name); 02697 02698 block_set_scope (block, 02699 obstack_copy0 (obstack, name, prefix_len), 02700 obstack); 02701 } 02702 } 02703 02704 /* This handles a single symbol from the symbol-file, building symbols 02705 into a GDB symtab. It takes these arguments and an implicit argument. 02706 02707 TYPE is the type field of the ".stab" symbol entry. 02708 DESC is the desc field of the ".stab" entry. 02709 VALU is the value field of the ".stab" entry. 02710 NAME is the symbol name, in our address space. 02711 SECTION_OFFSETS is a set of amounts by which the sections of this 02712 object file were relocated when it was loaded into memory. Note 02713 that these section_offsets are not the objfile->section_offsets but 02714 the pst->section_offsets. All symbols that refer to memory 02715 locations need to be offset by these amounts. 02716 OBJFILE is the object file from which we are reading symbols. It 02717 is used in end_symtab. */ 02718 02719 void 02720 process_one_symbol (int type, int desc, CORE_ADDR valu, char *name, 02721 const struct section_offsets *section_offsets, 02722 struct objfile *objfile) 02723 { 02724 struct gdbarch *gdbarch = get_objfile_arch (objfile); 02725 struct context_stack *new; 02726 /* This remembers the address of the start of a function. It is 02727 used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries 02728 are relative to the current function's start address. On systems 02729 other than Solaris 2, this just holds the SECT_OFF_TEXT value, 02730 and is used to relocate these symbol types rather than 02731 SECTION_OFFSETS. */ 02732 static CORE_ADDR function_start_offset; 02733 02734 /* This holds the address of the start of a function, without the 02735 system peculiarities of function_start_offset. */ 02736 static CORE_ADDR last_function_start; 02737 02738 /* If this is nonzero, we've seen an N_SLINE since the start of the 02739 current function. We use this to tell us to move the first sline 02740 to the beginning of the function regardless of what its given 02741 value is. */ 02742 static int sline_found_in_function = 1; 02743 02744 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this 02745 source file. Used to detect the SunPRO solaris compiler. */ 02746 static int n_opt_found; 02747 02748 /* The stab type used for the definition of the last function. 02749 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */ 02750 static int function_stab_type = 0; 02751 02752 if (!block_address_function_relative) 02753 { 02754 /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the 02755 function start address, so just use the text offset. */ 02756 function_start_offset = 02757 ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 02758 } 02759 02760 /* Something is wrong if we see real data before seeing a source 02761 file name. */ 02762 02763 if (get_last_source_file () == NULL && type != (unsigned char) N_SO) 02764 { 02765 /* Ignore any symbols which appear before an N_SO symbol. 02766 Currently no one puts symbols there, but we should deal 02767 gracefully with the case. A complain()t might be in order, 02768 but this should not be an error (). */ 02769 return; 02770 } 02771 02772 switch (type) 02773 { 02774 case N_FUN: 02775 case N_FNAME: 02776 02777 if (*name == '\000') 02778 { 02779 /* This N_FUN marks the end of a function. This closes off 02780 the current block. */ 02781 struct block *block; 02782 02783 if (context_stack_depth <= 0) 02784 { 02785 lbrac_mismatch_complaint (symnum); 02786 break; 02787 } 02788 02789 /* The following check is added before recording line 0 at 02790 end of function so as to handle hand-generated stabs 02791 which may have an N_FUN stabs at the end of the function, 02792 but no N_SLINE stabs. */ 02793 if (sline_found_in_function) 02794 { 02795 CORE_ADDR addr = last_function_start + valu; 02796 02797 record_line (current_subfile, 0, 02798 gdbarch_addr_bits_remove (gdbarch, addr)); 02799 } 02800 02801 within_function = 0; 02802 new = pop_context (); 02803 02804 /* Make a block for the local symbols within. */ 02805 block = finish_block (new->name, &local_symbols, new->old_blocks, 02806 new->start_addr, new->start_addr + valu, 02807 objfile); 02808 02809 /* For C++, set the block's scope. */ 02810 if (SYMBOL_LANGUAGE (new->name) == language_cplus) 02811 cp_set_block_scope (new->name, block, &objfile->objfile_obstack); 02812 02813 /* May be switching to an assembler file which may not be using 02814 block relative stabs, so reset the offset. */ 02815 if (block_address_function_relative) 02816 function_start_offset = 0; 02817 02818 break; 02819 } 02820 02821 sline_found_in_function = 0; 02822 02823 /* Relocate for dynamic loading. */ 02824 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 02825 valu = gdbarch_addr_bits_remove (gdbarch, valu); 02826 last_function_start = valu; 02827 02828 goto define_a_symbol; 02829 02830 case N_LBRAC: 02831 /* This "symbol" just indicates the start of an inner lexical 02832 context within a function. */ 02833 02834 /* Ignore extra outermost context from SunPRO cc and acc. */ 02835 if (n_opt_found && desc == 1) 02836 break; 02837 02838 if (block_address_function_relative) 02839 /* Relocate for Sun ELF acc fn-relative syms. */ 02840 valu += function_start_offset; 02841 else 02842 /* On most machines, the block addresses are relative to the 02843 N_SO, the linker did not relocate them (sigh). */ 02844 valu += last_source_start_addr; 02845 02846 push_context (desc, valu); 02847 break; 02848 02849 case N_RBRAC: 02850 /* This "symbol" just indicates the end of an inner lexical 02851 context that was started with N_LBRAC. */ 02852 02853 /* Ignore extra outermost context from SunPRO cc and acc. */ 02854 if (n_opt_found && desc == 1) 02855 break; 02856 02857 if (block_address_function_relative) 02858 /* Relocate for Sun ELF acc fn-relative syms. */ 02859 valu += function_start_offset; 02860 else 02861 /* On most machines, the block addresses are relative to the 02862 N_SO, the linker did not relocate them (sigh). */ 02863 valu += last_source_start_addr; 02864 02865 if (context_stack_depth <= 0) 02866 { 02867 lbrac_mismatch_complaint (symnum); 02868 break; 02869 } 02870 02871 new = pop_context (); 02872 if (desc != new->depth) 02873 lbrac_mismatch_complaint (symnum); 02874 02875 if (local_symbols != NULL) 02876 { 02877 /* GCC development snapshots from March to December of 02878 2000 would output N_LSYM entries after N_LBRAC 02879 entries. As a consequence, these symbols are simply 02880 discarded. Complain if this is the case. */ 02881 complaint (&symfile_complaints, 02882 _("misplaced N_LBRAC entry; discarding local " 02883 "symbols which have no enclosing block")); 02884 } 02885 local_symbols = new->locals; 02886 02887 if (context_stack_depth > 1) 02888 { 02889 /* This is not the outermost LBRAC...RBRAC pair in the 02890 function, its local symbols preceded it, and are the ones 02891 just recovered from the context stack. Define the block 02892 for them (but don't bother if the block contains no 02893 symbols. Should we complain on blocks without symbols? 02894 I can't think of any useful purpose for them). */ 02895 if (local_symbols != NULL) 02896 { 02897 /* Muzzle a compiler bug that makes end < start. 02898 02899 ??? Which compilers? Is this ever harmful?. */ 02900 if (new->start_addr > valu) 02901 { 02902 complaint (&symfile_complaints, 02903 _("block start larger than block end")); 02904 new->start_addr = valu; 02905 } 02906 /* Make a block for the local symbols within. */ 02907 finish_block (0, &local_symbols, new->old_blocks, 02908 new->start_addr, valu, objfile); 02909 } 02910 } 02911 else 02912 { 02913 /* This is the outermost LBRAC...RBRAC pair. There is no 02914 need to do anything; leave the symbols that preceded it 02915 to be attached to the function's own block. We need to 02916 indicate that we just moved outside of the function. */ 02917 within_function = 0; 02918 } 02919 02920 break; 02921 02922 case N_FN: 02923 case N_FN_SEQ: 02924 /* This kind of symbol indicates the start of an object file. 02925 Relocate for dynamic loading. */ 02926 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 02927 break; 02928 02929 case N_SO: 02930 /* This type of symbol indicates the start of data for one 02931 source file. Finish the symbol table of the previous source 02932 file (if any) and start accumulating a new symbol table. 02933 Relocate for dynamic loading. */ 02934 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 02935 02936 n_opt_found = 0; 02937 02938 if (get_last_source_file ()) 02939 { 02940 /* Check if previous symbol was also an N_SO (with some 02941 sanity checks). If so, that one was actually the 02942 directory name, and the current one is the real file 02943 name. Patch things up. */ 02944 if (previous_stab_code == (unsigned char) N_SO) 02945 { 02946 patch_subfile_names (current_subfile, name); 02947 break; /* Ignore repeated SOs. */ 02948 } 02949 end_symtab (valu, objfile, SECT_OFF_TEXT (objfile)); 02950 end_stabs (); 02951 } 02952 02953 /* Null name means this just marks the end of text for this .o 02954 file. Don't start a new symtab in this case. */ 02955 if (*name == '\000') 02956 break; 02957 02958 if (block_address_function_relative) 02959 function_start_offset = 0; 02960 02961 start_stabs (); 02962 start_symtab (name, NULL, valu); 02963 record_debugformat ("stabs"); 02964 break; 02965 02966 case N_SOL: 02967 /* This type of symbol indicates the start of data for a 02968 sub-source-file, one whose contents were copied or included 02969 in the compilation of the main source file (whose name was 02970 given in the N_SO symbol). Relocate for dynamic loading. */ 02971 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 02972 start_subfile (name, current_subfile->dirname); 02973 break; 02974 02975 case N_BINCL: 02976 push_subfile (); 02977 add_new_header_file (name, valu); 02978 start_subfile (name, current_subfile->dirname); 02979 break; 02980 02981 case N_EINCL: 02982 start_subfile (pop_subfile (), current_subfile->dirname); 02983 break; 02984 02985 case N_EXCL: 02986 add_old_header_file (name, valu); 02987 break; 02988 02989 case N_SLINE: 02990 /* This type of "symbol" really just records one line-number -- 02991 core-address correspondence. Enter it in the line list for 02992 this symbol table. */ 02993 02994 /* Relocate for dynamic loading and for ELF acc 02995 function-relative symbols. */ 02996 valu += function_start_offset; 02997 02998 /* GCC 2.95.3 emits the first N_SLINE stab somwehere in the 02999 middle of the prologue instead of right at the start of the 03000 function. To deal with this we record the address for the 03001 first N_SLINE stab to be the start of the function instead of 03002 the listed location. We really shouldn't to this. When 03003 compiling with optimization, this first N_SLINE stab might be 03004 optimized away. Other (non-GCC) compilers don't emit this 03005 stab at all. There is no real harm in having an extra 03006 numbered line, although it can be a bit annoying for the 03007 user. However, it totally screws up our testsuite. 03008 03009 So for now, keep adjusting the address of the first N_SLINE 03010 stab, but only for code compiled with GCC. */ 03011 03012 if (within_function && sline_found_in_function == 0) 03013 { 03014 CORE_ADDR addr = processing_gcc_compilation == 2 ? 03015 last_function_start : valu; 03016 03017 record_line (current_subfile, desc, 03018 gdbarch_addr_bits_remove (gdbarch, addr)); 03019 sline_found_in_function = 1; 03020 } 03021 else 03022 record_line (current_subfile, desc, 03023 gdbarch_addr_bits_remove (gdbarch, valu)); 03024 break; 03025 03026 case N_BCOMM: 03027 common_block_start (name, objfile); 03028 break; 03029 03030 case N_ECOMM: 03031 common_block_end (objfile); 03032 break; 03033 03034 /* The following symbol types need to have the appropriate 03035 offset added to their value; then we process symbol 03036 definitions in the name. */ 03037 03038 case N_STSYM: /* Static symbol in data segment. */ 03039 case N_LCSYM: /* Static symbol in BSS segment. */ 03040 case N_ROSYM: /* Static symbol in read-only data segment. */ 03041 /* HORRID HACK DEPT. However, it's Sun's furgin' fault. 03042 Solaris 2's stabs-in-elf makes *most* symbols relative but 03043 leaves a few absolute (at least for Solaris 2.1 and version 03044 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on 03045 the fence. .stab "foo:S...",N_STSYM is absolute (ld 03046 relocates it) .stab "foo:V...",N_STSYM is relative (section 03047 base subtracted). This leaves us no choice but to search for 03048 the 'S' or 'V'... (or pass the whole section_offsets stuff 03049 down ONE MORE function call level, which we really don't want 03050 to do). */ 03051 { 03052 char *p; 03053 03054 /* Normal object file and NLMs have non-zero text seg offsets, 03055 but don't need their static syms offset in this fashion. 03056 XXX - This is really a crock that should be fixed in the 03057 solib handling code so that I don't have to work around it 03058 here. */ 03059 03060 if (!symfile_relocatable) 03061 { 03062 p = strchr (name, ':'); 03063 if (p != 0 && p[1] == 'S') 03064 { 03065 /* The linker relocated it. We don't want to add an 03066 elfstab_offset_sections-type offset, but we *do* 03067 want to add whatever solib.c passed to 03068 symbol_file_add as addr (this is known to affect 03069 SunOS 4, and I suspect ELF too). Since 03070 elfstab_offset_sections currently does not muck 03071 with the text offset (there is no Ttext.text 03072 symbol), we can get addr from the text offset. If 03073 elfstab_offset_sections ever starts dealing with 03074 the text offset, and we still need to do this, we 03075 need to invent a SECT_OFF_ADDR_KLUDGE or something. */ 03076 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 03077 goto define_a_symbol; 03078 } 03079 } 03080 /* Since it's not the kludge case, re-dispatch to the right 03081 handler. */ 03082 switch (type) 03083 { 03084 case N_STSYM: 03085 goto case_N_STSYM; 03086 case N_LCSYM: 03087 goto case_N_LCSYM; 03088 case N_ROSYM: 03089 goto case_N_ROSYM; 03090 default: 03091 internal_error (__FILE__, __LINE__, 03092 _("failed internal consistency check")); 03093 } 03094 } 03095 03096 case_N_STSYM: /* Static symbol in data segment. */ 03097 case N_DSLINE: /* Source line number, data segment. */ 03098 valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); 03099 goto define_a_symbol; 03100 03101 case_N_LCSYM: /* Static symbol in BSS segment. */ 03102 case N_BSLINE: /* Source line number, BSS segment. */ 03103 /* N_BROWS: overlaps with N_BSLINE. */ 03104 valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile)); 03105 goto define_a_symbol; 03106 03107 case_N_ROSYM: /* Static symbol in read-only data segment. */ 03108 valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile)); 03109 goto define_a_symbol; 03110 03111 case N_ENTRY: /* Alternate entry point. */ 03112 /* Relocate for dynamic loading. */ 03113 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 03114 goto define_a_symbol; 03115 03116 /* The following symbol types we don't know how to process. 03117 Handle them in a "default" way, but complain to people who 03118 care. */ 03119 default: 03120 case N_CATCH: /* Exception handler catcher. */ 03121 case N_EHDECL: /* Exception handler name. */ 03122 case N_PC: /* Global symbol in Pascal. */ 03123 case N_M2C: /* Modula-2 compilation unit. */ 03124 /* N_MOD2: overlaps with N_EHDECL. */ 03125 case N_SCOPE: /* Modula-2 scope information. */ 03126 case N_ECOML: /* End common (local name). */ 03127 case N_NBTEXT: /* Gould Non-Base-Register symbols??? */ 03128 case N_NBDATA: 03129 case N_NBBSS: 03130 case N_NBSTS: 03131 case N_NBLCS: 03132 unknown_symtype_complaint (hex_string (type)); 03133 /* FALLTHROUGH */ 03134 03135 /* The following symbol types don't need the address field 03136 relocated, since it is either unused, or is absolute. */ 03137 define_a_symbol: 03138 case N_GSYM: /* Global variable. */ 03139 case N_NSYMS: /* Number of symbols (Ultrix). */ 03140 case N_NOMAP: /* No map? (Ultrix). */ 03141 case N_RSYM: /* Register variable. */ 03142 case N_DEFD: /* Modula-2 GNU module dependency. */ 03143 case N_SSYM: /* Struct or union element. */ 03144 case N_LSYM: /* Local symbol in stack. */ 03145 case N_PSYM: /* Parameter variable. */ 03146 case N_LENG: /* Length of preceding symbol type. */ 03147 if (name) 03148 { 03149 int deftype; 03150 char *colon_pos = strchr (name, ':'); 03151 03152 if (colon_pos == NULL) 03153 deftype = '\0'; 03154 else 03155 deftype = colon_pos[1]; 03156 03157 switch (deftype) 03158 { 03159 case 'f': 03160 case 'F': 03161 function_stab_type = type; 03162 03163 /* Deal with the SunPRO 3.0 compiler which omits the 03164 address from N_FUN symbols. */ 03165 if (type == N_FUN 03166 && valu == ANOFFSET (section_offsets, 03167 SECT_OFF_TEXT (objfile)) 03168 && gdbarch_sofun_address_maybe_missing (gdbarch)) 03169 { 03170 CORE_ADDR minsym_valu = 03171 find_stab_function_addr (name, get_last_source_file (), 03172 objfile); 03173 03174 /* The function find_stab_function_addr will return 03175 0 if the minimal symbol wasn't found. 03176 (Unfortunately, this might also be a valid 03177 address.) Anyway, if it *does* return 0, it is 03178 likely that the value was set correctly to begin 03179 with... */ 03180 if (minsym_valu != 0) 03181 valu = minsym_valu; 03182 } 03183 03184 if (block_address_function_relative) 03185 /* For Solaris 2 compilers, the block addresses and 03186 N_SLINE's are relative to the start of the 03187 function. On normal systems, and when using GCC on 03188 Solaris 2, these addresses are just absolute, or 03189 relative to the N_SO, depending on 03190 BLOCK_ADDRESS_ABSOLUTE. */ 03191 function_start_offset = valu; 03192 03193 within_function = 1; 03194 03195 if (context_stack_depth > 1) 03196 { 03197 complaint (&symfile_complaints, 03198 _("unmatched N_LBRAC before symtab pos %d"), 03199 symnum); 03200 break; 03201 } 03202 03203 if (context_stack_depth > 0) 03204 { 03205 struct block *block; 03206 03207 new = pop_context (); 03208 /* Make a block for the local symbols within. */ 03209 block = finish_block (new->name, &local_symbols, 03210 new->old_blocks, new->start_addr, 03211 valu, objfile); 03212 03213 /* For C++, set the block's scope. */ 03214 if (SYMBOL_LANGUAGE (new->name) == language_cplus) 03215 cp_set_block_scope (new->name, block, 03216 &objfile->objfile_obstack); 03217 } 03218 03219 new = push_context (0, valu); 03220 new->name = define_symbol (valu, name, desc, type, objfile); 03221 break; 03222 03223 default: 03224 define_symbol (valu, name, desc, type, objfile); 03225 break; 03226 } 03227 } 03228 break; 03229 03230 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it 03231 for a bunch of other flags, too. Someday we may parse their 03232 flags; for now we ignore theirs and hope they'll ignore ours. */ 03233 case N_OPT: /* Solaris 2: Compiler options. */ 03234 if (name) 03235 { 03236 if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0) 03237 { 03238 processing_gcc_compilation = 2; 03239 } 03240 else 03241 n_opt_found = 1; 03242 } 03243 break; 03244 03245 case N_MAIN: /* Name of main routine. */ 03246 /* FIXME: If one has a symbol file with N_MAIN and then replaces 03247 it with a symbol file with "main" and without N_MAIN. I'm 03248 not sure exactly what rule to follow but probably something 03249 like: N_MAIN takes precedence over "main" no matter what 03250 objfile it is in; If there is more than one N_MAIN, choose 03251 the one in the symfile_objfile; If there is more than one 03252 N_MAIN within a given objfile, complain() and choose 03253 arbitrarily. (kingdon) */ 03254 if (name != NULL) 03255 set_main_name (name); 03256 break; 03257 03258 /* The following symbol types can be ignored. */ 03259 case N_OBJ: /* Solaris 2: Object file dir and name. */ 03260 case N_PATCH: /* Solaris 2: Patch Run Time Checker. */ 03261 /* N_UNDF: Solaris 2: File separator mark. */ 03262 /* N_UNDF: -- we will never encounter it, since we only process 03263 one file's symbols at once. */ 03264 case N_ENDM: /* Solaris 2: End of module. */ 03265 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */ 03266 break; 03267 } 03268 03269 /* '#' is a GNU C extension to allow one symbol to refer to another 03270 related symbol. 03271 03272 Generally this is used so that an alias can refer to its main 03273 symbol. */ 03274 gdb_assert (name); 03275 if (name[0] == '#') 03276 { 03277 /* Initialize symbol reference names and determine if this is a 03278 definition. If a symbol reference is being defined, go ahead 03279 and add it. Otherwise, just return. */ 03280 03281 char *s = name; 03282 int refnum; 03283 03284 /* If this stab defines a new reference ID that is not on the 03285 reference list, then put it on the reference list. 03286 03287 We go ahead and advance NAME past the reference, even though 03288 it is not strictly necessary at this time. */ 03289 refnum = symbol_reference_defined (&s); 03290 if (refnum >= 0) 03291 if (!ref_search (refnum)) 03292 ref_add (refnum, 0, name, valu); 03293 name = s; 03294 } 03295 03296 previous_stab_code = type; 03297 } 03298 03299 /* FIXME: The only difference between this and elfstab_build_psymtabs 03300 is the call to install_minimal_symbols for elf, and the support for 03301 split sections. If the differences are really that small, the code 03302 should be shared. */ 03303 03304 /* Scan and build partial symbols for an coff symbol file. 03305 The coff file has already been processed to get its minimal symbols. 03306 03307 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read 03308 rolled into one. 03309 03310 OBJFILE is the object file we are reading symbols from. 03311 ADDR is the address relative to which the symbols are (e.g. 03312 the base address of the text segment). 03313 TEXTADDR is the address of the text section. 03314 TEXTSIZE is the size of the text section. 03315 STABSECTS is the list of .stab sections in OBJFILE. 03316 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the 03317 .stabstr section exists. 03318 03319 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read, 03320 adjusted for coff details. */ 03321 03322 void 03323 coffstab_build_psymtabs (struct objfile *objfile, 03324 CORE_ADDR textaddr, unsigned int textsize, 03325 struct stab_section_list *stabsects, 03326 file_ptr stabstroffset, unsigned int stabstrsize) 03327 { 03328 int val; 03329 bfd *sym_bfd = objfile->obfd; 03330 char *name = bfd_get_filename (sym_bfd); 03331 struct dbx_symfile_info *info; 03332 unsigned int stabsize; 03333 03334 /* There is already a dbx_symfile_info allocated by our caller. 03335 It might even contain some info from the coff symtab to help us. */ 03336 info = DBX_SYMFILE_INFO (objfile); 03337 03338 DBX_TEXT_ADDR (objfile) = textaddr; 03339 DBX_TEXT_SIZE (objfile) = textsize; 03340 03341 #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ 03342 DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE; 03343 DBX_STRINGTAB_SIZE (objfile) = stabstrsize; 03344 03345 if (stabstrsize > bfd_get_size (sym_bfd)) 03346 error (_("ridiculous string table size: %d bytes"), stabstrsize); 03347 DBX_STRINGTAB (objfile) = (char *) 03348 obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1); 03349 OBJSTAT (objfile, sz_strtab += stabstrsize + 1); 03350 03351 /* Now read in the string table in one big gulp. */ 03352 03353 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET); 03354 if (val < 0) 03355 perror_with_name (name); 03356 val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd); 03357 if (val != stabstrsize) 03358 perror_with_name (name); 03359 03360 stabsread_new_init (); 03361 buildsym_new_init (); 03362 free_header_files (); 03363 init_header_files (); 03364 03365 processing_acc_compilation = 1; 03366 03367 /* In a coff file, we've already installed the minimal symbols that came 03368 from the coff (non-stab) symbol table, so always act like an 03369 incremental load here. */ 03370 if (stabsects->next == NULL) 03371 { 03372 stabsize = bfd_section_size (sym_bfd, stabsects->section); 03373 DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile); 03374 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos; 03375 } 03376 else 03377 { 03378 struct stab_section_list *stabsect; 03379 03380 DBX_SYMCOUNT (objfile) = 0; 03381 for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next) 03382 { 03383 stabsize = bfd_section_size (sym_bfd, stabsect->section); 03384 DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile); 03385 } 03386 03387 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos; 03388 03389 symbuf_sections = stabsects->next; 03390 symbuf_left = bfd_section_size (sym_bfd, stabsects->section); 03391 symbuf_read = 0; 03392 } 03393 03394 dbx_symfile_read (objfile, 0); 03395 } 03396 03397 /* Scan and build partial symbols for an ELF symbol file. 03398 This ELF file has already been processed to get its minimal symbols. 03399 03400 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read 03401 rolled into one. 03402 03403 OBJFILE is the object file we are reading symbols from. 03404 ADDR is the address relative to which the symbols are (e.g. 03405 the base address of the text segment). 03406 STABSECT is the BFD section information for the .stab section. 03407 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the 03408 .stabstr section exists. 03409 03410 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read, 03411 adjusted for elf details. */ 03412 03413 void 03414 elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect, 03415 file_ptr stabstroffset, unsigned int stabstrsize) 03416 { 03417 int val; 03418 bfd *sym_bfd = objfile->obfd; 03419 char *name = bfd_get_filename (sym_bfd); 03420 struct dbx_symfile_info *info; 03421 struct cleanup *back_to = make_cleanup (null_cleanup, NULL); 03422 03423 /* There is already a dbx_symfile_info allocated by our caller. 03424 It might even contain some info from the ELF symtab to help us. */ 03425 info = DBX_SYMFILE_INFO (objfile); 03426 03427 /* Find the first and last text address. dbx_symfile_read seems to 03428 want this. */ 03429 find_text_range (sym_bfd, objfile); 03430 03431 #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ 03432 DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE; 03433 DBX_SYMCOUNT (objfile) 03434 = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile); 03435 DBX_STRINGTAB_SIZE (objfile) = stabstrsize; 03436 DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; 03437 DBX_STAB_SECTION (objfile) = stabsect; 03438 03439 if (stabstrsize > bfd_get_size (sym_bfd)) 03440 error (_("ridiculous string table size: %d bytes"), stabstrsize); 03441 DBX_STRINGTAB (objfile) = (char *) 03442 obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1); 03443 OBJSTAT (objfile, sz_strtab += stabstrsize + 1); 03444 03445 /* Now read in the string table in one big gulp. */ 03446 03447 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET); 03448 if (val < 0) 03449 perror_with_name (name); 03450 val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd); 03451 if (val != stabstrsize) 03452 perror_with_name (name); 03453 03454 stabsread_new_init (); 03455 buildsym_new_init (); 03456 free_header_files (); 03457 init_header_files (); 03458 03459 processing_acc_compilation = 1; 03460 03461 symbuf_read = 0; 03462 symbuf_left = bfd_section_size (objfile->obfd, stabsect); 03463 stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL); 03464 if (stabs_data) 03465 make_cleanup (free_current_contents, (void *) &stabs_data); 03466 03467 /* In an elf file, we've already installed the minimal symbols that came 03468 from the elf (non-stab) symbol table, so always act like an 03469 incremental load here. dbx_symfile_read should not generate any new 03470 minimal symbols, since we will have already read the ELF dynamic symbol 03471 table and normal symbol entries won't be in the ".stab" section; but in 03472 case it does, it will install them itself. */ 03473 dbx_symfile_read (objfile, 0); 03474 03475 do_cleanups (back_to); 03476 } 03477 03478 /* Scan and build partial symbols for a file with special sections for stabs 03479 and stabstrings. The file has already been processed to get its minimal 03480 symbols, and any other symbols that might be necessary to resolve GSYMs. 03481 03482 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read 03483 rolled into one. 03484 03485 OBJFILE is the object file we are reading symbols from. 03486 ADDR is the address relative to which the symbols are (e.g. the base address 03487 of the text segment). 03488 STAB_NAME is the name of the section that contains the stabs. 03489 STABSTR_NAME is the name of the section that contains the stab strings. 03490 03491 This routine is mostly copied from dbx_symfile_init and 03492 dbx_symfile_read. */ 03493 03494 void 03495 stabsect_build_psymtabs (struct objfile *objfile, char *stab_name, 03496 char *stabstr_name, char *text_name) 03497 { 03498 int val; 03499 bfd *sym_bfd = objfile->obfd; 03500 char *name = bfd_get_filename (sym_bfd); 03501 asection *stabsect; 03502 asection *stabstrsect; 03503 asection *text_sect; 03504 struct dbx_symfile_info *dbx; 03505 03506 stabsect = bfd_get_section_by_name (sym_bfd, stab_name); 03507 stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name); 03508 03509 if (!stabsect) 03510 return; 03511 03512 if (!stabstrsect) 03513 error (_("stabsect_build_psymtabs: Found stabs (%s), " 03514 "but not string section (%s)"), 03515 stab_name, stabstr_name); 03516 03517 dbx = XCNEW (struct dbx_symfile_info); 03518 set_objfile_data (objfile, dbx_objfile_data_key, dbx); 03519 03520 text_sect = bfd_get_section_by_name (sym_bfd, text_name); 03521 if (!text_sect) 03522 error (_("Can't find %s section in symbol file"), text_name); 03523 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); 03524 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); 03525 03526 DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist); 03527 DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect) 03528 / DBX_SYMBOL_SIZE (objfile); 03529 DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect); 03530 DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING 03531 INSIDE BFD DATA 03532 STRUCTURES */ 03533 03534 if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd)) 03535 error (_("ridiculous string table size: %d bytes"), 03536 DBX_STRINGTAB_SIZE (objfile)); 03537 DBX_STRINGTAB (objfile) = (char *) 03538 obstack_alloc (&objfile->objfile_obstack, 03539 DBX_STRINGTAB_SIZE (objfile) + 1); 03540 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1); 03541 03542 /* Now read in the string table in one big gulp. */ 03543 03544 val = bfd_get_section_contents (sym_bfd, /* bfd */ 03545 stabstrsect, /* bfd section */ 03546 DBX_STRINGTAB (objfile), /* input buffer */ 03547 0, /* offset into section */ 03548 DBX_STRINGTAB_SIZE (objfile)); /* amount to 03549 read */ 03550 03551 if (!val) 03552 perror_with_name (name); 03553 03554 stabsread_new_init (); 03555 buildsym_new_init (); 03556 free_header_files (); 03557 init_header_files (); 03558 03559 /* Now, do an incremental load. */ 03560 03561 processing_acc_compilation = 1; 03562 dbx_symfile_read (objfile, 0); 03563 } 03564 03565 static const struct sym_fns aout_sym_fns = 03566 { 03567 dbx_new_init, /* init anything gbl to entire symtab */ 03568 dbx_symfile_init, /* read initial info, setup for sym_read() */ 03569 dbx_symfile_read, /* read a symbol file into symtab */ 03570 NULL, /* sym_read_psymbols */ 03571 dbx_symfile_finish, /* finished with file, cleanup */ 03572 default_symfile_offsets, /* parse user's offsets to internal form */ 03573 default_symfile_segments, /* Get segment information from a file. */ 03574 NULL, 03575 default_symfile_relocate, /* Relocate a debug section. */ 03576 NULL, /* sym_probe_fns */ 03577 &psym_functions 03578 }; 03579 03580 void 03581 _initialize_dbxread (void) 03582 { 03583 add_symtab_fns (bfd_target_aout_flavour, &aout_sym_fns); 03584 03585 dbx_objfile_data_key 03586 = register_objfile_data_with_cleanup (NULL, dbx_free_symfile_info); 03587 }