X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fcoffread.c;h=f24ec0713a09007293d9d36c86e996691155f04e;hb=4e9668d0d1ddad73af7c20a92a00704fbea2a8d9;hp=c0f42670e72e9df24de996031a1f0e2f27f476a9;hpb=63e43d3aedb8b1112899c2d0ad74cbbee687e5d6;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/coffread.c b/gdb/coffread.c index c0f42670e7..f24ec0713a 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1,5 +1,5 @@ /* Read coff symbol tables and convert to internal format, for GDB. - Copyright (C) 1987-2015 Free Software Foundation, Inc. + Copyright (C) 1987-2018 Free Software Foundation, Inc. Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu). This file is part of GDB. @@ -43,8 +43,6 @@ #include "psymtab.h" #include "build-id.h" -extern void _initialize_coffread (void); - /* Key for COFF-associated data. */ static const struct objfile_data *coff_objfile_data_key; @@ -207,7 +205,8 @@ static void read_one_sym (struct coff_symbol *, struct internal_syment *, union internal_auxent *); -static void coff_symtab_read (long, unsigned int, struct objfile *); +static void coff_symtab_read (minimal_symbol_reader &, + long, unsigned int, struct objfile *); /* We are called once per section from coff_symfile_read. We need to examine each section we are passed, check to see @@ -253,8 +252,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip) { struct stab_section_list *n, **pn; - n = ((struct stab_section_list *) - xmalloc (sizeof (struct stab_section_list))); + n = XNEW (struct stab_section_list); n->section = sectp; n->next = NULL; for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next) @@ -394,7 +392,9 @@ coff_start_symtab (struct objfile *objfile, const char *name) NULL, /* The start address is irrelevant, since we set last_source_start_addr in coff_end_symtab. */ - 0); + 0, + /* Let buildsym.c deduce the language for this symtab. */ + language_unknown); record_debugformat ("COFF"); } @@ -462,7 +462,8 @@ is_import_fixup_symbol (struct coff_symbol *cs, } static struct minimal_symbol * -record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address, +record_minimal_symbol (minimal_symbol_reader &reader, + struct coff_symbol *cs, CORE_ADDR address, enum minimal_symbol_type type, int section, struct objfile *objfile) { @@ -480,8 +481,7 @@ record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address, return NULL; } - return prim_record_minimal_symbol_and_info (cs->c_name, address, - type, section, objfile); + return reader.record_with_info (cs->c_name, address, type, section); } /* coff_symfile_init () @@ -559,10 +559,9 @@ static bfd *symfile_bfd; /* Read a symbol file, after initialization by coff_symfile_init. */ static void -coff_symfile_read (struct objfile *objfile, int symfile_flags) +coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) { struct coff_symfile_info *info; - struct dbx_symfile_info *dbxinfo; bfd *abfd = objfile->obfd; coff_data_type *cdata = coff_data (abfd); char *name = bfd_get_filename (abfd); @@ -570,11 +569,11 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) unsigned int num_symbols; int symtab_offset; int stringtab_offset; - struct cleanup *back_to, *cleanup_minimal_symbols; + struct cleanup *back_to; int stabstrsize; - info = objfile_data (objfile, coff_objfile_data_key); - dbxinfo = DBX_SYMFILE_INFO (objfile); + info = (struct coff_symfile_info *) objfile_data (objfile, + coff_objfile_data_key); symfile_bfd = abfd; /* Kludge for swap routines. */ /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */ @@ -647,18 +646,17 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) if (val < 0) error (_("\"%s\": can't get string table"), name); - init_minimal_symbol_collection (); - cleanup_minimal_symbols = make_cleanup_discard_minimal_symbols (); + minimal_symbol_reader reader (objfile); /* Now that the executable file is positioned at symbol table, process it and define symbols accordingly. */ - coff_symtab_read ((long) symtab_offset, num_symbols, objfile); + coff_symtab_read (reader, (long) symtab_offset, num_symbols, objfile); /* Install any minimal symbols that have been collected as the current minimal symbols for this objfile. */ - install_minimal_symbols (objfile); + reader.install (); if (pe_file) { @@ -701,10 +699,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) } } - /* Free the installed minimal symbol data. */ - do_cleanups (cleanup_minimal_symbols); - - bfd_map_over_sections (abfd, coff_locate_sections, (void *) info); + if (!(objfile->flags & OBJF_READNEVER)) + bfd_map_over_sections (abfd, coff_locate_sections, (void *) info); if (info->stabsects) { @@ -737,20 +733,17 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) /* Try to add separate debug file if no symbols table found. */ if (!objfile_has_partial_symbols (objfile)) { - char *debugfile; - - debugfile = find_separate_debug_file_by_buildid (objfile); + std::string debugfile = find_separate_debug_file_by_buildid (objfile); - if (debugfile == NULL) + if (debugfile.empty ()) debugfile = find_separate_debug_file_by_debuglink (objfile); - make_cleanup (xfree, debugfile); - if (debugfile) + if (!debugfile.empty ()) { - bfd *abfd = symfile_bfd_open (debugfile); + gdb_bfd_ref_ptr abfd (symfile_bfd_open (debugfile.c_str ())); - make_cleanup_bfd_unref (abfd); - symbol_file_add_separate (abfd, debugfile, symfile_flags, objfile); + symbol_file_add_separate (abfd.get (), debugfile.c_str (), + symfile_flags, objfile); } } @@ -784,7 +777,8 @@ coff_symfile_finish (struct objfile *objfile) We read them one at a time using read_one_sym (). */ static void -coff_symtab_read (long symtab_offset, unsigned int nsyms, +coff_symtab_read (minimal_symbol_reader &reader, + long symtab_offset, unsigned int nsyms, struct objfile *objfile) { struct gdbarch *gdbarch = get_objfile_arch (objfile); @@ -841,9 +835,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, if (type_vector) /* Get rid of previous one. */ xfree (type_vector); type_vector_length = INITIAL_TYPE_VECTOR_LENGTH; - type_vector = (struct type **) - xmalloc (type_vector_length * sizeof (struct type *)); - memset (type_vector, 0, type_vector_length * sizeof (struct type *)); + type_vector = XCNEWVEC (struct type *, type_vector_length); coff_start_symtab (objfile, ""); @@ -884,7 +876,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, int section = cs_to_section (cs, objfile); tmpaddr = cs->c_value; - record_minimal_symbol (cs, tmpaddr, mst_text, + record_minimal_symbol (reader, cs, tmpaddr, mst_text, section, objfile); fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr; @@ -936,6 +928,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, backtraces, so filter them out (from phdm@macqel.be). */ if (within_function) break; + /* Fall through. */ case C_STAT: case C_THUMBLABEL: case C_THUMBSTAT: @@ -972,7 +965,8 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, /* At least on a 3b1, gcc generates swbeg and string labels that look like this. Ignore them. */ break; - /* Fall in for static symbols that don't start with '.' */ + /* For static symbols that don't start with '.'... */ + /* Fall through. */ case C_THUMBEXT: case C_THUMBEXTFUNC: case C_EXT: @@ -1044,7 +1038,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, ms_type = mst_unknown; } - msym = record_minimal_symbol (cs, tmpaddr, ms_type, + msym = record_minimal_symbol (reader, cs, tmpaddr, ms_type, sec, objfile); if (msym) gdbarch_coff_make_msymbol_special (gdbarch, @@ -1206,7 +1200,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, { /* We've got no debugging symbols, but it's a portable executable, so try to read the export table. */ - read_pe_exported_syms (objfile); + read_pe_exported_syms (reader, objfile); } if (get_last_source_file ()) @@ -2102,12 +2096,13 @@ coff_read_struct_type (int index, int length, int lastsym, case C_MOU: /* Get space to record the next field's data. */ - newobj = (struct nextfield *) alloca (sizeof (struct nextfield)); + newobj = XALLOCA (struct nextfield); newobj->next = list; list = newobj; /* Save the data. */ - list->field.name = obstack_copy0 (&objfile->objfile_obstack, + list->field.name + = (const char *) obstack_copy0 (&objfile->objfile_obstack, name, strlen (name)); FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux, objfile); @@ -2119,12 +2114,13 @@ coff_read_struct_type (int index, int length, int lastsym, case C_FIELD: /* Get space to record the next field's data. */ - newobj = (struct nextfield *) alloca (sizeof (struct nextfield)); + newobj = XALLOCA (struct nextfield); newobj->next = list; list = newobj; /* Save the data. */ - list->field.name = obstack_copy0 (&objfile->objfile_obstack, + list->field.name + = (const char *) obstack_copy0 (&objfile->objfile_obstack, name, strlen (name)); FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux, objfile); @@ -2195,9 +2191,9 @@ coff_read_enum_type (int index, int length, int lastsym, case C_MOE: sym = allocate_symbol (objfile); - SYMBOL_SET_LINKAGE_NAME (sym, - obstack_copy0 (&objfile->objfile_obstack, - name, strlen (name))); + name = (char *) obstack_copy0 (&objfile->objfile_obstack, name, + strlen (name)); + SYMBOL_SET_LINKAGE_NAME (sym, name); SYMBOL_ACLASS_INDEX (sym) = LOC_CONST; SYMBOL_DOMAIN (sym) = VAR_DOMAIN; SYMBOL_VALUE (sym) = ms->c_value;