From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 03/13 v2] Add iterate_over_lwps to gdbserver
Date: Thu, 09 Oct 2014 10:18:00 -0000 [thread overview]
Message-ID: <1412848358-9958-4-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1412848358-9958-1-git-send-email-gbenson@redhat.com>
This commit introduces a new function, iterate_over_lwps, that
shared Linux code can use to call a function for each LWP that
matches certain criteria. This function already existed in GDB
and was in use by GDB's various low-level Linux x86 debug register
setters. An equivalent was written for gdbserver and gdbserver's
low-level Linux x86 debug register setters were modified to use
it.
gdb/ChangeLog:
* linux-nat.h: Include nat/linux-nat.h.
(iterate_over_lwps): Move declaration to nat/linux-nat.h.
* nat/linux-nat.h (struct lwp_info): New forward declaration.
(iterate_over_lwps_ftype): New typedef.
(iterate_over_lwps): New declaration.
* linux-nat.h (iterate_over_lwps): Update comment. Use
iterate_over_lwps_ftype. Update callback return value check.
gdb/gdbserver/ChangeLog:
* linux-low.h: Include nat/linux-nat.h.
* linux-low.c (iterate_over_lwps_args): New structure.
(iterate_over_lwps_filter): New function.
(iterate_over_lwps): Likewise.
* linux-x86-low.c (update_debug_registers_callback):
Updated signature to what iterate_over_lwps expects.
Remove PID check that iterate_over_lwps now performs.
(x86_dr_low_set_addr): Use iterate_over_lwps.
(x86_dr_low_set_control): Likewise.
---
gdb/ChangeLog | 10 +++++++
gdb/gdbserver/ChangeLog | 12 +++++++++
gdb/gdbserver/linux-low.c | 54 +++++++++++++++++++++++++++++++++++++++++
gdb/gdbserver/linux-low.h | 1 +
gdb/gdbserver/linux-x86-low.c | 33 +++++++++----------------
gdb/linux-nat.c | 9 ++----
gdb/linux-nat.h | 8 +-----
gdb/nat/linux-nat.h | 15 +++++++++++
8 files changed, 108 insertions(+), 34 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 6e1ed8a..c980d10 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1304,6 +1304,60 @@ num_lwps (int pid)
return count;
}
+/* The arguments passed to iterate_over_lwps. */
+
+struct iterate_over_lwps_args
+{
+ /* The FILTER argument passed to iterate_over_lwps. */
+ ptid_t filter;
+
+ /* The CALLBACK argument passed to iterate_over_lwps. */
+ iterate_over_lwps_ftype *callback;
+
+ /* The DATA argument passed to iterate_over_lwps. */
+ void *data;
+};
+
+/* Callback for find_inferior used by iterate_over_lwps to filter
+ calls to the callback supplied to that function. Returning a
+ nonzero value causes find_inferiors to stop iterating and return
+ the current inferior_list_entry. Returning zero indicates that
+ find_inferiors should continue iterating. */
+
+static int
+iterate_over_lwps_filter (struct inferior_list_entry *entry, void *args_p)
+{
+ struct iterate_over_lwps_args *args
+ = (struct iterate_over_lwps_args *) args_p;
+
+ if (ptid_match (entry->id, args->filter))
+ {
+ struct thread_info *thr = (struct thread_info *) entry;
+ struct lwp_info *lwp = get_thread_lwp (thr);
+
+ return (*args->callback) (lwp, args->data);
+ }
+
+ return 0;
+}
+
+/* See nat/linux-nat.h. */
+
+struct lwp_info *
+iterate_over_lwps (ptid_t filter,
+ iterate_over_lwps_ftype callback,
+ void *data)
+{
+ struct iterate_over_lwps_args args = {filter, callback, data};
+ struct inferior_list_entry *entry;
+
+ entry = find_inferior (&all_threads, iterate_over_lwps_filter, &args);
+ if (entry == NULL)
+ return NULL;
+
+ return get_thread_lwp ((struct thread_info *) entry);
+}
+
/* Detect zombie thread group leaders, and "exit" them. We can't reap
their exits until all other threads in the group have exited. */
diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h
index 4820929..11d73f3 100644
--- a/gdb/gdbserver/linux-low.h
+++ b/gdb/gdbserver/linux-low.h
@@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#include "nat/linux-nat.h"
#include "nat/gdb_thread_db.h"
#include <signal.h>
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index e8c6a9c..a861872 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -562,25 +562,16 @@ x86_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
}
static int
-update_debug_registers_callback (struct inferior_list_entry *entry,
- void *pid_p)
+update_debug_registers_callback (struct lwp_info *lwp, void *arg)
{
- struct thread_info *thr = (struct thread_info *) entry;
- struct lwp_info *lwp = get_thread_lwp (thr);
- int pid = *(int *) pid_p;
+ /* The actual update is done later just before resuming the lwp,
+ we just mark that the registers need updating. */
+ lwp->arch_private->debug_registers_changed = 1;
- /* Only update the threads of this process. */
- if (pid_of (thr) == pid)
- {
- /* The actual update is done later just before resuming the lwp,
- we just mark that the registers need updating. */
- lwp->arch_private->debug_registers_changed = 1;
-
- /* If the lwp isn't stopped, force it to momentarily pause, so
- we can update its debug registers. */
- if (!lwp->stopped)
- linux_stop_lwp (lwp);
- }
+ /* If the lwp isn't stopped, force it to momentarily pause, so
+ we can update its debug registers. */
+ if (!lwp->stopped)
+ linux_stop_lwp (lwp);
return 0;
}
@@ -591,11 +582,11 @@ static void
x86_dr_low_set_addr (int regnum, CORE_ADDR addr)
{
/* Only update the threads of this process. */
- int pid = pid_of (current_thread);
+ ptid_t pid_ptid = pid_to_ptid (ptid_get_pid (current_lwp_ptid ()));
gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR);
- find_inferior (&all_threads, update_debug_registers_callback, &pid);
+ iterate_over_lwps (pid_ptid, update_debug_registers_callback, NULL);
}
/* Return the inferior's debug register REGNUM. */
@@ -614,9 +605,9 @@ static void
x86_dr_low_set_control (unsigned long control)
{
/* Only update the threads of this process. */
- int pid = pid_of (current_thread);
+ ptid_t pid_ptid = pid_to_ptid (ptid_get_pid (current_lwp_ptid ()));
- find_inferior (&all_threads, update_debug_registers_callback, &pid);
+ iterate_over_lwps (pid_ptid, update_debug_registers_callback, NULL);
}
/* Return the inferior's DR7 debug control register. */
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 7d84589..1353d43 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -828,14 +828,11 @@ find_lwp_pid (ptid_t ptid)
return NULL;
}
-/* Call CALLBACK with its second argument set to DATA for every LWP in
- the list. If CALLBACK returns 1 for a particular LWP, return a
- pointer to the structure describing that LWP immediately.
- Otherwise return NULL. */
+/* See nat/linux-nat.h. */
struct lwp_info *
iterate_over_lwps (ptid_t filter,
- int (*callback) (struct lwp_info *, void *),
+ iterate_over_lwps_ftype callback,
void *data)
{
struct lwp_info *lp, *lpnext;
@@ -846,7 +843,7 @@ iterate_over_lwps (ptid_t filter,
if (ptid_match (lp->ptid, filter))
{
- if ((*callback) (lp, data))
+ if ((*callback) (lp, data) != 0)
return lp;
}
}
diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
index 0aa8377..0195c5a 100644
--- a/gdb/linux-nat.h
+++ b/gdb/linux-nat.h
@@ -17,8 +17,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#include "nat/linux-nat.h"
#include "target.h"
-
#include <signal.h>
struct arch_lwp_info;
@@ -126,12 +126,6 @@ extern int lin_lwp_attach_lwp (ptid_t ptid);
extern void linux_stop_lwp (struct lwp_info *lwp);
-/* Iterator function for lin-lwp's lwp list. */
-struct lwp_info *iterate_over_lwps (ptid_t filter,
- int (*callback) (struct lwp_info *,
- void *),
- void *data);
-
/* Create a prototype generic GNU/Linux target. The client can
override it with local methods. */
struct target_ops * linux_target (void);
diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h
index 71d4ee8..a2a0a98 100644
--- a/gdb/nat/linux-nat.h
+++ b/gdb/nat/linux-nat.h
@@ -20,6 +20,8 @@
#ifndef LINUX_NAT_H
#define LINUX_NAT_H
+struct lwp_info;
+
/* Unlike other extended result codes, WSTOPSIG (status) on
PTRACE_O_TRACESYSGOOD syscall events doesn't return SIGTRAP, but
instead SIGTRAP with bit 7 set. */
@@ -30,4 +32,17 @@
extern ptid_t current_lwp_ptid (void);
+/* Function type for the CALLBACK argument of iterate_over_lwps. */
+typedef int (iterate_over_lwps_ftype) (struct lwp_info *lwp, void *arg);
+
+/* Iterate over all LWPs. Calls CALLBACK with its second argument set
+ to DATA for every LWP in the list. If CALLBACK returns nonzero for
+ a particular LWP, return a pointer to the structure describing that
+ LWP immediately. Otherwise return NULL. This function must be
+ provided by the client. */
+
+extern struct lwp_info *iterate_over_lwps (ptid_t filter,
+ iterate_over_lwps_ftype callback,
+ void *data);
+
#endif /* LINUX_NAT_H */
--
1.7.1
next prev parent reply other threads:[~2014-10-09 10:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-09 9:53 [PATCH 00/13 v2] Refactor low-level Linux x86 debug register code Gary Benson
2014-10-09 9:53 ` [PATCH 02/13 v2] Add x86_debug_reg_state to gdbserver Gary Benson
2014-10-28 12:56 ` Pedro Alves
2014-10-09 9:53 ` [PATCH 04/13 v2] Make linux_stop_lwp be a shared function Gary Benson
2014-10-28 12:56 ` Pedro Alves
2014-10-09 9:53 ` [PATCH 01/13 v2] Introduce current_lwp_ptid Gary Benson
2014-10-28 12:56 ` Pedro Alves
2014-10-28 16:44 ` Doug Evans
2014-10-28 17:12 ` Doug Evans
2014-10-28 17:13 ` Doug Evans
2014-10-28 18:35 ` Pedro Alves
2014-10-28 19:43 ` Doug Evans
2014-10-31 18:57 ` Doug Evans
2014-10-09 9:54 ` [PATCH 12/13 v2] Move low-level Linux x86 debug register code to a shared file Gary Benson
2014-10-28 13:01 ` Pedro Alves
2014-10-09 10:18 ` [PATCH 05/13 v2] Introduce basic LWP accessors Gary Benson
2014-10-28 12:57 ` Pedro Alves
2014-10-09 10:18 ` [PATCH 07/13 v2] Make lwp_info.arch_private handling shared Gary Benson
2014-10-28 12:57 ` Pedro Alves
2014-10-09 10:18 ` Gary Benson [this message]
2014-10-28 12:56 ` [PATCH 03/13 v2] Add iterate_over_lwps to gdbserver Pedro Alves
2014-10-09 10:21 ` [PATCH 10/13 v2] Linux x86 low-level debug register comment synchronization Gary Benson
2014-10-28 12:59 ` Pedro Alves
2014-10-09 10:21 ` [PATCH 08/13 v2] Rename gdbserver's low-level Linux x86 debug register accessors Gary Benson
2014-10-28 12:58 ` Pedro Alves
2014-10-09 10:35 ` [PATCH 11/13 v2] Introduce x86_linux_update_debug_registers Gary Benson
2014-10-28 13:00 ` Pedro Alves
2014-10-09 10:35 ` [PATCH 06/13 v2] Change signature of linux_target_ops.new_thread Gary Benson
2014-10-28 12:57 ` Pedro Alves
2014-10-09 10:44 ` [PATCH 13/13 v2] Move duplicated Linux x86 code to nat/x86-linux.c Gary Benson
2014-10-28 13:01 ` Pedro Alves
2014-10-09 10:44 ` [PATCH 09/13 v2] Linux x86 low-level debug register code synchronization Gary Benson
2014-10-28 12:59 ` Pedro Alves
2015-03-24 14:11 ` [pushed] Refactor low-level Linux x86 debug register code Gary Benson
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=1412848358-9958-4-git-send-email-gbenson@redhat.com \
--to=gbenson@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