diff options
author | Jerome Gaillard <jgaillard@google.com> | 2021-01-26 12:36:12 +0000 |
---|---|---|
committer | Jerome Gaillard <jgaillard@google.com> | 2021-01-26 12:41:20 +0000 |
commit | 1e45d3f2239333217d3252f78151f4294fda4e80 (patch) | |
tree | efca6c6cb194e0693e74852e898e0d80b4cdd0f6 /debuggerd/libdebuggerd/utility.cpp | |
parent | a50f61f8fa903117a6df82d164628de310f16ae9 (diff) |
Revert "libdebuggerd: add protobuf implementation."
Revert "Let crash_dump read /proc/$PID."
Revert submission 1556807-tombstone_proto
Reason for revert: b/178455196, Broken test: android.seccomp.cts.SeccompHostJUnit4DeviceTest#testAppZygoteSyscalls on git_master on cf_x86_64_phone-userdebug
Reverted Changes:
Ide6811297:tombstoned: switch from goto to RAII.
I8d285c4b4:tombstoned: make it easier to add more types of ou...
Id0f0fa285:tombstoned: support for protobuf fds.
I6be6082ab:Let crash_dump read /proc/$PID.
Id812ca390:Make protobuf vendor_ramdisk_available.
Ieeece6e6d:libdebuggerd: add protobuf implementation.
Change-Id: Ia0a1ee57e7630e01c495dc166218f665340aad7f
Diffstat (limited to 'debuggerd/libdebuggerd/utility.cpp')
-rw-r--r-- | debuggerd/libdebuggerd/utility.cpp | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/debuggerd/libdebuggerd/utility.cpp b/debuggerd/libdebuggerd/utility.cpp index f406ad48e..7826efc5e 100644 --- a/debuggerd/libdebuggerd/utility.cpp +++ b/debuggerd/libdebuggerd/utility.cpp @@ -126,56 +126,56 @@ void _VLOG(log_t* log, enum logtype ltype, const char* fmt, va_list ap) { #define MEMORY_BYTES_TO_DUMP 256 #define MEMORY_BYTES_PER_LINE 16 -ssize_t dump_memory(void* out, size_t len, size_t* start_offset, uint64_t* addr, - unwindstack::Memory* memory) { +void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const std::string& label) { // Align the address to the number of bytes per line to avoid confusing memory tag output if // memory is tagged and we start from a misaligned address. Start 32 bytes before the address. - *addr &= ~(MEMORY_BYTES_PER_LINE - 1); - if (*addr >= 4128) { - *addr -= 32; + addr &= ~(MEMORY_BYTES_PER_LINE - 1); + if (addr >= 4128) { + addr -= 32; } // We don't want the address tag to appear in the addresses in the memory dump. - *addr = untag_address(*addr); + addr = untag_address(addr); // Don't bother if the address would overflow, taking tag bits into account. Note that // untag_address truncates to 32 bits on 32-bit platforms as a side effect of returning a // uintptr_t, so this also checks for 32-bit overflow. - if (untag_address(*addr + MEMORY_BYTES_TO_DUMP - 1) < *addr) { - return -1; + if (untag_address(addr + MEMORY_BYTES_TO_DUMP - 1) < addr) { + return; } - memset(out, 0, len); - - size_t bytes = memory->Read(*addr, reinterpret_cast<uint8_t*>(out), len); + // Dump 256 bytes + uintptr_t data[MEMORY_BYTES_TO_DUMP/sizeof(uintptr_t)]; + memset(data, 0, MEMORY_BYTES_TO_DUMP); + size_t bytes = memory->Read(addr, reinterpret_cast<uint8_t*>(data), sizeof(data)); if (bytes % sizeof(uintptr_t) != 0) { // This should never happen, but just in case. ALOGE("Bytes read %zu, is not a multiple of %zu", bytes, sizeof(uintptr_t)); bytes &= ~(sizeof(uintptr_t) - 1); } - *start_offset = 0; + uint64_t start = 0; bool skip_2nd_read = false; if (bytes == 0) { // In this case, we might want to try another read at the beginning of // the next page only if it's within the amount of memory we would have // read. size_t page_size = sysconf(_SC_PAGE_SIZE); - *start_offset = ((*addr + (page_size - 1)) & ~(page_size - 1)) - *addr; - if (*start_offset == 0 || *start_offset >= len) { + start = ((addr + (page_size - 1)) & ~(page_size - 1)) - addr; + if (start == 0 || start >= MEMORY_BYTES_TO_DUMP) { skip_2nd_read = true; } } - if (bytes < len && !skip_2nd_read) { + if (bytes < MEMORY_BYTES_TO_DUMP && !skip_2nd_read) { // Try to do one more read. This could happen if a read crosses a map, // but the maps do not have any break between them. Or it could happen // if reading from an unreadable map, but the read would cross back // into a readable map. Only requires one extra read because a map has // to contain at least one page, and the total number of bytes to dump // is smaller than a page. - size_t bytes2 = memory->Read(*addr + *start_offset + bytes, static_cast<uint8_t*>(out) + bytes, - len - bytes - *start_offset); + size_t bytes2 = memory->Read(addr + start + bytes, reinterpret_cast<uint8_t*>(data) + bytes, + sizeof(data) - bytes - start); bytes += bytes2; if (bytes2 > 0 && bytes % sizeof(uintptr_t) != 0) { // This should never happen, but we'll try and continue any way. @@ -185,21 +185,9 @@ ssize_t dump_memory(void* out, size_t len, size_t* start_offset, uint64_t* addr, } // If we were unable to read anything, it probably means that the register doesn't contain a - // valid pointer. + // valid pointer. In that case, skip the output for this register entirely rather than emitting 16 + // lines of dashes. if (bytes == 0) { - return -1; - } - - return bytes; -} - -void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const std::string& label) { - // Dump 256 bytes - uintptr_t data[MEMORY_BYTES_TO_DUMP / sizeof(uintptr_t)]; - size_t start_offset = 0; - - ssize_t bytes = dump_memory(data, sizeof(data), &start_offset, &addr, memory); - if (bytes == -1) { return; } @@ -213,7 +201,7 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const s // words are of course presented differently. uintptr_t* data_ptr = data; size_t current = 0; - size_t total_bytes = start_offset + bytes; + size_t total_bytes = start + bytes; for (size_t line = 0; line < MEMORY_BYTES_TO_DUMP / MEMORY_BYTES_PER_LINE; line++) { uint64_t tagged_addr = addr; long tag = memory->ReadTag(addr); @@ -226,7 +214,7 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const s addr += MEMORY_BYTES_PER_LINE; std::string ascii; for (size_t i = 0; i < MEMORY_BYTES_PER_LINE / sizeof(uintptr_t); i++) { - if (current >= start_offset && current + sizeof(uintptr_t) <= total_bytes) { + if (current >= start && current + sizeof(uintptr_t) <= total_bytes) { android::base::StringAppendF(&logline, " %" PRIPTR, static_cast<uint64_t>(*data_ptr)); // Fill out the ascii string from the data. |