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
This commit is contained in:
Elliott Hughes 2014-02-25 15:32:01 -08:00
parent 901553aaf4
commit ba76572789

View File

@ -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<int>(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<int>(2 * sizeof(void*)), rel_pc,
soname);
" #%02zd pc %" PAD_PTR " %s",
i, rel_pc, soname);
}
}
}