From 393707788800b05448201fbb184ba758e26960fd Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Fri, 26 Nov 2021 13:51:36 +0000 Subject: gdb: new 'maint flush source-cache' command This commit adds a new 'maint flush source-cache' command, this flushes the cache of source file contents. After flushing GDB is forced to reread source files the next time any source lines are to be displayed. I've added a test for this new feature. The test is a little weird, in that it modifies a source file after compilation, and makes use of the cache flush so that the changes show up when listing the source file. I'm not sure when such a situation would ever crop up in real life, but maybe we can imagine such cases. In reality, this command is useful for testing the syntax highlighting within GDB, we can adjust the syntax highlighting settings, flush the cache, and then get the file contents re-highlighted using the new settings. --- gdb/source-cache.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gdb/source-cache.c') diff --git a/gdb/source-cache.c b/gdb/source-cache.c index fc789ee..0650768 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -25,6 +25,7 @@ #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 @@ -323,6 +324,15 @@ source_cache::get_source_lines (struct symtab *s, int first_line, 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 { @@ -346,6 +356,10 @@ void _initialize_source_cache (); 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 -- cgit v1.1