From 9e97c9b17ae9b6922980465656b14bac5df2ea32 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 18 Jan 2017 21:03:51 +0200 Subject: [PATCH] dwarf: Make binary path calculation os-specific. /proc/self/exe only works on Linux, move path computation to os-* files --- include/tdep-aarch64/libunwind_i.h | 2 ++ include/tdep-arm/libunwind_i.h | 2 ++ include/tdep-hppa/libunwind_i.h | 2 ++ include/tdep-ia64/libunwind_i.h | 2 ++ include/tdep-mips/libunwind_i.h | 2 ++ include/tdep-ppc32/libunwind_i.h | 2 ++ include/tdep-ppc64/libunwind_i.h | 2 ++ include/tdep-sh/libunwind_i.h | 2 ++ include/tdep-tilegx/libunwind_i.h | 2 ++ include/tdep-x86/libunwind_i.h | 2 ++ include/tdep-x86_64/libunwind_i.h | 2 ++ src/dwarf/Gfind_proc_info-lsb.c | 6 +++++- src/os-freebsd.c | 21 +++++++++++++++++++++ src/os-hpux.c | 11 +++++++++++ src/os-linux.c | 10 ++++++++++ src/os-qnx.c | 10 ++++++++++ tests/check-namespace.sh.in | 14 ++++++++++++++ 17 files changed, 93 insertions(+), 1 deletion(-) diff --git a/include/tdep-aarch64/libunwind_i.h b/include/tdep-aarch64/libunwind_i.h index ca281550..ca26180d 100644 --- a/include/tdep-aarch64/libunwind_i.h +++ b/include/tdep-aarch64/libunwind_i.h @@ -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, diff --git a/include/tdep-arm/libunwind_i.h b/include/tdep-arm/libunwind_i.h index d3a279c9..21b8363f 100644 --- a/include/tdep-arm/libunwind_i.h +++ b/include/tdep-arm/libunwind_i.h @@ -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, diff --git a/include/tdep-hppa/libunwind_i.h b/include/tdep-hppa/libunwind_i.h index d5cc1b92..0f96b45d 100644 --- a/include/tdep-hppa/libunwind_i.h +++ b/include/tdep-hppa/libunwind_i.h @@ -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, diff --git a/include/tdep-ia64/libunwind_i.h b/include/tdep-ia64/libunwind_i.h index 7e57c7b6..2d9908ed 100644 --- a/include/tdep-ia64/libunwind_i.h +++ b/include/tdep-ia64/libunwind_i.h @@ -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, diff --git a/include/tdep-mips/libunwind_i.h b/include/tdep-mips/libunwind_i.h index d11894d9..56e0f3c0 100644 --- a/include/tdep-mips/libunwind_i.h +++ b/include/tdep-mips/libunwind_i.h @@ -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, diff --git a/include/tdep-ppc32/libunwind_i.h b/include/tdep-ppc32/libunwind_i.h index cc113c56..b1796bb8 100644 --- a/include/tdep-ppc32/libunwind_i.h +++ b/include/tdep-ppc32/libunwind_i.h @@ -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, diff --git a/include/tdep-ppc64/libunwind_i.h b/include/tdep-ppc64/libunwind_i.h index 5a5bddbc..51cca9e9 100644 --- a/include/tdep-ppc64/libunwind_i.h +++ b/include/tdep-ppc64/libunwind_i.h @@ -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, diff --git a/include/tdep-sh/libunwind_i.h b/include/tdep-sh/libunwind_i.h index 7bbb29b3..5e040894 100644 --- a/include/tdep-sh/libunwind_i.h +++ b/include/tdep-sh/libunwind_i.h @@ -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, diff --git a/include/tdep-tilegx/libunwind_i.h b/include/tdep-tilegx/libunwind_i.h index 9a4ec6a5..66a3b2cb 100644 --- a/include/tdep-tilegx/libunwind_i.h +++ b/include/tdep-tilegx/libunwind_i.h @@ -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, diff --git a/include/tdep-x86/libunwind_i.h b/include/tdep-x86/libunwind_i.h index b1c8b983..10993c6f 100644 --- a/include/tdep-x86/libunwind_i.h +++ b/include/tdep-x86/libunwind_i.h @@ -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, diff --git a/include/tdep-x86_64/libunwind_i.h b/include/tdep-x86_64/libunwind_i.h index e1271c1f..73e3879d 100644 --- a/include/tdep-x86_64/libunwind_i.h +++ b/include/tdep-x86_64/libunwind_i.h @@ -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, diff --git a/src/dwarf/Gfind_proc_info-lsb.c b/src/dwarf/Gfind_proc_info-lsb.c index d973c630..e14077b6 100644 --- a/src/dwarf/Gfind_proc_info-lsb.c +++ b/src/dwarf/Gfind_proc_info-lsb.c @@ -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); diff --git a/src/os-freebsd.c b/src/os-freebsd.c index 1aa1e078..a96877d9 100644 --- a/src/os-freebsd.c +++ b/src/os-freebsd.c @@ -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 diff --git a/src/os-hpux.c b/src/os-hpux.c index 2ee6fa74..d9435c1e 100644 --- a/src/os-hpux.c +++ b/src/os-hpux.c @@ -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 + diff --git a/src/os-linux.c b/src/os-linux.c index 652d6f2f..dc861a84 100644 --- a/src/os-linux.c +++ b/src/os-linux.c @@ -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 */ diff --git a/src/os-qnx.c b/src/os-qnx.c index 97bc7663..47909922 100644 --- a/src/os-qnx.c +++ b/src/os-qnx.c @@ -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 diff --git a/tests/check-namespace.sh.in b/tests/check-namespace.sh.in index 1ae81212..44c1932f 100644 --- a/tests/check-namespace.sh.in +++ b/tests/check-namespace.sh.in @@ -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