diff options
Diffstat (limited to 'debuggerd/libdebuggerd/utility.cpp')
| -rw-r--r-- | debuggerd/libdebuggerd/utility.cpp | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/debuggerd/libdebuggerd/utility.cpp b/debuggerd/libdebuggerd/utility.cpp index c8a3431b70..4e6df09c9a 100644 --- a/debuggerd/libdebuggerd/utility.cpp +++ b/debuggerd/libdebuggerd/utility.cpp @@ -44,7 +44,6 @@ using android::base::unique_fd; -// Whitelist output desired in the logcat output. bool is_allowed_in_logcat(enum logtype ltype) { if ((ltype == HEADER) || (ltype == REGISTERS) @@ -129,24 +128,23 @@ void _VLOG(log_t* log, enum logtype ltype, const char* fmt, va_list ap) { #define MEMORY_BYTES_PER_LINE 16 void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const std::string& label) { - // Align the address to sizeof(long) and start 32 bytes before the address. - addr &= ~(sizeof(long) - 1); + // 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; } - // Don't bother if the address looks too low, or looks too high. - if (addr < 4096 || -#if defined(__LP64__) - addr > 0x4000000000000000UL - MEMORY_BYTES_TO_DUMP) { -#else - addr > 0xffff0000 - MEMORY_BYTES_TO_DUMP) { -#endif + // We don't want the address tag to appear in the addresses in the memory dump. + 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; } - _LOG(log, logtype::MEMORY, "\n%s:\n", label.c_str()); - // Dump 256 bytes uintptr_t data[MEMORY_BYTES_TO_DUMP/sizeof(uintptr_t)]; memset(data, 0, MEMORY_BYTES_TO_DUMP); @@ -187,6 +185,15 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const s } } + // If we were unable to read anything, it probably means that the register doesn't contain a + // valid pointer. In that case, skip the output for this register entirely rather than emitting 16 + // lines of dashes. + if (bytes == 0) { + return; + } + + _LOG(log, logtype::MEMORY, "\n%s:\n", label.c_str()); + // Dump the code around memory as: // addr contents ascii // 0000000000008d34 ef000000e8bd0090 e1b00000512fff1e ............../Q @@ -197,8 +204,13 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const s size_t current = 0; 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); + if (tag >= 0) { + tagged_addr |= static_cast<uint64_t>(tag) << 56; + } std::string logline; - android::base::StringAppendF(&logline, " %" PRIPTR, addr); + android::base::StringAppendF(&logline, " %" PRIPTR, tagged_addr); addr += MEMORY_BYTES_PER_LINE; std::string ascii; @@ -226,23 +238,6 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const s } } -void read_with_default(const char* path, char* buf, size_t len, const char* default_value) { - unique_fd fd(open(path, O_RDONLY | O_CLOEXEC)); - if (fd != -1) { - int rc = TEMP_FAILURE_RETRY(read(fd.get(), buf, len - 1)); - if (rc != -1) { - buf[rc] = '\0'; - - // Trim trailing newlines. - if (rc > 0 && buf[rc - 1] == '\n') { - buf[rc - 1] = '\0'; - } - return; - } - } - strcpy(buf, default_value); -} - void drop_capabilities() { __user_cap_header_struct capheader; memset(&capheader, 0, sizeof(capheader)); |
