From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27941 invoked by alias); 7 Mar 2007 16:16:19 -0000 Received: (qmail 27931 invoked by uid 22791); 7 Mar 2007 16:16:18 -0000 X-Spam-Check-By: sourceware.org Received: from mail.br-automation.com (HELO brsmtp01.br-automation.com) (213.33.116.60) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 07 Mar 2007 16:16:10 +0000 To: gdb@sources.redhat.com Subject: relocations when doing file command at gdb prompt MIME-Version: 1.0 X-Mailer: Lotus Notes Release 6.5.4 March 27, 2005 Message-ID: From: Roland Puntaier Date: Wed, 07 Mar 2007 16:16:00 -0000 Content-Type: text/plain; charset="US-ASCII" X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2007-03/txt/msg00114.txt.bz2 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