step-over-lands-on-breakpoint.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* This testcase is part of GDB, the GNU debugger.
  2. Copyright 2014-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. pthread_barrier_t barrier;
  17. pthread_t child_thread;
  18. volatile unsigned int counter = 1;
  19. void *
  20. child_function (void *arg)
  21. {
  22. pthread_barrier_wait (&barrier);
  23. while (counter > 0)
  24. {
  25. counter++;
  26. asm (" nop"); /* set breakpoint child here */
  27. asm (" nop"); /* set breakpoint after step-over here */
  28. usleep (1);
  29. }
  30. pthread_exit (NULL);
  31. }
  32. int
  33. main ()
  34. {
  35. int res;
  36. long i;
  37. alarm (300);
  38. pthread_barrier_init (&barrier, NULL, 2);
  39. res = pthread_create (&child_thread, NULL, child_function, NULL);
  40. pthread_barrier_wait (&barrier);
  41. /* Use an infinite loop with no function calls so that "step" over
  42. this line never finishes before the breakpoint in the other
  43. thread triggers. That can happen if the step-over of thread 2 is
  44. done with displaced stepping on a target that is always in
  45. non-stop mode, as in that case GDB runs both threads
  46. simultaneously. */
  47. while (1); /* set wait-thread breakpoint here */
  48. pthread_join (child_thread, NULL);
  49. exit (EXIT_SUCCESS);
  50. }