blob: 00652e975d95f056e7834d5d7144f5669e440d57 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001
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
20void crash1(void);
21void crashnostack(void);
Bruce Beare84924902010-10-13 14:21:30 -070022void maybeabort(void);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080023
24static 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
37void test_call1()
38{
39 *((int*) 32) = 1;
40}
41
42void *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
53void *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
64int 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
77int 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
103void maybeabort()
104{
105 if(time(0) != 42) abort();
106}