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