public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Enze Li <lienze@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb: fix using clear command to delete non-user breakpoints(PR cli/7161)
Date: Mon, 18 Apr 2022 14:07:22 +0000 (GMT)	[thread overview]
Message-ID: <20220418140722.9FCED3858D28@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a5c69b1e49bae4d0dcb20f324cebb310c63495c6

commit a5c69b1e49bae4d0dcb20f324cebb310c63495c6
Author: Enze Li <lienze2010@hotmail.com>
Date:   Sun Apr 17 15:09:46 2022 +0800

    gdb: fix using clear command to delete non-user breakpoints(PR cli/7161)
    
    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

Diff:
---
 gdb/breakpoint.c                             |  3 +-
 gdb/testsuite/gdb.base/clear_non_user_bp.exp | 64 ++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)

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..d7bb8ab7e9a
--- /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 <http://www.gnu.org/licenses/>.
+
+# 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 $var" "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.base/main.c instead of adding a new one.
+if  { [gdb_compile "${srcdir}/${subdir}/main.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 main.c:21" \
+    ".*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"
+


                 reply	other threads:[~2022-04-18 14:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220418140722.9FCED3858D28@sourceware.org \
    --to=lienze@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).