step-over-trips-on-watchpoint.c 1.8 KB

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