9
3

my_stacktrace.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Copyright (c) 2001, 2011, Oracle and/or its affiliates.
  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; version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  13. #ifndef _my_stacktrace_h_
  14. #define _my_stacktrace_h_
  15. #include <my_global.h>
  16. #ifdef TARGET_OS_LINUX
  17. #if defined (__x86_64__) || defined (__i386__) || \
  18. (defined(__alpha__) && defined(__GNUC__))
  19. #define HAVE_STACKTRACE 1
  20. #endif
  21. #elif defined(__WIN__) || defined(HAVE_PRINTSTACK)
  22. #define HAVE_STACKTRACE 1
  23. #endif
  24. #if HAVE_BACKTRACE && (HAVE_BACKTRACE_SYMBOLS || HAVE_BACKTRACE_SYMBOLS_FD)
  25. #undef HAVE_STACKTRACE
  26. #define HAVE_STACKTRACE 1
  27. #endif
  28. #define HAVE_WRITE_CORE
  29. #if HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS && HAVE_ABI_CXA_DEMANGLE && \
  30. HAVE_WEAK_SYMBOL
  31. #define BACKTRACE_DEMANGLE 1
  32. #endif
  33. C_MODE_START
  34. #if defined(HAVE_STACKTRACE) || defined(HAVE_BACKTRACE)
  35. void my_init_stacktrace();
  36. void my_print_stacktrace(uchar* stack_bottom, ulong thread_stack);
  37. int my_safe_print_str(const char* val, int max_len);
  38. void my_write_core(int sig);
  39. #if BACKTRACE_DEMANGLE
  40. char *my_demangle(const char *mangled_name, int *status);
  41. #endif /* BACKTRACE_DEMANGLE */
  42. #ifdef __WIN__
  43. void my_set_exception_pointers(EXCEPTION_POINTERS *ep);
  44. #endif /* __WIN__ */
  45. #else
  46. #define my_init_stacktrace() do { } while(0)
  47. #endif /* ! (defined(HAVE_STACKTRACE) || defined(HAVE_BACKTRACE)) */
  48. #ifndef _WIN32
  49. #define MY_ADDR_RESOLVE_FORK
  50. #endif
  51. #if defined(HAVE_BFD_H) || defined(MY_ADDR_RESOLVE_FORK)
  52. #define HAVE_MY_ADDR_RESOLVE 1
  53. #endif
  54. typedef struct {
  55. const char *file;
  56. const char *func;
  57. uint line;
  58. } my_addr_loc;
  59. #ifdef HAVE_MY_ADDR_RESOLVE
  60. int my_addr_resolve(void *ptr, my_addr_loc *loc);
  61. const char *my_addr_resolve_init();
  62. #else
  63. #define my_addr_resolve_init() (0)
  64. #define my_addr_resolve(A,B) (1)
  65. #endif
  66. #ifdef HAVE_WRITE_CORE
  67. void my_write_core(int sig);
  68. #endif
  69. /**
  70. A (very) limited version of snprintf, which writes the result to STDERR.
  71. @sa my_safe_snprintf
  72. Implemented with simplicity, and async-signal-safety in mind.
  73. @note Has an internal buffer capacity of 512 bytes,
  74. which should suffice for our signal handling routines.
  75. */
  76. size_t my_safe_printf_stderr(const char* fmt, ...)
  77. ATTRIBUTE_FORMAT(printf, 1, 2);
  78. /**
  79. Writes up to count bytes from buffer to STDERR.
  80. Implemented with simplicity, and async-signal-safety in mind.
  81. @param buf Buffer containing data to be written.
  82. @param count Number of bytes to write.
  83. @returns Number of bytes written.
  84. */
  85. size_t my_write_stderr(const void *buf, size_t count);
  86. C_MODE_END
  87. #endif /* _my_stacktrace_h_ */