From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org, binutils@sourceware.org
Subject: [PATCH v3 4/6] Use LWP IDs with ptrace register requests on FreeBSD.
Date: Mon, 18 Jan 2016 02:28:00 -0000 [thread overview]
Message-ID: <1453084047-16175-5-git-send-email-jhb@FreeBSD.org> (raw)
In-Reply-To: <1453084047-16175-1-git-send-email-jhb@FreeBSD.org>
This allows gdb to fetch per-thread registers for multi-threaded FreeBSD
processes.
Export get_ptrace_pid() from inf-ptrace.c and use it to determine the PID
to pass to ptrace in pan-BSD native targets. NetBSD and OpenBSD also accept
LWP IDs for ptrace requests to fetch per-thread state.
gdb/ChangeLog:
* amd64bsd-nat.c (amd64bsd_fetch_inferior_registers): Use
get_ptrace_pid.
(amd64bsd_store_inferior_registers): Use get_ptrace_pid.
(amd64bsd_dr_get): Use get_ptrace_pid.
(amd64bsd_dr_set): Use get_ptrace_pid.
* i386bsd-nat.c (i386bsd_fetch_inferior_registers): Use get_ptrace_pid.
(i386bsd_store_inferior_registers): Use get_ptrace_pid.
(i386bsd_dr_get): Use get_ptrace_pid.
(i386bsd_dr_set): Use get_ptrace_pid.
* inf-ptrace.c (get_ptrace_pid): Export.
* inf-ptrace.h (get_ptrace_pid): Declare.
* ppcfbsd-nat.c (ppcfbsd_fetch_inferior_registers): Use lwp id.
(ppcfbsd_store_inferior_registers): Use lwp id.
---
gdb/ChangeLog | 16 ++++++++++++++++
gdb/amd64bsd-nat.c | 24 ++++++++++++------------
gdb/i386bsd-nat.c | 30 +++++++++++++++---------------
gdb/inf-ptrace.c | 2 +-
gdb/inf-ptrace.h | 5 +++++
gdb/ppcfbsd-nat.c | 12 ++++++------
6 files changed, 55 insertions(+), 34 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8f28959..feed337 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,21 @@
2016-01-16 John Baldwin <jhb@FreeBSD.org>
+ * amd64bsd-nat.c (amd64bsd_fetch_inferior_registers): Use
+ get_ptrace_pid.
+ (amd64bsd_store_inferior_registers): Use get_ptrace_pid.
+ (amd64bsd_dr_get): Use get_ptrace_pid.
+ (amd64bsd_dr_set): Use get_ptrace_pid.
+ * i386bsd-nat.c (i386bsd_fetch_inferior_registers): Use get_ptrace_pid.
+ (i386bsd_store_inferior_registers): Use get_ptrace_pid.
+ (i386bsd_dr_get): Use get_ptrace_pid.
+ (i386bsd_dr_set): Use get_ptrace_pid.
+ * inf-ptrace.c (get_ptrace_pid): Export.
+ * inf-ptrace.h (get_ptrace_pid): Declare.
+ * ppcfbsd-nat.c (ppcfbsd_fetch_inferior_registers): Use lwp id.
+ (ppcfbsd_store_inferior_registers): Use lwp id.
+
+2016-01-16 John Baldwin <jhb@FreeBSD.org>
+
* fbsd_tdep.c (fbsd_core_pid_to_str): New function.
(fbsd_init_abi): Add "core_pid_to_str" gdbarch method.
diff --git a/gdb/amd64bsd-nat.c b/gdb/amd64bsd-nat.c
index aa79c13..fb7e4fa 100644
--- a/gdb/amd64bsd-nat.c
+++ b/gdb/amd64bsd-nat.c
@@ -52,7 +52,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops,
{
struct reg regs;
- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't get registers"));
@@ -70,7 +70,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops,
if (amd64bsd_xsave_len != 0)
{
xstateregs = alloca (amd64bsd_xsave_len);
- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
perror_with_name (_("Couldn't get extended state status"));
@@ -79,7 +79,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops,
}
#endif
- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't get floating point status"));
@@ -100,13 +100,13 @@ amd64bsd_store_inferior_registers (struct target_ops *ops,
{
struct reg regs;
- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't get registers"));
amd64_collect_native_gregset (regcache, ®s, regnum);
- if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't write registers"));
@@ -123,26 +123,26 @@ amd64bsd_store_inferior_registers (struct target_ops *ops,
if (amd64bsd_xsave_len != 0)
{
xstateregs = alloca (amd64bsd_xsave_len);
- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
perror_with_name (_("Couldn't get extended state status"));
amd64_collect_xsave (regcache, regnum, xstateregs, 0);
- if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETXSTATE, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xstateregs, amd64bsd_xsave_len) == -1)
perror_with_name (_("Couldn't write extended state status"));
return;
}
#endif
- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't get floating point status"));
amd64_collect_fxsave (regcache, regnum, &fpregs);
- if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't write floating point status"));
}
@@ -172,7 +172,7 @@ amd64bsd_dr_get (ptid_t ptid, int regnum)
{
struct dbreg dbregs;
- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
perror_with_name (_("Couldn't read debug registers"));
@@ -184,7 +184,7 @@ amd64bsd_dr_set (int regnum, unsigned long value)
{
struct dbreg dbregs;
- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
perror_with_name (_("Couldn't get debug registers"));
@@ -195,7 +195,7 @@ amd64bsd_dr_set (int regnum, unsigned long value)
DBREG_DRX ((&dbregs), regnum) = value;
- if (ptrace (PT_SETDBREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETDBREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
perror_with_name (_("Couldn't write debug registers"));
}
diff --git a/gdb/i386bsd-nat.c b/gdb/i386bsd-nat.c
index 71f962c..5d45c33 100644
--- a/gdb/i386bsd-nat.c
+++ b/gdb/i386bsd-nat.c
@@ -138,7 +138,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
{
struct reg regs;
- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't get registers"));
@@ -160,7 +160,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
char *xstateregs;
xstateregs = alloca (i386bsd_xsave_len);
- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
perror_with_name (_("Couldn't get extended state status"));
@@ -171,7 +171,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
#ifdef HAVE_PT_GETXMMREGS
if (have_ptrace_xmmregs != 0
- && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid),
+ && ptrace(PT_GETXMMREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
{
have_ptrace_xmmregs = 1;
@@ -181,7 +181,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
{
have_ptrace_xmmregs = 0;
#endif
- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't get floating point status"));
@@ -203,13 +203,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
{
struct reg regs;
- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't get registers"));
i386bsd_collect_gregset (regcache, ®s, regnum);
- if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't write registers"));
@@ -230,13 +230,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
char *xstateregs;
xstateregs = alloca (i386bsd_xsave_len);
- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
perror_with_name (_("Couldn't get extended state status"));
i387_collect_xsave (regcache, -1, xstateregs, 0);
- if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETXSTATE, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xstateregs, i386bsd_xsave_len) == -1)
perror_with_name (_("Couldn't write extended state status"));
return;
@@ -245,14 +245,14 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
#ifdef HAVE_PT_GETXMMREGS
if (have_ptrace_xmmregs != 0
- && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid),
+ && ptrace(PT_GETXMMREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
{
have_ptrace_xmmregs = 1;
i387_collect_fxsave (regcache, regnum, xmmregs);
- if (ptrace (PT_SETXMMREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETXMMREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) xmmregs, 0) == -1)
perror_with_name (_("Couldn't write XMM registers"));
}
@@ -260,13 +260,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
{
have_ptrace_xmmregs = 0;
#endif
- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't get floating point status"));
i387_collect_fsave (regcache, regnum, &fpregs);
- if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't write floating point status"));
#ifdef HAVE_PT_GETXMMREGS
@@ -305,7 +305,7 @@ i386bsd_dr_get (ptid_t ptid, int regnum)
{
struct dbreg dbregs;
- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
perror_with_name (_("Couldn't read debug registers"));
@@ -317,7 +317,7 @@ i386bsd_dr_set (int regnum, unsigned int value)
{
struct dbreg dbregs;
- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
perror_with_name (_("Couldn't get debug registers"));
@@ -328,7 +328,7 @@ i386bsd_dr_set (int regnum, unsigned int value)
DBREG_DRX ((&dbregs), regnum) = value;
- if (ptrace (PT_SETDBREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETDBREGS, get_ptrace_pid (inferior_ptid),
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
perror_with_name (_("Couldn't write debug registers"));
}
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index 8f8f4ee..329d8fb 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -304,7 +304,7 @@ inf_ptrace_interrupt (struct target_ops *self, ptid_t ptid)
/* Return which PID to pass to ptrace in order to observe/control the
tracee identified by PTID. */
-static pid_t
+pid_t
get_ptrace_pid (ptid_t ptid)
{
pid_t pid;
diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h
index ec40590..0a26720 100644
--- a/gdb/inf-ptrace.h
+++ b/gdb/inf-ptrace.h
@@ -33,4 +33,9 @@ extern struct target_ops *
inf_ptrace_trad_target (CORE_ADDR (*register_u_offset)
(struct gdbarch *, int, int));
+/* Return which PID to pass to ptrace in order to observe/control the
+ tracee identified by PTID. */
+
+extern pid_t get_ptrace_pid (ptid_t);
+
#endif
diff --git a/gdb/ppcfbsd-nat.c b/gdb/ppcfbsd-nat.c
index b41ed70..999e383 100644
--- a/gdb/ppcfbsd-nat.c
+++ b/gdb/ppcfbsd-nat.c
@@ -121,7 +121,7 @@ ppcfbsd_fetch_inferior_registers (struct target_ops *ops,
{
gdb_gregset_t regs;
- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETREGS, ptid_get_lwp (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't get registers"));
@@ -132,7 +132,7 @@ ppcfbsd_fetch_inferior_registers (struct target_ops *ops,
const struct regset *fpregset = ppc_fbsd_fpregset ();
gdb_fpregset_t fpregs;
- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETFPREGS, ptid_get_lwp (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't get FP registers"));
@@ -149,13 +149,13 @@ ppcfbsd_store_inferior_registers (struct target_ops *ops,
{
gdb_gregset_t regs;
- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETREGS, ptid_get_lwp (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't get registers"));
fill_gregset (regcache, ®s, regno);
- if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETREGS, ptid_get_lwp (inferior_ptid),
(PTRACE_TYPE_ARG3) ®s, 0) == -1)
perror_with_name (_("Couldn't write registers"));
@@ -163,13 +163,13 @@ ppcfbsd_store_inferior_registers (struct target_ops *ops,
{
gdb_fpregset_t fpregs;
- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_GETFPREGS, ptid_get_lwp (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't get FP registers"));
fill_fpregset (regcache, &fpregs, regno);
- if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
+ if (ptrace (PT_SETFPREGS, ptid_get_lwp (inferior_ptid),
(PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
perror_with_name (_("Couldn't set FP registers"));
}
--
2.7.0
next prev parent reply other threads:[~2016-01-18 2:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-18 2:28 [PATCH v3 0/6] Support kernel-backed user threads " John Baldwin
2016-01-18 2:28 ` John Baldwin [this message]
2016-01-18 12:32 ` [PATCH v3 4/6] Use LWP IDs with ptrace register requests " Pedro Alves
2016-01-18 2:28 ` [PATCH v3 5/6] Add support for LWP-based threads " John Baldwin
2016-01-18 12:37 ` Pedro Alves
2016-01-18 16:00 ` Eli Zaretskii
2016-01-18 17:06 ` John Baldwin
2016-01-18 2:28 ` [PATCH v3 1/6] Add support to readelf for reading FreeBSD ELF core notes John Baldwin
2016-01-19 16:50 ` Christophe Lyon
2016-01-19 17:10 ` John Baldwin
2016-01-19 17:12 ` Pedro Alves
2016-01-18 2:28 ` [PATCH v3 3/6] Display per-thread information for threads in FreeBSD cores John Baldwin
2016-01-18 2:28 ` [PATCH v3 6/6] Dump register notes for each thread when generating a FreeBSD core John Baldwin
2016-01-18 12:38 ` Pedro Alves
2016-01-18 2:28 ` [PATCH v3 2/6] Add a psuedosection for the NT_FREEBSD_THRMISC note John Baldwin
2016-01-18 12:38 ` Pedro Alves
2016-01-18 17:06 ` John Baldwin
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=1453084047-16175-5-git-send-email-jhb@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=binutils@sourceware.org \
--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).