public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Enze Li <lienze2010@hotmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdb: prevent the use of the clear command to remove the internal breakpoint (PR cli/7161)
Date: Mon, 14 Mar 2022 20:24:06 +0800	[thread overview]
Message-ID: <MEAP282MB02934158E060B08C8A69930EDD0F9@MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM> (raw)

This patch fixes the PR cli/7161 - "clear command removes internal
breakpoints".

In this patch, a new function "internal_breakpoint" is added to
determine whether the breakpoint is internal or not.  If the
breakpoint is internal when using the clear command, no action will
be taken, thus preventing the use of the clear command to remove
the interal breakpoint.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7161
---
 gdb/breakpoint.c | 10 +++++++++-
 gdb/breakpoint.h |  3 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a3cfeea6989..08628d885e7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -6477,6 +6477,13 @@ pending_breakpoint_p (struct breakpoint *b)
   return b->loc == NULL;
 }
 
+/* See breakpoint.h.  */
+bool
+internal_breakpoint (struct breakpoint *b)
+{
+  return b->ops == &internal_breakpoint_ops;
+}
+
 /* Print information on breakpoints (including watchpoints and tracepoints).
 
    If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
@@ -10979,7 +10986,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)
+	      && !internal_breakpoint (b))
 	    {
 	      for (bp_location *loc : b->locations ())
 		{
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index ba28219c236..c6ddfb0b87a 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1752,6 +1752,9 @@ extern int user_breakpoint_p (struct breakpoint *);
 /* Return true if this breakpoint is pending, false if not.  */
 extern int pending_breakpoint_p (struct breakpoint *);
 
+/* Return true if this breakpoint is internal, false if not.  */
+extern bool internal_breakpoint (struct breakpoint *b);
+
 /* Attempt to determine architecture of location identified by SAL.  */
 extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
 
-- 
2.35.1


             reply	other threads:[~2022-03-14 12:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 12:24 Enze Li [this message]
2022-03-14 13:53 ` Pedro Alves
2022-03-17 14:30   ` Enze Li
2022-03-14 13:55 ` Tom Tromey

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=MEAP282MB02934158E060B08C8A69930EDD0F9@MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM \
    --to=lienze2010@hotmail.com \
    --cc=gdb-patches@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).