From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84714 invoked by alias); 7 Feb 2020 09:41:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 84702 invoked by uid 89); 7 Feb 2020 09:41:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*p:D*org X-HELO: mail-wm1-f67.google.com Received: from mail-wm1-f67.google.com (HELO mail-wm1-f67.google.com) (209.85.128.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Feb 2020 09:41:16 +0000 Received: by mail-wm1-f67.google.com with SMTP id f129so1950098wmf.2 for ; Fri, 07 Feb 2020 01:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=HbNlSheKqFCkvnEksOPcN10/TkEkhjIIad8k75JVdME=; b=ENb19SJ9ny/E6369DtUWqY4YL0iFVwDxAHAVNldE6NOkmeIxjY3S0ns3+tNci1+xnX 01bQ832epV1lx5TofU8m28ekxUIt+Xo2ikbyqGtJ112omZFn2YfbE8NbCmWwWt8tlNPP x6XUmxTRUGRPhj/tiZG6QTWVu5kQp0AaStAVLigvJSs1lY8fGTP9jcoO1zbLNfSYq4hr 7dPEXAEMg9As1NRpO4Or3IqhyB/+lixSMDBsVPARvRnPlKs2gcx9f8lASnAFz3H/4ukE BwwoQ7WKRheDVPxh967Rb6/uQts5rn4X4gjg+MkDjsfb4vr8UXAUXnDZ6X9/XPnot/qy IlUw== Return-Path: Received: from [10.10.0.24] ([94.107.206.26]) by smtp.gmail.com with ESMTPSA id a6sm2696723wrm.69.2020.02.07.01.41.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Feb 2020 01:41:13 -0800 (PST) Subject: Re: [PATCH] New testcase for PR tui/25126 (staled source cache) To: Sergio Durigan Junior , GDB Patches References: <20200206225943.26709-1-sergiodj@redhat.com> From: Luis Machado Message-ID: <4a3db909-8677-fb84-39cf-84495266fdd8@linaro.org> Date: Fri, 07 Feb 2020 09:41:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200206225943.26709-1-sergiodj@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00148.txt.bz2 On 2/6/20 7:59 PM, Sergio Durigan Junior wrote: > I'm dealing with a Fedora GDB bug that is related to PR tui/25126, and > I thought I'd write a specific testcase for it because I couldn't find > one. > > The idea is to get the simple reproducer from the bug and tweak the > testcase around it. This one was a bit hard because, since we need to > modify the source file and recompile it, it involved a bit of TCL-foo > to do things. Also for this reason, I'm only enabling the test for > native boards. > > I tested this with an upstream GDB and made sure everything is > passing. I also tested with a faulty GDB and made sure the test > failed. > > gdb/testsuite/ChangeLog: > 2020-02-07 Sergio Durigan Junior > > PR tui/25126 > * gdb.base/cached-source-file.c: New file. > * gdb.base/cached-source-file.exp: New file. > > Change-Id: Ib1b074342ebe8613c6d1dfde631691ebdf6d81c6 > --- > gdb/testsuite/gdb.base/cached-source-file.c | 37 ++++++++ > gdb/testsuite/gdb.base/cached-source-file.exp | 94 +++++++++++++++++++ > 2 files changed, 131 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/cached-source-file.c > create mode 100644 gdb/testsuite/gdb.base/cached-source-file.exp > > diff --git a/gdb/testsuite/gdb.base/cached-source-file.c b/gdb/testsuite/gdb.base/cached-source-file.c > new file mode 100644 > index 0000000000..9f698dcffe > --- /dev/null > +++ b/gdb/testsuite/gdb.base/cached-source-file.c > @@ -0,0 +1,37 @@ > +/* 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 . */ > + Instead of pointing at a PR number, wouldn't it be better to state what this particular source file plans to achieve or help achieve? Personally, i find it a bit more useful. Then again, if it is a simple test and it will be obvious from code comments, it shouldn't be necessary. > +/* Test for PR tui/25126. > + > + The .exp testcase depends on the line numbers and contents from > + this file If you change this file, make sure to double-check the > + testcase. */ > + > +#include > + > +void > +foo (void) > +{ > + printf ("hello\n"); /* break-here */ > +} > + > +int > +main () > +{ > + foo (); > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/cached-source-file.exp b/gdb/testsuite/gdb.base/cached-source-file.exp > new file mode 100644 > index 0000000000..f98bec09ca > --- /dev/null > +++ b/gdb/testsuite/gdb.base/cached-source-file.exp > @@ -0,0 +1,94 @@ > +# Copyright (C) 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 . > + Same as above about explaining what the test wants to achieve. > +# Test for PR tui/25126. Would it make the test run fine with remote stubs if the TUI wasn't used? Just wondering. > +# This bug is reproducible even without using the TUI. > + > +standard_testfile > + > +# Only run on native boards. > +if { [use_gdb_stub] || [target_info gdb_protocol] == "extended-remote" } { > + return -1 > +} > + > +# Because we need to modify the source file later, it's better if we Typo... "just copy it to our..." > +# just copy if to our output directory (instead of messing with the > +# user's source directory). > +set newsrc [standard_output_file $testfile].c > +file copy -force -- $srcdir/$subdir/$srcfile $newsrc > +set srcfile $newsrc > + > +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { > + return -1 > +} > + > +# Get the line number for the line with the "break-here" marker. > +set bp_line [gdb_get_line_number "break-here" $srcfile] > + I've learned about it recently, but i think using gdb_assert here would be nice instead of the if/else block. > +if { [runto "$srcfile:$bp_line"] } { > + pass "run to $srcfile:$bp_line" > +} else { > + fail "run to $srcfile:$bp_line" > +} > + > +# Do a "list" and check that the printed line matches the line of the > +# original source file. > +gdb_test_no_output "set listsize 1" > +gdb_test "list" "$bp_line\[ \t\]+printf \\(\"hello\\\\n\"\\); /\\* break-here \\*/" \ > + "check the first version of the source file" > + > +# Modify the original source file, and add an extra line into it. > +# 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 "break-here" $line] != -1 } { > + # Put a "printf" line before the "break-here" line. > + puts $bkpsrcfd " printf (\"foo\\n\");" > + } > + puts $bkpsrcfd $line > +} > + > +close $bkpsrcfd > +close $srcfd > +file rename -force $bkpsrc $srcfile > +# Give it some time to perform the renaming. For some reason, TCL > +# needs some time after "file rename" in order to properly rename the > +# file. In case a system takes longer, should we loop and make sure the renamed file really exists, as opposed to sleeping for just a second? > +sleep 1 > + > +# Recompile the modified source. We use "gdb_compile" here instead of > +# "prepare_for_testing" because we don't want to call "clean_restart". > +if { [gdb_compile "${srcfile}" "${binfile}" executable {debug}] != "" } { > + return -1 > +} > + > +# Rerun the program. This should not only force GDB to reload the I'm guessing line 6 is the one with the "break-here" marker? In that case, should we mention that instead of the line number? Unless the line number is really important. > +# source cache, but also to break at line 6 again, which now has > +# different contents. > +gdb_test_multiple "run" "rerun program" { > + -re {The program being debugged has been started already\.\r\nStart it from the beginning\? \(y or n\) $} { > + set binregex [string_to_regexp $binfile] > + gdb_test "y" "\\`$binregex\\' has changed; re-reading symbols\.\r\nStarting program: ${binregex}.*" \ > + "rerun program" > + } > +} > + > +# Again, perform the listing and check that the line indeed has > +# changed for GDB. > +gdb_test "list" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\);" \ > + "verify that the source code is properly reloaded" > Otherwise LGTM. Thanks!