mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
Make process_lookup_symbol() return a string. Delete
2006-08-20 Soren Sandmann <sandmann@daimi.au.dk> * process.h: Make process_lookup_symbol() return a string. Delete process_lookup_symbol_with_filename(). * process.c (struct Process): Make "undefined" a string (lookup_kernel_symbol): Return a string (process_lookup_symbol): Return a string, not a symbol * collector.c (unique_dup): Take a string instead of a Symbol. (lookup_symbol): Make sym a string instead of a Symbol. * binfile.c (bin_symbol_get_name): New function. * binfile.[ch] (struct BinSymbol): Rename Symbol to BinSymbol and make it an opaque structure. * binfile.[ch]: Remove unused symbol operations
This commit is contained in:
committed by
Søren Sandmann Pedersen
parent
7d8f3c232d
commit
a880ee7f60
20
ChangeLog
20
ChangeLog
@ -1,3 +1,23 @@
|
||||
2006-08-20 Soren Sandmann <sandmann@daimi.au.dk>
|
||||
|
||||
* process.h: Make process_lookup_symbol() return a string. Delete
|
||||
process_lookup_symbol_with_filename().
|
||||
|
||||
* process.c (struct Process): Make "undefined" a string
|
||||
(lookup_kernel_symbol): Return a string
|
||||
(process_lookup_symbol): Return a string, not a symbol
|
||||
|
||||
* collector.c (unique_dup): Take a string instead of a
|
||||
Symbol.
|
||||
(lookup_symbol): Make sym a string instead of a Symbol.
|
||||
|
||||
* binfile.c (bin_symbol_get_name): New function.
|
||||
|
||||
* binfile.[ch] (struct BinSymbol): Rename Symbol to BinSymbol and
|
||||
make it an opaque structure.
|
||||
|
||||
* binfile.[ch]: Remove unused symbol operations
|
||||
|
||||
2006-08-20 Soren Sandmann <sandmann@daimi.au.dk>
|
||||
|
||||
* elfparser.c (elf_parser_new_from_file): New function
|
||||
|
||||
86
binfile.c
86
binfile.c
@ -38,13 +38,20 @@
|
||||
static void bfd_nonfatal (const char *string);
|
||||
static void bfd_fatal (const char *string);
|
||||
|
||||
/* Symbol */
|
||||
struct BinSymbol
|
||||
{
|
||||
char * name;
|
||||
gulong address;
|
||||
};
|
||||
|
||||
/* Binary File */
|
||||
struct BinFile
|
||||
{
|
||||
char * filename;
|
||||
int n_symbols;
|
||||
Symbol *symbols;
|
||||
Symbol undefined;
|
||||
BinSymbol *symbols;
|
||||
BinSymbol undefined;
|
||||
int ref_count;
|
||||
ino_t inode;
|
||||
};
|
||||
@ -287,8 +294,8 @@ demangle (bfd *bfd, const char *name)
|
||||
static gint
|
||||
compare_address (const void *a, const void *b)
|
||||
{
|
||||
const Symbol *symbol1 = a;
|
||||
const Symbol *symbol2 = b;
|
||||
const BinSymbol *symbol1 = a;
|
||||
const BinSymbol *symbol2 = b;
|
||||
|
||||
if (symbol1->address < symbol2->address)
|
||||
return -1;
|
||||
@ -373,13 +380,13 @@ read_symbols (BinFile *bf)
|
||||
if (!text_section)
|
||||
return;
|
||||
|
||||
symbols = g_array_new (FALSE, FALSE, sizeof (Symbol));
|
||||
symbols = g_array_new (FALSE, FALSE, sizeof (BinSymbol));
|
||||
|
||||
/* g_print ("%s: text vma: %x\n", bf->filename, text_section->vma); */
|
||||
|
||||
for (i = 0; i < n_symbols; i++)
|
||||
{
|
||||
Symbol symbol;
|
||||
BinSymbol symbol;
|
||||
|
||||
if ((bfd_symbols[i]->flags & BSF_FUNCTION) &&
|
||||
(bfd_symbols[i]->section == text_section))
|
||||
@ -405,10 +412,10 @@ read_symbols (BinFile *bf)
|
||||
#endif
|
||||
|
||||
/* Sort the symbols by address */
|
||||
qsort (symbols->data, symbols->len, sizeof(Symbol), compare_address);
|
||||
qsort (symbols->data, symbols->len, sizeof (BinSymbol), compare_address);
|
||||
|
||||
bf->n_symbols = symbols->len;
|
||||
bf->symbols = (Symbol *)g_array_free (symbols, FALSE);
|
||||
bf->symbols = (BinSymbol *)g_array_free (symbols, FALSE);
|
||||
}
|
||||
|
||||
static GHashTable *bin_files;
|
||||
@ -476,15 +483,15 @@ bin_file_free (BinFile *bf)
|
||||
* Look up a symbol. @address should be in file coordinates
|
||||
*
|
||||
**/
|
||||
const Symbol *
|
||||
const BinSymbol *
|
||||
bin_file_lookup_symbol (BinFile *bf,
|
||||
gulong address)
|
||||
{
|
||||
int first = 0;
|
||||
int last = bf->n_symbols - 1;
|
||||
int middle = last;
|
||||
Symbol *data;
|
||||
Symbol *result;
|
||||
BinSymbol *data;
|
||||
BinSymbol *result;
|
||||
|
||||
if (!bf->symbols || (bf->n_symbols == 0))
|
||||
return &(bf->undefined);
|
||||
@ -539,61 +546,10 @@ bin_file_lookup_symbol (BinFile *bf,
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Symbol */
|
||||
Symbol *
|
||||
symbol_copy (const Symbol *orig)
|
||||
const char *
|
||||
bin_symbol_get_name (const BinSymbol *symbol)
|
||||
{
|
||||
Symbol *copy;
|
||||
|
||||
copy = g_new (Symbol, 1);
|
||||
copy->name = g_strdup (orig->name);
|
||||
copy->address = orig->address;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
gboolean
|
||||
symbol_equal (const void *sa,
|
||||
const void *sb)
|
||||
{
|
||||
const Symbol *syma = sa;
|
||||
const Symbol *symb = sb;
|
||||
|
||||
if (symb->address != syma->address)
|
||||
return FALSE;
|
||||
|
||||
/* symbols compare equal if their names are both NULL */
|
||||
|
||||
if (!syma->name && !symb->name)
|
||||
return TRUE;
|
||||
|
||||
if (!syma)
|
||||
return FALSE;
|
||||
|
||||
if (!symb)
|
||||
return FALSE;
|
||||
|
||||
return strcmp (syma->name, symb->name) == 0;
|
||||
}
|
||||
|
||||
guint
|
||||
symbol_hash (const void *s)
|
||||
{
|
||||
const Symbol *symbol = s;
|
||||
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
return symbol->name? g_str_hash (symbol->name) : 0 + symbol->address;
|
||||
}
|
||||
|
||||
void
|
||||
symbol_free (Symbol *symbol)
|
||||
{
|
||||
if (symbol->name)
|
||||
g_free (symbol->name);
|
||||
g_free (symbol);
|
||||
return symbol->name;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
16
binfile.h
16
binfile.h
@ -28,27 +28,17 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct BinFile BinFile;
|
||||
typedef struct Symbol Symbol;
|
||||
typedef struct BinSymbol BinSymbol;
|
||||
|
||||
/* Binary File */
|
||||
|
||||
BinFile * bin_file_new (const char *filename);
|
||||
void bin_file_free (BinFile *bin_file);
|
||||
const Symbol *bin_file_lookup_symbol (BinFile *bin_file,
|
||||
const BinSymbol *bin_file_lookup_symbol (BinFile *bin_file,
|
||||
gulong address);
|
||||
ino_t bin_file_get_inode (BinFile *bin_file);
|
||||
|
||||
/* Symbol */
|
||||
struct Symbol
|
||||
{
|
||||
char * name;
|
||||
gulong address;
|
||||
};
|
||||
|
||||
Symbol * symbol_copy (const Symbol *orig);
|
||||
gboolean symbol_equal (const void *syma,
|
||||
const void *symb);
|
||||
guint symbol_hash (const void *sym);
|
||||
void symbol_free (Symbol *symbol);
|
||||
const char * bin_symbol_get_name (const BinSymbol *symbol);
|
||||
|
||||
#endif
|
||||
|
||||
12
collector.c
12
collector.c
@ -265,15 +265,15 @@ typedef struct
|
||||
} ResolveInfo;
|
||||
|
||||
static char *
|
||||
unique_dup (GHashTable *unique_symbols, char *s)
|
||||
unique_dup (GHashTable *unique_symbols, const char *sym)
|
||||
{
|
||||
char *result;
|
||||
|
||||
result = g_hash_table_lookup (unique_symbols, s);
|
||||
result = g_hash_table_lookup (unique_symbols, sym);
|
||||
if (!result)
|
||||
{
|
||||
result = g_strdup (s);
|
||||
g_hash_table_insert (unique_symbols, s, result);
|
||||
result = g_strdup (sym);
|
||||
g_hash_table_insert (unique_symbols, (char *)sym, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -282,9 +282,9 @@ unique_dup (GHashTable *unique_symbols, char *s)
|
||||
static char *
|
||||
lookup_symbol (Process *process, gpointer address, GHashTable *unique_symbols)
|
||||
{
|
||||
const Symbol *s = process_lookup_symbol (process, (gulong)address);
|
||||
const char *sym = process_lookup_symbol (process, (gulong)address);
|
||||
|
||||
return unique_dup (unique_symbols, s->name);
|
||||
return unique_dup (unique_symbols, sym);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
31
process.c
31
process.c
@ -57,8 +57,8 @@ struct Process
|
||||
GList *bad_pages;
|
||||
|
||||
int pid;
|
||||
|
||||
Symbol undefined;
|
||||
|
||||
const char *undefined;
|
||||
};
|
||||
|
||||
static void
|
||||
@ -152,8 +152,7 @@ create_process (const char *cmdline, int pid)
|
||||
p->bad_pages = NULL;
|
||||
p->maps = NULL;
|
||||
p->pid = pid;
|
||||
p->undefined.name = NULL;
|
||||
p->undefined.address = 0x00;
|
||||
p->undefined = NULL;
|
||||
|
||||
g_assert (!g_hash_table_lookup (processes_by_pid, GINT_TO_POINTER (pid)));
|
||||
g_assert (!g_hash_table_lookup (processes_by_cmdline, cmdline));
|
||||
@ -532,24 +531,27 @@ get_kernel_symbols (void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const Symbol *
|
||||
static const char *
|
||||
lookup_kernel_symbol (gulong address)
|
||||
{
|
||||
static Symbol kernel;
|
||||
static const char *const kernel = "In kernel";
|
||||
|
||||
#if 0
|
||||
g_print ("kernel binary: %s\n", find_kernel_binary ());
|
||||
#endif
|
||||
|
||||
|
||||
return kernel; /* Can we just return "In kernel"? */
|
||||
#if 0
|
||||
kernel.name = "In kernel";
|
||||
kernel.address = 0x00001337;
|
||||
return &kernel;
|
||||
#endif
|
||||
}
|
||||
|
||||
const Symbol *
|
||||
const char *
|
||||
process_lookup_symbol (Process *process, gulong address)
|
||||
{
|
||||
const Symbol *result;
|
||||
const BinSymbol *result;
|
||||
Map *map = process_locate_map (process, address);
|
||||
|
||||
/* g_print ("addr: %x\n", address); */
|
||||
@ -562,14 +564,13 @@ process_lookup_symbol (Process *process, gulong address)
|
||||
}
|
||||
else if (!map)
|
||||
{
|
||||
if (!process->undefined.name)
|
||||
if (!process->undefined)
|
||||
{
|
||||
process->undefined.name =
|
||||
g_strdup_printf ("(??? %s)", process->cmdline);
|
||||
process->undefined.address = 0xBABE0001;
|
||||
process->undefined =
|
||||
g_strdup_printf ("No map (%s)", process->cmdline);
|
||||
}
|
||||
|
||||
return &process->undefined;
|
||||
return process->undefined;
|
||||
}
|
||||
|
||||
address -= map->start;
|
||||
@ -599,7 +600,7 @@ process_lookup_symbol (Process *process, gulong address)
|
||||
|
||||
/* g_print ("(%x) %x %x name; %s\n", address, map->start, map->offset, result->name); */
|
||||
|
||||
return result;
|
||||
return bin_symbol_get_name (result);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
||||
@ -51,12 +51,7 @@ Process * process_get_from_pid (int pid);
|
||||
void process_ensure_map (Process *process,
|
||||
int pid,
|
||||
gulong address);
|
||||
const Symbol *process_lookup_symbol (Process *process,
|
||||
gulong address);
|
||||
const Symbol *process_lookup_symbol_with_filename (Process *process,
|
||||
int pid,
|
||||
gulong map_start,
|
||||
const char *filename,
|
||||
const char * process_lookup_symbol (Process *process,
|
||||
gulong address);
|
||||
const char * process_get_cmdline (Process *process);
|
||||
void process_flush_caches (void);
|
||||
|
||||
Reference in New Issue
Block a user