*** Changes since GDB 11
+* New commands
+
maint set backtrace-on-fatal-signal on|off
maint show backtrace-on-fatal-signal
This setting is 'on' by default. When 'on' GDB will print a limited
fatal signal. This only supported on some platforms where the
backtrace and backtrace_symbols_fd functions are available.
+set source open on|off
+show source open
+ This setting, which is on by default, controls whether GDB will try
+ to open source code files. Switching this off will stop GDB trying
+ to open and read source code files, which can be useful if the files
+ are located over a slow network connection.
+
* Python API
** New function gdb.add_history(), which takes a gdb.Value object
struct cmd_list_element *showchecklist;
+struct cmd_list_element *setsourcelist;
+
+struct cmd_list_element *showsourcelist;
+
/* Command tracing state. */
int source_verbose = 0;
extern struct cmd_list_element *save_cmdlist;
+/* Chain containing all defined "set source" subcommands. */
+
+extern struct cmd_list_element *setsourcelist;
+
+/* Chain containing all defined "show source" subcommands. */
+
+extern struct cmd_list_element *showsourcelist;
+
/* Limit the call depth of user-defined commands */
extern unsigned int max_user_call_depth;
* Search:: Searching source files
* Source Path:: Specifying source directories
* Machine Code:: Source and machine code
+* Disable Reading Source:: Disable Reading Source Code
@end menu
@node List
instruction.
@end table
+@node Disable Reading Source
+@section Disable Reading Source Code
+@cindex source code, disable access
+
+In some cases it can be desirable to prevent @value{GDBN} from
+accessing source code files. One case where this might be desirable
+is if the source code files are located over a slow network
+connection.
+
+The following command can be used to control whether @value{GDBN}
+should access source code files or not:
+
+@table @code
+@kindex set source open
+@kindex show source open
+@item set source open @r{[}on@r{|}off@r{]}
+@itemx show source open
+When this option is @code{on}, which is the default, @value{GDBN} will
+access source code files when needed, for example to print source
+lines when @value{GDBN} stops, or in response to the @code{list}
+command.
+
+When this option is @code{off}, @value{GDBN} will not access source
+code files.
+@end table
@node Data
@chapter Examining Data
{
fprintf_filtered (file, _("Filenames are displayed as \"%s\".\n"), value);
}
-
+
+/* When true GDB will stat and open source files as required, but when
+ false, GDB will avoid accessing source files as much as possible. */
+
+static bool source_open = true;
+
+/* Implement 'show source open'. */
+
+static void
+show_source_open (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Source opening is \"%s\".\n"), value);
+}
+
/* Line number of last line printed. Default for various commands.
current_source_line is usually, but not always, the same as this. */
const char *p;
int result;
- /* Quick way out if we already know its full name. */
+ /* If reading of source files is disabled then return a result indicating
+ the attempt to read this source file failed. GDB will then display
+ the filename and line number instead. */
+ if (!source_open)
+ return scoped_fd (-1);
+ /* Quick way out if we already know its full name. */
if (*fullname)
{
/* The user may have requested that source paths be rewritten
*fullname = std::move (rewritten_fullname);
result = gdb_open_cloexec (fullname->get (), OPEN_MODE, 0);
+
if (result >= 0)
{
*fullname = gdb_realpath (fullname->get ());
/* If printing of source lines is disabled, just print file and line
number. */
- if (uiout->test_flags (ui_source_list))
+ if (uiout->test_flags (ui_source_list) && source_open)
{
/* Only prints "No such file or directory" once. */
if (s == last_source_visited)
if (loc->symtab () == nullptr)
select_source_symtab (0);
+ if (!source_open)
+ error (_("source code access disabled"));
+
scoped_fd desc (open_source_file (loc->symtab ()));
if (desc.get () < 0)
perror_with_name (symtab_to_filename_for_display (loc->symtab ()));
}
}
+/* Handle the "set source" base command. */
+
+static void
+set_source (const char *arg, int from_tty)
+{
+ help_list (setsourcelist, "set source ", all_commands, gdb_stdout);
+}
+
+/* Handle the "show source" base command. */
+
+static void
+show_source (const char *args, int from_tty)
+{
+ help_list (showsourcelist, "show source ", all_commands, gdb_stdout);
+}
+
\f
void _initialize_source ();
void
show_filename_display_string,
&setlist, &showlist);
+ add_prefix_cmd ("source", no_class, set_source,
+ _("Generic command for setting how sources are handled."),
+ &setsourcelist, 0, &setlist);
+
+ add_prefix_cmd ("source", no_class, show_source,
+ _("Generic command for showing source settings."),
+ &showsourcelist, 0, &showlist);
+
+ add_setshow_boolean_cmd ("open", class_files, &source_open, _("\
+Set whether GDB should open source files."), _("\
+Show whether GDB should open source files."), _("\
+When this option is on GDB will open source files and display the\n\
+contents when appropriate, for example, when GDB stops, or the list\n\
+command is used.\n\
+When this option is off GDB will not try to open source files, instead\n\
+GDB will print the file and line number that would have been displayed.\n\
+This can be useful if access to source code files is slow, for example\n\
+due to the source being located over a slow network connection."),
+ NULL,
+ show_source_open,
+ &setsourcelist, &showsourcelist);
}
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2021 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/>. */
+
+#include <stdio.h>
+
+int
+main (int argc, char* argv[])
+{
+ printf ("source code line.");
+ return 0;
+}
--- /dev/null
+# Copyright 2021 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 the 'set source open on|off' command.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+gdb_test "show source open" "Source opening is \"on\"\\." \
+ "source opening is initially on"
+gdb_test_no_output "set listsize 1"
+gdb_test_no_output "set source open on"
+gdb_test "list 18" "18\t#include <stdio.h>" "source reading on"
+
+# File opening is turned off therefore source lines are not printed.
+gdb_test_no_output "set source open off"
+gdb_test "show source open" "Source opening is \"off\"\\." \
+ "source opening is now off"
+gdb_test "list 18" "18\tin .*/${srcfile}" "source reading off"
+
+gdb_test "forward-search main" "source code access disabled"
+gdb_test "reverse-search main" "source code access disabled"
+
+# And finally, turn source code reading back on.
+gdb_test_no_output "set source open on" \
+ "turn source reading back on"
+gdb_test "show source open" "Source opening is \"on\"\\." \
+ "source opening is on again"
+gdb_test "list 18" "18\t#include <stdio.h>" "source reading on again"