| 1 |
struct task_struct; |
| 2 |
#include "../sym.h" |
| 3 |
#include <assert.h> |
| 4 |
#include <elfutils/libdwfl.h> |
| 5 |
|
| 6 |
typedef struct |
| 7 |
{ |
| 8 |
char *fn; |
| 9 |
unsigned long offset; |
| 10 |
} module_args; |
| 11 |
|
| 12 |
|
| 13 |
static int |
| 14 |
module_callback (Dwfl_Module *mod, void **userdata __attribute__((unused)), |
| 15 |
const char *name, Dwarf_Addr start, void *arg) |
| 16 |
{ |
| 17 |
module_args *modargs = (module_args*)arg; |
| 18 |
if (strcmp (modargs->fn, name) == 0) |
| 19 |
{ |
| 20 |
modargs->offset += start; |
| 21 |
return DWARF_CB_ABORT; |
| 22 |
} |
| 23 |
|
| 24 |
return DWARF_CB_OK; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
static unsigned long _stp_umodule_relocate(const char *path, |
| 29 |
unsigned long offset, |
| 30 |
struct task_struct *task) |
| 31 |
{ |
| 32 |
static char *debuginfo_path; |
| 33 |
static const Dwfl_Callbacks proc_callbacks = |
| 34 |
{ |
| 35 |
.find_debuginfo = dwfl_standard_find_debuginfo, |
| 36 |
.debuginfo_path = &debuginfo_path, |
| 37 |
|
| 38 |
.find_elf = dwfl_linux_proc_find_elf, |
| 39 |
}; |
| 40 |
Dwfl *dwfl = dwfl_begin (&proc_callbacks); |
| 41 |
if (dwfl == NULL) |
| 42 |
_stp_error ("dwfl_begin: %s", dwfl_errmsg (-1)); |
| 43 |
|
| 44 |
int result = dwfl_linux_proc_report (dwfl, getpid()); |
| 45 |
if (result < 0) |
| 46 |
_stp_error ("dwfl_linux_proc_report: %s", dwfl_errmsg (-1)); |
| 47 |
else if (result > 0) |
| 48 |
_stp_error ("dwfl_linux_proc_report"); |
| 49 |
|
| 50 |
if (dwfl_report_end (dwfl, NULL, NULL) != 0) |
| 51 |
_stp_error ("dwfl_report_end: %s", dwfl_errmsg (-1)); |
| 52 |
|
| 53 |
module_args modargs = |
| 54 |
{ |
| 55 |
.fn = (char*)path, |
| 56 |
.offset = offset |
| 57 |
}; |
| 58 |
|
| 59 |
if (dwfl_getmodules (dwfl, module_callback, &modargs, 0) == -1) |
| 60 |
_stp_error ("dwfl_getmodules: %s", dwfl_errmsg (-1)); |
| 61 |
dwfl_end (dwfl); |
| 62 |
return modargs.offset; |
| 63 |
} |