From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2147.outbound.protection.outlook.com [40.92.62.147]) by sourceware.org (Postfix) with ESMTPS id 0E30A3858430 for ; Sat, 16 Apr 2022 03:42:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0E30A3858430 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MkHRzcG4sKXwOmPCzwj6tAAeDJ/4qLPPgB3wSG/5ax5PTGc5P4D+HIk7wvda/+Lpua6FlnuqHnh/LP1l6SKe/f923OBEVb/AVfc0/67NcqdXVOAzbVaF6ctvyTyuvSRCdgrUdRnMaYcaX3FUrnNVJi0UdjwIad3epHYm1QxLPTubiMiggOUqkqbGXosPluUGrXdUCPaosUsqyORWST/0WODLCGDZhtD4L4hGbuVtAdj3Cz2DjI2yt/3PtHI8pyBhg2WdF7ufRh4tJwAM0QmdHGnqFyr6PmkI30/5pBIKiXjVEm/5ykafYP5MlwK05c8suwmyOPYxRs1a7oxySXDQOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9dZ6sMk1xNQruQ65rVompoyj7LRpQYu+YoGsr6nuVqk=; b=XvP7JP1EmlbKIQbYbTE29E0i+ydsu6hwyRgqWEo14aN8mqIIPbyiZZ3+HM6E2PuhSHrqeN/mHJSS0b3UVOaLbTuV4cC+TTwhXHWuWakn1N5xyLx5XeP1N0lnphXNESVamUG4BGYbo4IgIuPSoBQMJJFqk9DRc29qIrlyNJA3yxKJF7zkGLI7EmZNTY1SHARv77gbZOxkoG45ZZAEqLqgd72BlAlhcziSPAU1l1wSgdKzpBA5fjT+eX4fLeh79yO6ps3wMsTe4teTYKGd5ueRVkHH9xS/IActIImhdpTJQ/cqqhiAJ8DVy4BrHAHdcubEK6otiaNNs6eO/UgjPEQdYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:71::10) by SY4P282MB4143.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:1c6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Sat, 16 Apr 2022 03:42:17 +0000 Received: from MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM ([fe80::5804:c2bb:bc94:3cec]) by MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM ([fe80::5804:c2bb:bc94:3cec%6]) with mapi id 15.20.5164.020; Sat, 16 Apr 2022 03:42:17 +0000 From: Enze Li To: tom@tromey.com Cc: gdb-patches@sourceware.org Subject: [PATCH v3] gdb: fix using clear command to delete non-user breakpoints(PR cli/7161) Date: Sat, 16 Apr 2022 11:42:03 +0800 Message-ID: X-Mailer: git-send-email 2.35.1 In-Reply-To: <87sfqez4de.fsf@tromey.com> References: <87sfqez4de.fsf@tromey.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [o2okwG4YvWcPjg3UFh/Sm/kcPWVeU6JB] X-ClientProxiedBy: HK2PR0302CA0013.apcprd03.prod.outlook.com (2603:1096:202::23) To MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:71::10) X-Microsoft-Original-Message-ID: <20220416034203.21912-1-lienze2010@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1ed2460c-4df8-400e-97a5-08da1f5b1a8d X-MS-TrafficTypeDiagnostic: SY4P282MB4143:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NdSPKE20PDX7gxkk+qe6u+Dl4TaB0LJLIhLLI+lHWUJaNYrzUKJbTPEZbqwYDGZ+bV3i/PUBXHO+UxnUphjiqhmxl6LxcIh8aLa18HbeDka+lkSF/sXilY8oR985yZw8Ei4a+hOShajdlpWngZI5Vbe3ODA/b2A4dUOX8YNbQ8GEuyY9OgciUwTDFht/Fwcshssbyg5tsaMSxA/iZzt2Wx2ZYmaZGDTaOG27pgTRNOkgytuwV6HgpRFhBy3zQnQv077WvqwCzJjG0myaq7zxajfTqolJfwlAsTnfJeVbWnzKlda42C3bGO9uLCKuN9c6lMWkczEAhSxZbIXywioFvPLKjpYI5GTyUlBwXnBDuPeTpbTH0mUowpQ3fga9KZLT+N/frUEwi0HTbWPr0VoBmY8D4sx+XtSQvPKHR/yXSCHOCxyAxUSS+RT7TgY6v/zQ4koTiM123j7VfpvnVGZDRXoiztMO2SPh9my/4897XVbQL9HyTK80KwtAF5CXja80F0IZv8xhfqTeq1On3N9cXm39sJNmpVaxv8cVm/YyxwyuVHNyoNLlvp8cKu/vd6bKgKU0+r+CDvAlFqZYEX9mUgobM2pwb71uE+JlOs8E35VFXnaO/UsQ/EI/K3tc9F34 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?DLCtbencbGoTmlbOLA6GQ7JlXxALrqnyCeePq0yHAHVbZzpNPVbTzCADZobD?= =?us-ascii?Q?nPmB0Kd9swIZjK+of5xZjQln9mLJW1ApRofxBOCFYlGDnxvlrXSUPTvE0hNi?= =?us-ascii?Q?a/pLeSb4WQ0K0/oagqVQzn7aRbXvh9Ft0kF7EIcfHKgp4PVuc0qgi4tTa75c?= =?us-ascii?Q?IB5SVpWI4fq1KgijIfJE6MUeNRh/h9pIlHAETTiffPQnK5wicBkQzxKi3lYy?= =?us-ascii?Q?51evaEOlReqohzthdd61ryYcTQdBIkb8MeS6LrzMXJvWMg8BeyUANd+tka6x?= =?us-ascii?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/4D5plDppO0/?= =?us-ascii?Q?iyOvcj4z9XaY5pIt1xZoSGimy+4Dt858aTkypDK7V5AZIFYNXAmdICDW2KaV?= =?us-ascii?Q?ZRl6X39swrWVhFDfGzIKXot9pXY5SUIAntu/KCche5fkHQwSb4wkQo8y5Gv8?= =?us-ascii?Q?+8K9ps6SroRRBezh/YdlwTp5TCXMNFzzEZ6Vw2m3GLlYNaTk2yGDlj7HbW+B?= =?us-ascii?Q?M+HHBNVD60C+O5JQe8nWkaS7aS+28B42i0GWuhttC2XpmclocESwqa4ZFvdW?= =?us-ascii?Q?ek4eKv8WYF8=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-746f3.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 1ed2460c-4df8-400e-97a5-08da1f5b1a8d X-MS-Exchange-CrossTenant-AuthSource: MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2022 03:42:17.7287 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY4P282MB4143 X-Spam-Status: No, score=-11.2 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, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Sat, 16 Apr 2022 03:42:24 -0000 The clear command shouldn't delete momentary and internal breakpoints, nor internal breakpoints created via Python's gdb.Breakpoint. This patch fixes this issue and adds a testcase. Regression tested on x86_64 openSUSE Tumbleweed(VERSION_ID="20220413"). Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7161 --- gdb/breakpoint.c | 3 +- gdb/testsuite/gdb.base/clear_non_user_bp.exp | 64 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/clear_non_user_bp.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 1a227e5d120..ff27174b91f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -10921,7 +10921,8 @@ clear_command (const char *arg, int from_tty) { int match = 0; /* Are we going to delete b? */ - if (b->type != bp_none && !is_watchpoint (b)) + if (b->type != bp_none && !is_watchpoint (b) + && user_breakpoint_p (b)) { for (bp_location *loc : b->locations ()) { diff --git a/gdb/testsuite/gdb.base/clear_non_user_bp.exp b/gdb/testsuite/gdb.base/clear_non_user_bp.exp new file mode 100644 index 00000000000..4f0731e06f6 --- /dev/null +++ b/gdb/testsuite/gdb.base/clear_non_user_bp.exp @@ -0,0 +1,64 @@ +# 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 . + +# Regression test for PR gdb/7161. Test that GDB cannot delete non-user +# breakpoints with clear command. + +proc get_maint_info_bp { var } { + global expect_out + global gdb_prompt + + gdb_test_multiple "maint info break -1" "find address of internal bp $var" { + -re ".*(0x\[0-9a-f\]+).*$gdb_prompt $" { + return $expect_out(1,string) + } + timeout { + perror "couldn't find address of $var" + return "" + } + } + return "" +} + +standard_testfile .c + +# this testcase just needs a "Hello world" source file, reuse +# gdb.server/sysroot.c instead of adding a new one. +if { [gdb_compile "${srcdir}/gdb.server/sysroot.c" "${binfile}" executable {debug}] != "" } { + untested "failed to compile" + return -1 +} + +# Start with a fresh gdb. +clean_restart ${binfile} + +if ![runto_main] then { + return 0 +} + +gdb_test "break sysroot.c:23" \ + ".*Breakpoint.* at .*" \ + "set breakpoint" + +set bp_addr [get_maint_info_bp "-1"] + +gdb_test "maint info break -1" \ + "-1.*shlib events.*keep y.*$bp_addr.*" \ + "maint info breakpoint -1 error" + +gdb_test "clear *$bp_addr" \ + "No breakpoint at \\*$bp_addr." \ + "clear internal breakpoint error" + -- 2.35.1