mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 07:00:53 +00:00
support prelinked binaries
This commit is contained in:
18
binfile.c
18
binfile.c
@ -24,6 +24,7 @@ struct BinFile
|
|||||||
int n_symbols;
|
int n_symbols;
|
||||||
Symbol *symbols;
|
Symbol *symbols;
|
||||||
Symbol undefined;
|
Symbol undefined;
|
||||||
|
gulong address;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bfd *
|
static bfd *
|
||||||
@ -277,6 +278,7 @@ read_symbols (BinFile *bf)
|
|||||||
int i;
|
int i;
|
||||||
bfd *bfd;
|
bfd *bfd;
|
||||||
GArray *symbols;
|
GArray *symbols;
|
||||||
|
asection *sec;
|
||||||
|
|
||||||
bf->symbols = NULL;
|
bf->symbols = NULL;
|
||||||
bf->n_symbols = 0;
|
bf->n_symbols = 0;
|
||||||
@ -299,6 +301,16 @@ read_symbols (BinFile *bf)
|
|||||||
if (!bfd_symbols)
|
if (!bfd_symbols)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bf->address = 0xffffffff;
|
||||||
|
for (sec = bfd->sections; sec != NULL; sec = sec->next)
|
||||||
|
{
|
||||||
|
if (sec->flags & SEC_LOAD)
|
||||||
|
{
|
||||||
|
if ((gulong)sec->vma < bf->address)
|
||||||
|
bf->address = sec->vma & ~4095;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
text_section = bfd_get_section_by_name (bfd, ".text");
|
text_section = bfd_get_section_by_name (bfd, ".text");
|
||||||
if (!text_section)
|
if (!text_section)
|
||||||
return;
|
return;
|
||||||
@ -362,6 +374,12 @@ bin_file_free (BinFile *bf)
|
|||||||
g_free (bf);
|
g_free (bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gulong
|
||||||
|
bin_file_get_load_address (BinFile *bf)
|
||||||
|
{
|
||||||
|
return bf->address;
|
||||||
|
}
|
||||||
|
|
||||||
const Symbol *
|
const Symbol *
|
||||||
bin_file_lookup_symbol (BinFile *bf,
|
bin_file_lookup_symbol (BinFile *bf,
|
||||||
gulong address)
|
gulong address)
|
||||||
|
|||||||
@ -12,6 +12,7 @@ BinFile * bin_file_new (const char *filename);
|
|||||||
void bin_file_free (BinFile *bin_file);
|
void bin_file_free (BinFile *bin_file);
|
||||||
const Symbol *bin_file_lookup_symbol (BinFile *bin_file,
|
const Symbol *bin_file_lookup_symbol (BinFile *bin_file,
|
||||||
gulong address);
|
gulong address);
|
||||||
|
gulong bin_file_get_load_address (BinFile *bf);
|
||||||
|
|
||||||
/* Symbol */
|
/* Symbol */
|
||||||
struct Symbol
|
struct Symbol
|
||||||
|
|||||||
13
process.c
13
process.c
@ -48,6 +48,8 @@ initialize (void)
|
|||||||
static gboolean
|
static gboolean
|
||||||
should_offset (const char *filename, int pid)
|
should_offset (const char *filename, int pid)
|
||||||
{
|
{
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
gboolean result = TRUE;
|
gboolean result = TRUE;
|
||||||
|
|
||||||
struct stat stat1, stat2;
|
struct stat stat1, stat2;
|
||||||
@ -266,11 +268,18 @@ process_lookup_symbol (Process *process, gulong address)
|
|||||||
return &undefined;
|
return &undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if (map->do_offset)
|
||||||
|
address -= map->start;
|
||||||
|
*/
|
||||||
|
|
||||||
if (!map->bin_file)
|
if (!map->bin_file)
|
||||||
map->bin_file = bin_file_new (map->filename);
|
map->bin_file = bin_file_new (map->filename);
|
||||||
|
|
||||||
if (map->do_offset)
|
/* FIXME - this seems to work with prelinked binaries, but is
|
||||||
address -= map->start;
|
* it correct? IE., will normal binaries always have a preferred_addres of 0?
|
||||||
|
*/
|
||||||
|
address -= map->start;
|
||||||
|
address += bin_file_get_load_address (map->bin_file);
|
||||||
|
|
||||||
result = bin_file_lookup_symbol (map->bin_file, address);
|
result = bin_file_lookup_symbol (map->bin_file, address);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -119,7 +119,8 @@ on_read (gpointer data)
|
|||||||
filename = trace.filename;
|
filename = trace.filename;
|
||||||
|
|
||||||
for (i = 0; i < trace.n_addresses; ++i)
|
for (i = 0; i < trace.n_addresses; ++i)
|
||||||
process_ensure_map (process, trace.pid, (gulong)trace.addresses[i]);
|
process_ensure_map (process, trace.pid,
|
||||||
|
(gulong)trace.addresses[i]);
|
||||||
g_assert (!app->generating_profile);
|
g_assert (!app->generating_profile);
|
||||||
|
|
||||||
stack_stash_add_trace (
|
stack_stash_add_trace (
|
||||||
|
|||||||
Reference in New Issue
Block a user