From e8bc77eb845ab5557a4c98fe0da604d4a3740bef Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 22 May 2015 14:26:13 -0700 Subject: 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 --- debuggerd/arm64/machine.cpp | 67 ++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) (limited to 'debuggerd/arm64') 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 #include -#include +#include #include -#include #include -#include #include -#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 + +#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(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(regs.pc), "code around pc:"); + + if (regs.pc != regs.sp) { + dump_memory(log, backtrace, static_cast(regs.sp), "code around sp:"); + } } void dump_registers(log_t* log, pid_t tid) { -- cgit v1.2.3