aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/cli/cli-cmds.c2
-rw-r--r--gdb/testsuite/gdb.base/list-nodebug.c21
-rw-r--r--gdb/testsuite/gdb.base/list-nodebug.exp37
3 files changed, 60 insertions, 0 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 8cadd63..cfe7b71 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1291,6 +1291,8 @@ list_command (const char *arg, int from_tty)
set_default_source_symtab_and_line ();
cursal = get_current_source_symtab_and_line ();
}
+ if (cursal.symtab == nullptr)
+ error (_("No debug information available to print source lines."));
list_around_line (arg, cursal);
/* Set the repeat args so just pressing "enter" after using "list ."
will print the following lines instead of the same lines again. */
diff --git a/gdb/testsuite/gdb.base/list-nodebug.c b/gdb/testsuite/gdb.base/list-nodebug.c
new file mode 100644
index 0000000..078517c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/list-nodebug.c
@@ -0,0 +1,21 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ 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/>. */
+
+int main ()
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/list-nodebug.exp b/gdb/testsuite/gdb.base/list-nodebug.exp
new file mode 100644
index 0000000..08de054
--- /dev/null
+++ b/gdb/testsuite/gdb.base/list-nodebug.exp
@@ -0,0 +1,37 @@
+# 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 .'"