diff options
author | Josh Gao <jmgao@google.com> | 2016-06-15 17:29:00 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2016-06-17 13:11:29 -0700 |
commit | 9c02dc5916c1cee43e4a0840d0d5099878e3793c (patch) | |
tree | 405ed24030a9db302c1d8e0b770c748a54974c9c /debuggerd/crasher.cpp | |
parent | 2d690a920f1b2f67e267160083aab711b35ab3fc (diff) |
debuggerd: add libdebuggerd_client.
Bug: http://b/24414818
Change-Id: I079c534d2c952b6975bf0428eb86cc7a55525737
Diffstat (limited to 'debuggerd/crasher.cpp')
-rw-r--r-- | debuggerd/crasher.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/debuggerd/crasher.cpp b/debuggerd/crasher.cpp index bdeaf0b33..a37df3350 100644 --- a/debuggerd/crasher.cpp +++ b/debuggerd/crasher.cpp @@ -16,6 +16,10 @@ #include <cutils/sockets.h> #include <log/log.h> +#if defined(STATIC_CRASHER) +#include "debuggerd/client.h" +#endif + #ifndef __unused #define __unused __attribute__((__unused__)) #endif @@ -43,7 +47,7 @@ __attribute__ ((noinline)) static void smash_stack_dummy_function(volatile int* // Assign local array address to global variable to force stack guards. // Use another noinline function to corrupt the stack. __attribute__ ((noinline)) static int smash_stack(volatile int* plen) { - printf("crasher: deliberately corrupting stack...\n"); + printf("%s: deliberately corrupting stack...\n", __progname); char buf[128]; smash_stack_dummy_buf = buf; @@ -135,7 +139,7 @@ static void sigsegv_non_null() { static int do_action(const char* arg) { - fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid()); + fprintf(stderr, "%s: init pid=%d tid=%d\n", __progname, getpid(), gettid()); if (!strncmp(arg, "thread-", strlen("thread-"))) { return do_action_on_thread(arg + strlen("thread-")); @@ -209,9 +213,26 @@ static int do_action(const char* arg) int main(int argc, char **argv) { - fprintf(stderr,"crasher: built at " __TIME__ "!@\n"); + fprintf(stderr, "%s: built at " __TIME__ "!@\n", __progname); + +#if defined(STATIC_CRASHER) + debuggerd_callbacks_t callbacks = { + .get_abort_message = []() { + static struct { + size_t size; + char msg[32]; + } msg; + + msg.size = strlen("dummy abort message"); + memcpy(msg.msg, "dummy abort message", strlen("dummy abort message")); + return reinterpret_cast<abort_msg_t*>(&msg); + }, + .post_dump = nullptr + }; + debuggerd_init(&callbacks); +#endif - if(argc > 1) { + if (argc > 1) { return do_action(argv[1]); } else { crash1(); |