X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fsymfile.c;h=8d63484af1177a8c22e8a4cac0ca394478667efd;hb=697f7479bbe7c27def5b0f3b5cc06143bb5c88ab;hp=feca03b6d94fdb50af955feb732905b50f3b1a3b;hpb=81a9a963a1d5374ada16859384e378b5561f4b2a;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/symfile.c b/gdb/symfile.c index feca03b6d9..8d63484af1 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -38,8 +38,9 @@ #include "demangle.h" #include "inferior.h" /* for write_pc */ #include "gdb-stabs.h" -#include "obstack.h" +#include "gdb_obstack.h" #include "completer.h" +#include "bcache.h" #include #include @@ -120,6 +121,8 @@ static void cashier_psymtab (struct partial_symtab *); bfd *symfile_bfd_open (char *); +int get_section_index (struct objfile *, char *); + static void find_sym_fns (struct objfile *); static void decrement_reading_symtab (void *); @@ -537,6 +540,34 @@ default_symfile_offsets (struct objfile *objfile, if (sect) objfile->sect_index_rodata = sect->index; + /* This is where things get really weird... We MUST have valid + indices for the various sect_index_* members or gdb will abort. + So if for example, there is no ".text" section, we have to + accomodate that. Except when explicitly adding symbol files at + some address, section_offsets contains nothing but zeros, so it + doesn't matter which slot in section_offsets the individual + sect_index_* members index into. So if they are all zero, it is + safe to just point all the currently uninitialized indices to the + first slot. */ + + for (i = 0; i < objfile->num_sections; i++) + { + if (ANOFFSET (objfile->section_offsets, i) != 0) + { + break; + } + } + if (i == objfile->num_sections) + { + if (objfile->sect_index_text == -1) + objfile->sect_index_text = 0; + if (objfile->sect_index_data == -1) + objfile->sect_index_data = 0; + if (objfile->sect_index_bss == -1) + objfile->sect_index_bss = 0; + if (objfile->sect_index_rodata == -1) + objfile->sect_index_rodata = 0; + } } /* Process a symbol file, as either the main file or as a dynamically @@ -577,6 +608,9 @@ syms_from_objfile (struct objfile *objfile, struct section_addr_info *addrs, init_entry_point_info (objfile); find_sym_fns (objfile); + if (objfile->sf == NULL) + return; /* No symbols. */ + /* Make sure that partially constructed symbol tables will be cleaned up if an error occurs during symbol reading. */ old_chain = make_cleanup_free_objfile (objfile); @@ -891,6 +925,9 @@ symbol_file_add (char *name, int from_tty, struct section_addr_info *addrs, } } + if (objfile->sf == NULL) + return objfile; /* No symbols. */ + new_symfile_objfile (objfile, mainline, from_tty); if (target_new_objfile_hook) @@ -1109,6 +1146,18 @@ symfile_bfd_open (char *name) return (sym_bfd); } +/* Return the section index for the given section name. Return -1 if + the section was not found. */ +int +get_section_index (struct objfile *objfile, char *section_name) +{ + asection *sect = bfd_get_section_by_name (objfile->obfd, section_name); + if (sect) + return sect->index; + else + return -1; +} + /* Link a new symtab_fns into the global symtab_fns list. Called on gdb startup by the _initialize routine in each object file format reader, to register information about each format the the reader is prepared @@ -1134,6 +1183,11 @@ find_sym_fns (struct objfile *objfile) enum bfd_flavour our_flavour = bfd_get_flavour (objfile->obfd); char *our_target = bfd_get_target (objfile->obfd); + if (our_flavour == bfd_target_srec_flavour + || our_flavour == bfd_target_ihex_flavour + || our_flavour == bfd_target_tekhex_flavour) + return; /* No symbols. */ + /* Special kludge for apollo. See dstread.c. */ if (STREQN (our_target, "apollo", 6)) our_flavour = (enum bfd_flavour) -2; @@ -1687,7 +1741,10 @@ reread_symbols (void) sizeof (objfile->static_psymbols)); /* Free the obstacks for non-reusable objfiles */ - free_bcache (&objfile->psymbol_cache); + bcache_xfree (objfile->psymbol_cache); + objfile->psymbol_cache = bcache_xmalloc (); + bcache_xfree (objfile->macro_cache); + objfile->macro_cache = bcache_xmalloc (); obstack_free (&objfile->psymbol_obstack, 0); obstack_free (&objfile->symbol_obstack, 0); obstack_free (&objfile->type_obstack, 0); @@ -1711,8 +1768,8 @@ reread_symbols (void) objfile->md = NULL; /* obstack_specify_allocation also initializes the obstack so it is empty. */ - obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0, - xmalloc, xfree); + objfile->psymbol_cache = bcache_xmalloc (); + objfile->macro_cache = bcache_xmalloc (); obstack_specify_allocation (&objfile->psymbol_obstack, 0, 0, xmalloc, xfree); obstack_specify_allocation (&objfile->symbol_obstack, 0, 0, @@ -1806,8 +1863,9 @@ add_filename_language (char *ext, enum language lang) if (fl_table_next >= fl_table_size) { fl_table_size += 10; - filename_language_table = xrealloc (filename_language_table, - fl_table_size); + filename_language_table = + xrealloc (filename_language_table, + fl_table_size * sizeof (*filename_language_table)); } filename_language_table[fl_table_next].ext = xstrdup (ext); @@ -1905,9 +1963,9 @@ init_filename_language_table (void) add_filename_language (".c++", language_cplus); add_filename_language (".java", language_java); add_filename_language (".class", language_java); - add_filename_language (".ch", language_chill); - add_filename_language (".c186", language_chill); - add_filename_language (".c286", language_chill); + /* OBSOLETE add_filename_language (".ch", language_chill); */ + /* OBSOLETE add_filename_language (".c186", language_chill); */ + /* OBSOLETE add_filename_language (".c286", language_chill); */ add_filename_language (".f", language_fortran); add_filename_language (".F", language_fortran); add_filename_language (".s", language_asm); @@ -2320,7 +2378,7 @@ add_psymbol_to_list (char *name, int namelength, namespace_enum namespace, /* Create local copy of the partial symbol */ memcpy (buf, name, namelength); buf[namelength] = '\0'; - SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache); + SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache); /* val and coreaddr are mutually exclusive, one of them *will* be zero */ if (val != 0) { @@ -2337,7 +2395,7 @@ add_psymbol_to_list (char *name, int namelength, namespace_enum namespace, SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language); /* Stash the partial symbol away in the cache */ - psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache); + psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache); /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ if (list->next >= list->list + list->size) @@ -2372,7 +2430,7 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name, memcpy (buf, name, namelength); buf[namelength] = '\0'; - SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache); + SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache); buf = alloca (dem_namelength + 1); memcpy (buf, dem_name, dem_namelength); @@ -2383,11 +2441,11 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name, case language_c: case language_cplus: SYMBOL_CPLUS_DEMANGLED_NAME (&psymbol) = - bcache (buf, dem_namelength + 1, &objfile->psymbol_cache); + bcache (buf, dem_namelength + 1, objfile->psymbol_cache); break; - case language_chill: - SYMBOL_CHILL_DEMANGLED_NAME (&psymbol) = - bcache (buf, dem_namelength + 1, &objfile->psymbol_cache); + /* OBSOLETE case language_chill: */ + /* OBSOLETE SYMBOL_CHILL_DEMANGLED_NAME (&psymbol) = */ + /* OBSOLETE bcache (buf, dem_namelength + 1, objfile->psymbol_cache); */ /* FIXME What should be done for the default case? Ignoring for now. */ } @@ -2408,7 +2466,7 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name, SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language); /* Stash the partial symbol away in the cache */ - psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache); + psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache); /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ if (list->next >= list->list + list->size) @@ -3214,7 +3272,7 @@ _initialize_symfile (void) "Load symbol table from executable file FILE.\n\ The `file' command can also load symbol tables, as well as setting the file\n\ to execute.", &cmdlist); - c->completer = filename_completer; + set_cmd_completer (c, filename_completer); c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, "Usage: add-symbol-file FILE ADDR [-s -s ...]\n\ @@ -3222,9 +3280,9 @@ Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\ ADDR is the starting address of the file's text.\n\ The optional arguments are section-name section-address pairs and\n\ should be specified if the data and bss segments are not contiguous\n\ -with the text. SECT is a section name to be loaded at SECT_ADDR.", +with the text. SECT is a section name to be loaded at SECT_ADDR.", &cmdlist); - c->completer = filename_completer; + set_cmd_completer (c, filename_completer); c = add_cmd ("add-shared-symbol-files", class_files, add_shared_symbol_files_command, @@ -3236,7 +3294,7 @@ with the text. SECT is a section name to be loaded at SECT_ADDR.", c = add_cmd ("load", class_files, load_command, "Dynamically load FILE into the running program, and record its symbols\n\ for access from GDB.", &cmdlist); - c->completer = filename_completer; + set_cmd_completer (c, filename_completer); add_show_from_set (add_set_cmd ("symbol-reloading", class_support, var_boolean,