Home | History | Annotate | Line # | Download | only in gdb.threads
      1 /* This testcase is part of GDB, the GNU debugger.
      2 
      3    Copyright 2023-2024 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 #include <pthread.h>
     19 #include <unistd.h>
     20 
     21 /* This is set from GDB to allow the main thread to exit.  */
     22 
     23 volatile int dont_exit_just_yet = 1;
     24 
     25 /* Somewhere to place a breakpoint.  */
     26 
     27 void
     28 breakpt ()
     29 {
     30   /* Just spin.  When the test is started under GDB we never enter the spin
     31      loop, but when we attach, the worker thread will be spinning here.  */
     32   while (dont_exit_just_yet)
     33     sleep (1);
     34 }
     35 
     36 /* Thread function, doesn't do anything but hit a breakpoint.  */
     37 
     38 void *
     39 thread_worker (void *arg)
     40 {
     41   breakpt ();
     42   return NULL;
     43 }
     44 
     45 int
     46 main ()
     47 {
     48   pthread_t thr;
     49 
     50   alarm (300);
     51 
     52   /* Create a thread.  */
     53   pthread_create (&thr, NULL, thread_worker, NULL);
     54   pthread_detach (thr);
     55 
     56   /* Spin until GDB releases us.  */
     57   while (dont_exit_just_yet)
     58     sleep (1);
     59 
     60   _exit (0);
     61 }
     62