1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Support for printing a backtrace when GDB hits an error. This is not
19 for printing backtraces of the inferior, but backtraces of GDB itself. */
24 #ifdef HAVE_LIBBACKTRACE
25 # include "backtrace.h"
26 # include "backtrace-supported.h"
27 # if BACKTRACE_SUPPORTED && (! BACKTRACE_USES_MALLOC)
28 # define GDB_PRINT_INTERNAL_BACKTRACE
29 # define GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE
33 #if defined HAVE_EXECINFO_H \
34 && defined HAVE_EXECINFO_BACKTRACE \
35 && !defined GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE
36 # include <execinfo.h>
37 # define GDB_PRINT_INTERNAL_BACKTRACE
38 # define GDB_PRINT_INTERNAL_BACKTRACE_USING_EXECINFO
41 /* Define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON. This is a boolean value
42 that can be used as an initial value for a set/show user setting, where
43 the setting controls printing a GDB internal backtrace.
45 If backtrace printing is supported then this will have the value true,
46 but if backtrace printing is not supported then this has the value
48 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
49 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON true
51 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON false
54 /* Print a backtrace of the current GDB process to the current
55 gdb_stderr. The output is done in a signal async manner, so it is safe
56 to call from signal handlers. */
58 extern void gdb_internal_backtrace ();
60 /* A generic function that can be used as the set function for any set
61 command that enables printing of an internal backtrace. Command C must
62 be a boolean set command.
64 If GDB doesn't support printing a backtrace, and the user has tried to
65 set the variable associated with command C to true, then the associated
66 variable will be set back to false, and an error thrown.
68 If GDB does support printing a backtrace then this function does
71 extern void gdb_internal_backtrace_set_cmd (const char *args
, int from_tty
,
74 #endif /* BT_UTILS_H */