summaryrefslogtreecommitdiffstats
path: root/debuggerd/crasher.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-12-10 14:15:42 -0800
committerElliott Hughes <enh@google.com>2012-12-10 14:15:42 -0800
commitaa4213057ba1723e4f164e54f80bb7621c3cb6b3 (patch)
tree24796628e7f96a594b6e2823b089cb4ed6737b5e /debuggerd/crasher.c
parent5144fa28c59825118c8f6e6bee832708f9748b89 (diff)
downloadcore-aa4213057ba1723e4f164e54f80bb7621c3cb6b3.tar.gz
core-aa4213057ba1723e4f164e54f80bb7621c3cb6b3.tar.bz2
core-aa4213057ba1723e4f164e54f80bb7621c3cb6b3.zip
Expand crasher with a "thread-" prefix to crash on another thread.
So "thread-nostack" runs the "nostack" code on a new thread, and "thread-abort" runs the "abort" code on a new thread, and so on. Bug: http://code.google.com/p/android/issues/detail?id=16672 Change-Id: I026a0e43eea147f1a7a74243846954599bcf4238
Diffstat (limited to 'debuggerd/crasher.c')
-rw-r--r--debuggerd/crasher.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/debuggerd/crasher.c b/debuggerd/crasher.c
index 00652e975..74eaa4983 100644
--- a/debuggerd/crasher.c
+++ b/debuggerd/crasher.c
@@ -20,6 +20,7 @@
void crash1(void);
void crashnostack(void);
void maybeabort(void);
+int do_action(const char* arg);
static void debuggerd_connect()
{
@@ -74,24 +75,46 @@ int ctest()
return 0;
}
-int main(int argc, char **argv)
+static void* thread_callback(void* raw_arg)
+{
+ return (void*) do_action((const char*) raw_arg);
+}
+
+int do_action_on_thread(const char* arg)
{
+ pthread_t t;
+ pthread_create(&t, NULL, thread_callback, (void*) arg);
+ void* result = NULL;
+ pthread_join(t, &result);
+ return (int) result;
+}
+
+int do_action(const char* arg)
+{
+ if(!strncmp(arg, "thread-", strlen("thread-"))) {
+ return do_action_on_thread(arg + strlen("thread-"));
+ }
+
+ if(!strcmp(arg,"nostack")) crashnostack();
+ if(!strcmp(arg,"ctest")) return ctest();
+ if(!strcmp(arg,"exit")) exit(1);
+ if(!strcmp(arg,"abort")) maybeabort();
+
pthread_t thr;
pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ pthread_create(&thr, &attr, test_thread, 0);
+ while(1) sleep(1);
+}
- fprintf(stderr,"crasher: " __TIME__ "!@\n");
+int main(int argc, char **argv)
+{
+ fprintf(stderr,"crasher: built at " __TIME__ "!@\n");
fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid());
if(argc > 1) {
- if(!strcmp(argv[1],"nostack")) crashnostack();
- if(!strcmp(argv[1],"ctest")) return ctest();
- if(!strcmp(argv[1],"exit")) exit(1);
- if(!strcmp(argv[1],"abort")) maybeabort();
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_create(&thr, &attr, test_thread, 0);
- while(1) sleep(1);
+ return do_action(argv[1]);
} else {
crash1();
// *((int*) 0) = 42;