public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: remove breakpoint_find_if
@ 2021-08-30 20:10 Simon Marchi
  2021-08-31  0:22 ` John Baldwin
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2021-08-30 20:10 UTC (permalink / raw)
  To: gdb-patches

Remove breakpoint_find_if, replace its sole usage with using
all_breakpoints directly instead.  At the same time, change return
types to use bool.

Change-Id: I9ec392236b4804b362d16ab563330b9c07311106
---
 gdb/break-catch-syscall.c | 26 ++++++++++++--------------
 gdb/breakpoint.c          | 13 -------------
 gdb/breakpoint.h          | 18 ++----------------
 gdb/infrun.c              |  2 +-
 4 files changed, 15 insertions(+), 44 deletions(-)

diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 78e7079a831b..32736f024ad2 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -486,15 +486,12 @@ catch_syscall_enabled (void)
   return inf_data->total_syscalls_count != 0;
 }
 
-/* Helper function for catching_syscall_number.  If B is a syscall
-   catchpoint for SYSCALL_NUMBER, return 1 (which will make
-   'breakpoint_find_if' return).  Otherwise, return 0.  */
+/* Helper function for catching_syscall_number.  return true if B is a syscall
+   catchpoint for SYSCALL_NUMBER, else false.  */
 
-static int
-catching_syscall_number_1 (struct breakpoint *b,
-			   void *data)
+static bool
+catching_syscall_number_1 (struct breakpoint *b, int syscall_number)
 {
-  int syscall_number = (int) (uintptr_t) data;
 
   if (is_syscall_catchpoint_enabled (b))
     {
@@ -504,22 +501,23 @@ catching_syscall_number_1 (struct breakpoint *b,
 	{
 	  for (int iter : c->syscalls_to_be_caught)
 	    if (syscall_number == iter)
-	      return 1;
+	      return true;
 	}
       else
-	return 1;
+	return true;
     }
 
-  return 0;
+  return false;
 }
 
-int
+bool
 catching_syscall_number (int syscall_number)
 {
-  struct breakpoint *b = breakpoint_find_if (catching_syscall_number_1,
-					 (void *) (uintptr_t) syscall_number);
+  for (breakpoint *b : all_breakpoints ())
+    if (catching_syscall_number_1 (b, syscall_number))
+      return true;
 
-  return b != NULL;
+  return false;
 }
 
 /* Complete syscall names.  Used by "catch syscall".  */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index feca224ccf42..f6c9683aecf1 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -627,19 +627,6 @@ static struct cmd_list_element *breakpoint_set_cmdlist;
 static struct cmd_list_element *breakpoint_show_cmdlist;
 struct cmd_list_element *save_cmdlist;
 
-/* See declaration at breakpoint.h.  */
-
-struct breakpoint *
-breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
-		    void *user_data)
-{
-  for (breakpoint *b : all_breakpoints ())
-    if (func (b, user_data) != 0)
-      return b;
-
-  return nullptr;
-}
-
 /* Return whether a breakpoint is an active enabled breakpoint.  */
 static int
 breakpoint_enabled (struct breakpoint *b)
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index ab65f41a91b5..2b15622f98d2 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -885,20 +885,6 @@ struct watchpoint : public breakpoint
   CORE_ADDR hw_wp_mask;
 };
 
-/* Given a function FUNC (struct breakpoint *B, void *DATA) and
-   USER_DATA, call FUNC for every known breakpoint passing USER_DATA
-   as argument.
-
-   If FUNC returns 1, the loop stops and the current
-   'struct breakpoint' being processed is returned.  If FUNC returns
-   zero, the loop continues.
-
-   This function returns either a 'struct breakpoint' pointer or NULL.
-   It was based on BFD's bfd_sections_find_if function.  */
-
-extern struct breakpoint *breakpoint_find_if
-  (int (*func) (struct breakpoint *b, void *d), void *user_data);
-
 /* Return true if BPT is either a software breakpoint or a hardware
    breakpoint.  */
 
@@ -1678,8 +1664,8 @@ extern int catch_syscall_enabled (void);
 
 /* Checks if we are catching syscalls with the specific
    syscall_number.  Used for "filtering" the catchpoints.
-   Returns 0 if not, greater than 0 if we are.  */
-extern int catching_syscall_number (int syscall_number);
+   Returns false if not, true if we are.  */
+extern bool catching_syscall_number (int syscall_number);
 
 /* Return a tracepoint with the given number if found.  */
 extern struct tracepoint *get_tracepoint (int num);
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 5ee650fa4645..694bbe665f4b 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4458,7 +4458,7 @@ handle_syscall_event (struct execution_control_state *ecs)
   ecs->event_thread->set_stop_pc (regcache_read_pc (regcache));
 
   if (catch_syscall_enabled () > 0
-      && catching_syscall_number (syscall_number) > 0)
+      && catching_syscall_number (syscall_number))
     {
       infrun_debug_printf ("syscall number=%d", syscall_number);
 
-- 
2.33.0


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

* Re: [PATCH] gdb: remove breakpoint_find_if
  2021-08-30 20:10 [PATCH] gdb: remove breakpoint_find_if Simon Marchi
@ 2021-08-31  0:22 ` John Baldwin
  2021-08-31 14:03   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: John Baldwin @ 2021-08-31  0:22 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 8/30/21 1:10 PM, Simon Marchi via Gdb-patches wrote:
> Remove breakpoint_find_if, replace its sole usage with using
> all_breakpoints directly instead.  At the same time, change return
> types to use bool.

Looks good to me.

-- 
John Baldwin

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

* Re: [PATCH] gdb: remove breakpoint_find_if
  2021-08-31  0:22 ` John Baldwin
@ 2021-08-31 14:03   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2021-08-31 14:03 UTC (permalink / raw)
  To: John Baldwin, gdb-patches



On 2021-08-30 8:22 p.m., John Baldwin wrote:
> On 8/30/21 1:10 PM, Simon Marchi via Gdb-patches wrote:
>> Remove breakpoint_find_if, replace its sole usage with using
>> all_breakpoints directly instead.  At the same time, change return
>> types to use bool.
> 
> Looks good to me.

Pushed, thanks.

Simon

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

end of thread, other threads:[~2021-08-31 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 20:10 [PATCH] gdb: remove breakpoint_find_if Simon Marchi
2021-08-31  0:22 ` John Baldwin
2021-08-31 14:03   ` Simon Marchi

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