Update copyright year range in all GDB files
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-inferior.c
CommitLineData
595939de
PM
1#include <stdio.h>
2#include <stdlib.h>
3#include <stdint.h>
4#include <string.h>
f66713d2 5#include <pthread.h>
595939de
PM
6
7#define CHUNK_SIZE 16000 /* same as findcmd.c's */
8#define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */
f66713d2 9#define NUMTH 8
595939de 10
e992ef73
TT
11int8_t int8_search_buf[100];
12int16_t int16_search_buf[100];
13int32_t int32_search_buf[100];
14int64_t int64_search_buf[100];
595939de
PM
15
16static char *search_buf;
17static int search_buf_size;
18
595939de
PM
19
20int f2 (int a)
21{
b5916bbd
JB
22 /* We use a `char[]' type below rather than the typical `char *'
23 to make sure that `str' gets allocated on the stack. Otherwise,
24 the compiler may place the "hello, testsuite" string inside
25 a read-only section, preventing us from over-writing it from GDB. */
26 char str[] = "hello, testsuite";
595939de
PM
27
28 puts (str); /* Break here. */
29
30 return ++a;
31}
32
33int f1 (int a, int b)
34{
35 return f2(a) + b;
36}
37
38static void
39init_bufs ()
40{
41 search_buf_size = BUF_SIZE;
42 search_buf = malloc (search_buf_size);
43 if (search_buf == NULL)
44 exit (1);
45 memset (search_buf, 'x', search_buf_size);
46}
47
f66713d2
JK
48static void *
49thread (void *param)
50{
51 pthread_barrier_t *barrier = (pthread_barrier_t *) param;
52
53 pthread_barrier_wait (barrier);
54
55 return param;
56}
57
58static void
59check_threads (pthread_barrier_t *barrier)
60{
61 pthread_barrier_wait (barrier);
62}
63
64extern int
65test_threads (void)
66{
67 pthread_t threads[NUMTH];
68 pthread_barrier_t barrier;
69 int i;
70
71 pthread_barrier_init (&barrier, NULL, NUMTH + 1);
72
73 for (i = 0; i < NUMTH; ++i)
74 pthread_create (&threads[i], NULL, thread, &barrier);
75
76 check_threads (&barrier);
77
78 for (i = 0; i < NUMTH; ++i)
79 pthread_join (threads[i], NULL);
80
81 pthread_barrier_destroy (&barrier);
82
83 return 0;
84}
85
595939de
PM
86int main (int argc, char *argv[])
87{
f66713d2 88 test_threads ();
595939de
PM
89 init_bufs ();
90
91 return f1 (1, 2);
92}
This page took 1.222668 seconds and 4 git commands to generate.