This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
[RFC] Fix SECT_OFF_* indexes
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: [RFC] Fix SECT_OFF_* indexes
- From: Elena Zannoni <ezannoni at cygnus dot com>
- Date: Thu, 20 Apr 2000 21:01:36 -0400 (EDT)
This patch makes SECT_OFF_{TEXT, DATA, BSS, RODATA} correspond to the
real indexes that bfd uses, whatever they are.
I have tested this mainly on elf-stabs combinations.
The som reader and the xcoff reader have been pretty much left
untouched. There is room for improvement on the SOM side, because I am
not clear about the naming convenction for SOM sections and how they
map to the notion of sections that gdb has. If somebody is willing to
fix this, feel free.
Basically what this patch does is make SECT_OFF_* variables instead of
constants. The values are derived from bfd information.
With this patch it is possible for elf-stabs to have gdb do the following:
Test program
test.c
------
static int count = 100;
const int ttt = 456;
static int someVar;
void testIt(void)
{
someVar += count;
}
int anotherVar;
%gcc -c -o test1.o -g test.c
%ld -r -o test.o test1.o
% objdump -h ~/test.o
/home/ezannoni/test.o: file format elf32-sparc
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000001c 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .rodata 00000004 00000000 00000000 00000050 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .data 00000004 00000000 00000000 00000054 2**2
CONTENTS, ALLOC, LOAD, DATA
3 .bss 00000008 00000000 00000000 00000058 2**2
ALLOC
4 .stab 00000180 00000000 00000000 00000058 2**2
CONTENTS, RELOC, READONLY, DEBUGGING
5 .stabstr 000003b3 00000000 00000000 000001d8 2**0
CONTENTS, READONLY, DEBUGGING
6 .comment 0000001c 00000000 00000000 0000058b 2**0
CONTENTS, READONLY
kwikemart.cygnus.com: 139 % ./gdb -nw
GNU gdb 20000204
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.5.1".
Setting up the environment for debugging gdb.
.gdbinit:5: Error in sourced command file:
No symbol table is loaded. Use the "file" command.
(gdb) add-symbol-file ~/test.o 0x1000 -s .data 0x2000 -s .bss 0x3000 -s .rodata 0x4000
add symbol table from file "/home/ezannoni/test.o" at
.text_addr = 0x1000
.data_addr = 0x2000
.bss_addr = 0x3000
.rodata_addr = 0x4000
(y or n) y
Reading symbols from /home/ezannoni/test.o...done.
(gdb) p &count
$1 = (int *) 0x2000
(gdb) p &testIt
$2 = (void (*)()) 0x1000 <testIt>
(gdb) p &someVar
$3 = (int *) 0x3000
(gdb) p &anotherVar
$4 = (int *) 0x3004
(gdb) p &ttt
$5 = (int *) 0x4000
I wonder if I have consider all the angles to the problem, feel free
to comment.
Elena
2000-04-20 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* gdb-stabs.h: Delete SECT_OFF_TEXT, SECT_OFF_DATA, SECT_OFF_BSS,
SECT_OFF_RODATA constants. They are now variables. Export them.
* symfile.c (default_symfile_offsets): Declare SECT_OFF_*.
* symfile.c (default_symfile_offsets): Assign values to SECT_OFF_*
according to what the user specified or just get the values from
bfd itself.
* somread.c (som_symfile_offsets): Initialize SECT_OFF_{TEXT,
DATA, BSS, RODATA}.
* xcoffread.c (xcoff_symfile_offsets): Ditto.
* elfread.c (elf_symtab_read): Compute offset using the bfd
section index, instead of SECT_OFF_TEXT.
* coffread.c (coff_symtab_read): Don't use a switch statement any
more, sec is not a constant now.
Index: coffread.c
===================================================================
RCS file: /cvs/src/src/gdb/coffread.c,v
retrieving revision 1.2
diff -c -u -p -r1.2 coffread.c
--- coffread.c 2000/02/08 04:39:01 1.2
+++ coffread.c 2000/04/21 00:57:28
@@ -969,10 +969,8 @@ coff_symtab_read (symtab_offset, nsyms,
|| cs->c_sclass == C_THUMBEXT)
tmpaddr += ANOFFSET (objfile->section_offsets, sec);
- switch (sec)
+ if (sec == SECT_OFF_TEXT || sec == SECT_OFF_RODATA)
{
- case SECT_OFF_TEXT:
- case SECT_OFF_RODATA:
ms_type =
cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
|| cs->c_sclass == C_THUMBEXT ?
@@ -981,21 +979,23 @@ coff_symtab_read (symtab_offset, nsyms,
if (tmpaddr & 1) /* FIXME: delete this line */
SMASH_TEXT_ADDRESS (tmpaddr);
#endif
- break;
- case SECT_OFF_DATA:
+ }
+ else
+ if (sec == SECT_OFF_DATA)
+ {
ms_type =
cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT ?
mst_data : mst_file_data;
- break;
- case SECT_OFF_BSS:
+ }
+ else
+ if (sec == SECT_OFF_BSS)
+ {
ms_type =
cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT ?
mst_data : mst_file_data;
- break;
- default:
- ms_type = mst_unknown;
- break;
- }
+ }
+ else
+ ms_type = mst_unknown;
}
if (cs->c_name[0] != '@' /* Skip tdesc symbols */ )
Index: elfread.c
===================================================================
RCS file: /cvs/src/src/gdb/elfread.c,v
retrieving revision 1.4
diff -c -u -p -r1.4 elfread.c
--- elfread.c 2000/02/15 04:48:23 1.4
+++ elfread.c 2000/04/21 00:57:29
@@ -293,8 +293,7 @@ elf_symtab_read (objfile, dynamic)
if (number_of_symbols < 0)
error ("Can't read symbols from %s: %s", bfd_get_filename (objfile->obfd),
bfd_errmsg (bfd_get_error ()));
- /* FIXME: Should use section specific offset, not SECT_OFF_TEXT. */
- offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
+
for (i = 0; i < number_of_symbols; i++)
{
sym = symbol_table[i];
@@ -304,6 +303,8 @@ elf_symtab_read (objfile, dynamic)
that are null strings (may happen). */
continue;
}
+
+ offset = ANOFFSET (objfile->section_offsets, sym->section->index);
if (dynamic
&& sym->section == &bfd_und_section
Index: gdb-stabs.h
===================================================================
RCS file: /cvs/src/src/gdb/gdb-stabs.h,v
retrieving revision 1.1.1.3
diff -c -u -p -r1.1.1.3 gdb-stabs.h
--- gdb-stabs.h 1999/10/05 23:08:13 1.1.1.3
+++ gdb-stabs.h 2000/04/21 00:57:29
@@ -32,12 +32,12 @@
stabs symbols. Every psymtab built from stabs will have these offsets
filled in by these guidelines, so that when actually reading symbols, the
proper offset can simply be selected and added to the symbol value. */
+extern int SECT_OFF_TEXT;
+extern int SECT_OFF_DATA;
+extern int SECT_OFF_BSS;
+extern int SECT_OFF_RODATA;
-#define SECT_OFF_TEXT 0
-#define SECT_OFF_DATA 1
-#define SECT_OFF_BSS 2
-#define SECT_OFF_RODATA 3
-#define SECT_OFF_MAX 16 /* Count of possible values */
+#define SECT_OFF_MAX 40 /* Count of possible values */
/* The stab_section_info chain remembers info from the ELF symbol table,
while psymtabs are being built for the other symbol tables in the
Index: somread.c
===================================================================
RCS file: /cvs/src/src/gdb/somread.c,v
retrieving revision 1.1.1.7
diff -c -u -p -r1.1.1.7 somread.c
--- somread.c 1999/10/05 23:08:49 1.1.1.7
+++ somread.c 2000/04/21 00:57:29
@@ -465,17 +465,37 @@ som_symfile_offsets (objfile, addrs)
struct section_addr_info *addrs;
{
int i;
+ CORE_ADDR text_addr;
objfile->num_sections = SECT_OFF_MAX;
objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
+ /* FIXME: ezannoni 2000-04-20 The section names in SOM are not
+ .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
+ SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't
+ know the correspondence between SOM sections and GDB's idea of
+ section names. So for now we default to what is was before these
+ changes.*/
+ SECT_OFF_TEXT = 0;
+ SECT_OFF_DATA = 1;
+ SECT_OFF_BSS = 2;
+ SECT_OFF_RODATA = 3;
+
/* First see if we're a shared library. If so, get the section
offsets from the library, else get them from addrs. */
if (!som_solib_section_offsets (objfile, objfile->section_offsets))
{
+ /* Note: Here is OK to compare with ".text" because this is the
+ name that gdb itself gives to that section, not the SOM
+ name. */
+ for (i = 0; i < SECT_OFF_MAX && addrs->other[i].name; i++)
+ if (strcmp (addrs->other[i].name, ".text") == 0)
+ break;
+ text_addr = addrs->other[i].addr;
+
for (i = 0; i < SECT_OFF_MAX; i++)
- ANOFFSET (objfile->section_offsets, i) = addrs -> text_addr;
+ ANOFFSET (objfile->section_offsets, i) = text_addr;
}
}
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.7
diff -c -u -p -r1.7 symfile.c
--- symfile.c 2000/04/17 16:09:04 1.7
+++ symfile.c 2000/04/21 00:57:30
@@ -198,6 +198,19 @@ int symbol_reloading = 0;
*/
int auto_solib_add = 1;
+
+
+/* Indexes in the section_offsets array. These are initialized by the
+ *_symfile_offsets() family of functions (som_symfile_offsets,
+ xcoff_symfile_offsets, default_symfile_offsets). In theory they
+ should correspond to the section indexes used by bfd for the
+ current objfile. The exception to this for the time being is the
+ SOM version. */
+int SECT_OFF_TEXT = -1;
+int SECT_OFF_DATA = -1;
+int SECT_OFF_BSS = -1;
+int SECT_OFF_RODATA = -1;
+
/* Since this function is called from within qsort, in an ANSI environment
@@ -518,13 +531,15 @@ default_symfile_offsets (objfile, addrs)
struct section_addr_info *addrs;
{
int i;
+ asection *sect = NULL;
objfile->num_sections = SECT_OFF_MAX;
objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
memset (objfile->section_offsets, 0, SIZEOF_SECTION_OFFSETS);
- /* Now calculate offsets for other sections. */
+ /* Now calculate offsets for section that were specified by the
+ caller. */
for (i = 0; i < MAX_SECTIONS && addrs->other[i].name; i++)
{
struct other_sections *osp ;
@@ -532,19 +547,53 @@ default_symfile_offsets (objfile, addrs)
osp = &addrs->other[i] ;
if (addrs->other[i].addr == 0)
continue;
-#if 0
+
+ /* Remember the index in the section_offsets array of the .text,
+ .data, .bss and .rodata sections. */
+
if (strcmp (".text", osp->name) == 0)
SECT_OFF_TEXT = osp->sectindex ;
else if (strcmp (".data", osp->name) == 0)
SECT_OFF_DATA = osp->sectindex ;
else if (strcmp (".bss", osp->name) == 0)
SECT_OFF_BSS = osp->sectindex ;
-#endif
+ else if (strcmp (".rodata", osp->name) == 0)
+ SECT_OFF_RODATA = osp->sectindex ;
+
/* Record all sections in offsets */
+ /* The section_offsets in the objfile are here filled in using
+ the BFD index. */
ANOFFSET (objfile->section_offsets, osp->sectindex) = osp->addr;
}
-}
+ /* If some of the section indexes that we'll need later on has not
+ been initialized let's do it now, using the bfd indexes. */
+
+ if (SECT_OFF_TEXT == -1)
+ {
+ sect = bfd_get_section_by_name (objfile->obfd, ".text");
+ if (sect)
+ SECT_OFF_TEXT = sect->index;
+ }
+ if (SECT_OFF_DATA == -1)
+ {
+ sect = bfd_get_section_by_name (objfile->obfd, ".data");
+ if (sect)
+ SECT_OFF_DATA = sect->index;
+ }
+ if (SECT_OFF_BSS == -1)
+ {
+ sect = bfd_get_section_by_name (objfile->obfd, ".bss");
+ if (sect)
+ SECT_OFF_BSS = sect->index;
+ }
+ if (SECT_OFF_RODATA == -1)
+ {
+ sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
+ if (sect)
+ SECT_OFF_RODATA = sect->index;
+ }
+}
/* Process a symbol file, as either the main file or as a dynamically
loaded file.
@@ -631,12 +680,12 @@ syms_from_objfile (objfile, addrs, mainl
if (lower_sect == NULL)
warning ("no loadable sections found in added symbol-file %s",
objfile->name);
- else if ((bfd_get_section_flags (objfile->obfd, lower_sect) & SEC_CODE)
- == 0)
- warning ("Lowest section in %s is %s at %s",
- objfile->name,
- bfd_section_name (objfile->obfd, lower_sect),
- paddr (bfd_section_vma (objfile->obfd, lower_sect)));
+ else
+ if ((bfd_get_section_flags (objfile->obfd, lower_sect) & SEC_CODE) == 0)
+ warning ("Lowest section in %s is %s at %s",
+ objfile->name,
+ bfd_section_name (objfile->obfd, lower_sect),
+ paddr (bfd_section_vma (objfile->obfd, lower_sect)));
if (lower_sect != NULL)
lower_offset = bfd_section_vma (objfile->obfd, lower_sect);
else
Index: xcoffread.c
===================================================================
RCS file: /cvs/src/src/gdb/xcoffread.c,v
retrieving revision 1.1.1.9
diff -c -u -p -r1.1.1.9 xcoffread.c
--- xcoffread.c 1999/12/07 03:56:07 1.1.1.9
+++ xcoffread.c 2000/04/21 00:57:31
@@ -2763,22 +2763,43 @@ xcoff_symfile_offsets (objfile, addrs)
struct objfile *objfile;
struct section_addr_info *addrs;
{
+ asection *sect = NULL;
int i;
objfile->num_sections = SECT_OFF_MAX;
objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
- /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
- of the .text section. This strikes me as wrong--whether the
- offset to be applied to symbol reading is relative to the start
- address of the section depends on the symbol format. In any
- event, this whole "addr" concept is pretty broken (it doesn't
- handle any section but .text sensibly), so just ignore the addr
- parameter and use 0. rs6000-nat.c will set the correct section
- offsets via objfile_relocate. */
+ /* Initialize the section indexes for future use. */
+ sect = bfd_get_section_by_name (objfile->obfd, ".text");
+ if (sect)
+ SECT_OFF_TEXT = sect->index;
+
+ sect = bfd_get_section_by_name (objfile->obfd, ".data");
+ if (sect)
+ SECT_OFF_DATA = sect->index;
+
+ sect = bfd_get_section_by_name (objfile->obfd, ".bss");
+ if (sect)
+ SECT_OFF_BSS = sect->index;
+
+ sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
+ if (sect)
+ SECT_OFF_RODATA = sect->index;
+
for (i = 0; i < objfile->num_sections; ++i)
- ANOFFSET (objfile->section_offsets, i) = 0;
+ {
+ /* syms_from_objfile kindly subtracts from addr the
+ bfd_section_vma of the .text section. This strikes me as
+ wrong--whether the offset to be applied to symbol reading is
+ relative to the start address of the section depends on the
+ symbol format. In any event, this whole "addr" concept is
+ pretty broken (it doesn't handle any section but .text
+ sensibly), so just ignore the addr parameter and use 0.
+ rs6000-nat.c will set the correct section offsets via
+ objfile_relocate. */
+ ANOFFSET (objfile->section_offsets, i) = 0;
+ }
}
/* Register our ability to parse symbols for xcoff BFD files. */