From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24216 invoked by alias); 11 Feb 2020 11:10:20 -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 24208 invoked by uid 89); 11 Feb 2020 11:10:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.8 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= X-HELO: mail-wm1-f68.google.com Received: from mail-wm1-f68.google.com (HELO mail-wm1-f68.google.com) (209.85.128.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 11:10:17 +0000 Received: by mail-wm1-f68.google.com with SMTP id t23so2965362wmi.1 for ; Tue, 11 Feb 2020 03:10:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=i4nZwPihl6ADnw0QUqoBTPz72+QfU6L3lMtgl9mYHQ0=; b=MZ9MGaVffpNrB359y0UNPRDetVkA28/XpDYmcSP7FpkgYEwaNfRZh2q8MMYpFjnlyC 1fxRyMHmbeo2JZLDs1wVNALhk3he1wAELq5aIT2+bgj2OcF2Gd0foBKg2w/ZoftTuOxC 2OoKFVGiVzArYarAA0rS0x8m0jpGxA+02lTSDEJYRPlTB68d5gVknljQNLNPcrdKeCgI k/2rWr+6Y0lAeiVKmEdab7ucZiugmviS23KA8jO+MDBQATw4U2kSqT/nLpJ0fqlO1nUw 8DfrkXTmw5XYGv8pwROpoklDY5CGAvyjq1LAYAWr0DmfsT/t+br0MFW2DcDGdKMigsFD 1IOg== Return-Path: Received: from localhost (host81-151-181-192.range81-151.btcentralplus.com. [81.151.181.192]) by smtp.gmail.com with ESMTPSA id n3sm4788961wrs.8.2020.02.11.03.10.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Feb 2020 03:10:15 -0800 (PST) Date: Tue, 11 Feb 2020 11:10:00 -0000 From: Andrew Burgess To: Sergio Durigan Junior Cc: GDB Patches , Luis Machado Subject: Re: [PATCH v2] New testcase for PR tui/25126 (staled source cache) Message-ID: <20200211111014.GO4020@embecosm.com> References: <20200206225943.26709-1-sergiodj@redhat.com> <20200210200221.14846-1-sergiodj@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200210200221.14846-1-sergiodj@redhat.com> X-Fortune: Immanuel Kant but Kubla Khan. X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00378.txt.bz2 * Sergio Durigan Junior [2020-02-10 15:02:20 -0500]: > 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-10 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 | 43 ++++++++ > gdb/testsuite/gdb.base/cached-source-file.exp | 99 +++++++++++++++++++ > 2 files changed, 142 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..6f62c29799 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/cached-source-file.c > @@ -0,0 +1,43 @@ > +/* 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 . */ > + > +/* Test for PR tui/25126. > + > + The bug is about a regression that makes GDB not reload its source > + code cache when the inferior's symbols are reloaded, which leads to > + wrong backtraces/listings. > + > + This bug is reproducible even without using the TUI. > + > + 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..f6e5f081f0 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/cached-source-file.exp > @@ -0,0 +1,99 @@ > +# 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 . > + > +# Test for PR tui/25126. > +# > +# The bug is about a regression that makes GDB not reload its source > +# code cache when the inferior's symbols are reloaded, which leads to > +# wrong backtraces/listings. > +# > +# 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 > +# just copy it 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] > + > +gdb_assert { [runto "$srcfile:$bp_line"] } \ > + "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\"); /* new-marker */" > + } > + puts $bkpsrcfd $line > +} > + > +close $bkpsrcfd > +close $srcfd > +file rename -force -- $bkpsrc $srcfile > +# Here, we have to wait 1 second because of the way GDB keeps track to > +# check whether the binary has changed or not. GDB uses stat(2) and > +# currently checks 'st_mtime', whose precision is measured in > +# seconds. Since the whole file-copying/rename operation can take > +# less than 1 second, GDB can mistakenly assume that the binary is > +# still the same if we don't wait here. Maybe rewrite this comment as: We have to wait 1 second because of the way GDB checks whether the binary has changed or not. GDB uses stat(2) and currently checks 'st_mtime', whose precision is measured in seconds. Since the copy, rename, and rebuild can take less than 1 second, GDB might mistakenly assume that the binary is unchanged. Otherwise this looks good to me and can be applied. Thanks, Andrew > +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 > +# source cache, but also to break at BP_LINE 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\"\\); /\\\* new-marker \\\*/.*" \ > + "verify that the source code is properly reloaded" > -- > 2.21.0 >