multiple-step-overs.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* This testcase is part of GDB, the GNU debugger.
  2. Copyright 2009-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 <pthread.h>
  14. #include <unistd.h>
  15. #include <stdlib.h>
  16. #include <signal.h>
  17. unsigned int args[2];
  18. pthread_barrier_t barrier;
  19. pthread_t child_thread_2, child_thread_3;
  20. void
  21. sigusr1_handler (int signo)
  22. {
  23. }
  24. void
  25. callme (void)
  26. {
  27. }
  28. void *
  29. child_function_3 (void *arg)
  30. {
  31. int my_number = (long) arg;
  32. volatile int *myp = (int *) &args[my_number];
  33. pthread_barrier_wait (&barrier);
  34. while (*myp > 0)
  35. {
  36. (*myp) ++;
  37. callme (); /* set breakpoint thread 3 here */
  38. }
  39. pthread_exit (NULL);
  40. }
  41. void *
  42. child_function_2 (void *arg)
  43. {
  44. int my_number = (long) arg;
  45. volatile int *myp = (int *) &args[my_number];
  46. pthread_barrier_wait (&barrier);
  47. while (*myp > 0)
  48. {
  49. (*myp) ++;
  50. callme (); /* set breakpoint thread 2 here */
  51. }
  52. pthread_exit (NULL);
  53. }
  54. static int
  55. wait_threads (void)
  56. {
  57. return 1; /* in wait_threads */
  58. }
  59. int
  60. main ()
  61. {
  62. int res;
  63. long i;
  64. signal (SIGUSR1, sigusr1_handler);
  65. /* Call these early so that PLTs for these are resolved soon,
  66. instead of in the threads. RTLD_NOW should work as well. */
  67. usleep (0);
  68. pthread_barrier_init (&barrier, NULL, 1);
  69. pthread_barrier_wait (&barrier);
  70. pthread_barrier_init (&barrier, NULL, 2);
  71. i = 0;
  72. args[i] = 1;
  73. res = pthread_create (&child_thread_2,
  74. NULL, child_function_2, (void *) i);
  75. pthread_barrier_wait (&barrier);
  76. callme ();
  77. i = 1;
  78. args[i] = 1;
  79. res = pthread_create (&child_thread_3,
  80. NULL, child_function_3, (void *) i);
  81. pthread_barrier_wait (&barrier);
  82. wait_threads (); /* set wait-threads breakpoint here */
  83. pthread_join (child_thread_2, NULL);
  84. pthread_join (child_thread_3, NULL);
  85. exit(EXIT_SUCCESS);
  86. }