X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fcoffread.c;h=94d0554dab5d47c5e817f315d09a0c212e758d99;hb=d2f4b8feb92563f328897af142d05e796cde26bd;hp=3494eb1f69cda1c09861ef4c6afb772b41a055ad;hpb=aff410f1800950c650dc4fbaf32aff513e12cf54;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/coffread.c b/gdb/coffread.c index 3494eb1f69..94d0554dab 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1,7 +1,5 @@ /* Read coff symbol tables and convert to internal format, for GDB. - Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, - 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, - 2010 Free Software Foundation, Inc. + Copyright (C) 1987-2005, 2007-2012 Free Software Foundation, Inc. Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu). This file is part of GDB. @@ -49,6 +47,10 @@ extern void _initialize_coffread (void); +/* The objfile we are currently reading. */ + +static struct objfile *coffread_objfile; + struct coff_symfile_info { file_ptr min_lineno_offset; /* Where in file lowest line#s are. */ @@ -178,7 +180,7 @@ static int init_lineno (bfd *, long, int); static char *getsymname (struct internal_syment *); -static char *coff_getfilename (union internal_auxent *); +static const char *coff_getfilename (union internal_auxent *); static void free_stringtab (void); @@ -309,7 +311,7 @@ cs_section_address (struct coff_symbol *cs, bfd *abfd) args.resultp = § bfd_map_over_sections (abfd, find_targ_sec, &args); if (sect != NULL) - addr = bfd_get_section_vma (objfile->obfd, sect); + addr = bfd_get_section_vma (abfd, sect); return addr; } @@ -355,7 +357,7 @@ coff_alloc_type (int index) We will fill it in later if we find out how. */ if (type == NULL) { - type = alloc_type (current_objfile); + type = alloc_type (coffread_objfile); *type_addr = type; } return type; @@ -366,7 +368,7 @@ coff_alloc_type (int index) it indicates the start of data for one original source file. */ static void -coff_start_symtab (char *name) +coff_start_symtab (const char *name) { start_symtab ( /* We fill in the filename later. start_symtab puts this pointer @@ -388,7 +390,7 @@ coff_start_symtab (char *name) text. */ static void -complete_symtab (char *name, CORE_ADDR start_addr, unsigned int size) +complete_symtab (const char *name, CORE_ADDR start_addr, unsigned int size) { if (last_source_file != NULL) xfree (last_source_file); @@ -405,12 +407,10 @@ complete_symtab (char *name, CORE_ADDR start_addr, unsigned int size) static void coff_end_symtab (struct objfile *objfile) { - struct symtab *symtab; - last_source_start_addr = current_source_start_addr; - symtab = end_symtab (current_source_end_addr, objfile, - SECT_OFF_TEXT (objfile)); + end_symtab (current_source_end_addr, objfile, + SECT_OFF_TEXT (objfile)); /* Reinitialize for beginning of new file. */ last_source_file = NULL; @@ -450,12 +450,11 @@ record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address, static void coff_symfile_init (struct objfile *objfile) { - /* Allocate struct to keep track of stab reading. */ - objfile->deprecated_sym_stab_info = (struct dbx_symfile_info *) - xmalloc (sizeof (struct dbx_symfile_info)); + struct dbx_symfile_info *dbx; - memset (objfile->deprecated_sym_stab_info, 0, - sizeof (struct dbx_symfile_info)); + /* Allocate struct to keep track of stab reading. */ + dbx = XCNEW (struct dbx_symfile_info); + set_objfile_data (objfile, dbx_objfile_data_key, dbx); /* Allocate struct to keep track of the symfile. */ objfile->deprecated_sym_private @@ -528,7 +527,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) int stabstrsize; info = (struct coff_symfile_info *) objfile->deprecated_sym_private; - dbxinfo = objfile->deprecated_sym_stab_info; + dbxinfo = DBX_SYMFILE_INFO (objfile); symfile_bfd = abfd; /* Kludge for swap routines. */ /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */ @@ -623,8 +622,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) { if (!info->stabstrsect) { - error (_("The debugging information in `%s' is corrupted.\n" - "The file has a `.stabs' section, but no `.stabstr' section."), + error (_("The debugging information in `%s' is corrupted.\nThe " + "file has a `.stabs' section, but no `.stabstr' section."), name); } @@ -639,7 +638,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) info->stabsects, info->stabstrsect->filepos, stabstrsize); } - if (dwarf2_has_info (objfile)) + if (dwarf2_has_info (objfile, NULL)) { /* DWARF2 sections. */ dwarf2_build_psymtabs (objfile); @@ -653,13 +652,14 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) char *debugfile; debugfile = find_separate_debug_file_by_debuglink (objfile); + make_cleanup (xfree, debugfile); if (debugfile) { bfd *abfd = symfile_bfd_open (debugfile); + make_cleanup_bfd_unref (abfd); symbol_file_add_separate (abfd, symfile_flags, objfile); - xfree (debugfile); } } @@ -715,7 +715,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, int in_source_file = 0; int next_file_symnum = -1; /* Name of the current file. */ - char *filestring = ""; + const char *filestring = ""; int depth = 0; int fcn_first_line = 0; CORE_ADDR fcn_first_line_addr = 0; @@ -747,7 +747,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, if (val < 0) perror_with_name (objfile->name); - current_objfile = objfile; + coffread_objfile = objfile; nlist_bfd_global = objfile->obfd; nlist_nsyms_global = nsyms; last_source_file = NULL; @@ -904,22 +904,14 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, if (cs->c_secnum == N_UNDEF) { - /* This is a common symbol. See if the target - environment knows where it has been relocated to. */ - CORE_ADDR reladdr; - - if (target_lookup_symbol (cs->c_name, &reladdr)) - { - /* Error in lookup; ignore symbol. */ - break; - } - tmpaddr = reladdr; - /* The address has already been relocated; make sure that - objfile_relocate doesn't relocate it again. */ - sec = -2; - ms_type = cs->c_sclass == C_EXT - || cs->c_sclass == C_THUMBEXT ? - mst_bss : mst_file_bss; + /* This is a common symbol. We used to rely on + the target to tell us whether it knows where + the symbol has been relocated to, but none of + the target implementations actually provided + that operation. So we just ignore the symbol, + the same way we would do if we had a target-side + symbol lookup which returned no match. */ + break; } else if (cs->c_secnum == N_ABS) { @@ -948,7 +940,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC || cs->c_sclass == C_THUMBEXT ? mst_text : mst_file_text; - tmpaddr = gdbarch_smash_text_address (gdbarch, tmpaddr); + tmpaddr = gdbarch_addr_bits_remove (gdbarch, tmpaddr); } else if (bfd_section->flags & SEC_ALLOC && bfd_section->flags & SEC_LOAD) @@ -1023,7 +1015,8 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, if (context_stack_depth <= 0) { /* We attempted to pop an empty context stack. */ complaint (&symfile_complaints, - _("`.ef' symbol without matching `.bf' symbol ignored starting at symnum %d"), + _("`.ef' symbol without matching `.bf' " + "symbol ignored starting at symnum %d"), cs->c_symnum); within_function = 0; break; @@ -1034,7 +1027,8 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, if (context_stack_depth > 0 || new == NULL) { complaint (&symfile_complaints, - _("Unmatched .ef symbol(s) ignored starting at symnum %d"), + _("Unmatched .ef symbol(s) ignored " + "starting at symnum %d"), cs->c_symnum); within_function = 0; break; @@ -1088,9 +1082,10 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, else if (strcmp (cs->c_name, ".eb") == 0) { if (context_stack_depth <= 0) - { /* We attempted to pop an empty context stack. */ + { /* We attempted to pop an empty context stack. */ complaint (&symfile_complaints, - _("`.eb' symbol without matching `.bb' symbol ignored starting at symnum %d"), + _("`.eb' symbol without matching `.bb' " + "symbol ignored starting at symnum %d"), cs->c_symnum); break; } @@ -1098,8 +1093,9 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, new = pop_context (); if (depth-- != new->depth) { - complaint (&symfile_complaints, - _("Mismatched .eb symbol ignored starting at symnum %d"), + complaint (&symfile_complaints, + _("Mismatched .eb symbol ignored " + "starting at symnum %d"), symnum); break; } @@ -1138,7 +1134,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms, ALL_OBJFILE_SYMTABS (objfile, s) patch_opaque_types (s); - current_objfile = NULL; + coffread_objfile = NULL; } /* Routines for reading headers and symbols from executable. */ @@ -1159,14 +1155,14 @@ read_one_sym (struct coff_symbol *cs, cs->c_symnum = symnum; bytes = bfd_bread (temp_sym, local_symesz, nlist_bfd_global); if (bytes != local_symesz) - error ("%s: error reading symbols", current_objfile->name); + error (_("%s: error reading symbols"), coffread_objfile->name); bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *) sym); cs->c_naux = sym->n_numaux & 0xff; if (cs->c_naux >= 1) { bytes = bfd_bread (temp_aux, local_auxesz, nlist_bfd_global); if (bytes != local_auxesz) - error ("%s: error reading symbols", current_objfile->name); + error (_("%s: error reading symbols"), coffread_objfile->name); bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass, 0, cs->c_naux, (char *) aux); @@ -1176,7 +1172,7 @@ read_one_sym (struct coff_symbol *cs, { bytes = bfd_bread (temp_aux, local_auxesz, nlist_bfd_global); if (bytes != local_auxesz) - error ("%s: error reading symbols", current_objfile->name); + error (_("%s: error reading symbols"), coffread_objfile->name); } } cs->c_name = getsymname (sym); @@ -1306,15 +1302,18 @@ getsymname (struct internal_syment *symbol_entry) Return only the last component of the name. Result is in static storage and is only good for temporary use. */ -static char * +static const char * coff_getfilename (union internal_auxent *aux_entry) { static char buffer[BUFSIZ]; - char *temp; - char *result; + const char *result; if (aux_entry->x_file.x_n.x_zeroes == 0) - strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset); + { + if (strlen (stringtab + aux_entry->x_file.x_n.x_offset) >= BUFSIZ) + internal_error (__FILE__, __LINE__, _("coff file name too long")); + strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset); + } else { strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN); @@ -1325,8 +1324,7 @@ coff_getfilename (union internal_auxent *aux_entry) /* FIXME: We should not be throwing away the information about what directory. It should go into dirname of the symtab, or some such place. */ - if ((temp = strrchr (result, '/')) != NULL) - result = temp + 1; + result = lbasename (result); return (result); } @@ -1456,10 +1454,11 @@ patch_type (struct type *type, struct type *real_type) if (TYPE_NAME (real_target)) { + /* The previous copy of TYPE_NAME is allocated by + process_coff_symbol. */ if (TYPE_NAME (target)) - xfree (TYPE_NAME (target)); - TYPE_NAME (target) = concat (TYPE_NAME (real_target), - (char *) NULL); + xfree ((char*) TYPE_NAME (target)); + TYPE_NAME (target) = xstrdup (TYPE_NAME (real_target)); } } @@ -1471,7 +1470,7 @@ static void patch_opaque_types (struct symtab *s) { struct block *b; - struct dict_iterator iter; + struct block_iterator iter; struct symbol *real_sym; /* Go through the per-file symbols only. */ @@ -1487,7 +1486,7 @@ patch_opaque_types (struct symtab *s) && TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR && TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0) { - char *name = SYMBOL_LINKAGE_NAME (real_sym); + const char *name = SYMBOL_LINKAGE_NAME (real_sym); int hash = hashname (name); struct symbol *sym, *prev; @@ -1648,7 +1647,7 @@ process_coff_symbol (struct coff_symbol *cs, SYMBOL_CLASS (sym) = LOC_TYPEDEF; SYMBOL_DOMAIN (sym) = VAR_DOMAIN; - /* If type has no name, give it one */ + /* If type has no name, give it one. */ if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) { if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR @@ -1676,7 +1675,7 @@ process_coff_symbol (struct coff_symbol *cs, } else TYPE_NAME (SYMBOL_TYPE (sym)) = - concat (SYMBOL_LINKAGE_NAME (sym), (char *) NULL); + xstrdup (SYMBOL_LINKAGE_NAME (sym)); } /* Keep track of any type which points to empty structured @@ -2159,7 +2158,7 @@ coff_read_enum_type (int index, int length, int lastsym, SYMBOL_TYPE (xsym) = type; TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym); - SET_FIELD_BITPOS (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym)); + SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym)); if (SYMBOL_VALUE (xsym) < 0) unsigned_enum = 0; TYPE_FIELD_BITSIZE (type, n) = 0; @@ -2185,6 +2184,7 @@ static const struct sym_fns coff_sym_fns = for sym_read() */ coff_symfile_read, /* sym_read: read a symbol file into symtab */ + NULL, /* sym_read_psymbols */ coff_symfile_finish, /* sym_finish: finished with file, cleanup */ default_symfile_offsets, /* sym_offsets: xlate external to @@ -2195,6 +2195,7 @@ static const struct sym_fns coff_sym_fns = default_symfile_relocate, /* sym_relocate: Relocate a debug section. */ + NULL, /* sym_probe_fns */ &psym_functions };