1 /* Copyright (C) 2021-2022 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. */
21 #ifdef HAVE_LIBBACKTRACE
22 # include "backtrace.h"
23 # include "backtrace-supported.h"
24 # if BACKTRACE_SUPPORTED && (! BACKTRACE_USES_MALLOC)
25 # define GDB_PRINT_INTERNAL_BACKTRACE
26 # define GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE
30 #if defined HAVE_EXECINFO_H \
31 && defined HAVE_EXECINFO_BACKTRACE \
32 && !defined PRINT_BACKTRACE_ON_FATAL_SIGNAL
33 # include <execinfo.h>
34 # define GDB_PRINT_INTERNAL_BACKTRACE
35 # define GDB_PRINT_INTERNAL_BACKTRACE_USING_EXECINFO
38 /* Define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON. This is a boolean value
39 that can be used as an initial value for a set/show user setting, where
40 the setting controls printing a GDB internal backtrace.
42 If backtrace printing is supported then this will have the value true,
43 but if backtrace printing is not supported then this has the value
45 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
46 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON true
48 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON false
51 /* Print a backtrace of the current GDB process to the current
52 gdb_stderr. The output is done in a signal async manner, so it is safe
53 to call from signal handlers. */
55 extern void gdb_internal_backtrace ();
57 /* A generic function that can be used as the set function for any set
58 command that enables printing of an internal backtrace. Command C must
59 be a boolean set command.
61 If GDB doesn't support printing a backtrace, and the user has tried to
62 set the variable associated with command C to true, then the associated
63 variable will be set back to false, and an error thrown.
65 If GDB does support printing a backtrace then this function does
68 extern void gdb_internal_backtrace_set_cmd (const char *args
, int from_tty
,