mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 20:14:06 +08:00
b77a357567
In passing I spotted some incorrect #ifdef logic in bt-utils.h. The
logic in question has existed since the file was originally added in
commit:
commit abbbd4a3e0
Date: Wed Aug 11 13:24:33 2021 +0100
gdb: use libbacktrace to create a better backtrace for fatal signals
The code is trying to select between using libbacktrace or using the
execinfo supplied backtrace API.
First we check to see if we can use libbacktrace. If we can then we
include some header files, and then set some defines to indicate that
libbacktrace is being used.
Then we check if execinfo is available, if it is then we include
<execinfo.h> and set some alternative defines.
In theory the second block of logic should not trigger if the first
block (that uses libbacktrace) has also triggered, but we incorrectly
check the define 'PRINT_BACKTRACE_ON_FATAL_SIGNAL' instead of checking
for 'GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE', so the second
block triggers more than it should. The
'PRINT_BACKTRACE_ON_FATAL_SIGNAL' define is not defined anywhere, this
was a mistake in the original commit.
In reality this is harmless, we include <execinfo.h> when we don't
need too, but in by-utils.c the libbacktrace define is always checked
for before the execinfo define, so we never actually end up using the
execinfo path (when libbacktrace is available). But I figure its
still worth cleaning this up.
I've tested GDB in a "default" build where libbacktrace is used, and
when configuring with --disable-libbacktrace which causes the execinfo
backtrace API to be used instead, both still appear to work fine.
There should be no user visible changes after this commit.
75 lines
2.7 KiB
C
75 lines
2.7 KiB
C
/* Copyright (C) 2021-2023 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
/* Support for printing a backtrace when GDB hits an error. This is not
|
|
for printing backtraces of the inferior, but backtraces of GDB itself. */
|
|
|
|
#ifndef BT_UTILS_H
|
|
#define BT_UTILS_H
|
|
|
|
#ifdef HAVE_LIBBACKTRACE
|
|
# include "backtrace.h"
|
|
# include "backtrace-supported.h"
|
|
# if BACKTRACE_SUPPORTED && (! BACKTRACE_USES_MALLOC)
|
|
# define GDB_PRINT_INTERNAL_BACKTRACE
|
|
# define GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE
|
|
# endif
|
|
#endif
|
|
|
|
#if defined HAVE_EXECINFO_H \
|
|
&& defined HAVE_EXECINFO_BACKTRACE \
|
|
&& !defined GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE
|
|
# include <execinfo.h>
|
|
# define GDB_PRINT_INTERNAL_BACKTRACE
|
|
# define GDB_PRINT_INTERNAL_BACKTRACE_USING_EXECINFO
|
|
#endif
|
|
|
|
/* Define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON. This is a boolean value
|
|
that can be used as an initial value for a set/show user setting, where
|
|
the setting controls printing a GDB internal backtrace.
|
|
|
|
If backtrace printing is supported then this will have the value true,
|
|
but if backtrace printing is not supported then this has the value
|
|
false. */
|
|
#ifdef GDB_PRINT_INTERNAL_BACKTRACE
|
|
# define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON true
|
|
#else
|
|
# define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON false
|
|
#endif
|
|
|
|
/* Print a backtrace of the current GDB process to the current
|
|
gdb_stderr. The output is done in a signal async manner, so it is safe
|
|
to call from signal handlers. */
|
|
|
|
extern void gdb_internal_backtrace ();
|
|
|
|
/* A generic function that can be used as the set function for any set
|
|
command that enables printing of an internal backtrace. Command C must
|
|
be a boolean set command.
|
|
|
|
If GDB doesn't support printing a backtrace, and the user has tried to
|
|
set the variable associated with command C to true, then the associated
|
|
variable will be set back to false, and an error thrown.
|
|
|
|
If GDB does support printing a backtrace then this function does
|
|
nothing. */
|
|
|
|
extern void gdb_internal_backtrace_set_cmd (const char *args, int from_tty,
|
|
cmd_list_element *c);
|
|
|
|
#endif /* BT_UTILS_H */
|