summaryrefslogtreecommitdiffstats
path: root/libcorkscrew/arch-mips/ptrace-mips.c
diff options
context:
space:
mode:
authorChris Dearman <chris.dearman@imgtec.com>2013-12-06 04:29:37 -0800
committerChris Dearman <chris.dearman@imgtec.com>2013-12-11 12:50:46 -0800
commit5299857825f10bbc724e1598cc348a5ceafd444b (patch)
tree0461b8aba2d319e74177650d7ce310599f49d7c0 /libcorkscrew/arch-mips/ptrace-mips.c
parentbcf1454cf6a2fadc30c5189c3756b3cb96149745 (diff)
downloadsystem_core-5299857825f10bbc724e1598cc348a5ceafd444b.zip
system_core-5299857825f10bbc724e1598cc348a5ceafd444b.tar.gz
system_core-5299857825f10bbc724e1598cc348a5ceafd444b.tar.bz2
Dwarf backtrace for MIPS
The Dwarf parsing code was copied from backtrace-x86.c and modified for MIPS Change-Id: I62c698fbbea28be39320a921dd778269dc478528
Diffstat (limited to 'libcorkscrew/arch-mips/ptrace-mips.c')
-rw-r--r--libcorkscrew/arch-mips/ptrace-mips.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/libcorkscrew/arch-mips/ptrace-mips.c b/libcorkscrew/arch-mips/ptrace-mips.c
index f0ea110..ba3b60a 100644
--- a/libcorkscrew/arch-mips/ptrace-mips.c
+++ b/libcorkscrew/arch-mips/ptrace-mips.c
@@ -19,10 +19,59 @@
#include "../ptrace-arch.h"
+#include <stddef.h>
+#include <elf.h>
#include <cutils/log.h>
+static void load_eh_frame_hdr(pid_t pid, map_info_t* mi, uintptr_t *eh_frame_hdr) {
+ uint32_t elf_phoff;
+ uint32_t elf_phentsize_ehsize;
+ uint32_t elf_shentsize_phnum;
+
+
+ try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff);
+ ALOGV("reading 0x%08x elf_phoff:%x", mi->start + offsetof(Elf32_Ehdr, e_phoff), elf_phoff);
+ try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize), &elf_phentsize_ehsize);
+ ALOGV("reading 0x%08x elf_phentsize_ehsize:%x", mi->start + offsetof(Elf32_Ehdr, e_ehsize), elf_phentsize_ehsize);
+ try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum), &elf_shentsize_phnum);
+ ALOGV("reading 0x%08x elf_shentsize_phnum:%x", mi->start + offsetof(Elf32_Ehdr, e_phnum), elf_shentsize_phnum);
+
+
+
+ if (try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff)
+ && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize),
+ &elf_phentsize_ehsize)
+ && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum),
+ &elf_shentsize_phnum)) {
+ uint32_t elf_phentsize = elf_phentsize_ehsize >> 16;
+ uint32_t elf_phnum = elf_shentsize_phnum & 0xffff;
+ for (uint32_t i = 0; i < elf_phnum; i++) {
+ uintptr_t elf_phdr = mi->start + elf_phoff + i * elf_phentsize;
+ uint32_t elf_phdr_type;
+ if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) {
+ break;
+ }
+ if (elf_phdr_type == PT_GNU_EH_FRAME) {
+ uint32_t elf_phdr_offset;
+ if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset),
+ &elf_phdr_offset)) {
+ break;
+ }
+ *eh_frame_hdr = mi->start + elf_phdr_offset;
+ ALOGV("Parsed .eh_frame_hdr info for %s: start=0x%08x", mi->name, *eh_frame_hdr);
+ return;
+ }
+ }
+ }
+ *eh_frame_hdr = 0;
+}
+
void load_ptrace_map_info_data_arch(pid_t pid, map_info_t* mi, map_info_data_t* data) {
+ ALOGV("load_ptrace_map_info_data_arch");
+ load_eh_frame_hdr(pid, mi, &data->eh_frame_hdr);
}
-void free_ptrace_map_info_data_arch(map_info_t* mi, map_info_data_t* data) {
+void free_ptrace_map_info_data_arch(map_info_t* mi __attribute__((unused)),
+ map_info_data_t* data __attribute__((unused))) {
+ ALOGV("free_ptrace_map_info_data_arch");
}