diff options
author | Christopher Ferris <cferris@google.com> | 2015-05-22 14:26:13 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2015-05-27 17:21:38 -0700 |
commit | e8bc77eb845ab5557a4c98fe0da604d4a3740bef (patch) | |
tree | a2e19db2503de6abcfc6926c57b6920bdde14ddf /debuggerd/arm64 | |
parent | 7c7895755cf23140f08b7416ceff006dbbf7a411 (diff) | |
download | core-e8bc77eb845ab5557a4c98fe0da604d4a3740bef.tar.gz core-e8bc77eb845ab5557a4c98fe0da604d4a3740bef.tar.bz2 core-e8bc77eb845ab5557a4c98fe0da604d4a3740bef.zip |
Refactor dump_memory function.
- Add dumping memory around registers for x86/x86_64.
- Add unit tests for new dump_memory function.
- Cleanup all of the machine.cpp files.
- Increase the high address check for 32 bit, and decrease the high
address allowed for 64 bit slightly to match mips64.
Bug: 21206576
Change-Id: I6f75141f3282db48b10f7c695a1cf2eb75a08351
Diffstat (limited to 'debuggerd/arm64')
-rw-r--r-- | debuggerd/arm64/machine.cpp | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/debuggerd/arm64/machine.cpp b/debuggerd/arm64/machine.cpp index 8b17d536c..2e097da00 100644 --- a/debuggerd/arm64/machine.cpp +++ b/debuggerd/arm64/machine.cpp @@ -17,50 +17,37 @@ #include <elf.h> #include <errno.h> -#include <inttypes.h> +#include <stdint.h> #include <string.h> -#include <sys/types.h> #include <sys/ptrace.h> -#include <sys/user.h> #include <sys/uio.h> -#include "../utility.h" -#include "../machine.h" - -void dump_memory_and_code(log_t* log, pid_t tid) { - struct user_pt_regs regs; - struct iovec io; - io.iov_base = ®s; - io.iov_len = sizeof(regs); - - if (ptrace(PTRACE_GETREGSET, tid, (void*)NT_PRSTATUS, &io) == -1) { - _LOG(log, logtype::ERROR, "%s: ptrace failed to get registers: %s\n", - __func__, strerror(errno)); - return; - } - - for (int reg = 0; reg < 31; reg++) { - uintptr_t addr = regs.regs[reg]; - - /* - * Don't bother if it looks like a small int or ~= null, or if - * it's in the kernel area. - */ - if (addr < 4096 || addr >= (1UL<<63)) { - continue; - } - - _LOG(log, logtype::MEMORY, "\nmemory near x%d:\n", reg); - dump_memory(log, tid, addr); - } - - _LOG(log, logtype::MEMORY, "\ncode around pc:\n"); - dump_memory(log, tid, (uintptr_t)regs.pc); - - if (regs.pc != regs.sp) { - _LOG(log, logtype::MEMORY, "\ncode around sp:\n"); - dump_memory(log, tid, (uintptr_t)regs.sp); - } +#include <backtrace/Backtrace.h> + +#include "machine.h" +#include "utility.h" + +void dump_memory_and_code(log_t* log, Backtrace* backtrace) { + struct user_pt_regs regs; + struct iovec io; + io.iov_base = ®s; + io.iov_len = sizeof(regs); + + if (ptrace(PTRACE_GETREGSET, backtrace->Tid(), reinterpret_cast<void*>(NT_PRSTATUS), &io) == -1) { + _LOG(log, logtype::ERROR, "%s: ptrace failed to get registers: %s", + __func__, strerror(errno)); + return; + } + + for (int reg = 0; reg < 31; reg++) { + dump_memory(log, backtrace, regs.regs[reg], "memory near x%d:", reg); + } + + dump_memory(log, backtrace, static_cast<uintptr_t>(regs.pc), "code around pc:"); + + if (regs.pc != regs.sp) { + dump_memory(log, backtrace, static_cast<uintptr_t>(regs.sp), "code around sp:"); + } } void dump_registers(log_t* log, pid_t tid) { |