From ba76572789740ec1a04da30dd89121ef5cb0bf44 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 25 Feb 2014 15:32:01 -0800 Subject: [PATCH] Fix log_backtrace assertion failure caused by LP64 fix. When libc.debug.malloc is enabled, stack backtraces fail with: bionic/libc/bionic/libc_logging.cpp:378: assertion "conversion specifier unsupported" failed The cause was a change to the format specifier from "%08x" to "%0*x" to pass the field width as an additional parameter. Unfortunately this modifier isn't supported by out_vformat() in libc_logging.cpp. Changed to use "%016x" if __LP64__ is defined; "%08x" otherwise. Bug: 13177507 Change-Id: Ibf07263acf14da086d3c3788872f4b5477bd5708 --- libc/bionic/debug_stacktrace.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libc/bionic/debug_stacktrace.cpp b/libc/bionic/debug_stacktrace.cpp index 5ddc00c69..83171add9 100644 --- a/libc/bionic/debug_stacktrace.cpp +++ b/libc/bionic/debug_stacktrace.cpp @@ -37,6 +37,12 @@ #include "debug_mapinfo.h" #include "private/libc_logging.h" +#if defined(__LP64__) +#define PAD_PTR "016" PRIxPTR +#else +#define PAD_PTR "08" PRIxPTR +#endif + /* depends how the system includes define this */ #ifdef HAVE_UNWIND_CONTEXT_STRUCT typedef struct _Unwind_Context __unwind_context; @@ -164,19 +170,14 @@ __LIBC_HIDDEN__ void log_backtrace(uintptr_t* frames, size_t frame_count) { const char* best_name = (demangled_symbol != NULL) ? demangled_symbol : symbol; __libc_format_log(ANDROID_LOG_ERROR, "libc", - " #%02zd pc %0*" PRIxPTR " %s (%s+%" PRIuPTR ")", - i, - static_cast(2 * sizeof(void*)), rel_pc, - soname, - best_name, frames[i] - offset); + " #%02zd pc %" PAD_PTR " %s (%s+%" PRIuPTR ")", + i, rel_pc, soname, best_name, frames[i] - offset); free(demangled_symbol); } else { __libc_format_log(ANDROID_LOG_ERROR, "libc", - " #%02zd pc %0*" PRIxPTR " %s", - i, - static_cast(2 * sizeof(void*)), rel_pc, - soname); + " #%02zd pc %" PAD_PTR " %s", + i, rel_pc, soname); } } }