Move bin file cache to state object

This commit is contained in:
Søren Sandmann Pedersen
2009-09-08 00:06:12 -04:00
parent 604d07600a
commit 0ceaff7a66
2 changed files with 101 additions and 103 deletions

View File

@ -258,9 +258,6 @@ get_debug_binaries (GList *files,
return files;
}
static GHashTable *bin_files;
static char **
get_lines (const char *format, pid_t pid)
{
@ -331,59 +328,43 @@ get_vdso_bytes (size_t *length)
BinFile *
bin_file_new (const char *filename)
{
/* FIXME: should be able to return an error */
ElfParser *elf = NULL;
BinFile *bf;
if (!bin_files)
bin_files = g_hash_table_new (g_str_hash, g_str_equal);
bf = g_new0 (BinFile, 1);
bf = g_hash_table_lookup (bin_files, filename);
bf->inode_check = FALSE;
bf->filename = g_strdup (filename);
bf->undefined_name = g_strdup_printf ("In file %s", filename);
bf->ref_count = 1;
bf->elf_files = NULL;
if (bf)
if (strcmp (filename, "[vdso]") == 0)
{
bf->ref_count++;
const guint8 *vdso_bytes;
gsize length;
vdso_bytes = get_vdso_bytes (&length);
if (vdso_bytes)
elf = elf_parser_new_from_data (vdso_bytes, length);
}
else
{
ElfParser *elf = NULL;
elf = elf_parser_new (filename, NULL);
}
bf = g_new0 (BinFile, 1);
if (elf)
{
/* We need the text offset of the actual binary, not the
* (potential) debug binaries
*/
bf->text_offset = elf_parser_get_text_offset (elf);
bf->inode_check = FALSE;
bf->filename = g_strdup (filename);
bf->undefined_name = g_strdup_printf ("In file %s", filename);
bf->ref_count = 1;
bf->elf_files = NULL;
bf->elf_files = get_debug_binaries (bf->elf_files, elf, filename);
bf->elf_files = g_list_append (bf->elf_files, elf);
g_hash_table_insert (bin_files, bf->filename, bf);
if (strcmp (filename, "[vdso]") == 0)
{
const guint8 *vdso_bytes;
gsize length;
vdso_bytes = get_vdso_bytes (&length);
if (vdso_bytes)
elf = elf_parser_new_from_data (vdso_bytes, length);
}
else
{
elf = elf_parser_new (filename, NULL);
}
if (elf)
{
/* We need the text offset of the actual binary, not the
* (potential) debug binaries
*/
bf->text_offset = elf_parser_get_text_offset (elf);
bf->elf_files = get_debug_binaries (bf->elf_files, elf, filename);
bf->elf_files = g_list_append (bf->elf_files, elf);
bf->inode = read_inode (filename);
}
bf->inode = read_inode (filename);
}
return bf;
@ -394,8 +375,6 @@ bin_file_free (BinFile *bin_file)
{
if (--bin_file->ref_count == 0)
{
g_hash_table_remove (bin_files, bin_file->filename);
g_list_foreach (bin_file->elf_files, (GFunc)elf_parser_free, NULL);
g_list_free (bin_file->elf_files);

View File

@ -335,6 +335,7 @@ struct state_t
GHashTable *processes_by_pid;
GHashTable *unique_comms;
GHashTable *unique_symbols;
GHashTable *bin_files;
};
static void
@ -433,6 +434,9 @@ state_new (void)
state->unique_symbols = g_hash_table_new (g_direct_hash, g_direct_equal);
state->unique_comms = g_hash_table_new (g_str_hash, g_str_equal);
state->bin_files = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free,
(GDestroyNotify)bin_file_free);
return state;
}
@ -665,6 +669,21 @@ make_message (state_t *state, const char *format, ...)
return result;
}
static BinFile *
state_get_bin_file (state_t *state, const char *filename)
{
BinFile *bf = g_hash_table_lookup (state->bin_files, filename);
if (!bf)
{
bf = bin_file_new (filename);
g_hash_table_insert (state->bin_files, g_strdup (filename), bf);
}
return bf;
}
static char *
lookup_symbol (state_t *state,
process_t *process,
@ -695,7 +714,7 @@ lookup_symbol (state_t *state,
address += map->offset;
if (!map->bin_file)
map->bin_file = bin_file_new (map->filename);
map->bin_file = state_get_bin_file (state, map->filename);
if (map->inode && !bin_file_check_inode (map->bin_file, map->inode))
{