debug lin-lwp' respectively. Turning this setting on prints debug
messages relating to GDB's handling of native Linux inferiors.
+maint flush source-cache
+ Flush the contents of the source code cache.
+
* Changed commands
maint packet
register fetching, or frame unwinding. The command @code{flushregs}
is deprecated in favor of @code{maint flush register-cache}.
+@kindex maint flush source-cache
+@cindex source code, caching
+@item maint flush source-cache
+Flush @value{GDBN}'s cache of source code file contents. After
+@value{GDBN} reads a source file, and optionally applies styling
+(@pxref{Output Styling}), the file contents are cached. This command
+clears that cache. The next time @value{GDBN} wants to show lines
+from a source file, the content will be re-read.
+
+This command is useful when debugging issues related to source code
+styling. After flushing the cache any source code displayed by
+@value{GDBN} will be re-read and re-styled.
+
@kindex maint print objfiles
@cindex info for known object files
@item maint print objfiles @r{[}@var{regexp}@r{]}
#include "gdbsupport/selftest.h"
#include "objfiles.h"
#include "exec.h"
+#include "cli/cli-cmds.h"
#ifdef HAVE_SOURCE_HIGHLIGHT
/* If Gnulib redirects 'open' and 'close' to its replacements
first_line, last_line, lines);
}
+/* Implement 'maint flush source-cache' command. */
+
+static void
+source_cache_flush_command (const char *command, int from_tty)
+{
+ forget_cached_source_info ();
+ printf_filtered (_("Source cache flushed.\n"));
+}
+
#if GDB_SELF_TEST
namespace selftests
{
void
_initialize_source_cache ()
{
+ add_cmd ("source-cache", class_maintenance, source_cache_flush_command,
+ _("Force gdb to flush its source code cache."),
+ &maintenanceflushlist);
+
#if GDB_SELF_TEST
selftests::register_test ("source-cache", selftests::extract_lines_test);
#endif
# changed for GDB.
gdb_test "list" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\); /\\\* new-marker \\\*/.*" \
"verify that the source code is properly reloaded"
+
+# Modify the source file again. As before, this only works locally
+# because of the TCL commands.
+set bkpsrc [standard_output_file $testfile].c.bkp
+set bkpsrcfd [open $bkpsrc w]
+set srcfd [open $srcfile r]
+
+while { [gets $srcfd line] != -1 } {
+ if { [string first "new-marker" $line] != -1 } {
+ # Modify the printf line that we added previously.
+ puts $bkpsrcfd " printf (\"foo\\n\"); /* new-marker updated */"
+ } else {
+ puts $bkpsrcfd $line
+ }
+}
+
+close $bkpsrcfd
+close $srcfd
+file rename -force -- $bkpsrc $srcfile
+
+# As before, delay so that at least one second has passed. GDB still
+# will not spot that the source file has changed, as GDB doesn't do a
+# time check unless the binary has also changed, this delay just
+# allows us to confirm this behaviour.
+sleep 1
+
+# List the printf line again, we should not see the file changes yet
+# as the binary is unchanged, so the cached contents will still be
+# used.
+gdb_test "list ${bp_line}" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\); /\\\* new-marker \\\*/.*" \
+ "verify that the source code change is not seen yet"
+
+gdb_test "maint flush source-cache" "Source cache flushed\\."
+
+# List the printf line again. After the cache flush GDB will re-read
+# the source file and we should now see the changes.
+gdb_test "list ${bp_line}" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\); /\\\* new-marker updated \\\*/.*" \
+ "verify that the updated source code change is not seen"