Home | History | Annotate | Line # | Download | only in gdb
      1 /* Copyright (C) 2021-2024 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 #ifndef GDB_BT_UTILS_H
     22 #define GDB_BT_UTILS_H
     23 
     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
     30 # endif
     31 #endif
     32 
     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
     39 #endif
     40 
     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.
     44 
     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
     47    false.  */
     48 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
     49 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON true
     50 #else
     51 # define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON false
     52 #endif
     53 
     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.  */
     57 
     58 extern void gdb_internal_backtrace ();
     59 
     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.
     63 
     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.
     67 
     68    If GDB does support printing a backtrace then this function does
     69    nothing.  */
     70 
     71 extern void gdb_internal_backtrace_set_cmd (const char *args, int from_tty,
     72 					    cmd_list_element *c);
     73 
     74 /* Initialize language specific strings.  */
     75 
     76 extern void gdb_internal_backtrace_init_str ();
     77 
     78 #endif /* GDB_BT_UTILS_H */
     79