gdb: adjust gdbarch_tdep calls in nat files
[binutils-gdb.git] / gdb / bt-utils.h
1 /* Copyright (C) 2021 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
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.
9
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.
14
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/>. */
17
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. */
20
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
27 # endif
28 #endif
29
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
36 #endif
37
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.
41
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
44 false. */
45 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
46 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON true
47 #else
48 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON false
49 #endif
50
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. */
54
55 extern void gdb_internal_backtrace ();
56
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.
60
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.
64
65 If GDB does support printing a backtrace then this function does
66 nothing. */
67
68 extern void gdb_internal_backtrace_set_cmd (const char *args, int from_tty,
69 cmd_list_element *c);