public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Sergio Durigan Junior <sergiodj@redhat.com>
Subject: [PATCH 1/2] Implement breakpoint_find_if
Date: Tue, 10 Mar 2015 23:28:00 -0000	[thread overview]
Message-ID: <1426030105-15485-2-git-send-email-sergiodj@redhat.com> (raw)
In-Reply-To: <1426030105-15485-1-git-send-email-sergiodj@redhat.com>

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-10  Sergio Durigan Junior  <sergiodj@redhat.com>

	* breakpoint.c (breakpoint_find_if): New function.
	* breakpoint.h (breakpoint_find_if): New prototype.
---
 gdb/breakpoint.c | 17 +++++++++++++++++
 gdb/breakpoint.h | 14 ++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 923523e..c0ab1d7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -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)
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 85c2240..b85939a 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -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.  */
 
-- 
1.9.3

  reply	other threads:[~2015-03-10 23:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-10 23:28 [PATCH 0/2] Separate syscall catchpoint code from gdb/breakpoint.c Sergio Durigan Junior
2015-03-10 23:28 ` Sergio Durigan Junior [this message]
2015-03-11 11:22   ` [PATCH 1/2] Implement breakpoint_find_if Yao Qi
2015-03-11 18:18     ` Sergio Durigan Junior
2015-03-10 23:28 ` [PATCH 2/2] Create gdb/break-catch-syscall.c Sergio Durigan Junior
2015-03-11 11:32   ` Yao Qi
2015-03-11 18:15     ` Sergio Durigan Junior

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=1426030105-15485-2-git-send-email-sergiodj@redhat.com \
    --to=sergiodj@redhat.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).