This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
relocations when doing file command at gdb prompt
- From: Roland Puntaier <Roland dot Puntaier at br-automation dot com>
- To: gdb at sources dot redhat dot com
- Date: Wed, 7 Mar 2007 17:16:02 +0100
- Subject: relocations when doing file command at gdb prompt
Hi,
maybe someone can help me.
The Problem
-----------
I try to remote debug an embedded device with gdb.
(gdb) target remote XXX
I found that in
remote.c:
get_offsets(){...
objfiles.c:
objfile_relocate(){...
l->item[i].pc is quite out of range.
My investigations so far
------------------------
The pc value comes from the preceeding file command:
(gdb) file -readnow YYY
dbxread.c:
process_one_symbol(){...
function_start_offset = ANOFFSET (section_offsets,
SECT_OFF_TEXT (objfile));
...
case N_SLINE:...
valu += function_start_offset;
...
record_line(,,valu);
buildsym.c:
record_line(,,pc){...e->pc = ADDR_BITS_REMOVE(pc);
function_start_offset had twice the value it should have when
compared to objdump output.
The wrong values showed up first in
bfd/simple.c:
bfd_simple_get_relocated_section_contents(){...
contents = bfd_get_relocated_section_contents(){...
bfd/reloc.c:
bfd_generic_get_relocated_section_contents (reloc.c:4432){...
bfd_perform_relocation{...
symbol = *(reloc_entry->sym_ptr_ptr);
...
relocation = symbol->value;
...
output_base = reloc_target_output_section->vma;
relocation += output_base + symbol->section->output_offset;
...
DOIT(x);
output_base had a value equal x, such that x got doubled.
x is section_offsets from above.
There is a branch, if symbol->section->output_section==0, that
makes output_base=0;
symbol->section->output_section gets its value from the
bfd_simple_get_relocated_section_contents
{...bfd_canonicalize_symtab()
{...elf_slurp_symbol_table (elfcode.h)
{...bfd_elf_get_elf_syms
...
sym->symbol.section = bfd_section_from_elf_index ()
{...return elf_elfsections
(abfd)[index]->bfd_section;
And bfd_section->output_section is filled in
symbol_file_command{...symbol_file_add_main_1{...symbol_file_add{...
symbol_file_add_from_bfd{...
symbol_file_add_with_addrs_or_offsets{...
syms_from_objfile()
{...elf_symfile_read (elfread.c)
{...elfstab_build_psymtabs (dbxread.c)
{...symfile_relocate_debug_section (symfile.c)
{...bfd_map_over_sections (abfd,
symfile_dummy_outputs, NULL);
I first thought to change symfile_dummy_outputs (symfile.c), by replacing
sectp->output_section = sectp;
with
sectp->output_section = NULL;
I tried this, but unfortunately later on in
bfd_simple_get_relocated_section_contents(simple.c:209),
(bfd_map_over_sections (abfd, simple_save_output_info, saved_offsets);)
which is called immediately afterwards from
symfile_relocate_debug_section,
output_section is set to section again. This time by bfd and not gdb.
I changed simple_save_output_info to set output_section=NULL.
And now linetable's pc had the value as in the file.
Question/Goal
-------------
Is there another way to make gdb/bfd consistently relocate symbol
information, when doing the gdb file command?
The best for me would be to have old_offset relative to the
beginning of the sections, then objfile_relocate would add
new_offset-old_offset, where new_offset would be the new address.
regards, Roland