Fix "maint print" error messages
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-inferior.c
blob870f7196444eede5b895b35cc1ce75a57c935f81
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <string.h>
5 #include <pthread.h>
7 #define CHUNK_SIZE 16000 /* same as findcmd.c's */
8 #define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */
9 #define NUMTH 8
11 int8_t int8_search_buf[100];
12 int16_t int16_search_buf[100];
13 int32_t int32_search_buf[100];
14 int64_t int64_search_buf[100];
16 static char *search_buf;
17 static int search_buf_size;
19 int8_t int8_global = 42;
21 int f2 (int a)
23 /* We use a `char[]' type below rather than the typical `char *'
24 to make sure that `str' gets allocated on the stack. Otherwise,
25 the compiler may place the "hello, testsuite" string inside
26 a read-only section, preventing us from over-writing it from GDB. */
27 char str[] = "hello, testsuite";
29 puts (str); /* Break here. */
31 return ++a;
34 int f1 (int a, int b)
36 return f2(a) + b;
39 static void
40 init_bufs ()
42 search_buf_size = BUF_SIZE;
43 search_buf = malloc (search_buf_size);
44 if (search_buf == NULL)
45 exit (1);
46 memset (search_buf, 'x', search_buf_size);
49 static void *
50 thread (void *param)
52 pthread_barrier_t *barrier = (pthread_barrier_t *) param;
54 pthread_barrier_wait (barrier);
56 return param;
59 static void
60 check_threads (pthread_barrier_t *barrier)
62 pthread_barrier_wait (barrier);
65 extern int
66 test_threads (void)
68 pthread_t threads[NUMTH];
69 pthread_barrier_t barrier;
70 int i;
72 pthread_barrier_init (&barrier, NULL, NUMTH + 1);
74 for (i = 0; i < NUMTH; ++i)
75 pthread_create (&threads[i], NULL, thread, &barrier);
77 check_threads (&barrier);
79 for (i = 0; i < NUMTH; ++i)
80 pthread_join (threads[i], NULL);
82 pthread_barrier_destroy (&barrier);
84 return 0;
87 int main (int argc, char *argv[])
89 test_threads ();
90 init_bufs ();
92 return f1 (1, 2);