process-dies-while-handling-bp.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* This testcase is part of GDB, the GNU debugger.
  2. Copyright 2015-2022 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <assert.h>
  14. #include <pthread.h>
  15. #include <unistd.h>
  16. /* Number of threads. Each thread continuously steps over a
  17. breakpoint. */
  18. #define NTHREADS 10
  19. pthread_t threads[NTHREADS];
  20. pthread_barrier_t barrier;
  21. /* Used to create a conditional breakpoint that always fails. */
  22. volatile int zero;
  23. static void *
  24. thread_func (void *arg)
  25. {
  26. pthread_barrier_wait (&barrier);
  27. while (1)
  28. {
  29. usleep (1); /* set break here */
  30. }
  31. return NULL;
  32. }
  33. int
  34. main (void)
  35. {
  36. int ret;
  37. int i;
  38. /* Don't run forever. */
  39. alarm (180);
  40. pthread_barrier_init (&barrier, NULL, NTHREADS + 1);
  41. /* Start the threads that constantly hits a conditional breakpoint
  42. that needs to be stepped over. */
  43. for (i = 0; i < NTHREADS; i++)
  44. {
  45. ret = pthread_create (&threads[i], NULL, thread_func, NULL);
  46. assert (ret == 0);
  47. }
  48. /* Wait until all threads are up and running. */
  49. pthread_barrier_wait (&barrier);
  50. /* Let them start hitting the breakpoint. */
  51. usleep (100);
  52. /* Exit abruptly. */
  53. return 0;
  54. }