Merge "Add offset to backtrace_string printing."
diff --git a/libc/malloc_debug/backtrace.cpp b/libc/malloc_debug/backtrace.cpp
index 88f5a1d..907944f 100644
--- a/libc/malloc_debug/backtrace.cpp
+++ b/libc/malloc_debug/backtrace.cpp
@@ -153,18 +153,27 @@
if (soname == nullptr) {
soname = "<unknown>";
}
+
+ char offset_buf[128];
+ if (entry != nullptr && entry->offset != 0) {
+ snprintf(offset_buf, sizeof(offset_buf), " (offset 0x%" PRIxPTR ")", entry->offset);
+ } else {
+ offset_buf[0] = '\0';
+ }
+
char buf[1024];
if (symbol != nullptr) {
char* demangled_symbol = __cxa_demangle(symbol, nullptr, nullptr, nullptr);
const char* best_name = (demangled_symbol != nullptr) ? demangled_symbol : symbol;
async_safe_format_buffer(
- buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s (%s+%" PRIuPTR ")\n", frame_num,
- rel_pc, soname, best_name, frames[frame_num] - offset);
+ buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s%s (%s+%" PRIuPTR ")\n", frame_num,
+ rel_pc, soname, offset_buf, best_name, frames[frame_num] - offset);
free(demangled_symbol);
} else {
async_safe_format_buffer(
- buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s\n", frame_num, rel_pc, soname);
+ buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s%s\n", frame_num, rel_pc, soname,
+ offset_buf);
}
str += buf;
}