Update copyright year in most headers.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / current-lwp-dead.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2009, 2010 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 Do not use threads as we need to exploit a bug in LWP code masked by the
19 threads code otherwise.
20
21 INFERIOR_PTID must point to exited LWP. Here we use the initial LWP as it
22 is automatically INFERIOR_PTID for GDB.
23
24 Finally we need to call target_resume (RESUME_ALL, ...) which we invoke by
25 NEW_THREAD_EVENT (called from the new LWP as initial LWP is exited now). */
26
27 #define _GNU_SOURCE
28 #include <sched.h>
29 #include <assert.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32
33 #define STACK_SIZE 0x1000
34
35 static int
36 fn_return (void *unused)
37 {
38 return 0; /* at-fn_return */
39 }
40
41 static int
42 fn (void *unused)
43 {
44 int i;
45 unsigned char *stack;
46 int new_pid;
47
48 i = sleep (1);
49 assert (i == 0);
50
51 stack = malloc (STACK_SIZE);
52 assert (stack != NULL);
53
54 new_pid = clone (fn_return, stack + STACK_SIZE, CLONE_FILES | CLONE_VM, NULL,
55 NULL, NULL, NULL);
56 assert (new_pid > 0);
57
58 return 0;
59 }
60
61 int
62 main (int argc, char **argv)
63 {
64 unsigned char *stack;
65 int new_pid;
66
67 stack = malloc (STACK_SIZE);
68 assert (stack != NULL);
69
70 new_pid = clone (fn, stack + STACK_SIZE, CLONE_FILES | CLONE_VM, NULL, NULL,
71 NULL, NULL);
72 assert (new_pid > 0);
73
74 return 0;
75 }
This page took 0.032484 seconds and 4 git commands to generate.