bt-utils.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (C) 2021-2022 Free Software Foundation, Inc.
  2. This file is part of GDB.
  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. /* Support for printing a backtrace when GDB hits an error. This is not
  14. for printing backtraces of the inferior, but backtraces of GDB itself. */
  15. #ifndef BT_UTILS_H
  16. #define BT_UTILS_H
  17. #ifdef HAVE_LIBBACKTRACE
  18. # include "backtrace.h"
  19. # include "backtrace-supported.h"
  20. # if BACKTRACE_SUPPORTED && (! BACKTRACE_USES_MALLOC)
  21. # define GDB_PRINT_INTERNAL_BACKTRACE
  22. # define GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE
  23. # endif
  24. #endif
  25. #if defined HAVE_EXECINFO_H \
  26. && defined HAVE_EXECINFO_BACKTRACE \
  27. && !defined PRINT_BACKTRACE_ON_FATAL_SIGNAL
  28. # include <execinfo.h>
  29. # define GDB_PRINT_INTERNAL_BACKTRACE
  30. # define GDB_PRINT_INTERNAL_BACKTRACE_USING_EXECINFO
  31. #endif
  32. /* Define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON. This is a boolean value
  33. that can be used as an initial value for a set/show user setting, where
  34. the setting controls printing a GDB internal backtrace.
  35. If backtrace printing is supported then this will have the value true,
  36. but if backtrace printing is not supported then this has the value
  37. false. */
  38. #ifdef GDB_PRINT_INTERNAL_BACKTRACE
  39. # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON true
  40. #else
  41. # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON false
  42. #endif
  43. /* Print a backtrace of the current GDB process to the current
  44. gdb_stderr. The output is done in a signal async manner, so it is safe
  45. to call from signal handlers. */
  46. extern void gdb_internal_backtrace ();
  47. /* A generic function that can be used as the set function for any set
  48. command that enables printing of an internal backtrace. Command C must
  49. be a boolean set command.
  50. If GDB doesn't support printing a backtrace, and the user has tried to
  51. set the variable associated with command C to true, then the associated
  52. variable will be set back to false, and an error thrown.
  53. If GDB does support printing a backtrace then this function does
  54. nothing. */
  55. extern void gdb_internal_backtrace_set_cmd (const char *args, int from_tty,
  56. cmd_list_element *c);
  57. #endif /* BT_UTILS_H */