aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2020-11-20 19:34:21 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2020-12-13 12:36:16 +0000
commitee9812a00153ad788319dae1cde901cf216f9fba (patch)
treef70cd83590cd7d42a6e81d6f7958bce5b40a1d45
parent50a5f1878e22b09ebea30ad60a2164b80af6efdb (diff)
downloadgdb-ee9812a00153ad788319dae1cde901cf216f9fba.zip
gdb-ee9812a00153ad788319dae1cde901cf216f9fba.tar.gz
gdb-ee9812a00153ad788319dae1cde901cf216f9fba.tar.bz2
gdb: new command 'maint flush dcache'
Add a new command to flush the dcache. gdb/ChangeLog: * NEWS: Mention new commands. * target-dcache.c: Add 'cli/cli-cmds.h' include. (maint_flush_dcache_command): New function. (_initialize_target_dcache): Create new 'maint flush dcache' command. gdb/doc/ChangeLog: * gdb.texinfo (Caching Target Data): Document 'maint flush dcache'. gdb/testsuite/ChangeLog: * gdb.base/dcache-flush.c: New file. * gdb.base/dcache-flush.exp: New file.
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/NEWS3
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo6
-rw-r--r--gdb/target-dcache.c19
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/dcache-flush.c33
-rw-r--r--gdb/testsuite/gdb.base/dcache-flush.exp64
8 files changed, 143 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f7ca2c9..80dc1e0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2020-12-13 Andrew Burgess <andrew.burgess@embecosm.com>
+ * NEWS: Mention new commands.
+ * target-dcache.c: Add 'cli/cli-cmds.h' include.
+ (maint_flush_dcache_command): New function.
+ (_initialize_target_dcache): Create new 'maint flush dcache'
+ command.
+
+2020-12-13 Andrew Burgess <andrew.burgess@embecosm.com>
+
* NEWS: Mention new commands, and that the old commands are now
deprecated.
* cli/cli-cmds.c (maintenanceflushlist): Define.
diff --git a/gdb/NEWS b/gdb/NEWS
index 4d96388..66702862 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -44,6 +44,9 @@ maintenance flush register-cache
These new commands are equivalent to the already existing commands
'maintenance flush-symbol-cache' and 'flushregs' respectively.
+maintenance flush dcache
+ A new command to flush the dcache.
+
* Changed commands
break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6ad728e..5650974 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,10 @@
2020-12-13 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb.texinfo (Caching Target Data): Document 'maint flush
+ dcache'.
+
+2020-12-13 Andrew Burgess <andrew.burgess@embecosm.com>
+
* gdb.texinfo (Symbols): Document 'maint flush symbol-cache'.
(Maintenance Commands): Document 'maint flush register-cache'.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 5bafb9d..5b6ac854 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -13494,6 +13494,12 @@ Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
@kindex show dcache line-size
Show default size of dcache lines.
+@item maint flush dcache
+@cindex dcache, flushing
+@kindex maint flush dcache
+Flush the contents (if any) of the dcache. This maintainer command is
+useful when debugging the dcache implementation.
+
@end table
@node Searching Memory
diff --git a/gdb/target-dcache.c b/gdb/target-dcache.c
index 0226d67..90b60f6 100644
--- a/gdb/target-dcache.c
+++ b/gdb/target-dcache.c
@@ -19,6 +19,7 @@
#include "target-dcache.h"
#include "gdbcmd.h"
#include "progspace.h"
+#include "cli/cli-cmds.h"
/* The target dcache is kept per-address-space. This key lets us
associate the cache with the address space. */
@@ -152,6 +153,16 @@ code_cache_enabled_p (void)
return code_cache_enabled;
}
+/* Implement the 'maint flush dcache' command. */
+
+static void
+maint_flush_dcache_command (const char *command, int from_tty)
+{
+ target_dcache_invalidate ();
+ if (from_tty)
+ printf_filtered (_("The dcache was flushed.\n"));
+}
+
void _initialize_target_dcache ();
void
_initialize_target_dcache ()
@@ -178,4 +189,12 @@ access is on."),
set_code_cache,
show_code_cache,
&setlist, &showlist);
+
+ add_cmd ("dcache", class_maintenance, maint_flush_dcache_command,
+ _("\
+Force gdb to flush its target memory data cache.\n\
+\n\
+The dcache caches all target memory accesses where possible, this\n\
+includes the stack-cache and the code-cache."),
+ &maintenanceflushlist);
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 130de8a..3411f6c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2020-12-13 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb.base/dcache-flush.c: New file.
+ * gdb.base/dcache-flush.exp: New file.
+
+2020-12-13 Andrew Burgess <andrew.burgess@embecosm.com>
+
* gdb.base/c-linkage-name.exp: Update to use new 'maint flush ...'
commands.
* gdb.base/killed-outside.exp: Likewise.
diff --git a/gdb/testsuite/gdb.base/dcache-flush.c b/gdb/testsuite/gdb.base/dcache-flush.c
new file mode 100644
index 0000000..b512ea3
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dcache-flush.c
@@ -0,0 +1,33 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2020 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 __attribute__((noinline))
+func (int *v1, int *v2)
+{
+ return *v1 - *v2 - 1;
+}
+
+int
+main ()
+{
+ int var1 = 4;
+ int var2 = 3;
+ int res;
+
+ res = func (&var1, &var2);
+ return res;
+}
diff --git a/gdb/testsuite/gdb.base/dcache-flush.exp b/gdb/testsuite/gdb.base/dcache-flush.exp
new file mode 100644
index 0000000..6c7d2f4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dcache-flush.exp
@@ -0,0 +1,64 @@
+# Copyright 2020 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 the dcache can be flushed.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile}] } {
+ return -1
+}
+
+if ![runto func] {
+ return -1
+}
+
+gdb_test "up" ".* main .*"
+gdb_test "p var1" " = 4"
+gdb_test "p var2" " = 3"
+
+# By reading var1 and var2 we should have at least one line in the
+# dcache.
+gdb_test "info dcache" \
+ [multi_line \
+ "Dcache $decimal lines of $decimal bytes each." \
+ "Contains data for process $decimal" \
+ "Line 0: address $hex \[$decimal hits\].*" \
+ "Cache state: $decimal active lines, $decimal hits" ] \
+ "check dcache before flushing"
+
+# Flush the dcache.
+gdb_test "maint flush dcache" "The dcache was flushed\."
+
+# Check the dcache is now empty.
+gdb_test "info dcache" \
+ [multi_line "Dcache $decimal lines of $decimal bytes each." \
+ "No data cache available." ] \
+ "check dcache after flushing"
+
+# Read the stack variables again, refilling the dcache.
+with_test_prefix "refilling" {
+ gdb_test "p var1" " = 4"
+ gdb_test "p var2" " = 3"
+}
+
+# And check we have some content back in the dcache.
+gdb_test "info dcache" \
+ [multi_line \
+ "Dcache $decimal lines of $decimal bytes each." \
+ "Contains data for process $decimal" \
+ "Line 0: address $hex \[$decimal hits\].*" \
+ "Cache state: $decimal active lines, $decimal hits" ] \
+ "check dcache before refilling"