No description
Find a file
Andrew Burgess f42bd4f05d gdb: fix crash from 'shell' when GDB has no terminal
Bug PR gdb/33716 identifies a problem where GDB will crash when using
the 'shell' command if GDB is not attached to a terminal.  E.g.:

  $ gdb -nw -nh -q -batch -ex 'shell echo hello' </dev/null
  hello

  Fatal signal: Segmentation fault
  ----- Backtrace -----
  ... etc ...

This problem was introduced with commit:

  commit 3a7f7d0be3
  Date:   Fri Jul 25 19:07:59 2025 +0200

      [gdb/tui] Fix shell command terminal settings

This commit introduces 'class scoped_gdb_ttystate', a RAII class which
backs up and restores the current terminal state.  Unfortunately, the
implementation tries to backup and restore the state even when GDB is
not attached to a terminal.

If GDB is not attached to a terminal then serial_get_tty_state
will (on a Unix like system) return a NULL pointer.  Calling
serial_set_tty_state with a NULL state object will trigger the crash
seen above.

Elsewhere in GDB, calling serial_set_tty_state is guarded by calling
gdb_has_a_terminal().  I propose that we only try to backup the
terminal state if GDB is actually connected to a terminal.  The call
to serial_set_tty_state will only be made if the backed up tty state
is not NULL.

With this change in place the crash is resolved.  There's a new test
to cover this case.

While I'm here I added a gdb_assert in ser-unix.c which would have
triggered in this case before we saw the crash.  And I've extended the
comment in serial.h to document that serial_get_tty_state can return
NULL.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33716

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-12-16 14:03:49 +00:00
bfd Automatic date update in version.in 2025-12-16 00:00:22 +00:00
binutils Re: tekhex test for commit bf0f85df12 2025-09-06 10:33:16 +09:30
config config: Update obsolete autoconf macro 2025-08-14 17:40:37 -04:00
contrib contrib: sync dg-extract-results.{sh,py} with GCC 2025-07-05 11:20:44 +01:00
cpu Add markers for 2.45 branch 2025-07-13 08:35:45 +01:00
elfcpp Add markers for 2.45 branch 2025-07-13 08:35:45 +01:00
etc Update year range in copyright notice of binutils files 2025-01-01 18:29:57 +10:30
gas x86: check reloc types for relaxable branches 2025-09-05 08:33:27 +02:00
gdb gdb: fix crash from 'shell' when GDB has no terminal 2025-12-16 14:03:49 +00:00
gdbserver GDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support 2025-08-29 18:35:58 -03:00
gdbsupport gdbsupport: remove unecessary template on iterator_range constructor 2025-08-30 23:04:26 -04:00
gnulib gnulib: Update obsolete autoconf macros 2025-08-12 21:12:50 -04:00
gold gold: configury: fix obsolete macros 2025-07-23 19:49:50 -04:00
gprof Update obsolete autoconf macros 2025-08-07 22:14:49 +09:30
gprofng gprofng: do not skip weak symbols 2025-07-19 12:54:32 -07:00
include PR 33302, Symbols truncated on i386pep target 2025-08-25 08:28:38 +09:30
ld Update x86: Add GLIBC_ABI_GNU2_TLS version dependency 2025-09-06 06:19:25 -07:00
libbacktrace autoupdate: regen after replacing obsolete macros 2024-06-10 08:25:56 +09:30
libctf Update obsolete autoconf macros 2025-08-07 22:14:49 +09:30
libdecnumber regen config 2023-08-12 10:27:57 +09:30
libiberty libiberty: sync with gcc 2025-08-07 10:33:44 +01:00
libsframe libsframe: use offsets to FDE and FRE sub-sections 2025-08-23 12:10:31 -07:00
opcodes csky disassembler leak 2025-09-03 10:12:01 +09:30
readline readline/tcap.h: Update definitions for C23 2025-05-02 12:00:05 -06:00
sim sim: riscv: Fix build issue due to INSN_CLASS_C was changed to INSN_CLASS_ZCA 2025-07-10 21:50:19 +08:00
texinfo
zlib zlib: import zlib-1.3.1 [PR32933] 2025-07-31 14:45:21 +01:00
.cvsignore
.editorconfig Add top-level .editorconfig file 2022-01-28 08:25:42 -05:00
.gitattributes binutils-gdb/git: highlight whitespace errors in source files 2022-07-25 14:35:41 +01:00
.gitignore Add Vim swap files to .gitignore 2025-02-28 16:06:25 +00:00
.pre-commit-config.yaml Bump flake8 version 2025-08-28 09:01:33 -06:00
ar-lib
ChangeLog Add markers for 2.45 branch 2025-07-13 08:35:45 +01:00
compile
config-ml.in MSP430: Add -fno-exceptions multilib 2023-08-12 10:24:26 +09:30
config.guess Sync config.guess and config.sub with latest versions from the config project. 2025-01-17 10:18:30 +00:00
config.rpath
config.sub Sync config.guess and config.sub with latest versions from the config project. 2025-01-17 10:18:30 +00:00
configure nios2: Remove binutils support for Nios II target. 2024-11-26 19:13:07 +00:00
configure.ac nios2: Remove binutils support for Nios II target. 2024-11-26 19:13:07 +00:00
COPYING
COPYING.LIB
COPYING.LIBGLOSS
COPYING.NEWLIB
COPYING3
COPYING3.LIB
depcomp
djunpack.bat
install-sh
libtool.m4 FDPIC: Handle arm*-*-uclinuxfdpiceabi in configure scripts 2023-08-12 10:25:06 +09:30
ltgcc.m4
ltmain.sh ltmain.sh: allow more flags at link-time 2024-09-25 19:06:10 +01:00
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS Fix compiling bfd/vms-lib.c for a 32-bit host. 2024-03-18 10:26:16 +00:00
Makefile.def Fix 64-bit BFD detection causing build failures 2025-04-28 18:53:30 +01:00
Makefile.in Fix 64-bit BFD detection causing build failures 2025-04-28 18:53:30 +01:00
Makefile.tpl Revert "Pass GUILE down to subdirectories" 2024-03-22 11:07:28 -06:00
makefile.vms
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
README-maintainer-mode Note that at least dejagnu version 1.5.3 is required in order to be ale to run the testsuites. 2022-10-04 10:54:19 +01:00
SECURITY.txt Add a SECURITY.txt file describing the GNU Binutils' project's stance on security related bugs. 2023-04-20 16:52:11 +01:00
setup.com
src-release.sh Rename 'binutils' to 'binutils_with_gold'. Rename 'bin_no_gold' to 'binutils'. Add 'gold' 2025-02-04 11:50:02 +00:00
symlink-tree
test-driver
ylwrap

		   README for GNU development tools

This directory contains various GNU compilers, assemblers, linkers, 
debuggers, etc., plus their support routines, definitions, and documentation.

If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README;  if with a libg++ release,
see libg++/README, etc.  That'll give you info about this
package -- supported targets, how to use it, how to report bugs, etc.

It is now possible to automatically configure and build a variety of
tools with one command.  To build all of the tools contained herein,
run the ``configure'' script here, e.g.:

	./configure 
	make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
	make install

(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''.  You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)

If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make.  For example (assuming sh/bash/ksh):

	CC=gcc ./configure
	make

A similar example using csh:

	setenv CC gcc
	./configure
	make

Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc.  See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.

REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.