]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Implement breakpoint_find_if
authorSergio Durigan Junior <sergiodj@redhat.com>
Wed, 11 Mar 2015 18:09:51 +0000 (14:09 -0400)
committerSergio Durigan Junior <sergiodj@redhat.com>
Wed, 11 Mar 2015 18:13:49 +0000 (14:13 -0400)
This commit implements the 'breakpoint_find_if' function, which allows
code external to gdb/breakpoint.c to iterate through the list of
'struct breakpoint *'.  This is needed in order to create the
'gdb/break-catch-syscall.c' file, because one of its functions
(catching_syscall_number) needs to do this iteration.

My first thought was to share the ALL_BREAKPOINTS* macros on
gdb/breakpoint.h, but they use a global variable local to
gdb/breakpoint.c, and I did not want to share that variable.  So, in
order to keep the minimal separation, I decided to implement this
way of iterating through the existing 'struct breakpoint *'.

This function was based on BFD's bfd_sections_find_if.  If the
user-provided function returns 0, the iteration proceeds.  Otherwise,
the iteration stops and the function returns the 'struct breakpoint *'
that is being processed.  This means that the return value of this
function can be either NULL or a pointer to a 'struct breakpoint'.

gdb/ChangeLog:
2015-03-11  Sergio Durigan Junior  <sergiodj@redhat.com>

* breakpoint.c (breakpoint_find_if): New function.
* breakpoint.h (breakpoint_find_if): New prototype.

gdb/ChangeLog
gdb/breakpoint.c
gdb/breakpoint.h

index 8aa3862cc9fdd9698ad6fc9a502762cccb7cae02..ca9fc1587cb2bbc704c83a1339c5d3b58384393a 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-11  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       * breakpoint.c (breakpoint_find_if): New function.
+       * breakpoint.h (breakpoint_find_if): New prototype.
+
 2015-03-11  Gary Benson <gbenson@redhat.com>
 
        * remote-fileio.h (remote_fileio_to_host_stat): New declaration.
index 923523ee271044cdded7d8fe49050d06de247dbd..c0ab1d76241d90be28f88baf0731213598de7faf 100644 (file)
@@ -644,6 +644,23 @@ 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)
+{
+  struct breakpoint *b = NULL;
+
+  ALL_BREAKPOINTS (b)
+    {
+      if (func (b, user_data) != 0)
+       break;
+    }
+
+  return b;
+}
+
 /* Return whether a breakpoint is an active enabled breakpoint.  */
 static int
 breakpoint_enabled (struct breakpoint *b)
index 85c224081722f2333608d662167c41e11a3a08bf..b85939aaf07ffd282881f0097ca63f81d89e14cb 100644 (file)
@@ -825,6 +825,20 @@ struct watchpoint
   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.  */