X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fxcoffread.c;h=bc4877389b0f1ce7e0c84388298cdb1c2df39180;hb=39ef2f6256737db92f5d60fa201fe0b301bb8100;hp=41ff583628a5fb83df8ca388ad3108201c81cf81;hpb=baa62830ed84d45b414ff677b7bce900a21923ce;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 41ff583628..bc4877389b 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -28,6 +28,7 @@ #include #endif #include +#include #include "coff/internal.h" #include "libcoff.h" /* FIXME, internal data from BFD */ @@ -53,10 +54,6 @@ #include "aout/stab_gnu.h" -/* Key for XCOFF-associated data. */ - -static const struct objfile_data *xcoff_objfile_data_key; - /* We put a pointer to this structure in the read_symtab_private field of the psymtab. */ @@ -125,32 +122,35 @@ static CORE_ADDR first_object_file_end; static unsigned local_symesz; -struct coff_symfile_info +struct xcoff_symfile_info { - file_ptr min_lineno_offset; /* Where in file lowest line#s are. */ - file_ptr max_lineno_offset; /* 1+last byte of line#s in file. */ + file_ptr min_lineno_offset {}; /* Where in file lowest line#s are. */ + file_ptr max_lineno_offset {}; /* 1+last byte of line#s in file. */ /* Pointer to the string table. */ - char *strtbl; + char *strtbl = nullptr; /* Pointer to debug section. */ - char *debugsec; + char *debugsec = nullptr; /* Pointer to the a.out symbol table. */ - char *symtbl; + char *symtbl = nullptr; /* Number of symbols in symtbl. */ - int symtbl_num_syms; + int symtbl_num_syms = 0; /* Offset in data section to TOC anchor. */ - CORE_ADDR toc_offset; + CORE_ADDR toc_offset = 0; }; +/* Key for XCOFF-associated data. */ + +static const struct objfile_key xcoff_objfile_data_key; + /* Convenience macro to access the per-objfile XCOFF data. */ #define XCOFF_DATA(objfile) \ - ((struct coff_symfile_info *) objfile_data ((objfile), \ - xcoff_objfile_data_key)) + xcoff_objfile_data_key.get (objfile) /* XCOFF names for dwarf sections. There is no compressed sections. */ @@ -235,8 +235,6 @@ static void read_xcoff_symtab (struct objfile *, struct partial_symtab *); static void add_stab_to_list (char *, struct pending_stabs **); #endif -static int compare_lte (const void *, const void *); - static struct linetable *arrange_linetable (struct linetable *); static void record_include_end (struct coff_symbol *); @@ -268,9 +266,9 @@ find_targ_sec (bfd *abfd, asection *sect, void *obj) if (sect->target_index == args->targ_index) { /* This is the section. Figure out what SECT_OFF_* code it is. */ - if (bfd_get_section_flags (abfd, sect) & SEC_CODE) + if (bfd_section_flags (sect) & SEC_CODE) *args->resultp = SECT_OFF_TEXT (objfile); - else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD) + else if (bfd_section_flags (sect) & SEC_LOAD) *args->resultp = SECT_OFF_DATA (objfile); else *args->resultp = gdb_bfd_section_index (abfd, sect); @@ -408,18 +406,6 @@ add_stab_to_list (char *stabname, struct pending_stabs **stabvector) /* *INDENT-ON* */ - -/* compare line table entry addresses. */ - -static int -compare_lte (const void *lte1p, const void *lte2p) -{ - struct linetable_entry *lte1 = (struct linetable_entry *) lte1p; - struct linetable_entry *lte2 = (struct linetable_entry *) lte2p; - - return lte1->pc - lte2->pc; -} - /* Given a line table with function entries are marked, arrange its functions in ascending order and strip off function entry markers and return it in a newly created table. If the old one is good @@ -472,8 +458,9 @@ arrange_linetable (struct linetable *oldLineTb) return oldLineTb; } else if (function_count > 1) - qsort (fentry, function_count, - sizeof (struct linetable_entry), compare_lte); + std::sort (fentry, fentry + function_count, + [] (const linetable_entry <e1, const linetable_entry& lte2) + { return lte1.pc < lte2.pc; }); /* Allocate a new line table. */ newLineTb = (struct linetable *) @@ -1006,7 +993,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) { bfd *abfd = objfile->obfd; char *raw_auxptr; /* Pointer to first raw aux entry for sym. */ - struct coff_symfile_info *xcoff = XCOFF_DATA (objfile); + struct xcoff_symfile_info *xcoff = XCOFF_DATA (objfile); char *strtbl = xcoff->strtbl; char *debugsec = xcoff->debugsec; const char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF"; @@ -1046,7 +1033,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) pst_symtab_language = deduce_language_from_filename (filestring); start_stabs (); - start_symtab (objfile, filestring, (char *) NULL, file_start_addr, + start_symtab (objfile, filestring, NULL, file_start_addr, pst_symtab_language); record_debugformat (debugfmt); symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum; @@ -1140,8 +1127,8 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) } start_stabs (); - start_symtab (objfile, "_globals_", (char *) NULL, - (CORE_ADDR) 0, pst_symtab_language); + start_symtab (objfile, "_globals_", NULL, + 0, pst_symtab_language); record_debugformat (debugfmt); cur_src_end_addr = first_object_file_end; /* Done with all files, everything from here on is globals. */ @@ -1167,7 +1154,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) c_type value of main symbol table will be set only in case of C_EXT/C_HIDEEXT/C_WEAKEXT storage class symbols. Bit 10 of type is set if symbol is a function, ie the value is set - to 32(0x20). So we need to read the first function auxiliay entry + to 32(0x20). So we need to read the first function auxiliary entry which contains the size. */ if (cs->c_naux > 1 && ISFCN (cs->c_type)) { @@ -1185,7 +1172,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) continue; } /* Read the csect auxiliary header, which is always the last by - onvention. */ + convention. */ bfd_coff_swap_aux_in (abfd, raw_auxptr + ((coff_data (abfd)->local_symesz) @@ -1231,7 +1218,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) /* Give all csects for this source file the same name. */ start_symtab (objfile, filestring, NULL, - (CORE_ADDR) 0, pst_symtab_language); + 0, pst_symtab_language); record_debugformat (debugfmt); } @@ -1351,8 +1338,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) filestring = cs->c_name; start_stabs (); - start_symtab (objfile, filestring, (char *) NULL, (CORE_ADDR) 0, - pst_symtab_language); + start_symtab (objfile, filestring, NULL, 0, pst_symtab_language); record_debugformat (debugfmt); last_csect_name = 0; @@ -1541,8 +1527,8 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) #define SYMNAME_ALLOC(NAME, ALLOCED) \ - ((ALLOCED) ? (NAME) : obstack_copy0 (&objfile->objfile_obstack, \ - (NAME), strlen (NAME))) + ((ALLOCED) ? (NAME) : obstack_strdup (&objfile->objfile_obstack, \ + (NAME))) /* process one xcoff symbol. */ @@ -1578,7 +1564,7 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile) initialize_objfile_symbol (sym); /* default assumptions */ - SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off; + SET_SYMBOL_VALUE_ADDRESS (sym, cs->c_value + off); SYMBOL_DOMAIN (sym) = VAR_DOMAIN; SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile); @@ -1588,8 +1574,7 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile) will be patched with the type from its stab entry later on in patch_block_stabs (), unless the file was compiled without -g. */ - SYMBOL_SET_LINKAGE_NAME (sym, ((const char *) - SYMNAME_ALLOC (name, symname_alloced))); + SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced)); SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol; SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK; @@ -1677,7 +1662,9 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile) cs->c_name, 0, 0, objfile); if (sym != NULL) { - SYMBOL_VALUE_ADDRESS (sym) += static_block_base; + SET_SYMBOL_VALUE_ADDRESS (sym, + SYMBOL_VALUE_ADDRESS (sym) + + static_block_base); SYMBOL_SECTION (sym) = static_block_section; } return sym; @@ -1710,7 +1697,7 @@ coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile) static void read_symbol (struct internal_syment *symbol, int symno) { - struct coff_symfile_info *xcoff = XCOFF_DATA (this_symtab_objfile); + struct xcoff_symfile_info *xcoff = XCOFF_DATA (this_symtab_objfile); int nsyms = xcoff->symtbl_num_syms; char *stbl = xcoff->symtbl; @@ -1747,7 +1734,7 @@ read_symbol_lineno (int symno) struct objfile *objfile = this_symtab_objfile; int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd); - struct coff_symfile_info *info = XCOFF_DATA (objfile); + struct xcoff_symfile_info *info = XCOFF_DATA (objfile); int nsyms = info->symtbl_num_syms; char *stbl = info->symtbl; char *strtbl = info->strtbl; @@ -1813,7 +1800,7 @@ gotit: static void find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo) { - struct coff_symfile_info *info; + struct xcoff_symfile_info *info; int size, count; file_ptr offset, maxoff; @@ -1823,7 +1810,7 @@ find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo) return; size = count * coff_data (abfd)->local_linesz; - info = (struct coff_symfile_info *) vpinfo; + info = (struct xcoff_symfile_info *) vpinfo; offset = asect->line_filepos; maxoff = offset + size; @@ -1934,11 +1921,8 @@ xcoff_new_init (struct objfile *objfile) static void xcoff_symfile_init (struct objfile *objfile) { - struct coff_symfile_info *xcoff; - /* Allocate struct to keep track of the symfile. */ - xcoff = XNEW (struct coff_symfile_info); - set_objfile_data (objfile, xcoff_objfile_data_key, xcoff); + xcoff_objfile_data_key.emplace (objfile); /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we find this causes a significant slowdown in gdb then we could @@ -1971,7 +1955,7 @@ init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile) int val; unsigned char lengthbuf[4]; char *strtbl; - struct coff_symfile_info *xcoff = XCOFF_DATA (objfile); + struct xcoff_symfile_info *xcoff = XCOFF_DATA (objfile); xcoff->strtbl = NULL; @@ -2026,16 +2010,13 @@ static unsigned int first_fun_line_offset; static struct partial_symtab * xcoff_start_psymtab (struct objfile *objfile, - const char *filename, int first_symnum, - std::vector &global_psymbols, - std::vector &static_psymbols) + const char *filename, int first_symnum) { struct partial_symtab *result = start_psymtab_common (objfile, filename, /* We fill in textlow later. */ - 0, - global_psymbols, static_psymbols); + 0); result->read_symtab_private = XOBNEW (&objfile->objfile_obstack, struct symloc); @@ -2078,9 +2059,8 @@ xcoff_end_psymtab (struct objfile *objfile, struct partial_symtab *pst, pst->number_of_dependencies = number_dependencies; if (number_dependencies) { - pst->dependencies = XOBNEWVEC (&objfile->objfile_obstack, - struct partial_symtab *, - number_dependencies); + pst->dependencies + = objfile->partial_symtabs->allocate_dependencies (number_dependencies); memcpy (pst->dependencies, dependency_list, number_dependencies * sizeof (struct partial_symtab *)); } @@ -2099,7 +2079,7 @@ xcoff_end_psymtab (struct objfile *objfile, struct partial_symtab *pst, /* We could save slight bits of space by only making one of these, shared by the entire set of include files. FIXME-someday. */ subpst->dependencies = - XOBNEW (&objfile->objfile_obstack, struct partial_symtab *); + objfile->partial_symtabs->allocate_dependencies (1); subpst->dependencies[0] = pst; subpst->number_of_dependencies = 1; @@ -2317,9 +2297,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, pst = xcoff_start_psymtab (objfile, filestring, - symnum_before, - objfile->global_psymbols, - objfile->static_psymbols); + symnum_before); } } /* Activate the misc_func_recorded mechanism for @@ -2366,7 +2344,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, section. */ bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile); if (bfd_sect) - toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect); + toc_offset -= bfd_section_vma (bfd_sect); break; case XMC_TC: @@ -2501,9 +2479,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, pst = xcoff_start_psymtab (objfile, filestring, - symnum_before, - objfile->global_psymbols, - objfile->static_psymbols); + symnum_before); last_csect_name = NULL; } break; @@ -2658,10 +2634,10 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, namestring = gdbarch_static_transform_name (gdbarch, namestring); - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, VAR_DOMAIN, LOC_STATIC, SECT_OFF_DATA (objfile), - &objfile->static_psymbols, + psymbol_placement::STATIC, symbol.n_value, psymtab_language, objfile); continue; @@ -2669,10 +2645,10 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, case 'G': /* The addresses in these entries are reported to be wrong. See the code that reads 'G's for symtabs. */ - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, VAR_DOMAIN, LOC_STATIC, SECT_OFF_DATA (objfile), - &objfile->global_psymbols, + psymbol_placement::GLOBAL, symbol.n_value, psymtab_language, objfile); continue; @@ -2688,16 +2664,16 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, || (p == namestring + 1 && namestring[0] != ' ')) { - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, STRUCT_DOMAIN, LOC_TYPEDEF, -1, - &objfile->static_psymbols, + psymbol_placement::STATIC, 0, psymtab_language, objfile); if (p[2] == 't') { /* Also a typedef with the same name. */ - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, VAR_DOMAIN, LOC_TYPEDEF, -1, - &objfile->static_psymbols, + psymbol_placement::STATIC, 0, psymtab_language, objfile); p += 1; } @@ -2707,9 +2683,9 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, case 't': if (p != namestring) /* a name is there, not just :T... */ { - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, VAR_DOMAIN, LOC_TYPEDEF, -1, - &objfile->static_psymbols, + psymbol_placement::STATIC, 0, psymtab_language, objfile); } check_enum: @@ -2769,9 +2745,9 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, ; /* Note that the value doesn't matter for enum constants in psymtabs, just in symtabs. */ - add_psymbol_to_list (p, q - p, 1, + add_psymbol_to_list (p, q - p, true, VAR_DOMAIN, LOC_CONST, -1, - &objfile->static_psymbols, + psymbol_placement::STATIC, 0, psymtab_language, objfile); /* Point past the name. */ p = q; @@ -2787,9 +2763,9 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, case 'c': /* Constant, e.g. from "const" in Pascal. */ - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, VAR_DOMAIN, LOC_CONST, -1, - &objfile->static_psymbols, + psymbol_placement::STATIC, 0, psymtab_language, objfile); continue; @@ -2804,10 +2780,10 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, function_outside_compilation_unit_complaint (name); xfree (name); } - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), - &objfile->static_psymbols, + psymbol_placement::STATIC, symbol.n_value, psymtab_language, objfile); continue; @@ -2834,10 +2810,10 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, if (startswith (namestring, "@FIX")) continue; - add_psymbol_to_list (namestring, p - namestring, 1, + add_psymbol_to_list (namestring, p - namestring, true, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), - &objfile->global_psymbols, + psymbol_placement::GLOBAL, symbol.n_value, psymtab_language, objfile); continue; @@ -2933,7 +2909,7 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) int num_symbols; /* # of symbols */ file_ptr symtab_offset; /* symbol table and */ file_ptr stringtab_offset; /* string table file offsets */ - struct coff_symfile_info *info; + struct xcoff_symfile_info *info; const char *name; unsigned int size; @@ -2966,7 +2942,7 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) secp = bfd_get_section_by_name (abfd, ".debug"); if (secp) { - length = bfd_section_size (abfd, secp); + length = bfd_section_size (secp); if (length) { debugsec @@ -2998,14 +2974,11 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) if (val != size) perror_with_name (_("reading symbol table")); - /* If we are reinitializing, or if we have never loaded syms yet, init. */ - if (objfile->global_psymbols.capacity () == 0 - && objfile->static_psymbols.capacity () == 0) - /* I'm not sure how how good num_symbols is; the rule of thumb in - init_psymbol_list was developed for a.out. On the one hand, - num_symbols includes auxents. On the other hand, it doesn't - include N_SLINE. */ - init_psymbol_list (objfile, num_symbols); + /* I'm not sure how how good num_symbols is; the rule of thumb in + init_psymbol_list was developed for a.out. On the one hand, + num_symbols includes auxents. On the other hand, it doesn't + include N_SLINE. */ + init_psymbol_list (objfile, num_symbols); scoped_free_pendings free_pending; minimal_symbol_reader reader (objfile); @@ -3046,8 +3019,7 @@ xcoff_symfile_offsets (struct objfile *objfile, if (objfile->num_sections == 0) return; /* Is that even possible? Better safe than sorry. */ - first_section_name - = bfd_section_name (objfile->obfd, objfile->sections[0].the_bfd_section); + first_section_name = bfd_section_name (objfile->sections[0].the_bfd_section); if (objfile->sect_index_text == 0 && strcmp (first_section_name, ".text") != 0) @@ -3106,7 +3078,7 @@ xcoff_get_core_n_import_files (bfd *abfd) if (sect == NULL) return -1; /* Not a core file. */ - for (offset = 0; offset < bfd_get_section_size (sect);) + for (offset = 0; offset < bfd_section_size (sect);) { int next; @@ -3154,19 +3126,8 @@ xcoff_get_n_import_files (bfd *abfd) return l_nimpid - 1; } -/* Free the per-objfile xcoff data. */ - -static void -xcoff_free_info (struct objfile *objfile, void *arg) -{ - xfree (arg); -} - void _initialize_xcoffread (void) { add_symtab_fns (bfd_target_xcoff_flavour, &xcoff_sym_fns); - - xcoff_objfile_data_key = register_objfile_data_with_cleanup (NULL, - xcoff_free_info); }