summaryrefslogtreecommitdiffstats
path: root/libc/bionic/malloc_debug_qemu.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-01-17 18:36:06 -0800
committerElliott Hughes <enh@google.com>2013-01-18 22:20:06 -0800
commit1e980b6bc8315d00a07312b25486531247abd98c (patch)
tree539f2c0c63fca27d5eb6ba184d658bb0e11a32d9 /libc/bionic/malloc_debug_qemu.cpp
parente4ca88d9fa8757e4fb4056fcafa5bc15b406a2fd (diff)
downloadbionic-1e980b6bc8315d00a07312b25486531247abd98c.zip
bionic-1e980b6bc8315d00a07312b25486531247abd98c.tar.gz
bionic-1e980b6bc8315d00a07312b25486531247abd98c.tar.bz2
Fix the duplication in the debugging code.
We had two copies of the backtrace code, and two copies of the libcorkscrew /proc/pid/maps code. This patch gets us down to one. We also had hacks so we could log in the malloc debugging code. This patch pulls the non-allocating "printf" code out of the dynamic linker so everyone can share. This patch also makes the leak diagnostics easier to read, and makes it possible to paste them directly into the 'stack' tool (by using relative PCs). This patch also fixes the stdio standard stream leak that was causing a leak warning every time tf_daemon ran. Bug: 7291287 Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
Diffstat (limited to 'libc/bionic/malloc_debug_qemu.cpp')
-rw-r--r--libc/bionic/malloc_debug_qemu.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/libc/bionic/malloc_debug_qemu.cpp b/libc/bionic/malloc_debug_qemu.cpp
index e586b1b..812a451 100644
--- a/libc/bionic/malloc_debug_qemu.cpp
+++ b/libc/bionic/malloc_debug_qemu.cpp
@@ -257,8 +257,8 @@ static void dump_malloc_descriptor(char* str,
INFO_TRACING_ENABLED)
/* Prints a string to the emulator's stdout.
- * In early stages of system loading, logging mesages via
- * __libc_android_log_print API is not available, because ADB API has not been
+ * In early stages of system loading, logging messages to logcat
+ * is not available, because ADB API has not been
* hooked up yet. So, in order to see such messages we need to print them to
* the emulator's stdout.
* Parameters passed to this macro are the same as parameters for printf
@@ -289,8 +289,7 @@ static void dump_malloc_descriptor(char* str,
*/
#define qemu_debug_log(format, ...) \
do { \
- __libc_android_log_print(ANDROID_LOG_DEBUG, "memcheck", \
- (format), ##__VA_ARGS__); \
+ __libc_format_log(ANDROID_LOG_DEBUG, "memcheck", (format), ##__VA_ARGS__); \
if (tracing_flags & DEBUG_TRACING_ENABLED) { \
qemu_log(ANDROID_LOG_DEBUG, (format), ##__VA_ARGS__); \
} \
@@ -298,8 +297,7 @@ static void dump_malloc_descriptor(char* str,
#define qemu_error_log(format, ...) \
do { \
- __libc_android_log_print(ANDROID_LOG_ERROR, "memcheck", \
- (format), ##__VA_ARGS__); \
+ __libc_format_log(ANDROID_LOG_ERROR, "memcheck", (format), ##__VA_ARGS__); \
if (tracing_flags & ERROR_TRACING_ENABLED) { \
qemu_log(ANDROID_LOG_ERROR, (format), ##__VA_ARGS__); \
} \
@@ -307,8 +305,7 @@ static void dump_malloc_descriptor(char* str,
#define qemu_info_log(format, ...) \
do { \
- __libc_android_log_print(ANDROID_LOG_INFO, "memcheck", \
- (format), ##__VA_ARGS__); \
+ __libc_format_log(ANDROID_LOG_INFO, "memcheck", (format), ##__VA_ARGS__); \
if (tracing_flags & INFO_TRACING_ENABLED) { \
qemu_log(ANDROID_LOG_INFO, (format), ##__VA_ARGS__); \
} \
@@ -318,20 +315,19 @@ static void dump_malloc_descriptor(char* str,
* Param:
* type - Message type: debug, error, or info
* desc - MallocDesc instance to dump.
- * frmt + rest - Formats message preceding dumped descriptor.
+ * fmt + rest - Formats message preceding dumped descriptor.
*/
-#define log_mdesc(type, desc, frmt, ...) \
+#define log_mdesc(type, desc, fmt, ...) \
do { \
if (tracing_enabled(type)) { \
char log_str[4096]; \
- size_t str_len; \
- snprintf(log_str, sizeof(log_str), frmt, ##__VA_ARGS__); \
+ __libc_format_buffer(log_str, sizeof(log_str), fmt, ##__VA_ARGS__); \
log_str[sizeof(log_str) - 1] = '\0'; \
- str_len = strlen(log_str); \
+ size_t str_len = strlen(log_str); \
dump_malloc_descriptor(log_str + str_len, \
sizeof(log_str) - str_len, \
(desc)); \
- type##_log(log_str); \
+ type##_log("%s", log_str); \
} \
} while (0)