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
This commit is contained in:
Soren Sandmann
2006-10-08 04:03:02 +00:00
committed by Søren Sandmann Pedersen
parent 6a7178f612
commit 52274fadd6
7 changed files with 162 additions and 11 deletions

View File

@ -322,6 +322,21 @@ compare_sym (const void *a, const void *b)
return 1;
}
#if 0
static void
dump_symbols (ElfParser *parser, ElfSym *syms, guint n_syms)
{
int i;
for (i = 0; i < n_syms; ++i)
{
ElfSym *s = &(syms[i]);
g_print (" %s: %lx\n", elf_parser_get_sym_name (parser, s), s->address);
}
}
#endif
static void
read_table (ElfParser *parser,
const Section *sym_table,
@ -381,8 +396,12 @@ read_table (ElfParser *parser,
parser->sym_strings = str_table->offset;
parser->n_symbols = n_functions;
parser->symbols = g_renew (ElfSym, parser->symbols, parser->n_symbols);
qsort (parser->symbols, parser->n_symbols, sizeof (ElfSym), compare_sym);
#if 0
dump_symbols (parser, parser->symbols, parser->n_symbols);
#endif
}
static void
@ -432,7 +451,7 @@ elf_parser_get_load_address (ElfParser *parser)
load_address = MIN (load_address, addr);
}
}
#if 0
g_print ("load address: %8p\n", (void *)load_address);
#endif
@ -473,10 +492,12 @@ do_lookup (ElfSym *symbols,
}
}
/* Address should be given in 'offset into text segment' */
const ElfSym *
elf_parser_lookup_symbol (ElfParser *parser,
gulong address)
{
Section *text;
const ElfSym *result;
gsize size;
@ -485,15 +506,22 @@ elf_parser_lookup_symbol (ElfParser *parser,
if (parser->n_symbols == 0)
return NULL;
address += elf_parser_get_load_address (parser);
#if 0
text = find_section (parser, ".text");
if (!text)
return NULL;
address += text->load_address;
g_print ("the address we are looking up is %p\n", address);
#endif
result = do_lookup (parser->symbols, address, 0, parser->n_symbols - 1);
if (result)
{
g_print ("found %s at %lx\n", elf_parser_get_sym_name (parser, result), result->address);
}
if (result)
{
BinRecord *symbol;
@ -513,6 +541,21 @@ elf_parser_lookup_symbol (ElfParser *parser,
return result;
}
gulong
elf_parser_get_text_offset (ElfParser *parser)
{
const Section *text;
g_return_val_if_fail (parser != NULL, (gulong)-1);
text = find_section (parser, ".text");
if (!text)
return (gulong)-1;
return text->offset;
}
const char *
elf_parser_get_debug_link (ElfParser *parser, guint32 *crc32)
{