This command now gives an error if any unexpected arguments are
found after the command.
+list .
+ When using the command "list ." in a location that has no debug information
+ or no file loaded, GDB now says that there is no debug information to print
+ lines. This makes it more obvious that there is no information, as opposed
+ to implying there is no inferior loaded.
+
* New commands
info missing-debug-handler
/* Pull in the current default source line if necessary. */
if (arg == NULL || ((arg[0] == '+' || arg[0] == '-' || arg[0] == '.') && arg[1] == '\0'))
{
- set_default_source_symtab_and_line ();
- symtab_and_line cursal = get_current_source_symtab_and_line ();
-
/* If this is the first "list" since we've set the current
source line, center the listing around that line. */
if (get_first_line_listed () == 0 && (arg == nullptr || arg[0] != '.'))
{
- list_around_line (arg, cursal);
+ set_default_source_symtab_and_line ();
+ list_around_line (arg, get_current_source_symtab_and_line ());
}
/* "l" and "l +" lists the next few lines, unless we're listing past
the end of the file. */
else if (arg == nullptr || arg[0] == '+')
{
+ set_default_source_symtab_and_line ();
+ const symtab_and_line cursal = get_current_source_symtab_and_line ();
if (last_symtab_line (cursal.symtab) >= cursal.line)
print_source_lines (cursal.symtab,
source_lines_range (cursal.line), 0);
else
- {
- error (_("End of the file was already reached, use \"list .\" to"
- " list the current location again"));
- }
+ error (_("End of the file was already reached, use \"list .\" to"
+ " list the current location again"));
}
/* "l -" lists previous ten lines, the ones before the ten just
listed. */
else if (arg[0] == '-')
{
+ set_default_source_symtab_and_line ();
+ const symtab_and_line cursal = get_current_source_symtab_and_line ();
+
if (get_first_line_listed () == 1)
error (_("Already at the start of %s."),
symtab_to_filename_for_display (cursal.symtab));
+
source_lines_range range (get_first_line_listed (),
source_lines_range::BACKWARD);
print_source_lines (cursal.symtab, range, 0);
/* "list ." lists the default location again. */
else if (arg[0] == '.')
{
+ symtab_and_line cursal;
if (target_has_stack ())
{
/* Find the current line by getting the PC of the currently
frame_info_ptr frame = get_selected_frame (nullptr);
CORE_ADDR curr_pc = get_frame_pc (frame);
cursal = find_pc_line (curr_pc, 0);
+
+ if (cursal.symtab == nullptr)
+ error
+ (_("Insufficient debug info for showing source lines at "
+ "current PC (%s)."), paddress (get_frame_arch (frame),
+ curr_pc));
}
else
{
/* The inferior is not running, so reset the current source
location to the default (usually the main function). */
clear_current_source_symtab_and_line ();
- set_default_source_symtab_and_line ();
+ try
+ {
+ set_default_source_symtab_and_line ();
+ }
+ catch (const gdb_exception &e)
+ {
+ error (_("Insufficient debug info for showing source "
+ "lines at default location"));
+ }
cursal = get_current_source_symtab_and_line ();
+
+ gdb_assert (cursal.symtab != nullptr);
}
- 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. */
if (from_tty)
--- /dev/null
+/* 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/>. */
+
+extern void bar (int *);
+
+void
+foo (int *x)
+{
+ bar (x);
+}
--- /dev/null
+/* 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/>. */
+
+extern void foo (int *x);
+
+int x;
+
+void
+bar (int *p)
+{
+ *p++;
+}
+
+int
+main ()
+{
+ foo (&x);
+ return 0;
+}
--- /dev/null
+# Copyright 2005-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/>.
+
+# This test is here to confirm that the command "list ." will print the
+# same message if GDB detects no debug information at all, or detects some
+# but nothing for the current objfile.
+
+require !use_gdb_stub
+
+set linkflags [list additional_flags="-static"]
+
+if { ![gdb_can_simple_compile static-libc \
+ {
+ void main (void) { return 0; }
+ } \
+ executable $linkflags] } {
+ untested "Can't statically link"
+ return -1
+}
+
+standard_testfile .c -extra.c
+
+foreach_with_prefix debug {"none" "some"} {
+
+ set flags "nodebug"
+ if {$debug == "some"} {
+ set flags "debug"
+ }
+
+ if {[prepare_for_testing_full "failed to prepare" \
+ [list ${testfile}-${debug} $linkflags \
+ $srcfile [list nodebug] \
+ $srcfile2 [list $debug]]]} {
+ return -1
+ }
+
+ gdb_test "list ." \
+ "^Insufficient debug info for showing source lines at default location" \
+ "print before start"
+
+ if { ![runto bar] } {
+ return -1
+ }
+
+ gdb_test "list ." \
+ "^Insufficient debug info for showing source lines at current PC \\($::hex\\)\\." \
+ "print after start"
+}
# Check that GDB doesn't crash when we use list . on an inferior with
# no debug information
-gdb_test "list ." "No debug.*" "first 'list .'"
+gdb_test "list ." "Insufficient 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 .'"
+gdb_test "list ." "Insufficient debug.*" "second 'list .'"