summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2015-01-15 14:47:36 -0800
committerChristopher Ferris <cferris@google.com>2015-01-20 17:22:07 -0800
commit9774df613409c91f01ced1483bc01f42f6b4bf63 (patch)
tree3da5f40e44d496b2b9278d0cd2ab6b0ebce454e9 /libcutils
parent45c4c06ffe6f38e0f77f37f488e07f2537eddd45 (diff)
downloadcore-9774df613409c91f01ced1483bc01f42f6b4bf63.tar.gz
core-9774df613409c91f01ced1483bc01f42f6b4bf63.tar.bz2
core-9774df613409c91f01ced1483bc01f42f6b4bf63.zip
Move 32 bit/64 bit check into debuggerd.
On 64 bit systems, calls to dump_backtrace_to_file or dump_tombstone try and directly contact the correct debuggerd (32 bit vs 64 bit) by reading the elf information for the executable. Unfortunately, system_server makes a call to dump_backtrace_to_file and it doesn't have permissions to read the executable data, so it defaults to always contacting the 64 bit debuggerd. This CL changes the code so that all dump requests go to the 64 bit debuggerd, which reads the elf information and redirects requests for 32 bit processes to the 32 bit debuggerd. Testing: - Forced the watchdog code in system_server to dump stacks and verified that all native stacks are dumped correctly. - Verified that dumpstate and bugreport still properly dump the native processes on a 64 bit and 32 bit system. - Intentionally forced the 64 bit to 32 bit redirect to write only a byte at a time and verified there are no errors, and no dropped data. - Used debuggerd and debuggerd64 to dump 32 bit and 64 bit processes seemlessly. - Used debuggerd on a 32 bit system to dump native stacks. Bug: https://code.google.com/p/android/issues/detail?id=97024 Change-Id: Ie01945153bdc1c4ded696c7334b61d58575314d1
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/debugger.c58
1 files changed, 5 insertions, 53 deletions
diff --git a/libcutils/debugger.c b/libcutils/debugger.c
index b8a2efc49..2cd8ec3f5 100644
--- a/libcutils/debugger.c
+++ b/libcutils/debugger.c
@@ -29,33 +29,6 @@
#define LOG_TAG "DEBUG"
#include <log/log.h>
-#if defined(__LP64__)
-#include <elf.h>
-
-static bool is32bit(pid_t tid) {
- char* exeline;
- if (asprintf(&exeline, "/proc/%d/exe", tid) == -1) {
- return false;
- }
- int fd = open(exeline, O_RDONLY | O_CLOEXEC);
- free(exeline);
- if (fd == -1) {
- return false;
- }
-
- char ehdr[EI_NIDENT];
- ssize_t bytes = read(fd, &ehdr, sizeof(ehdr));
- close(fd);
- if (bytes != (ssize_t) sizeof(ehdr) || memcmp(ELFMAG, ehdr, SELFMAG) != 0) {
- return false;
- }
- if (ehdr[EI_CLASS] == ELFCLASS32) {
- return true;
- }
- return false;
-}
-#endif
-
static int send_request(int sock_fd, void* msg_ptr, size_t msg_len) {
int result = 0;
if (TEMP_FAILURE_RETRY(write(sock_fd, msg_ptr, msg_len)) != (ssize_t) msg_len) {
@@ -72,32 +45,11 @@ static int send_request(int sock_fd, void* msg_ptr, size_t msg_len) {
static int make_dump_request(debugger_action_t action, pid_t tid, int timeout_secs) {
const char* socket_name;
debugger_msg_t msg;
- size_t msg_len;
- void* msg_ptr;
-
-#if defined(__LP64__)
- debugger32_msg_t msg32;
- if (is32bit(tid)) {
- msg_len = sizeof(debugger32_msg_t);
- memset(&msg32, 0, msg_len);
- msg32.tid = tid;
- msg32.action = action;
- msg_ptr = &msg32;
-
- socket_name = DEBUGGER32_SOCKET_NAME;
- } else
-#endif
- {
- msg_len = sizeof(debugger_msg_t);
- memset(&msg, 0, msg_len);
- msg.tid = tid;
- msg.action = action;
- msg_ptr = &msg;
-
- socket_name = DEBUGGER_SOCKET_NAME;
- }
+ memset(&msg, 0, sizeof(msg));
+ msg.tid = tid;
+ msg.action = action;
- int sock_fd = socket_local_client(socket_name, ANDROID_SOCKET_NAMESPACE_ABSTRACT,
+ int sock_fd = socket_local_client(DEBUGGER_SOCKET_NAME, ANDROID_SOCKET_NAMESPACE_ABSTRACT,
SOCK_STREAM | SOCK_CLOEXEC);
if (sock_fd < 0) {
return -1;
@@ -116,7 +68,7 @@ static int make_dump_request(debugger_action_t action, pid_t tid, int timeout_se
}
}
- if (send_request(sock_fd, msg_ptr, msg_len) < 0) {
+ if (send_request(sock_fd, &msg, sizeof(msg)) < 0) {
TEMP_FAILURE_RETRY(close(sock_fd));
return -1;
}