From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14360 invoked by alias); 21 Sep 2003 01:48:11 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 14351 invoked from network); 21 Sep 2003 01:48:07 -0000 Received: from unknown (HELO zenia.home) (12.223.225.216) by sources.redhat.com with SMTP; 21 Sep 2003 01:48:07 -0000 Received: by zenia.home (Postfix, from userid 5433) id 03DA82075B; Sat, 20 Sep 2003 20:45:07 -0500 (EST) To: gdb-patches@sources.redhat.com Subject: 6.0 BRANCH PATCH: fix dbxread handling of variables' section offsets From: Jim Blandy Date: Sun, 21 Sep 2003 01:48:00 -0000 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-09/txt/msg00439.txt.bz2 This patch is smaller than the ChangeLog entries would suggest. 2003-09-19 Jim Blandy Merge from mainline: 2003-09-12 Jim Blandy * dbxread.c (read_dbx_symtab): Don't report an internal error if the file has no .data, .bss, or .rodata sections. Instead wait until we see a variable alleged to live in one of those sections. 2003-09-12 Jim Blandy * dbxread.c (read_dbx_symtab): If we have no .data section and no .bss section, presume that any variables we find live in the .rodata section. 2003-09-12 Jim Blandy * dbxread.c (read_dbx_symtab): Add FIXME about finding section offsets for global and static variables. 2003-09-09 Jim Blandy * dbxread.c (read_dbx_symtab): The N_DATA and N_DATA | N_EXT symbol types are, by definition, in the .data section, so it is correct to use SECT_OFF_DATA (objfile) here, not data_sect_index. If there is no .data section, there should be no N_DATA or N_DATA | N_EXT symbols. 2003-07-10 Jim Blandy * Makefile.in (dbxread.o): Note new dependency on $(gdb_assert_h). * dbxread.c: #include "gdb_assert.h". (read_dbx_symtab): If the objfile has no .data section, use the section index for the .bss section instead. Index: gdb/Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.410.2.14 diff -c -r1.410.2.14 Makefile.in *** gdb/Makefile.in 18 Aug 2003 18:10:52 -0000 1.410.2.14 --- gdb/Makefile.in 20 Sep 2003 00:12:18 -0000 *************** *** 1663,1669 **** $(gdb_stat_h) $(symtab_h) $(breakpoint_h) $(target_h) $(gdbcore_h) \ $(libaout_h) $(symfile_h) $(objfiles_h) $(buildsym_h) $(stabsread_h) \ $(gdb_stabs_h) $(demangle_h) $(language_h) $(complaints_h) \ ! $(cp_abi_h) $(aout_aout64_h) $(aout_stab_gnu_h) dcache.o: dcache.c $(defs_h) $(dcache_h) $(gdbcmd_h) $(gdb_string_h) \ $(gdbcore_h) $(target_h) delta68-nat.o: delta68-nat.c $(defs_h) --- 1663,1669 ---- $(gdb_stat_h) $(symtab_h) $(breakpoint_h) $(target_h) $(gdbcore_h) \ $(libaout_h) $(symfile_h) $(objfiles_h) $(buildsym_h) $(stabsread_h) \ $(gdb_stabs_h) $(demangle_h) $(language_h) $(complaints_h) \ ! $(cp_abi_h) $(aout_aout64_h) $(aout_stab_gnu_h) $(gdb_assert_h) dcache.o: dcache.c $(defs_h) $(dcache_h) $(gdbcmd_h) $(gdb_string_h) \ $(gdbcore_h) $(target_h) delta68-nat.o: delta68-nat.c $(defs_h) Index: gdb/dbxread.c =================================================================== RCS file: /cvs/src/src/gdb/dbxread.c,v retrieving revision 1.48 diff -c -r1.48 dbxread.c *** gdb/dbxread.c 11 Jun 2003 22:27:10 -0000 1.48 --- gdb/dbxread.c 20 Sep 2003 00:12:20 -0000 *************** *** 58,63 **** --- 58,64 ---- #include "language.h" /* Needed for local_hex_string */ #include "complaints.h" #include "cp-abi.h" + #include "gdb_assert.h" #include "aout/aout64.h" #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */ *************** *** 1304,1309 **** --- 1305,1311 ---- struct cleanup *back_to; bfd *abfd; int textlow_not_set; + int data_sect_index; /* Current partial symtab */ struct partial_symtab *pst; *************** *** 1355,1360 **** --- 1357,1394 ---- textlow_not_set = 1; has_line_numbers = 0; + /* FIXME: jimb/2003-09-12: We don't apply the right section's offset + to global and static variables. The stab for a global or static + variable doesn't give us any indication of which section it's in, + so we can't tell immediately which offset in + objfile->section_offsets we should apply to the variable's + address. + + We could certainly find out which section contains the variable + by looking up the variable's unrelocated address with + find_pc_section, but that would be expensive; this is the + function that constructs the partial symbol tables by examining + every symbol in the entire executable, and it's + performance-critical. So that expense would not be welcome. I'm + not sure what to do about this at the moment. + + What we have done for years is to simply assume that the .data + section's offset is appropriate for all global and static + variables. Recently, this was expanded to fall back to the .bss + section's offset if there is no .data section, and then to the + .rodata section's offset. */ + data_sect_index = objfile->sect_index_data; + if (data_sect_index == -1) + data_sect_index = SECT_OFF_BSS (objfile); + if (data_sect_index == -1) + data_sect_index = SECT_OFF_RODATA (objfile); + + /* If data_sect_index is still -1, that's okay. It's perfectly fine + for the file to have no .data, no .bss, and no .text at all, if + it also has no global or static variables. If it does, we will + get an internal error from an ANOFFSET macro below when we try to + use data_sect_index. */ + for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++) { /* Get the symbol for this run and pull out some info */ *************** *** 1757,1763 **** switch (p[1]) { case 'S': ! nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); #ifdef STATIC_TRANSFORM_NAME namestring = STATIC_TRANSFORM_NAME (namestring); #endif --- 1791,1797 ---- switch (p[1]) { case 'S': ! nlist.n_value += ANOFFSET (objfile->section_offsets, data_sect_index); #ifdef STATIC_TRANSFORM_NAME namestring = STATIC_TRANSFORM_NAME (namestring); #endif *************** *** 1768,1774 **** psymtab_language, objfile); continue; case 'G': ! nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); /* 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, --- 1802,1808 ---- psymtab_language, objfile); continue; case 'G': ! nlist.n_value += ANOFFSET (objfile->section_offsets, data_sect_index); /* 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,