tst-backtrace1.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright (C) 2004-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library 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 GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <execinfo.h>
  15. #include <pthread.h>
  16. #include <stdio.h>
  17. #define BT_SIZE 64
  18. void *bt_array[BT_SIZE];
  19. int bt_cnt;
  20. int
  21. do_bt (void)
  22. {
  23. bt_cnt = backtrace (bt_array, BT_SIZE);
  24. return 56;
  25. }
  26. int
  27. call_do_bt (void)
  28. {
  29. return do_bt () + 1;
  30. }
  31. void *
  32. tf (void *arg)
  33. {
  34. if (call_do_bt () != 57)
  35. return (void *) 1L;
  36. return NULL;
  37. }
  38. int
  39. do_test (void)
  40. {
  41. pthread_t th;
  42. if (pthread_create (&th, NULL, tf, NULL))
  43. {
  44. puts ("create failed");
  45. return 1;
  46. }
  47. void *res;
  48. if (pthread_join (th, &res))
  49. {
  50. puts ("join failed");
  51. return 1;
  52. }
  53. if (res != NULL)
  54. {
  55. puts ("thread failed");
  56. return 1;
  57. }
  58. char **text = backtrace_symbols (bt_array, bt_cnt);
  59. if (text == NULL)
  60. {
  61. puts ("backtrace_symbols failed");
  62. return 1;
  63. }
  64. for (int i = 0; i < bt_cnt; ++i)
  65. puts (text[i]);
  66. return 0;
  67. }
  68. #define TEST_FUNCTION do_test ()
  69. #include "../test-skeleton.c"