| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 |  | 
|  | 2 | //#include <cutils/misc.h> | 
|  | 3 |  | 
|  | 4 | #include <unistd.h> | 
|  | 5 | #include <stdio.h> | 
|  | 6 | #include <stdlib.h> | 
|  | 7 | #include <string.h> | 
|  | 8 | #include <sched.h> | 
|  | 9 | #include <errno.h> | 
|  | 10 |  | 
|  | 11 | #include <signal.h> | 
|  | 12 | #include <sys/ptrace.h> | 
|  | 13 | #include <sys/wait.h> | 
|  | 14 | #include <sys/socket.h> | 
|  | 15 |  | 
|  | 16 | #include <pthread.h> | 
|  | 17 |  | 
|  | 18 | #include <cutils/sockets.h> | 
|  | 19 |  | 
|  | 20 | void crash1(void); | 
|  | 21 | void crashnostack(void); | 
| Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 22 | void maybeabort(void); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 23 |  | 
|  | 24 | static void debuggerd_connect() | 
|  | 25 | { | 
|  | 26 | char tmp[1]; | 
|  | 27 | int s; | 
|  | 28 | sprintf(tmp, "%d", gettid()); | 
|  | 29 | s = socket_local_client("android:debuggerd", | 
|  | 30 | ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); | 
|  | 31 | if(s >= 0) { | 
|  | 32 | read(s, tmp, 1); | 
|  | 33 | close(s); | 
|  | 34 | } | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | void test_call1() | 
|  | 38 | { | 
|  | 39 | *((int*) 32) = 1; | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | void *test_thread(void *x) | 
|  | 43 | { | 
|  | 44 | printf("crasher: thread pid=%d tid=%d\n", getpid(), gettid()); | 
|  | 45 |  | 
|  | 46 | sleep(1); | 
|  | 47 | test_call1(); | 
|  | 48 | printf("goodbye\n"); | 
|  | 49 |  | 
|  | 50 | return 0; | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | void *noisy(void *x) | 
|  | 54 | { | 
|  | 55 | char c = (unsigned) x; | 
|  | 56 | for(;;) { | 
|  | 57 | usleep(250*1000); | 
|  | 58 | write(2, &c, 1); | 
|  | 59 | if(c == 'C') *((unsigned*) 0) = 42; | 
|  | 60 | } | 
|  | 61 | return 0; | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | int ctest() | 
|  | 65 | { | 
|  | 66 | pthread_t thr; | 
|  | 67 | pthread_attr_t attr; | 
|  | 68 | pthread_attr_init(&attr); | 
|  | 69 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | 
|  | 70 | pthread_create(&thr, &attr, noisy, (void*) 'A'); | 
|  | 71 | pthread_create(&thr, &attr, noisy, (void*) 'B'); | 
|  | 72 | pthread_create(&thr, &attr, noisy, (void*) 'C'); | 
|  | 73 | for(;;) ; | 
|  | 74 | return 0; | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | int main(int argc, char **argv) | 
|  | 78 | { | 
|  | 79 | pthread_t thr; | 
|  | 80 | pthread_attr_t attr; | 
|  | 81 |  | 
|  | 82 | fprintf(stderr,"crasher: " __TIME__ "!@\n"); | 
|  | 83 | fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid()); | 
|  | 84 |  | 
|  | 85 | if(argc > 1) { | 
|  | 86 | if(!strcmp(argv[1],"nostack")) crashnostack(); | 
|  | 87 | if(!strcmp(argv[1],"ctest")) return ctest(); | 
|  | 88 | if(!strcmp(argv[1],"exit")) exit(1); | 
|  | 89 | if(!strcmp(argv[1],"abort")) maybeabort(); | 
|  | 90 |  | 
|  | 91 | pthread_attr_init(&attr); | 
|  | 92 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | 
|  | 93 | pthread_create(&thr, &attr, test_thread, 0); | 
|  | 94 | while(1) sleep(1); | 
|  | 95 | } else { | 
|  | 96 | crash1(); | 
|  | 97 | //        *((int*) 0) = 42; | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | return 0; | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | void maybeabort() | 
|  | 104 | { | 
|  | 105 | if(time(0) != 42) abort(); | 
|  | 106 | } |