struct getmodules_callback_arg
{
- const char *object_name;
- Dwfl_Module *module_main; /* first */
- Dwfl_Module *module_libpthread;
+ const char *sym_name;
+ psaddr_t *sym_addr;
+ ps_err_e retval;
};
static int getmodules_callback (Dwfl_Module *module,
Dwarf_Addr module_low_addr, void *arg)
{
struct getmodules_callback_arg *getmodules_callback_arg = arg;
- const char *basename;
-
- if (getmodules_callback_arg->module_main == NULL)
- getmodules_callback_arg->module_main = module;
-
- basename = strrchr (module_name, '/');
- if (basename != NULL)
- basename++;
- else
- basename = module_name;
-
- /* FIXME */
- if (strcmp (basename, "libpthread-2.5.so") == 0)
- basename = "libpthread.so.0";
-
- if (strcmp (basename, getmodules_callback_arg->object_name) != 0)
- return DWARF_CB_OK;
-
- getmodules_callback_arg->module_libpthread = module;
- return DWARF_CB_ABORT;
-}
-
-/* Look up the named symbol in the named DSO in the symbol tables
- associated with the process being debugged, filling in *SYM_ADDR
- with the corresponding run-time address. */
-ps_err_e ps_pglobal_lookup (struct ps_prochandle *proc_handle,
- const char *object_name, const char *sym_name,
- psaddr_t *sym_addr)
-{
- Dwfl *dwfl = get_dwfl (proc_handle);
- struct getmodules_callback_arg getmodules_callback_arg;
int sym_count, ndx;
GElf_Sym sym;
- Dwfl_Module *module;
-
- getmodules_callback_arg.object_name = object_name;
- getmodules_callback_arg.module_main = NULL;
- getmodules_callback_arg.module_libpthread = NULL;
- dwfl_getmodules (dwfl, getmodules_callback, &getmodules_callback_arg, 0);
- if (getmodules_callback_arg.module_libpthread != NULL)
- module = getmodules_callback_arg.module_libpthread;
- else if (getmodules_callback_arg.module_main != NULL)
- module = getmodules_callback_arg.module_main;
- else
- return PS_NOSYM;
sym_count = dwfl_module_getsymtab (module);
assert (sym_count >= 0);
name_got = dwfl_module_getsym (module, ndx, &sym,
NULL);
assert (name_got != NULL);
- if (strcmp (name_got, sym_name) == 0)
+ if (strcmp (name_got, getmodules_callback_arg->sym_name) == 0)
break;
}
if (ndx == sym_count)
- return PS_NOSYM;
+ return DWARF_CB_OK;
- *sym_addr = (psaddr_t) sym.st_value;
- return PS_OK;
+ *getmodules_callback_arg->sym_addr = (psaddr_t) sym.st_value;
+ getmodules_callback_arg->retval = PS_OK;
+
+ return DWARF_CB_OK;
+}
+
+/* Look up the named symbol in the named DSO in the symbol tables
+ associated with the process being debugged, filling in *SYM_ADDR
+ with the corresponding run-time address. */
+ps_err_e ps_pglobal_lookup (struct ps_prochandle *proc_handle,
+ const char *object_name, const char *sym_name,
+ psaddr_t *sym_addr)
+{
+ Dwfl *dwfl = get_dwfl (proc_handle);
+ struct getmodules_callback_arg getmodules_callback_arg;
+ ptrdiff_t err_ptrdiff;
+
+ /* FIXME: `object_name' ignored due to missing unresolving of shared
+ libraries symbolic links. */
+ getmodules_callback_arg.sym_name = sym_name;
+ getmodules_callback_arg.sym_addr = sym_addr;
+ getmodules_callback_arg.retval = PS_NOSYM;
+ err_ptrdiff = dwfl_getmodules (dwfl, getmodules_callback,
+ &getmodules_callback_arg, 0);
+ assert (err_ptrdiff == 0);
+ return getmodules_callback_arg.retval;
}
#ifdef __x86_64__
proc_handle_local.dwfl = NULL;
err = td_ta_new (&proc_handle_local, &thread_agent);
assert (err == TD_OK || err == TD_NOLIBTHREAD);
- if (err == TD_OK)
+ if (err == TD_NOLIBTHREAD)
{
- puts ("multithreaded");
- thread_test (thread_agent);
+ puts ("singlethreaded");
+ return;
}
- else
- puts ("singlethreaded");
+ puts ("multithreaded");
+ thread_test (thread_agent);
+ err = td_ta_delete (thread_agent);
+ assert (err == TD_OK);
}
static void *start (void *arg)