mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-09 22:50:54 +00:00
Add commented out debug spew.
Tue Apr 5 20:13:44 2005 Søren Sandmann <sandmann@redhat.com> * process.c (process_ensure_map): Add commented out debug spew. * process.c (process_lookup_symbol): Remove all should_offset() function and all references to it. * binfile.c (bin_file_lookup_symbol): Document that address must be in file coordinates. * binfile.c (read_symbols): Remove misguided code that tried to guess the load address of the file. Instead, do all computations in "file coordinates". Also fix a memory leak. Add commented out debug spew. * binfile.c (separate_debug_file_exists): Fix signedness
This commit is contained in:
committed by
Søren Sandmann Pedersen
parent
700cf9c967
commit
88c3bbb880
17
ChangeLog
17
ChangeLog
@ -1,3 +1,20 @@
|
|||||||
|
Tue Apr 5 20:13:44 2005 Søren Sandmann <sandmann@redhat.com>
|
||||||
|
|
||||||
|
* process.c (process_ensure_map): Add commented out debug spew.
|
||||||
|
|
||||||
|
* process.c (process_lookup_symbol): Remove all should_offset()
|
||||||
|
function and all references to it.
|
||||||
|
|
||||||
|
* binfile.c (bin_file_lookup_symbol): Document that address must
|
||||||
|
be in file coordinates.
|
||||||
|
|
||||||
|
* binfile.c (read_symbols): Remove misguided code that tried to
|
||||||
|
guess the load address of the file. Instead, do all computations
|
||||||
|
in "file coordinates". Also fix a memory leak. Add commented out
|
||||||
|
debug spew.
|
||||||
|
|
||||||
|
* binfile.c (separate_debug_file_exists): Fix signedness
|
||||||
|
|
||||||
Tue Apr 5 14:34:43 2005 Søren Sandmann <sandmann@redhat.com>
|
Tue Apr 5 14:34:43 2005 Søren Sandmann <sandmann@redhat.com>
|
||||||
|
|
||||||
* sysprof-module.c (x_access_process_vm): Make it compile with
|
* sysprof-module.c (x_access_process_vm): Make it compile with
|
||||||
|
|||||||
47
binfile.c
47
binfile.c
@ -143,7 +143,7 @@ separate_debug_file_exists (const char *name, unsigned long crc)
|
|||||||
{
|
{
|
||||||
unsigned long file_crc = 0;
|
unsigned long file_crc = 0;
|
||||||
int fd;
|
int fd;
|
||||||
char buffer[8*1024];
|
guchar buffer[8*1024];
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
fd = open (name, O_RDONLY);
|
fd = open (name, O_RDONLY);
|
||||||
@ -280,8 +280,6 @@ read_symbols (BinFile *bf)
|
|||||||
int i;
|
int i;
|
||||||
bfd *bfd;
|
bfd *bfd;
|
||||||
GArray *symbols;
|
GArray *symbols;
|
||||||
asection *sec;
|
|
||||||
ulong load_address;
|
|
||||||
|
|
||||||
bf->symbols = NULL;
|
bf->symbols = NULL;
|
||||||
bf->n_symbols = 0;
|
bf->n_symbols = 0;
|
||||||
@ -295,6 +293,9 @@ read_symbols (BinFile *bf)
|
|||||||
{
|
{
|
||||||
bfd_close (bfd);
|
bfd_close (bfd);
|
||||||
bfd = open_bfd (separate_debug_file);
|
bfd = open_bfd (separate_debug_file);
|
||||||
|
#if 0
|
||||||
|
g_print ("bfd for %s is %s\n", bf->filename, separate_debug_file);
|
||||||
|
#endif
|
||||||
if (!bfd)
|
if (!bfd)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -304,16 +305,6 @@ read_symbols (BinFile *bf)
|
|||||||
if (!bfd_symbols)
|
if (!bfd_symbols)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
load_address = 0xffffffff;
|
|
||||||
for (sec = bfd->sections; sec != NULL; sec = sec->next)
|
|
||||||
{
|
|
||||||
if (sec->flags & SEC_LOAD)
|
|
||||||
{
|
|
||||||
if ((gulong)sec->vma < load_address)
|
|
||||||
load_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;
|
||||||
@ -331,12 +322,21 @@ read_symbols (BinFile *bf)
|
|||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
symbol.address = bfd_asymbol_value (bfd_symbols[i]) - load_address;
|
/* Store the address in file coordinates:
|
||||||
|
* - 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;
|
||||||
name = demangle (bfd, bfd_asymbol_name (bfd_symbols[i]));
|
name = demangle (bfd, bfd_asymbol_name (bfd_symbols[i]));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
symbol.name = g_strdup_printf ("%s (%s)", name, bf->filename);
|
symbol.name = g_strdup_printf ("%s (%s)", name, bf->filename);
|
||||||
#endif
|
#endif
|
||||||
symbol.name = g_strdup (name);
|
symbol.name = g_strdup (name);
|
||||||
|
#if 0
|
||||||
|
g_print ("symbol: %s (%s) %p\n", name, bf->filename, symbol.address);
|
||||||
|
#endif
|
||||||
|
|
||||||
free (name);
|
free (name);
|
||||||
|
|
||||||
g_array_append_vals (symbols, &symbol, 1);
|
g_array_append_vals (symbols, &symbol, 1);
|
||||||
@ -346,6 +346,13 @@ read_symbols (BinFile *bf)
|
|||||||
if (n_symbols)
|
if (n_symbols)
|
||||||
free (bfd_symbols);
|
free (bfd_symbols);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (!n_symbols)
|
||||||
|
g_print ("no symbols found for %s\n", bf->filename);
|
||||||
|
else
|
||||||
|
g_print ("symbols found for %s\n", bf->filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Sort the symbols by address */
|
/* Sort the symbols by address */
|
||||||
qsort (symbols->data, symbols->len, sizeof(Symbol), compare_address);
|
qsort (symbols->data, symbols->len, sizeof(Symbol), compare_address);
|
||||||
|
|
||||||
@ -382,6 +389,14 @@ bin_file_free (BinFile *bf)
|
|||||||
g_free (bf);
|
g_free (bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bin_file_lookup_symbol:
|
||||||
|
* @bf: A BinFile
|
||||||
|
* @address: The address to lookup
|
||||||
|
*
|
||||||
|
* Look up a symbol. @address should be in file coordinates
|
||||||
|
*
|
||||||
|
**/
|
||||||
const Symbol *
|
const Symbol *
|
||||||
bin_file_lookup_symbol (BinFile *bf,
|
bin_file_lookup_symbol (BinFile *bf,
|
||||||
gulong address)
|
gulong address)
|
||||||
@ -432,12 +447,12 @@ bin_file_lookup_symbol (BinFile *bf,
|
|||||||
*/
|
*/
|
||||||
if (strcmp (result->name, "call_gmon_start") == 0)
|
if (strcmp (result->name, "call_gmon_start") == 0)
|
||||||
return &(bf->undefined);
|
return &(bf->undefined);
|
||||||
#if 0
|
|
||||||
else if (strncmp (result->name, "__do_global_ctors_aux", strlen ("__do_global_ctors_aux")) == 0)
|
else if (strncmp (result->name, "__do_global_ctors_aux", strlen ("__do_global_ctors_aux")) == 0)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
g_print ("ctors: %p, pos: %p\n", address, result->address);
|
g_print ("ctors: %p, pos: %p\n", address, result->address);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
62
process.c
62
process.c
@ -23,7 +23,9 @@ struct Map
|
|||||||
gulong start;
|
gulong start;
|
||||||
gulong end;
|
gulong end;
|
||||||
gulong offset;
|
gulong offset;
|
||||||
|
#if 0
|
||||||
gboolean do_offset;
|
gboolean do_offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
BinFile * bin_file;
|
BinFile * bin_file;
|
||||||
};
|
};
|
||||||
@ -48,28 +50,6 @@ initialize (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
should_offset (const char *filename, int pid)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
gboolean result = TRUE;
|
|
||||||
|
|
||||||
struct stat stat1, stat2;
|
|
||||||
char *progname = g_strdup_printf ("/proc/%d/exe", pid);
|
|
||||||
|
|
||||||
if (stat (filename, &stat1) == 0)
|
|
||||||
{
|
|
||||||
if (stat (progname, &stat2) == 0)
|
|
||||||
result = !(stat1.st_ino == stat2.st_ino &&
|
|
||||||
stat1.st_dev == stat2.st_dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (progname);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
read_maps (int pid)
|
read_maps (int pid)
|
||||||
{
|
{
|
||||||
@ -119,6 +99,12 @@ read_maps (int pid)
|
|||||||
|
|
||||||
result = g_list_prepend (result, map);
|
result = g_list_prepend (result, map);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_print ("scanf\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (name);
|
g_free (name);
|
||||||
@ -202,6 +188,7 @@ void
|
|||||||
process_ensure_map (Process *process, int pid, gulong addr)
|
process_ensure_map (Process *process, int pid, gulong addr)
|
||||||
{
|
{
|
||||||
/* Round down to closest page */
|
/* Round down to closest page */
|
||||||
|
|
||||||
addr = (addr - addr % PAGE_SIZE);
|
addr = (addr - addr % PAGE_SIZE);
|
||||||
|
|
||||||
if (process_has_page (process, addr))
|
if (process_has_page (process, addr))
|
||||||
@ -217,7 +204,12 @@ process_ensure_map (Process *process, int pid, gulong addr)
|
|||||||
process->maps = read_maps (pid);
|
process->maps = read_maps (pid);
|
||||||
|
|
||||||
if (!process_has_page (process, addr))
|
if (!process_has_page (process, addr))
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
g_print ("Bad page: %p\n", addr);
|
||||||
|
#endif
|
||||||
process->bad_pages = g_list_prepend (process->bad_pages, (gpointer)addr);
|
process->bad_pages = g_list_prepend (process->bad_pages, (gpointer)addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -246,7 +238,7 @@ get_cmdline (int pid)
|
|||||||
{
|
{
|
||||||
g_free (cmdline);
|
g_free (cmdline);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return cmdline;
|
return cmdline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,35 +329,31 @@ process_lookup_symbol (Process *process, gulong address)
|
|||||||
undefined.name = g_strdup_printf ("??? %s", process->cmdline);
|
undefined.name = g_strdup_printf ("??? %s", process->cmdline);
|
||||||
undefined.address = 0xBABE0001;
|
undefined.address = 0xBABE0001;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
g_print ("no map for %p (%s)\n", address, process->cmdline);
|
||||||
|
#endif
|
||||||
|
|
||||||
return &undefined;
|
return &undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
g_print ("has map: %s\n", process->cmdline);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* if (map->do_offset) */
|
/* if (map->do_offset) */
|
||||||
/* address -= map->start; */
|
/* address -= map->start; */
|
||||||
|
|
||||||
|
/* convert address to file coordinates */
|
||||||
address -= map->start;
|
address -= map->start;
|
||||||
address += map->offset;
|
address += map->offset;
|
||||||
|
|
||||||
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 0
|
|
||||||
/* FIXME - this seems to work with prelinked binaries, but is
|
|
||||||
* it correct? IE., will normal binaries always have a preferred_addres of 0?
|
|
||||||
*/
|
|
||||||
address = address - map->start + map->offset + bin_file_get_load_address (map->bin_file);
|
|
||||||
address -= map->start;
|
|
||||||
address += map->offset;
|
|
||||||
address += bin_file_get_load_address (map->bin_file);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* g_print ("%s: start: %p, load: %p\n", */
|
/* g_print ("%s: start: %p, load: %p\n", */
|
||||||
/* map->filename, map->start, bin_file_get_load_address (map->bin_file)); */
|
/* map->filename, map->start, bin_file_get_load_address (map->bin_file)); */
|
||||||
|
|
||||||
if (should_offset (map->filename, process->pid))
|
result = bin_file_lookup_symbol (map->bin_file, address);
|
||||||
address -= map->start;
|
|
||||||
|
|
||||||
result = bin_file_lookup_symbol (map->bin_file, address);
|
|
||||||
|
|
||||||
/* g_print ("(%x) %x %x name; %s\n", address, map->start, map->offset, result->name); */
|
/* g_print ("(%x) %x %x name; %s\n", address, map->start, map->offset, result->name); */
|
||||||
|
|
||||||
|
|||||||
@ -293,6 +293,7 @@ on_read (gpointer data)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
int i;
|
||||||
g_print ("pid: %d\n", trace.pid);
|
g_print ("pid: %d\n", trace.pid);
|
||||||
for (i=0; i < trace.n_addresses; ++i)
|
for (i=0; i < trace.n_addresses; ++i)
|
||||||
g_print ("rd: %08x\n", trace.addresses[i]);
|
g_print ("rd: %08x\n", trace.addresses[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user