libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libunwind-devel] [PATCH 4/7] Add path and pathlen arguments to tdep_get


From: Anderson Lizardo
Subject: [Libunwind-devel] [PATCH 4/7] Add path and pathlen arguments to tdep_get_elf_image()
Date: Wed, 25 Jun 2008 07:51:11 -0400
User-agent: quilt/0.46-1

These new arguments are necessary for remote backtracing on ARM, because it
needs to fill a struct dl_phdr_info manually.

Signed-off-by: Anderson Lizardo <address@hidden>
Signed-off-by: Bruna Moreira <address@hidden>
---
 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                       |    4 +++-
 src/os-hpux.c                     |   14 ++++++++++----
 src/os-linux.c                    |    6 +++---
 src/ptrace/_UPT_find_proc_info.c  |    3 ++-
 12 files changed, 34 insertions(+), 17 deletions(-)

Index: libunwind-indt-split/include/tdep-arm/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-arm/libunwind_i.h
+++ libunwind-indt-split/include/tdep-arm/libunwind_i.h
@@ -245,7 +245,8 @@
                                     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,
Index: libunwind-indt-split/include/tdep-hppa/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-hppa/libunwind_i.h
+++ libunwind-indt-split/include/tdep-hppa/libunwind_i.h
@@ -252,7 +252,8 @@
                                     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,
Index: libunwind-indt-split/include/tdep-ia64/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-ia64/libunwind_i.h
+++ libunwind-indt-split/include/tdep-ia64/libunwind_i.h
@@ -244,7 +244,8 @@
 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,
Index: libunwind-indt-split/include/tdep-mips/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-mips/libunwind_i.h
+++ libunwind-indt-split/include/tdep-mips/libunwind_i.h
@@ -306,7 +306,8 @@
                                     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,
Index: libunwind-indt-split/include/tdep-ppc32/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-ppc32/libunwind_i.h
+++ libunwind-indt-split/include/tdep-ppc32/libunwind_i.h
@@ -289,7 +289,8 @@
                                     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,
Index: libunwind-indt-split/include/tdep-ppc64/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-ppc64/libunwind_i.h
+++ libunwind-indt-split/include/tdep-ppc64/libunwind_i.h
@@ -289,7 +289,8 @@
                                     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,
Index: libunwind-indt-split/include/tdep-x86/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-x86/libunwind_i.h
+++ libunwind-indt-split/include/tdep-x86/libunwind_i.h
@@ -255,7 +255,8 @@
                                     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,
Index: libunwind-indt-split/include/tdep-x86_64/libunwind_i.h
===================================================================
--- libunwind-indt-split.orig/include/tdep-x86_64/libunwind_i.h
+++ libunwind-indt-split/include/tdep-x86_64/libunwind_i.h
@@ -189,7 +189,8 @@
                                     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,
Index: libunwind-indt-split/src/elfxx.c
===================================================================
--- libunwind-indt-split.orig/src/elfxx.c
+++ libunwind-indt-split/src/elfxx.c
@@ -25,6 +25,7 @@
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
 #include <stdio.h>
+#include <sys/param.h>
 
 #include "libunwind_i.h"
 
@@ -145,9 +146,10 @@
   struct elf_image ei;
   Elf_W (Ehdr) *ehdr;
   Elf_W (Phdr) *phdr;
+  char path[MAXPATHLEN];
   int i, ret;
 
-  ret = tdep_get_elf_image (&ei, pid, ip, &segbase, &mapoff);
+  ret = tdep_get_elf_image (&ei, pid, ip, &segbase, &mapoff, path, 
sizeof(path));
   if (ret < 0)
     return ret;
 
Index: libunwind-indt-split/src/os-hpux.c
===================================================================
--- libunwind-indt-split.orig/src/os-hpux.c
+++ libunwind-indt-split/src/os-hpux.c
@@ -26,6 +26,7 @@
 #ifndef UNW_REMOTE_ONLY
 
 #include <dlfcn.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "libunwind_i.h"
@@ -34,10 +35,11 @@
 
 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,9 +53,13 @@
   *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;
+  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);
 
Index: libunwind-indt-split/src/os-linux.c
===================================================================
--- libunwind-indt-split.orig/src/os-linux.c
+++ libunwind-indt-split/src/os-linux.c
@@ -33,15 +33,15 @@
 
 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;
-  char path[PATH_MAX];
   int found = 0;
   unsigned long hi;
 
   maps_init (&mi, pid);
-  while (maps_next (&mi, segbase, &hi, mapoff, path, sizeof (path)))
+  while (maps_next (&mi, segbase, &hi, mapoff, path, pathlen))
     if (ip >= *segbase && ip < hi)
       {
        found = 1;
Index: libunwind-indt-split/src/ptrace/_UPT_find_proc_info.c
===================================================================
--- libunwind-indt-split.orig/src/ptrace/_UPT_find_proc_info.c
+++ libunwind-indt-split/src/ptrace/_UPT_find_proc_info.c
@@ -338,7 +338,8 @@
       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

-- 
Anderson Lizardo
Instituto Nokia de Tecnologia (INdT)
Manaus - Brazil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]