1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2021-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
27 /* Number of threads we'll create. */
37 /* Entry point for threads. Loops forever. */
40 thread_func (void *arg
)
42 /* Avoid setting the breakpoint at an instruction that wouldn't
43 require a fixup phase, like a branch/jump. In such a case, even
44 if GDB manages to detach the inferior with an incomplete
45 displaced step, GDB inferior may still not crash. A breakpoint
46 at a line that increments a variable is good bet that we end up
47 setting a breakpoint at an instruction that will require a fixup
48 phase to move the PC from the scratch pad to the instruction
49 after the breakpoint. */
50 volatile unsigned counter
= 0;
54 counter
++; /* Set breakpoint here. */
62 /* Allow for as much timeout as DejaGnu wants, plus a bit of
64 #define SECONDS (TIMEOUT + 20)
66 /* We'll exit after this many seconds. */
67 unsigned int seconds_left
= SECONDS
;
69 /* GDB sets this whenever it's about to start a new detach/attach
70 sequence. We react by resetting the seconds-left counter. */
71 volatile int again
= 0;
74 main (int argc
, char **argv
)
78 signal (SIGUSR1
, SIG_IGN
);
84 n_threads
= atoi (argv
[1]);
86 /* Spawn the test threads. */
87 for (i
= 0; i
< n_threads
; ++i
)
92 rc
= pthread_create (&child
, NULL
, thread_func
, NULL
);
96 /* Exit after a while if GDB is gone/crashes. But wait long enough
97 for one attach/detach sequence done by the .exp file. */
98 while (--seconds_left
> 0)
104 /* GDB should be reattaching soon. Restart the timer. */
106 seconds_left
= SECONDS
;
110 printf ("timeout, exiting\n");