summaryrefslogtreecommitdiffstats
path: root/debuggerd/libdebuggerd/elf_utils.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-08-21 14:31:17 -0700
committerJosh Gao <jmgao@google.com>2017-12-15 14:11:12 -0800
commit2b2ae0c88ef83c4c53297ff54fa601b18c014fa4 (patch)
tree832d3ab764da9a63d4e22001f18045fa13078dd5 /debuggerd/libdebuggerd/elf_utils.cpp
parent385ea22741ed5bad794fb6b1dff2b46481f241c4 (diff)
downloadsystem_core-2b2ae0c88ef83c4c53297ff54fa601b18c014fa4.tar.gz
system_core-2b2ae0c88ef83c4c53297ff54fa601b18c014fa4.tar.bz2
system_core-2b2ae0c88ef83c4c53297ff54fa601b18c014fa4.zip
crash_dump: fork a copy of the target's address space.
Reduce the amount of time that a process remains paused by pausing its threads, fetching their registers, and then performing unwinding on a copy of its address space. This also works around a kernel change that's in 4.9 that prevents ptrace from reading memory of processes that we don't have immediate permissions to ptrace (even if we previously ptraced them). Bug: http://b/62112103 Bug: http://b/63989615 Test: treehugger Change-Id: I7b9cc5dd8f54a354bc61f1bda0d2b7a8a55733c4
Diffstat (limited to 'debuggerd/libdebuggerd/elf_utils.cpp')
-rw-r--r--debuggerd/libdebuggerd/elf_utils.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/debuggerd/libdebuggerd/elf_utils.cpp b/debuggerd/libdebuggerd/elf_utils.cpp
index a35102f63..d7afc0b49 100644
--- a/debuggerd/libdebuggerd/elf_utils.cpp
+++ b/debuggerd/libdebuggerd/elf_utils.cpp
@@ -26,28 +26,28 @@
#include <string>
#include <android-base/stringprintf.h>
-#include <backtrace/Backtrace.h>
#include <log/log.h>
+#include <unwindstack/Memory.h>
#define NOTE_ALIGN(size) (((size) + 3) & ~3)
template <typename HdrType, typename PhdrType, typename NhdrType>
-static bool get_build_id(
- Backtrace* backtrace, uintptr_t base_addr, uint8_t* e_ident, std::string* build_id) {
+static bool get_build_id(unwindstack::Memory* memory, uintptr_t base_addr, uint8_t* e_ident,
+ std::string* build_id) {
HdrType hdr;
memcpy(&hdr.e_ident[0], e_ident, EI_NIDENT);
// First read the rest of the header.
- if (backtrace->Read(base_addr + EI_NIDENT, reinterpret_cast<uint8_t*>(&hdr) + EI_NIDENT,
- sizeof(HdrType) - EI_NIDENT) != sizeof(HdrType) - EI_NIDENT) {
+ if (memory->Read(base_addr + EI_NIDENT, reinterpret_cast<uint8_t*>(&hdr) + EI_NIDENT,
+ sizeof(HdrType) - EI_NIDENT) != sizeof(HdrType) - EI_NIDENT) {
return false;
}
for (size_t i = 0; i < hdr.e_phnum; i++) {
PhdrType phdr;
- if (backtrace->Read(base_addr + hdr.e_phoff + i * hdr.e_phentsize,
- reinterpret_cast<uint8_t*>(&phdr), sizeof(phdr)) != sizeof(phdr)) {
+ if (memory->Read(base_addr + hdr.e_phoff + i * hdr.e_phentsize,
+ reinterpret_cast<uint8_t*>(&phdr), sizeof(phdr)) != sizeof(phdr)) {
return false;
}
// Looking for the .note.gnu.build-id note.
@@ -56,7 +56,7 @@ static bool get_build_id(
uintptr_t addr = base_addr + phdr.p_offset;
while (hdr_size >= sizeof(NhdrType)) {
NhdrType nhdr;
- if (backtrace->Read(addr, reinterpret_cast<uint8_t*>(&nhdr), sizeof(nhdr)) != sizeof(nhdr)) {
+ if (memory->Read(addr, reinterpret_cast<uint8_t*>(&nhdr), sizeof(nhdr)) != sizeof(nhdr)) {
return false;
}
addr += sizeof(nhdr);
@@ -69,7 +69,7 @@ static bool get_build_id(
nhdr.n_descsz);
return false;
}
- if (backtrace->Read(addr, build_id_data, nhdr.n_descsz) != nhdr.n_descsz) {
+ if (memory->Read(addr, build_id_data, nhdr.n_descsz) != nhdr.n_descsz) {
return false;
}
@@ -95,10 +95,10 @@ static bool get_build_id(
return false;
}
-bool elf_get_build_id(Backtrace* backtrace, uintptr_t addr, std::string* build_id) {
+bool elf_get_build_id(unwindstack::Memory* memory, uintptr_t addr, std::string* build_id) {
// Read and verify the elf magic number first.
uint8_t e_ident[EI_NIDENT];
- if (backtrace->Read(addr, e_ident, SELFMAG) != SELFMAG) {
+ if (memory->Read(addr, e_ident, SELFMAG) != SELFMAG) {
return false;
}
@@ -107,14 +107,14 @@ bool elf_get_build_id(Backtrace* backtrace, uintptr_t addr, std::string* build_i
}
// Read the rest of EI_NIDENT.
- if (backtrace->Read(addr + SELFMAG, e_ident + SELFMAG, EI_NIDENT - SELFMAG) != EI_NIDENT - SELFMAG) {
+ if (memory->Read(addr + SELFMAG, e_ident + SELFMAG, EI_NIDENT - SELFMAG) != EI_NIDENT - SELFMAG) {
return false;
}
if (e_ident[EI_CLASS] == ELFCLASS32) {
- return get_build_id<Elf32_Ehdr, Elf32_Phdr, Elf32_Nhdr>(backtrace, addr, e_ident, build_id);
+ return get_build_id<Elf32_Ehdr, Elf32_Phdr, Elf32_Nhdr>(memory, addr, e_ident, build_id);
} else if (e_ident[EI_CLASS] == ELFCLASS64) {
- return get_build_id<Elf64_Ehdr, Elf64_Phdr, Elf64_Nhdr>(backtrace, addr, e_ident, build_id);
+ return get_build_id<Elf64_Ehdr, Elf64_Phdr, Elf64_Nhdr>(memory, addr, e_ident, build_id);
}
return false;