summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-04-25 17:35:09 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-04-25 17:35:09 +0100
commitb59ee5b767b2488de73c5265a990dd7bced874de (patch)
tree6613816d62f723daa6755ca6bdad23a4577386e0
parent4605365e0f7f2b6ebde4b6517772acc1bf05ad66 (diff)
Refactor out binfile opening so that it is performed just once per pass.
-rw-r--r--src/shared-objects.c83
1 files changed, 52 insertions, 31 deletions
diff --git a/src/shared-objects.c b/src/shared-objects.c
index 2ccce93..caad562 100644
--- a/src/shared-objects.c
+++ b/src/shared-objects.c
@@ -116,20 +116,8 @@ find_address_in_section (bfd *abfd, asection *section, void *data)
}
static void
-_shared_object_lookup_symbol (SharedObject *so,
- gulong offset,
- const char **function,
- const char **filename,
- const char **path,
- guint *line)
+_shared_object_open (SharedObject *so)
{
- struct find_address fa;
-
- *function = NULL;
- *filename = NULL;
- *path = NULL;
- *line = 0;
-
if (so->abfd == NULL) {
so->abfd = bfd_openr (so->name, NULL);
if (so->abfd == NULL)
@@ -144,6 +132,24 @@ _shared_object_lookup_symbol (SharedObject *so,
return;
}
}
+}
+
+
+static gboolean
+_shared_object_has_symbols (SharedObject *so)
+{
+ return so->abfd != NULL;
+}
+
+static void
+_shared_object_lookup_symbol (SharedObject *so,
+ gulong offset,
+ const char **function,
+ const char **filename,
+ const char **path,
+ guint *line)
+{
+ struct find_address fa;
fa.syms = so->syms;
fa.pc = offset;
@@ -184,6 +190,18 @@ _shared_object_close (SharedObject *so)
extern char *minibfd_demangle (const char *mangled, int options);
static void
+_shared_object_open (SharedObject *so)
+{
+ bin_file_open (&so->bin_file);
+}
+
+static gboolean
+_shared_object_has_symbols (SharedObject *so)
+{
+ return so->bin_file.real_filename != NULL;
+}
+
+static void
_shared_object_lookup_symbol (SharedObject *so,
gulong offset,
const char **function,
@@ -191,13 +209,6 @@ _shared_object_lookup_symbol (SharedObject *so,
const char **path,
guint *line)
{
- *function = NULL;
- *filename = NULL;
- *path = NULL;
- *line = 0;
-
- bin_file_open (&so->bin_file);
-
bin_file_lookup_symbol (&so->bin_file, offset,
function,
filename,
@@ -250,23 +261,33 @@ shared_objects_lookup_symbols (SharedObjects *objects)
for (so = objects->pending_lookups; so != NULL; so = so->pending_next) {
SymbolOffset *symbol = so->pending_lookups, *next;
+
+ _shared_object_open (so);
+
do {
const gchar *function, *path, *filename;
guint lineno;
g_assert (frames_get (frames, symbol->eip) == NULL);
- _shared_object_lookup_symbol (so, symbol->offset,
- &function,
- &filename,
- &path,
- &lineno);
- if (filename == NULL && (path != NULL && *path != '\0')) {
- const char *slash = strrchr (path, '/');
- if (slash)
- filename = slash + 1;
- else
- filename = path;
+ function = NULL;
+ filename = NULL;
+ path = NULL;
+ lineno = 0;
+
+ if (_shared_object_has_symbols (so)) {
+ _shared_object_lookup_symbol (so, symbol->offset,
+ &function,
+ &filename,
+ &path,
+ &lineno);
+ if (filename == NULL && (path != NULL && *path != '\0')) {
+ const char *slash = strrchr (path, '/');
+ if (slash)
+ filename = slash + 1;
+ else
+ filename = path;
+ }
}
frames_add (frames, symbol->eip, so->name,