From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CEE903858D37 for ; Wed, 21 Sep 2022 13:44:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CEE903858D37 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-657--8JvvZPCPuGUlb3e7MOOyA-1; Wed, 21 Sep 2022 09:44:13 -0400 X-MC-Unique: -8JvvZPCPuGUlb3e7MOOyA-1 Received: by mail-ed1-f69.google.com with SMTP id z2-20020a056402274200b004516734e755so4454193edd.3 for ; Wed, 21 Sep 2022 06:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=zHVMG7Y3/YWlkdZfQg43eLjDD5oHAPEnE+fJTkcpIZY=; b=ElwVEbfi+kxgRHGxnaKCcY1AjBz7P0kMCJe31do6zWRz0mRFSfQJlAy8bxwKHX6CFV sIZwAAt/mmr3C/O2f6Mu6JCE7q/6Fi2dNUHMl5xen13lAPpnEoiVR/iNHsJprg9LdHxt o2175Z8al8CTOoW4WD/BAvOkTyYPsSTmeacvIKh+8EPH/rI1PhkBVOswfpFIrDUCHJOj PksdyySLP7+A05fOa5/xiGwHF+WIeYQzr+Z8TtNffNPNbiO5hkoWB49thX5YZIVO5syv n8cPnYBPFU8h7G0zYrKo9G7rPVfzb0ORYh8Ly7fn3fxEANbVdWCanVF1XR+s3w1VWlQT Qdmg== X-Gm-Message-State: ACrzQf3nSIGg/x0CxO1TTviXJ8u24Stl+FuQvn1n6z4r2GddFck91yJP ou+AKVJugho+V6xl9MtF/Ah4OjddmnwYRmTicaWQp2lqsr/HH5WTksxUtEBsrpoW2GnrhNe7Qnb jkbWNXQ52uugixh6cqalOsg== X-Received: by 2002:a17:907:2cea:b0:77c:59aa:c00f with SMTP id hz10-20020a1709072cea00b0077c59aac00fmr20818353ejc.73.1663767852098; Wed, 21 Sep 2022 06:44:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4voRt+2fUClz35hjZuCJEznYIJuPZkMiewEVhH8loQlIclL7iJ2fXJx5A5Y0t9R+FmldaI3A== X-Received: by 2002:a17:907:2cea:b0:77c:59aa:c00f with SMTP id hz10-20020a1709072cea00b0077c59aac00fmr20818333ejc.73.1663767851782; Wed, 21 Sep 2022 06:44:11 -0700 (PDT) Received: from [192.168.0.45] (ip-213-220-232-121.bb.vodafone.cz. [213.220.232.121]) by smtp.gmail.com with ESMTPSA id c7-20020a056402158700b0045479a91f65sm1830883edv.23.2022.09.21.06.44.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Sep 2022 06:44:11 -0700 (PDT) Message-ID: Date: Wed, 21 Sep 2022 15:44:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH 1/3] [gdb/testsuite] Add gdb.python/py-finish-breakpoint-deletion.exp for Bug 18655 To: Johnson Sun , gdb-patches@sourceware.org References: <20220920172426.90659-1-j3.soon777@gmail.com> <20220920172426.90659-2-j3.soon777@gmail.com> From: Bruno Larsen In-Reply-To: <20220920172426.90659-2-j3.soon777@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-List-Received-Date: Wed, 21 Sep 2022 13:44:18 -0000 On 20/09/2022 19:24, Johnson Sun via Gdb-patches wrote: > This adds a minimal test that will fail (KFAIL) due to not deleting Python FinishBreakpoints. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18655 Hi Johnson! Thanks for working on this! In general, I think it is better to add the testcase in the same patch that fixes the behavior, so I think you can squash this commit into the next one. I also have some comments on code styling, which have been inlined. > --- > .../py-finish-breakpoint-deletion.c | 28 +++++++++++ > .../py-finish-breakpoint-deletion.exp | 47 +++++++++++++++++++ > .../py-finish-breakpoint-deletion.py | 33 +++++++++++++ > 3 files changed, 108 insertions(+) > create mode 100644 gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c > create mode 100644 gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp > create mode 100644 gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py > > diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c > new file mode 100644 > index 00000000000..d2e6783799c > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c > @@ -0,0 +1,28 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2011-2022 Free Software Foundation, Inc. Since the file is only being added in 2022, you can remove the range and just leave 2022 here. Goes for all copyright blurbs. > + > + 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 subroutine(int a) { > + return a; > +} Even for tests, whenever possible, code should follow the GNU coding style, so this function should look like: int subroutine (int a) {   return a; } Same goes for the main function. > + > +int main() { > + int i; > + for (i = 0; i < 5; i++) { > + subroutine(i); > + } > + return 0; > +} > diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp > new file mode 100644 > index 00000000000..778b53fbeda > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp > @@ -0,0 +1,47 @@ > +# Copyright (C) 2011-2022 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 . > + > +# This file is part of the GDB testsuite. It tests the mechanism > +# exposing values to Python. The description of the test here seems a bit off, is it a copy-paste mistake? I think the "check FinishBreakpoints (...)" comment can be used here instead. > + > +load_lib gdb-python.exp > + > +standard_testfile > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { is there a specific reason you decided to compile the testcase as C++ when the code is pure C? > + return -1 > +} > + > +# Skip all tests if Python scripting is not enabled. > +if { [skip_python_tests] } { continue } > + > +if ![runto_main] then { > + return 0 > +} > + > +set pyfile [gdb_remote_download host \ > + ${srcdir}/${subdir}/${testfile}.py] This looks unnecessary, I think you can just "source ${srcdir}/${subdir}/${testfile}.py" down below. > + > +# > +# Check FinishBreakpoints are deleted after used > +# > + > +gdb_test "python print (len(gdb.breakpoints()))" "1" "check default BP count" > +gdb_test "source $pyfile" ".*Python script imported.*" \ > + "import python scripts" change the 8 spaces here for a tab. Cheers, Bruno > +gdb_test "python print (len(gdb.breakpoints()))" "2" "check modified BP count" > +gdb_test "continue" "Breakpoint.*at.*" "run until FinishBreakpoint stops" > +setup_kfail "gdb/18655" "*-*-*" > +gdb_test "python print (len(gdb.breakpoints()))" "2" "check BP count" > diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py > new file mode 100644 > index 00000000000..8146940d41f > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py > @@ -0,0 +1,33 @@ > +# Copyright (C) 2011-2022 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 . > + > +# This file is part of the GDB testsuite. It tests python Finish > +# Breakpoints. > + > + > +class MyFinishBreakpoint(gdb.FinishBreakpoint): > + def stop(self): > + print("stopped at MyFinishBreakpoint") > + return self.return_value == 4 > + > +class MyBreakpoint(gdb.Breakpoint): > + def stop(self): > + print("stopped at MyBreakpoint") > + MyFinishBreakpoint() > + return False > + > +MyBreakpoint("subroutine", internal=True) > + > +print("Python script imported")