From bda89efc687067e1879d02bbdff41b2d88b1a62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Sandmann?= Date: Wed, 6 Apr 2005 03:04:34 +0000 Subject: [PATCH] Put back the weird loop, and stop pretending I understand this. This time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tue Apr 5 23:01:02 2005 Søren Sandmann * binfile.c (read_symbols): Put back the weird loop, and stop pretending I understand this. This time use SEC_ALLOC instead of SEC_LOAD. --- ChangeLog | 6 ++++++ binfile.c | 20 +++++++++++++++++++- process.c | 40 ++++++++++++---------------------------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e7e339c..aa9c6acf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Apr 5 23:01:02 2005 Søren Sandmann + + * binfile.c (read_symbols): Put back the weird loop, and stop + pretending I understand this. This time use SEC_ALLOC instead of + SEC_LOAD. + Tue Apr 5 20:13:44 2005 Søren Sandmann * process.c (process_ensure_map): Add commented out debug spew. diff --git a/binfile.c b/binfile.c index f7cdea67..35eea4a5 100644 --- a/binfile.c +++ b/binfile.c @@ -280,6 +280,8 @@ read_symbols (BinFile *bf) int i; bfd *bfd; GArray *symbols; + guint load_address; + struct bfd_section *sec; bf->symbols = NULL; bf->n_symbols = 0; @@ -305,6 +307,16 @@ read_symbols (BinFile *bf) if (!bfd_symbols) return; + load_address = 0xffffffff; + for (sec = bfd->sections; sec != NULL; sec = sec->next) + { + if (sec->flags & SEC_ALLOC) + { + if ((gulong)sec->vma < load_address) + load_address = sec->vma & ~4095; + } + } + text_section = bfd_get_section_by_name (bfd, ".text"); if (!text_section) return; @@ -326,7 +338,13 @@ read_symbols (BinFile *bf) * - all addresses are already offset by section->vma * - the section is positioned at section->filepos */ - symbol.address = bfd_asymbol_value (bfd_symbols[i]) - text_section->vma + text_section->filepos; +#if 0 + g_print ("file: %s\n", bf->filename); + g_print ("vma: %p\n", text_section->vma); + g_print ("vma: %p\n", text_section->filepos); +#endif + + symbol.address = bfd_asymbol_value (bfd_symbols[i]) - load_address; name = demangle (bfd, bfd_asymbol_name (bfd_symbols[i])); #if 0 diff --git a/process.c b/process.c index 13cc9611..c9c939ab 100644 --- a/process.c +++ b/process.c @@ -335,6 +335,9 @@ process_lookup_symbol (Process *process, gulong address) return &undefined; } +#if 0 + g_print ("has map: %s\n", process->cmdline); +#endif #if 0 g_print ("has map: %s\n", process->cmdline); @@ -343,7 +346,11 @@ process_lookup_symbol (Process *process, gulong address) /* if (map->do_offset) */ /* address -= map->start; */ +#if 0 /* convert address to file coordinates */ + g_print ("looking up %p ", address); +#endif + address -= map->start; address += map->offset; @@ -352,41 +359,18 @@ process_lookup_symbol (Process *process, gulong address) /* g_print ("%s: start: %p, load: %p\n", */ /* map->filename, map->start, bin_file_get_load_address (map->bin_file)); */ - + result = bin_file_lookup_symbol (map->bin_file, address); +#if 0 + g_print (" ---> %s\n", result->name); +#endif + /* g_print ("(%x) %x %x name; %s\n", address, map->start, map->offset, result->name); */ return result; } -#if 0 -const Symbol * -process_lookup_symbol_with_filename (Process *process, - int pid, - gulong map_start, - const char *filename, - gulong address) -{ - const Symbol *result; - BinFile *bin_file; - - if (!filename) - return process_lookup_symbol (process, address); - - bin_file = bin_file_new (filename); - - if (should_offset (filename, pid)) - address -= map_start; - - result = bin_file_lookup_symbol (bin_file, address); - - bin_file_free (bin_file); - - return result; -} -#endif - const char * process_get_cmdline (Process *process) {