testlib.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* testlib.h -- Header for test functions for libbacktrace library
  2. Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor, Google.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. (1) Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. (2) Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. (3) The name of the author may not be used to
  14. endorse or promote products derived from this software without
  15. specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  20. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  25. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. POSSIBILITY OF SUCH DAMAGE. */
  27. #ifndef LIBBACKTRACE_TESTLIB_H
  28. #define LIBBACKTRACE_TESTLIB_H
  29. /* Portable attribute syntax. Actually some of these tests probably
  30. won't work if the attributes are not recognized. */
  31. #ifndef GCC_VERSION
  32. # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  33. #endif
  34. #if (GCC_VERSION < 2007)
  35. # define __attribute__(x)
  36. #endif
  37. #ifndef ATTRIBUTE_UNUSED
  38. # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
  39. #endif
  40. /* Used to collect backtrace info. */
  41. struct info
  42. {
  43. char *filename;
  44. int lineno;
  45. char *function;
  46. };
  47. /* Passed to backtrace callback function. */
  48. struct bdata
  49. {
  50. struct info *all;
  51. size_t index;
  52. size_t max;
  53. int failed;
  54. };
  55. /* Passed to backtrace_simple callback function. */
  56. struct sdata
  57. {
  58. uintptr_t *addrs;
  59. size_t index;
  60. size_t max;
  61. int failed;
  62. };
  63. /* Passed to backtrace_syminfo callback function. */
  64. struct symdata
  65. {
  66. const char *name;
  67. uintptr_t val, size;
  68. int failed;
  69. };
  70. /* The backtrace state. */
  71. extern void *state;
  72. /* The number of failures. */
  73. extern int failures;
  74. extern const char *base (const char *p);
  75. extern void check (const char *name, int index, const struct info *all,
  76. int want_lineno, const char *want_function,
  77. const char *want_file, int *failed);
  78. extern int callback_one (void *, uintptr_t, const char *, int, const char *);
  79. extern void error_callback_one (void *, const char *, int);
  80. extern int callback_two (void *, uintptr_t);
  81. extern void error_callback_two (void *, const char *, int);
  82. extern void callback_three (void *, uintptr_t, const char *, uintptr_t,
  83. uintptr_t);
  84. extern void error_callback_three (void *, const char *, int);
  85. extern void error_callback_create (void *, const char *, int);
  86. #endif /* !defined(LIBBACKTRACE_TESTLIB_H) */