libunwind-devel
[Top][All Lists]
Advanced

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

[Libunwind-devel] [PATCH 7/7] Implement _UPTi_find_unwind_table() for AR


From: Anderson Lizardo
Subject: [Libunwind-devel] [PATCH 7/7] Implement _UPTi_find_unwind_table() for ARM
Date: Wed, 25 Jun 2008 07:51:14 -0400
User-agent: quilt/0.46-1

An ARM specific function is necessary because it is (currently) the only
architecture that needs to read information from the .debug_frame section.

Signed-off-by: Anderson Lizardo <address@hidden>
Signed-off-by: Bruna Moreira <address@hidden>
---
 src/dwarf/Gparser.c              |    3 +
 src/ptrace/_UPT_find_proc_info.c |   61 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)

Index: libunwind-indt-split/src/dwarf/Gparser.c
===================================================================
--- libunwind-indt-split.orig/src/dwarf/Gparser.c
+++ libunwind-indt-split/src/dwarf/Gparser.c
@@ -72,6 +72,9 @@
   int ret;
 
   as = c->as;
+#ifdef UNW_TARGET_ARM
+  as = unw_local_addr_space;
+#endif
   arg = c->as_arg;
   a = unw_get_accessors (as);
   curr_ip = c->pi.start_ip;
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
@@ -24,11 +24,13 @@
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
 #include <elf.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
 
 #include <sys/mman.h>
+#include <sys/stat.h>
 
 #include "_UPT_internal.h"
 
@@ -146,8 +148,60 @@
   return &ui->di_cache;
 }
 
-#elif UNW_TARGET_X86 || UNW_TARGET_X86_64 || UNW_TARGET_HPPA \
-|| UNW_TARGET_PPC64 || UNW_TARGET_ARM
+#elif UNW_TARGET_ARM
+
+int
+pid_matches_file (pid_t pid, const char *path)
+{
+  char path2[1024];
+  struct stat st1, st2;
+
+  if (stat (path, &st1) == -1)
+    {
+      Debug (1, "stat: %s: %s\n", path, strerror (errno));
+      return 0;
+    }
+  snprintf (path2, sizeof (path2), "/proc/%d/exe", pid);
+  if (stat (path2, &st2) == -1)
+    {
+      Debug (1, "stat: %s: %s\n", path2, strerror (errno));
+      return 0;
+    }
+  return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
+}
+
+HIDDEN unw_dyn_info_t *
+_UPTi_find_unwind_table (struct UPT_info *ui, unw_addr_space_t as,
+                        char *path, unw_word_t segbase, unw_word_t mapoff,
+                        unw_word_t ip)
+{
+  int found;
+  Elf32_Ehdr *ehdr;
+  struct dl_phdr_info info;
+
+  if (!_Uelf32_valid_object (&ui->ei))
+    return NULL;
+
+  ehdr = ui->ei.image;
+
+  if (pid_matches_file (ui->pid, path))
+    info.dlpi_addr = 0;
+  else
+    info.dlpi_addr = segbase;
+
+  info.dlpi_name = path;
+  info.dlpi_phdr = (Elf_W(Phdr) *) ((char *) ui->ei.image + ehdr->e_phoff);
+  info.dlpi_phnum = ehdr->e_phnum;
+
+  found = dwarf_find_debug_frame (0, &ui->di_cache, &info, ip);
+
+  if (!found)
+    return NULL;
+
+  return &ui->di_cache;
+}
+
+#elif UNW_TARGET_X86 || UNW_TARGET_X86_64 || UNW_TARGET_HPPA || 
UNW_TARGET_PPC64
 
 #include "dwarf-eh.h"
 #include "dwarf_i.h"
@@ -398,5 +452,8 @@
     }
   else
 #endif
+#if UNW_TARGET_ARM
+  as = unw_local_addr_space;
+#endif
   return tdep_search_unwind_table (as, ip, di, pi, need_unwind_info, arg);
 }

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




reply via email to

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