non-ldr-exc-2.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <stdio.h>
  17. #include <string.h>
  18. #include <assert.h>
  19. static const char *image;
  20. static volatile pthread_t main_thread;
  21. static char *argv1 = "go away";
  22. static void *
  23. thread_execler (void *arg)
  24. {
  25. int i;
  26. i = pthread_join (main_thread, NULL);
  27. assert (i == 0);
  28. /* Exec ourselves again. */
  29. if (execl (image, image, argv1, NULL) == -1) /* break-here */
  30. {
  31. perror ("execl");
  32. abort ();
  33. }
  34. return NULL;
  35. }
  36. int
  37. main (int argc, char **argv)
  38. {
  39. pthread_t thread;
  40. int i;
  41. image = argv[0];
  42. /* Pass "inf" as argument to keep re-execing ad infinitum, which can
  43. be useful for manual testing. Passing any other argument exits
  44. immediately (and that's what the execl above does by
  45. default). */
  46. if (argc == 2 && strcmp (argv[1], "inf") == 0)
  47. argv1 = argv[1];
  48. else if (argc > 1)
  49. exit (0);
  50. main_thread = pthread_self ();
  51. i = pthread_create (&thread, NULL, thread_execler, NULL);
  52. assert (i == 0);
  53. pthread_exit (NULL);
  54. /* NOTREACHED */
  55. return 0;
  56. }