From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RdoUNx3ju1+mTgAAWB0awg (envelope-from ) for ; Mon, 23 Nov 2020 11:28:13 -0500 Received: by simark.ca (Postfix, from userid 112) id D538B1F0AB; Mon, 23 Nov 2020 11:28:13 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 722E31E58E for ; Mon, 23 Nov 2020 11:28:13 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B4FE38708E4; Mon, 23 Nov 2020 16:28:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B4FE38708E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606148893; bh=NCec+BJNFUbwB28vV+wSWbv334fd8fLqPEx9KrTOTLw=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Zl387KwQsHVvNQobiWcktopYeNA3qytAMUVcA7H+V3ID6ykNsxJi0XExcaAam5awN cvFypxLuY6hNInebz4dbwkrs2OJm2SGgfRNY2kzKZe5EkqoRTNs64Ku3N0UCz/QdLw Te8Sh5VFece9ICoZGhMnWnvlsNhf/ZXn4A7Q84NE= Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 9394A38708E2 for ; Mon, 23 Nov 2020 16:28:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9394A38708E2 Received: by mail-qk1-x744.google.com with SMTP id u184so2900264qkf.3 for ; Mon, 23 Nov 2020 08:28:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NCec+BJNFUbwB28vV+wSWbv334fd8fLqPEx9KrTOTLw=; b=LyFCJz2fASfI3+DMi7f/IH6a8DLIRCNvn9aJrgDVUs/Ih2EgNv5xX7uCPPsV+YzqMo cHdWqz9eULk6x/6amCUFbZVDkOETzpc+Waf8OAhf2zVbDQrUminDJcZiCcPfoXanPRGO h+uuI32lwX1Mua6nKftfqBzfMBsDwGzhTcLostK03HI85Akw155XgqOv+GYEXZF4I7tq WqI03cMBqVC82t8FKWudXghTVDXx6Eygc/8uOm+ZD/jb3T/pvMdkCZeaCzY6SVF5jPrD aj5/S8phbOHHFFxmBfD4Djd/plKbarMBItGdKKtf06WEjlKmb94dW1esGUjulxG0y4YF /YCA== X-Gm-Message-State: AOAM530cvNyCP0e8tV4CgQniHCp3Dgh0JE5mSe4/Y4PbssKt6lYTzpKw XDk9rMeoMXppjYXJWvOFC7NgnLLKCKq1NQ== X-Google-Smtp-Source: ABdhPJxBaEDsiReyEATAkXldFoohDYfLUuTkkkXKHS1Ekr5kNBVsfv/DoOrqIqCLZCjeAOejy5eVVg== X-Received: by 2002:ae9:dc06:: with SMTP id q6mr244512qkf.310.1606148888922; Mon, 23 Nov 2020 08:28:08 -0800 (PST) Received: from ?IPv6:2804:7f0:8284:370e:18fe:65d7:a5d3:1acf? ([2804:7f0:8284:370e:18fe:65d7:a5d3:1acf]) by smtp.gmail.com with ESMTPSA id x2sm4270454qtw.3.2020.11.23.08.28.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Nov 2020 08:28:08 -0800 (PST) Subject: Re: [PATCH 2/2] gdb: new command 'maint flush dcache' To: Andrew Burgess , gdb-patches@sourceware.org References: Message-ID: Date: Mon, 23 Nov 2020 13:28:05 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 11/23/20 7:39 AM, Andrew Burgess wrote: > 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. > --- > gdb/ChangeLog | 8 ++++ > gdb/NEWS | 3 ++ > gdb/doc/ChangeLog | 5 ++ > gdb/doc/gdb.texinfo | 6 +++ > gdb/target-dcache.c | 19 ++++++++ > gdb/testsuite/ChangeLog | 5 ++ > gdb/testsuite/gdb.base/dcache-flush.c | 33 +++++++++++++ > gdb/testsuite/gdb.base/dcache-flush.exp | 64 +++++++++++++++++++++++++ > 8 files changed, 143 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/dcache-flush.c > create mode 100644 gdb/testsuite/gdb.base/dcache-flush.exp > > diff --git a/gdb/NEWS b/gdb/NEWS > index b07b054223f..ef59c7c1e69 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -32,6 +32,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/gdb.texinfo b/gdb/doc/gdb.texinfo > index 3745aa52973..7017823ef75 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -13494,6 +13494,12 @@ > @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 0226d672780..90b60f62f2e 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/gdb.base/dcache-flush.c b/gdb/testsuite/gdb.base/dcache-flush.c > new file mode 100644 > index 00000000000..b512ea31760 > --- /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 . */ > + > +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 00000000000..6c7d2f4bef8 > --- /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 . > + > +# 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" > LGTM