Files
binutils-gdb/gdb/testsuite/gdb.base/list-nodebug.exp
Guinevere Larsen 0068bd6fb3 gdb: fix "list ." related crash
When a user attempts to use the "list ." command with an inferior that
doesn't have debug symbols, GDB would crash. This was reported as PR
gdb/31256.

The crash would happen when attempting to get the current symtab_and_line
for the stop location, because the symtab would return a null pointer
and we'd attempt to dereference it to print the line.

This commit fixes that by checking for an empty symtab and erroring out
of the function if it happens.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31256
Approved-By: Tom Tromey <tom@tromey.com>
2024-01-23 16:58:55 +01:00

38 lines
1.3 KiB
Plaintext

# Copyright 2024 Free Software Foundation, Inc.
# 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/>.
# Test that using the command "list" in a file with no debug information
# will not crash GDB and will give reasonable output.
standard_testfile .c
if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
{nodebug}]} {
return -1
}
if {![runto_main]} {
untested "couldn't run to main"
return
}
# Check that GDB doesn't crash when we use list . on an inferior with
# no debug information
gdb_test "list ." "No debug.*" "first 'list .'"
# This should be called twice because the first list invocation since
# printing a frame may take a different codepath, which wouldn't
# trigger the crash.
gdb_test "list ." "No debug.*" "second 'list .'"