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
diff --git a/linker/debugger.cpp b/linker/debugger.cpp
index 5fd5cb7..a14e30a 100644
--- a/linker/debugger.cpp
+++ b/linker/debugger.cpp
@@ -27,7 +27,6 @@
*/
#include "linker.h"
-#include "linker_format.h"
#include <stdio.h>
#include <stdlib.h>
@@ -38,6 +37,7 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include <private/debug_format.h>
#include <private/logd.h>
extern "C" int tgkill(int tgid, int tid, int sig);
@@ -135,12 +135,12 @@
char buffer[128];
// "info" will be NULL if the siginfo_t information was not available.
if (info != NULL) {
- format_buffer(buffer, sizeof(buffer),
+ __libc_format_buffer(buffer, sizeof(buffer),
"Fatal signal %d (%s) at 0x%08x (code=%d), thread %d (%s)",
signum, signame, reinterpret_cast<uintptr_t>(info->si_addr),
info->si_code, gettid(), threadname);
} else {
- format_buffer(buffer, sizeof(buffer),
+ __libc_format_buffer(buffer, sizeof(buffer),
"Fatal signal %d (%s), thread %d (%s)",
signum, signame, gettid(), threadname);
}
@@ -215,7 +215,7 @@
if (ret < 0) {
/* read or write failed -- broken connection? */
- format_buffer(msgbuf, sizeof(msgbuf),
+ __libc_format_buffer(msgbuf, sizeof(msgbuf),
"Failed while talking to debuggerd: %s", strerror(errno));
__libc_android_log_write(ANDROID_LOG_FATAL, "libc", msgbuf);
}
@@ -223,7 +223,7 @@
close(s);
} else {
/* socket failed; maybe process ran out of fds */
- format_buffer(msgbuf, sizeof(msgbuf),
+ __libc_format_buffer(msgbuf, sizeof(msgbuf),
"Unable to open connection to debuggerd: %s", strerror(errno));
__libc_android_log_write(ANDROID_LOG_FATAL, "libc", msgbuf);
}