From 1787a2fd284a786b409af74047a12de02c644cd1 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Sat, 15 May 2010 12:14:09 -0700 Subject: [PATCH] Add path and pathlen arguments to tdep_get_elf_image() Signed-off-by: Andris Zeila --- include/tdep-arm/libunwind_i.h | 3 ++- include/tdep-hppa/libunwind_i.h | 3 ++- include/tdep-ia64/libunwind_i.h | 3 ++- include/tdep-mips/libunwind_i.h | 3 ++- include/tdep-ppc32/libunwind_i.h | 3 ++- include/tdep-ppc64/libunwind_i.h | 3 ++- include/tdep-x86/libunwind_i.h | 3 ++- include/tdep-x86_64/libunwind_i.h | 3 ++- src/elfxx.c | 3 ++- src/os-freebsd.c | 6 +++++- src/os-hpux.c | 18 +++++++++++++----- src/os-linux.c | 8 ++++++-- src/ptrace/_UPT_find_proc_info.c | 3 ++- 13 files changed, 44 insertions(+), 18 deletions(-) diff --git a/include/tdep-arm/libunwind_i.h b/include/tdep-arm/libunwind_i.h index 2e1c4285..faa35fce 100644 --- a/include/tdep-arm/libunwind_i.h +++ b/include/tdep-arm/libunwind_i.h @@ -248,7 +248,8 @@ extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, int need_unwind_info, void *arg); 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); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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 d89cc65e..50d1aabd 100644 --- a/include/tdep-hppa/libunwind_i.h +++ b/include/tdep-hppa/libunwind_i.h @@ -255,7 +255,8 @@ extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, int need_unwind_info, void *arg); 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); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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 4936d516..75cc220d 100644 --- a/include/tdep-ia64/libunwind_i.h +++ b/include/tdep-ia64/libunwind_i.h @@ -247,7 +247,8 @@ extern void tdep_put_unwind_info (unw_addr_space_t as, extern void *tdep_uc_addr (ucontext_t *uc, unw_regnum_t regnum, uint8_t *nat_bitnr); extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, - unsigned long *segbase, unsigned long *mapoff); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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 298fae81..160a6372 100644 --- a/include/tdep-mips/libunwind_i.h +++ b/include/tdep-mips/libunwind_i.h @@ -309,7 +309,8 @@ extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, int need_unwind_info, void *arg); 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); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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 b963bca8..e775dd64 100644 --- a/include/tdep-ppc32/libunwind_i.h +++ b/include/tdep-ppc32/libunwind_i.h @@ -292,7 +292,8 @@ extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, int need_unwind_info, void *arg); 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); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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 799b511f..bb6c977b 100644 --- a/include/tdep-ppc64/libunwind_i.h +++ b/include/tdep-ppc64/libunwind_i.h @@ -292,7 +292,8 @@ extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, int need_unwind_info, void *arg); 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); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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/libunwind_i.h b/include/tdep-x86/libunwind_i.h index bed8cbf0..bc381e91 100644 --- a/include/tdep-x86/libunwind_i.h +++ b/include/tdep-x86/libunwind_i.h @@ -271,7 +271,8 @@ extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, int need_unwind_info, void *arg); 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); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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 c0227251..ea502ec4 100644 --- a/include/tdep-x86_64/libunwind_i.h +++ b/include/tdep-x86_64/libunwind_i.h @@ -200,7 +200,8 @@ extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, int need_unwind_info, void *arg); 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); + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); 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/elfxx.c b/src/elfxx.c index 05b99438..06cc9bb6 100644 --- a/src/elfxx.c +++ b/src/elfxx.c @@ -25,6 +25,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include "libunwind_i.h" @@ -147,7 +148,7 @@ elf_w (get_proc_name) (unw_addr_space_t as, pid_t pid, unw_word_t ip, Elf_W (Phdr) *phdr; int i, ret; - ret = tdep_get_elf_image (&ei, pid, ip, &segbase, &mapoff); + ret = tdep_get_elf_image (&ei, pid, ip, &segbase, &mapoff, NULL, 0); if (ret < 0) return ret; diff --git a/src/os-freebsd.c b/src/os-freebsd.c index a6c42fee..6b1a6e17 100644 --- a/src/os-freebsd.c +++ b/src/os-freebsd.c @@ -52,7 +52,7 @@ free_mem(void *ptr, size_t sz) PROTECTED int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, - unsigned long *segbase, unsigned long *mapoff) + unsigned long *segbase, unsigned long *mapoff, char *path, size_t pathlen) { int mib[4], error, ret; size_t len, len1; @@ -87,6 +87,10 @@ tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, break; *segbase = kv->kve_start; *mapoff = kv->kve_offset; + if (path) + { + strncpy(path, kb->kve_path, pathlen); + } ret = elf_map_image(ei, kv->kve_path); break; } diff --git a/src/os-hpux.c b/src/os-hpux.c index 586ace2e..09100d0f 100644 --- a/src/os-hpux.c +++ b/src/os-hpux.c @@ -26,6 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef UNW_REMOTE_ONLY #include +#include #include #include "libunwind_i.h" @@ -34,10 +35,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ HIDDEN int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, - unsigned long *segbase, unsigned long *mapoff) + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen); { struct load_module_desc lmd; - const char *path; + const char *path2; if (pid != getpid ()) { @@ -51,10 +53,16 @@ tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, *segbase = lmd.text_base; *mapoff = 0; /* XXX fix me? */ - path = dlgetname (&lmd, sizeof (lmd), NULL, 0, 0); - if (!path) + path2 = dlgetname (&lmd, sizeof (lmd), NULL, 0, 0); + if (!path2) return -UNW_ENOINFO; - + if (path) + { + strncpy(path, path2, pathlen); + path[pathlen - 1] = '\0'; + if (strcmp(path, path2) != 0) + Debug(1, "buffer size (%d) not big enough to hold path\n", pathlen); + } Debug(1, "segbase=%lx, mapoff=%lx, path=%s\n", *segbase, *mapoff, path); return elf_map_image (ei, path); diff --git a/src/os-linux.c b/src/os-linux.c index 210edd05..791b27eb 100644 --- a/src/os-linux.c +++ b/src/os-linux.c @@ -33,7 +33,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ PROTECTED int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, - unsigned long *segbase, unsigned long *mapoff) + unsigned long *segbase, unsigned long *mapoff, + char *path, size_t pathlen) { struct map_iterator mi; int found = 0, rc; @@ -54,7 +55,10 @@ tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, maps_close (&mi); return -1; } - + if (path) + { + strncpy(path, mi.path, pathlen); + } rc = elf_map_image (ei, mi.path); maps_close (&mi); return rc; diff --git a/src/ptrace/_UPT_find_proc_info.c b/src/ptrace/_UPT_find_proc_info.c index fedda639..4d70bf59 100644 --- a/src/ptrace/_UPT_find_proc_info.c +++ b/src/ptrace/_UPT_find_proc_info.c @@ -342,7 +342,8 @@ get_unwind_info (struct UPT_info *ui, unw_addr_space_t as, unw_word_t ip) ui->di_cache.start_ip = ui->di_cache.end_ip = 0; } - if (tdep_get_elf_image (&ui->ei, ui->pid, ip, &segbase, &mapoff) < 0) + if (tdep_get_elf_image (&ui->ei, ui->pid, ip, &segbase, &mapoff, path, + sizeof(path)) < 0) return NULL; /* Here, SEGBASE is the starting-address of the (mmap'ped) segment