watchpoint-fork-parent.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Test case for forgotten hw-watchpoints after fork()-off of a process.
  2. Copyright 2012-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  14. #include <string.h>
  15. #include <errno.h>
  16. #include <sys/types.h>
  17. #include <unistd.h>
  18. #include <assert.h>
  19. #include <stdio.h>
  20. #include <sys/wait.h>
  21. #include "watchpoint-fork.h"
  22. void
  23. forkoff (int nr)
  24. {
  25. pid_t child, pid_got;
  26. int exit_code = 42 + nr;
  27. int status, i;
  28. child = fork ();
  29. switch (child)
  30. {
  31. case -1:
  32. assert (0);
  33. case 0:
  34. #if DEBUG
  35. printf ("child%d: %d\n", nr, (int) getpid ());
  36. /* Delay to get both the "child%d" and "parent%d" message printed without
  37. a race breaking expect by its endless wait on `$gdb_prompt$':
  38. Breakpoint 3, marker () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
  39. 33 }
  40. (gdb) parent2: 14223 */
  41. i = sleep (1);
  42. assert (i == 0);
  43. #endif
  44. /* We must not get caught here (against a forgotten breakpoint). */
  45. var++;
  46. marker ();
  47. _exit (exit_code);
  48. default:
  49. #if DEBUG
  50. printf ("parent%d: %d\n", nr, (int) child);
  51. /* Delay to get both the "child%d" and "parent%d" message printed, see
  52. above. */
  53. i = sleep (1);
  54. assert (i == 0);
  55. #endif
  56. pid_got = wait (&status);
  57. assert (pid_got == child);
  58. assert (WIFEXITED (status));
  59. assert (WEXITSTATUS (status) == exit_code);
  60. /* We must get caught here (against a false watchpoint removal). */
  61. marker ();
  62. }
  63. }