1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-16 21:27:38 +01:00

dwarf: Make binary path calculation os-specific.

/proc/self/exe only works on Linux, move path computation to os-* files
This commit is contained in:
Konstantin Belousov 2017-01-18 21:03:51 +02:00 committed by Dave Watson
parent 7885596b9c
commit 9e97c9b17a
17 changed files with 93 additions and 1 deletions

View file

@ -269,6 +269,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -306,6 +307,7 @@ extern void *tdep_uc_addr (unw_tdep_context_t *uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -257,6 +257,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -299,6 +300,7 @@ extern void *tdep_uc_addr (unw_tdep_context_t *uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -232,6 +232,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -269,6 +270,7 @@ extern void *tdep_uc_addr (ucontext_t *uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -226,6 +226,7 @@ struct ia64_global_unwind_state
#define tdep_find_proc_info UNW_OBJ(find_proc_info)
#define tdep_uc_addr UNW_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -263,6 +264,7 @@ extern void *tdep_uc_addr (ucontext_t *uc, unw_regnum_t regnum,
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -285,6 +285,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -321,6 +322,7 @@ extern void *tdep_uc_addr (ucontext_t *uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -260,6 +260,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -302,6 +303,7 @@ extern void *tdep_uc_addr (ucontext_t * uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t * valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -315,6 +315,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -357,6 +358,7 @@ extern void *tdep_uc_addr (ucontext_t * uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t * valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -233,6 +233,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -270,6 +271,7 @@ extern void *tdep_uc_addr (unw_tdep_context_t *uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -212,6 +212,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -253,6 +254,7 @@ extern int tdep_get_elf_image (struct elf_image *ei,
unsigned long *segbase,
unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c,
unw_regnum_t reg,
unw_word_t *valp,

View file

@ -246,6 +246,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#define tdep_fetch_frame(c,ip,n) do {} while(0)
@ -283,6 +284,7 @@ extern void *tdep_uc_addr (ucontext_t *uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -197,6 +197,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_search_unwind_table dwarf_search_unwind_table
#define tdep_find_unwind_table dwarf_find_unwind_table
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
#define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
#define tdep_access_reg UNW_OBJ(access_reg)
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
#if __linux__
@ -242,6 +243,7 @@ extern void *x86_64_r_uc_addr (ucontext_t *uc, int reg);
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
extern void tdep_get_exe_image_path (char *path);
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,

View file

@ -538,9 +538,13 @@ dwarf_find_eh_frame_section(struct dl_phdr_info *info)
const char *file = info->dlpi_name;
char secname[EH_FRAME_LEN];
static Elf_W (Shdr) sec_hdrs[100];
char exepath[PATH_MAX];
if (strlen(file) == 0)
file = "/proc/self/exe";
{
tdep_get_exe_image_path(exepath);
file = exepath;
}
Debug (1, "looking for .eh_frame section in %s\n",
file);

View file

@ -143,3 +143,24 @@ tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
free_mem(buf, len1);
return (ret);
}
#ifndef UNW_REMOTE_ONLY
PROTECTED void
tdep_get_exe_image_path (char *path)
{
int mib[4], error;
size_t len;
len = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = getpid();
error = sysctl(mib, 4, path, &len, NULL, 0);
if (error == -1)
path[0] = 0;
}
#endif

View file

@ -65,3 +65,14 @@ tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
return elf_map_image (ei, path);
}
#ifndef UNW_REMOTE_ONLY
PROTECTED void
tdep_get_exe_image_path (char *path)
{
path[0] = 0; /* XXX */
}
#endif

View file

@ -67,3 +67,13 @@ tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
maps_close (&mi);
return rc;
}
#ifndef UNW_REMOTE_ONLY
PROTECTED void
tdep_get_exe_image_path (char *path)
{
strcpy(path, "/proc/self/exe");
}
#endif /* !UNW_REMOTE_ONLY */

View file

@ -105,3 +105,13 @@ tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
return ret;
}
#ifndef UNW_REMOTE_ONLY
PROTECTED void
tdep_get_exe_image_path (char *path)
{
path[0] = 0; /* XXX */
}
#endif

View file

@ -124,6 +124,7 @@ check_local_unw_abi () {
case ${plat} in
arm)
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_is_fpreg
match _UL${plat}_search_unwind_table
match _UL${plat}_dwarf_search_unwind_table
@ -133,20 +134,24 @@ check_local_unw_abi () {
match _UL${plat}_dwarf_search_unwind_table
match _UL${plat}_dwarf_find_unwind_table
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_setcontext
;;
ia64)
match _UL${plat}_search_unwind_table
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
;;
x86)
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_is_fpreg
match _UL${plat}_dwarf_search_unwind_table
match _UL${plat}_dwarf_find_unwind_table
;;
x86_64)
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_is_fpreg
match _UL${plat}_dwarf_search_unwind_table
match _UL${plat}_dwarf_find_unwind_table
@ -155,6 +160,7 @@ check_local_unw_abi () {
ppc*)
match _U${plat}_get_func_addr
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_is_fpreg
match _UL${plat}_dwarf_search_unwind_table
match _UL${plat}_dwarf_find_unwind_table
@ -165,6 +171,7 @@ check_local_unw_abi () {
match _UL${plat}_dwarf_find_unwind_table
match _UL${plat}_local_addr_space_init
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match ${plat}_lock
;;
@ -210,6 +217,7 @@ check_generic_unw_abi () {
arm)
match _U${plat}_is_fpreg
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_search_unwind_table
match _U${plat}_dwarf_search_unwind_table
match _U${plat}_dwarf_find_unwind_table
@ -218,12 +226,14 @@ check_generic_unw_abi () {
match _U${plat}_dwarf_search_unwind_table
match _U${plat}_dwarf_find_unwind_table
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
;;
ia64)
match _U${plat}_search_unwind_table
match _U${plat}_find_dyn_list
if [ $plat = $build_plat ]; then
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
case $os in
linux*)
match _U${plat}_get_kernel_table
@ -233,18 +243,21 @@ check_generic_unw_abi () {
;;
x86)
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_is_fpreg
match _U${plat}_dwarf_search_unwind_table
match _U${plat}_dwarf_find_unwind_table
;;
x86_64)
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_is_fpreg
match _U${plat}_dwarf_search_unwind_table
match _U${plat}_dwarf_find_unwind_table
;;
ppc*)
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_get_func_addr
match _U${plat}_is_fpreg
match _U${plat}_dwarf_search_unwind_table
@ -254,6 +267,7 @@ check_generic_unw_abi () {
match _U${plat}_dwarf_search_unwind_table
match _U${plat}_dwarf_find_unwind_table
match _U${plat}_get_elf_image
match _U${plat}_get_exe_image_path
match _U${plat}_is_fpreg
match _U${plat}_local_addr_space_init
match ${plat}_lock