[RFA/tru64] Compute bfd_section for minimal symbols

Joel Brobecker
2004-11-10T18:02:20Z

[-- Attachment #1: Type: text/plain, Size: 2360 bytes --]

Hello,

I noticed we had a lot of errors like this in the testsuite logs:

(gdb) break main
warning: (Internal error: pc 0x12000134c in read in psymtab, but not in symtab.)

Breakpoint 1 at 0x120001364: file ./gdb.base/advance.c, line 41.

The reason for this is the following check in in find_pc_sect_symtab():

fixup_symbol_section (sym, objfile);
if (section == SYMBOL_BFD_SECTION (sym))
break;

This check makes sure that the symbol section matches the section
in which we expect to find the symbol. Unfortunately for us on Tru64,
the symbol bfd_section is not set. So we fail the check, and end up
discarding the correct symbol table.

Then when find_pc_sect_symtab() falls back to searching the partial
symtabs, it founds the psymtab corresponding to the symtab we just
rejected, and is surprised to see that it has already been read in.

ps = find_pc_sect_psymtab (pc, section);
if (ps)
{
if (ps->readin)
/* Might want to error() here (in case symtab is corrupt and
will cause a core dump), but maybe we can successfully
continue, so let's not. */
warning ("\
(Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
paddr_nz (pc));
s = PSYMTAB_TO_SYMTAB (ps);

Investigating the source of the problem showed that symbol bfd_section
is not provided by the debugging information, and hence it is retrieved
using the minimal symbols through:

fixup_symbol_section (sym, objfile);

That lead me to find that the bfd_section for the symbols was not
set either. The attached patch fixes this.

2004-11-10 Joel Brobecker <brobecker@gnat.com>

* mdebugread.c (record_minimal_symbol): New procedure.
(parse_partial_symbols): Use record_minimal_symbol to record
the new minimal symbols instead of prim_record_minimal_symbol
and prim_record_minimal_symbol_and_info.

Tested on alpha-tru64, fixes a few hundred regressions.
OK to apply?

Note that I only modified the code that loads the symbol table from
objects generated by GCC. I don't have a DEC C compiler, so I didn't
modify the part of parse_partial_symbols that deals with non-gcc
symbol tables because I wouldn't be able to test the changes. I can
make the changes blindly, but ...

Thanks,
--
Joel

[-- Attachment #2: mdebugread.c.diff --]
[-- Type: text/plain, Size: 5667 bytes --]

Index: mdebugread.c
===================================================================
RCS file: /cvs/src/src/gdb/mdebugread.c,v
retrieving revision 1.71
diff -u -p -r1.71 mdebugread.c
--- mdebugread.c 31 Oct 2004 17:57:43 -0000 1.71
+++ mdebugread.c 10 Nov 2004 17:34:02 -0000
@@ -2173,6 +2173,85 @@ function_outside_compilation_unit_compla
arg1);
}

+/* Use the STORAGE_CLASS to compute which section the given symbol
+ belongs to, and then records this new minimal symbol. */
+
+static void
+record_minimal_symbol (const char *name, const CORE_ADDR address,
+ enum minimal_symbol_type ms_type, int storage_class,
+ struct objfile *objfile)
+{
+ int section;
+ asection *bfd_section;
+
+ switch (storage_class)
+ {
+ case scText:
+ section = SECT_OFF_TEXT (objfile);
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".text");
+ break;
+ case scData:
+ section = SECT_OFF_DATA (objfile);
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".data");
+ break;
+ case scBss:
+ section = SECT_OFF_BSS (objfile);
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".bss");
+ break;
+ case scSData:
+ section = get_section_index (objfile, ".sdata");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".sdata");
+ break;
+ case scSBss:
+ section = get_section_index (objfile, ".sbss");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".sbss");
+ break;
+ case scRData:
+ section = get_section_index (objfile, ".rdata");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".rdata");
+ break;
+ case scInit:
+ section = get_section_index (objfile, ".init");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".init");
+ break;
+ case scXData:
+ section = get_section_index (objfile, ".xdata");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".xdata");
+ break;
+ case scPData:
+ section = get_section_index (objfile, ".pdata");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".pdata");
+ break;
+ case scFini:
+ section = get_section_index (objfile, ".fini");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".fini");
+ break;
+ case scRConst:
+ section = get_section_index (objfile, ".rconst");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".rconst");
+ break;
+#ifdef scTlsData
+ case scTlsData:
+ section = get_section_index (objfile, ".tlsdata");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".tlsdata");
+ break;
+#endif
+#ifdef scTlsBss
+ case scTlsBss:
+ section = get_section_index (objfile, ".tlsbss");
+ bfd_section = bfd_get_section_by_name (cur_bfd, ".tlsbss");
+ break;
+#endif
+ default:
+ /* This kind of symbol is not associated to a section. */
+ section = -1;
+ bfd_section = NULL;
+ }
+
+ prim_record_minimal_symbol_and_info (name, address, ms_type, NULL,
+ section, bfd_section, objfile);
+}
+
/* Master parsing procedure for first-pass reading of file symbols
into a partial_symtab. */

@@ -2487,7 +2566,8 @@ parse_partial_symbols (struct objfile *o
unknown_ext_complaint (name);
}
if (!ECOFF_IN_ELF (cur_bfd))
- prim_record_minimal_symbol (name, svalue, ms_type, objfile);
+ record_minimal_symbol (name, svalue, ms_type, ext_in->asym.sc,
+ objfile);
}

/* Pass 3 over files, over local syms: fill in static symbols */
@@ -2604,13 +2684,9 @@ parse_partial_symbols (struct objfile *o
if (sh.st == stStaticProc)
{
namestring = debug_info->ss + fh->issBase + sh.iss;
- prim_record_minimal_symbol_and_info (namestring,
- sh.value,
- mst_file_text,
- NULL,
- SECT_OFF_TEXT (objfile),
- NULL,
- objfile);
+ record_minimal_symbol (namestring, sh.value,
+ mst_file_text, sh.sc,
+ objfile);
}
procaddr = sh.value;

@@ -2652,13 +2728,9 @@ parse_partial_symbols (struct objfile *o
case scXData:
namestring = debug_info->ss + fh->issBase + sh.iss;
sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
- prim_record_minimal_symbol_and_info (namestring,
- sh.value,
- mst_file_data,
- NULL,
- SECT_OFF_DATA (objfile),
- NULL,
- objfile);
+ record_minimal_symbol (namestring, sh.value,
+ mst_file_data, sh.sc,
+ objfile);
break;

default:
@@ -2666,13 +2738,9 @@ parse_partial_symbols (struct objfile *o
then have the default be abs? */
namestring = debug_info->ss + fh->issBase + sh.iss;
sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
- prim_record_minimal_symbol_and_info (namestring,
- sh.value,
- mst_file_bss,
- NULL,
- SECT_OFF_BSS (objfile),
- NULL,
- objfile);
+ record_minimal_symbol (namestring, sh.value,
+ mst_file_bss, sh.sc,
+ objfile);
break;
}
}