tst-backtrace.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Test backtrace and backtrace_symbols: common code for examining
  2. backtraces.
  3. Copyright (C) 2013-2026 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <https://www.gnu.org/licenses/>. */
  16. #include <stdbool.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. /* Set to a non-zero value if the test fails. */
  20. volatile int ret;
  21. /* Accesses to X are used to prevent optimization. */
  22. volatile int x;
  23. /* Called if the test fails. */
  24. #define FAIL() \
  25. do { printf ("Failure on line %d\n", __LINE__); ret = 1; } while (0)
  26. /* Use this attribute to prevent inlining, so that all expected frames
  27. are present. */
  28. #define NO_INLINE __attribute__ ((weak)) __attribute_optimization_barrier__
  29. /* Look for a match in SYM from backtrace_symbols to NAME, a fragment
  30. of a function name. Ignore the filename before '(', but presume
  31. that the function names are chosen so they cannot accidentally
  32. match the hex offset before the closing ')'. */
  33. static inline bool
  34. match (const char *sym, const char *name)
  35. {
  36. const char *p = strchr (sym, '(');
  37. return p != NULL && strstr (p, name) != NULL;
  38. }