From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id DDDE9384F48F for ; Fri, 18 Nov 2022 12:16:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DDDE9384F48F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102a.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso4887961pjc.5 for ; Fri, 18 Nov 2022 04:16:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4vMkG7IFeqEjZccI6islk7YQlHPg/M/i2Mqr+c9/vkQ=; b=M6LwvLlFc6TkqJh7gsA7I8/AepcV/6ZnNWZzzEjCQ3IaLVVO778Zhe10A8OrYdi9/e tpGw6pRq4VsdvIctn/l7m7XDajxiPy6pUq1uK8kBGyK7vdtOjiL5fxFgrcRozu7Qa/Qs SRBg5AfEwWYqrqc1JzU5rN8jFS4f6bztDpJDawweDwTgLjvyOXxeWfcVSNKxGlKPfeVR XSJieE91tNEHefSQp4+3GO9VTtYlKBH/lA1OuJZ4Zd63AHRKK533k8rJF5J8U3uMDIRD olOvg+J1JexZjPNM1VTNo0wTV9KHUdwXTO/Dwf2lkCcdqjTgoBiifi1uhIwLSLz9Ge/Z P7+Q== 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:message-id:reply-to; bh=4vMkG7IFeqEjZccI6islk7YQlHPg/M/i2Mqr+c9/vkQ=; b=ZhwTDSjgDKsez3SGtmr0uwYCKJ9epFpDIPLz+ayDx+esGpkuS3oGdOGrzN3Y9TkxZY V/y1mcFLegE/AHUS8HEE59W2AYosePt/WqY2tam9Ro4wYigon1zLd8pYctJz0vlIuFq8 Q6NVxWGZSpK+ENSkD3j69l12EZSPSOgSmeQ7U+YSrXiC4GV/39JhV6lvree+XMc+yqI1 /PHToHpme9QPOIepDs1K/1x1EiSpquk8ZSJrR9VGhdPZVKcqmm4Cn5OG5xgvz0ToFCr6 5Or/KLt4XvIG/YGHfu/GRgCawIwC/PTy4RGtOA+AGIagISQa/SdlKHXvOK6ZunWFgHV+ jOUQ== X-Gm-Message-State: ANoB5pnah73kWbZEpjzpj9A7wSOQLVn5QhDoLAExrOjlHBBUXrZSCjXV lAVrS0fZXP6GCYFVCE72ZUQ= X-Google-Smtp-Source: AA0mqf7B9C43cagpki58EUynbkXIQa6pNJyTh+g3iYiI5KKFLrZsAZGdxtNsNxMbCkcvCUc3V/4RkA== X-Received: by 2002:a17:902:74c3:b0:188:f571:cea2 with SMTP id f3-20020a17090274c300b00188f571cea2mr5688771plt.146.1668773790720; Fri, 18 Nov 2022 04:16:30 -0800 (PST) Received: from [192.168.0.100] (intel10.cs.nthu.edu.tw. [140.114.89.60]) by smtp.gmail.com with ESMTPSA id u139-20020a627991000000b00561cf757749sm2997345pfc.183.2022.11.18.04.16.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 04:16:30 -0800 (PST) Message-ID: <182bf5c2-6075-1145-462b-703f0fa05ce3@gmail.com> Date: Fri, 18 Nov 2022 20:16:26 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: [PING] [PATCH v4] [PR python/18655] Fix deletion of FinishBreakpoints Content-Language: en-US To: SimonMarchi , BrunoLarsen , gdb-patches@sourceware.org References: <20221020173411.190318-1-j3.soon777@gmail.com> <20221020174917.192860-1-j3.soon777@gmail.com> From: Johnson Sun In-Reply-To: <20221020174917.192860-1-j3.soon777@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: Ping for: . Johnson On 10/21/2022 1:49 AM, Johnson Sun wrote: > Currently, FinishBreakpoints are set at the return address of a frame based on > the `finish' command, and are meant to be temporary breakpoints. However, they > are not being cleaned up after use, as reported in PR python/18655. This was > happening because the disposition of the breakpoint was not being set > correctly. > > This commit fixes this issue by correctly setting the disposition in the > post-stop hook of the breakpoint. It also adds a test to ensure this feature > isn't regressed in the future. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18655 > --- > gdb/python/py-finishbreakpoint.c | 2 +- > .../py-finish-breakpoint-deletion.c | 31 ++++++++++++++ > .../py-finish-breakpoint-deletion.exp | 41 +++++++++++++++++++ > .../py-finish-breakpoint-deletion.py | 32 +++++++++++++++ > 4 files changed, 105 insertions(+), 1 deletion(-) > 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/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c > index c80096f6810..d8b1aff0e2b 100644 > --- a/gdb/python/py-finishbreakpoint.c > +++ b/gdb/python/py-finishbreakpoint.c > @@ -145,7 +145,7 @@ bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj) > { > /* Can't delete it here, but it will be removed at the next stop. */ > disable_breakpoint (bp_obj->bp); > - gdb_assert (bp_obj->bp->disposition == disp_del); > + bp_obj->bp->disposition = disp_del_at_next_stop; > } > catch (const gdb_exception &except) > { > 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..b6e71513373 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c > @@ -0,0 +1,31 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 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 . */ > + > +static int > +subroutine (int a) > +{ > + return a; > +} > + > +int > +main (void) > +{ > + 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..cd882cee91d > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp > @@ -0,0 +1,41 @@ > +# Copyright (C) 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 . > + > +# Check that FinishBreakpoints are deleted after use. > + > +load_lib gdb-python.exp > + > +standard_testfile > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { > + return -1 > +} > + > +# Skip all tests if Python scripting is not enabled. > +if { [skip_python_tests] } { continue } > + > +if ![runto_main] then { > + return 0 > +} > + > +# For remote host testing > +set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] > + > +gdb_test "python print(len(gdb.breakpoints()))" "1" "check default BP count" > +gdb_test "source $pyfile" ".*Python script imported.*" \ > + "import python scripts" > +gdb_test "python print(len(gdb.breakpoints()))" "2" "check modified BP count" > +gdb_test "continue" "Breakpoint.*at.*" "run until FinishBreakpoint stops" > +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..ab05b0c35a3 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py > @@ -0,0 +1,32 @@ > +# Copyright (C) 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 . > + > + > +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")