Skip to content

Commit

Permalink
Add support for android local unwinding
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Muizelaar committed Feb 7, 2012
1 parent 51445f6 commit 79c42a7
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/dwarf.h
Expand Up @@ -40,7 +40,7 @@ struct dwarf_cursor; /* forward-declaration */

#include "dwarf-config.h"
#ifndef UNW_REMOTE_ONLY
#include <link.h>
//#include <link.h>
#endif
#include <pthread.h>

Expand Down Expand Up @@ -381,6 +381,7 @@ struct dwarf_callback_data

extern int dwarf_init (void);
#ifndef UNW_REMOTE_ONLY
struct dl_phdr_info;
extern int dwarf_callback (struct dl_phdr_info *info, size_t size, void *ptr);
extern int dwarf_find_proc_info (unw_addr_space_t as, unw_word_t ip,
unw_proc_info_t *pi,
Expand Down
6 changes: 3 additions & 3 deletions src/Makefile.am
Expand Up @@ -99,7 +99,7 @@ libunwind_la_SOURCES_local = \
$(libunwind_la_SOURCES_local_unwind)

noinst_HEADERS += os-linux.h
libunwind_la_SOURCES_os_linux = os-linux.c
libunwind_la_SOURCES_os_linux = os-linux.c dl-iterate-phdr.c

libunwind_la_SOURCES_os_hpux = os-hpux.c

Expand Down Expand Up @@ -147,14 +147,14 @@ libunwind_la_SOURCES_arm = $(libunwind_la_SOURCES_arm_common) \
arm/Lcreate_addr_space.c arm/Lget_proc_info.c arm/Lget_save_loc.c \
arm/Lglobal.c arm/Linit.c arm/Linit_local.c arm/Linit_remote.c \
arm/Lis_signal_frame.c arm/Lregs.c arm/Lresume.c arm/Lstep.c \
arm/Lex_tables.c
arm/Lex_tables.c os-linux.c dl-iterate-phdr.c

libunwind_arm_la_SOURCES_arm = $(libunwind_la_SOURCES_arm_common) \
$(libunwind_la_SOURCES_generic) \
arm/Gcreate_addr_space.c arm/Gget_proc_info.c arm/Gget_save_loc.c \
arm/Gglobal.c arm/Ginit.c arm/Ginit_local.c arm/Ginit_remote.c \
arm/Gis_signal_frame.c arm/Gregs.c arm/Gresume.c arm/Gstep.c \
arm/Gex_tables.c
arm/Gex_tables.c os-linux.c dl-iterate-phdr.c

# The list of files that go both into libunwind and libunwind-ia64:
noinst_HEADERS += ia64/init.h ia64/offsets.h ia64/regs.h \
Expand Down
1 change: 1 addition & 0 deletions src/arm/Gex_tables.c
Expand Up @@ -38,6 +38,7 @@ ABI for the ARM architecture can be found at:
#define ARM_EXIDX_COMPACT 0x80000000

#define ARM_EXTBL_OP_FINISH 0xb0
#include "dl-iterate-phdr.h"

enum arm_exbuf_cmd_flags {
ARM_EXIDX_VFP_SHIFT_16 = 1 << 16,
Expand Down
71 changes: 71 additions & 0 deletions src/dl-iterate-phdr.c
@@ -0,0 +1,71 @@
/* libunwind - a platform-independent unwind library
Copyright (C) 2003-2005 Hewlett-Packard Co
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of libunwind.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
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 <limits.h>
#include <stdio.h>

#include "libunwind_i.h"
#include "os-linux.h"
#include "dl-iterate-phdr.h"

int
dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, size_t size, void *data),
void *data)
{
struct map_iterator mi;
int found = 0, rc;
unsigned long hi;
unsigned long low;

if (maps_init (&mi, getpid()) < 0)
return -1;

unsigned long offset;
while (maps_next (&mi, &low, &hi, &offset)) {
struct dl_phdr_info info;
info.dlpi_name = mi.path;
info.dlpi_addr = low;

Elf_W(Ehdr) *ehdr;

struct elf_image ei;
ei.image = (void*)info.dlpi_addr;
ei.size = hi - low;

//if (!elf_w(valid_object) (&ei))
// continue;

ehdr = ei.image;
Elf_W(Phdr) *phdr = (Elf_W(Phdr) *) ((char *) ei.image + ehdr->e_phoff);
info.dlpi_phdr = phdr;
info.dlpi_phdr = ehdr->e_phnum;
callback(&info, sizeof(info), data);


}
maps_close (&mi);

return rc;
}
14 changes: 14 additions & 0 deletions src/dl-iterate-phdr.h
@@ -0,0 +1,14 @@
struct dl_phdr_info {
Elf_W(Addr) dlpi_addr; /* Base address of object */
const char *dlpi_name; /* (Null-terminated) name of
object */
const Elf_W(Phdr) *dlpi_phdr; /* Pointer to array of
ELF program headers
for this object */
Elf_W(Half) dlpi_phnum; /* # of items in dlpi_phdr */
};

int
dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, size_t size, void *data),
void *data);

4 changes: 2 additions & 2 deletions src/dwarf/Gfind_proc_info-lsb.c
Expand Up @@ -27,7 +27,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
(http://www.linuxbase.org/spec/). */

#ifndef UNW_REMOTE_ONLY
#include <link.h>
//#include <link.h>
#endif /* !UNW_REMOTE_ONLY */
#include <stddef.h>
#include <stdio.h>
Expand Down Expand Up @@ -534,7 +534,7 @@ dwarf_find_debug_frame (int found, unw_dyn_info_t *di_debug, unw_word_t ip,
#endif /* CONFIG_DEBUG_FRAME */

#ifndef UNW_REMOTE_ONLY

#include "dl-iterate-phdr.h"
/* ptr is a pointer to a dwarf_callback_data structure and, on entry,
member ip contains the instruction-pointer we're looking
for. */
Expand Down

0 comments on commit 79c42a7

Please sign in to comment.