public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: prevent the use of the clear command to remove the internal breakpoint (PR cli/7161)
@ 2022-03-14 12:24 Enze Li
  2022-03-14 13:53 ` Pedro Alves
  2022-03-14 13:55 ` Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: Enze Li @ 2022-03-14 12:24 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-17 14:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 12:24 [PATCH] gdb: prevent the use of the clear command to remove the internal breakpoint (PR cli/7161) Enze Li
2022-03-14 13:53 ` Pedro Alves
2022-03-17 14:30   ` Enze Li
2022-03-14 13:55 ` Tom Tromey

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).