summaryrefslogtreecommitdiff
path: root/binfile.c
diff options
context:
space:
mode:
authorSoren Sandmann <sandmann@daimi.au.dk>2006-10-08 04:03:02 +0000
committerSøren Sandmann Pedersen <ssp@src.gnome.org>2006-10-08 04:03:02 +0000
commit52274fadd6f2d013e662fa8965092f98c0d3d566 (patch)
treebffa5dfa1753161a7a59184518dc4745cfad6b18 /binfile.c
parent6a7178f612abbfe50795ef654c946669b70ed61d (diff)
Deal with address offsets. Address lookup is now:
2006-10-07 Soren Sandmann <sandmann@daimi.au.dk> Deal with address offsets. Address lookup is now: - First convert the address to an offset into the file - Then convert to an offset into the text segment - Then add the load address of the text segment (found in the debug binary) - Then finally lookup the result in the symbol table. * elfparser.c (elf_parser_get_text_offset): New function * elfparser.c (elf_parser_lookup_symbol): Treat addresses as offsets into the text segment. * binfile.c (bin_file_new): Store the offset of the text section of the actual binary (not the debug one) (bin_file_lookup_symbol): Subtract text_offset before passing address to elf parser. * module/sysprof-module.c: Remove include of linux/config.h
Diffstat (limited to 'binfile.c')
-rw-r--r--binfile.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/binfile.c b/binfile.c
index 494c9c9..4e7b36c 100644
--- a/binfile.c
+++ b/binfile.c
@@ -46,6 +46,8 @@ struct BinFile
ino_t inode;
char * undefined_name;
+
+ gulong text_offset;
};
/* FIXME: error handling */
@@ -154,6 +156,13 @@ bin_file_new (const char *filename)
{
bf = g_new0 (BinFile, 1);
bf->elf = elf_parser_new (filename, NULL);
+
+ /* We need the text offset of the actual binary, not the
+ * (potential) debug binary
+ */
+ if (bf->elf)
+ bf->text_offset = elf_parser_get_text_offset (bf->elf);
+
bf->elf = find_separate_debug_file (bf->elf, filename);
bf->inode = read_inode (filename);
bf->filename = g_strdup (filename);
@@ -188,10 +197,16 @@ bin_file_lookup_symbol (BinFile *bin_file,
{
if (bin_file->elf)
{
+ address -= bin_file->text_offset;
+
const ElfSym *sym = elf_parser_lookup_symbol (bin_file->elf, address);
+
if (sym)
+ {
+ g_print ("found %lx => %s\n", address, bin_symbol_get_name (bin_file, sym));
return (const BinSymbol *)sym;
+ }
}
return (const BinSymbol *)bin_file->undefined_name;