From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: jimw@sifive.com, palmer@sifive.com, jhb@FreeBSD.org,
Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 4/4] gdb/riscv: Add read_description method for riscv_linux_nat_target
Date: Thu, 29 Nov 2018 16:50:00 -0000 [thread overview]
Message-ID: <39fcb759028c9fe3b17c8fdd2469a7238f231296.1543509416.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1543509416.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1543509416.git.andrew.burgess@embecosm.com>
Adds riscv_linux_nat_target::read_description method to find a
suitable target description for the native linux target we are running
on.
Currently this will supply a suitably sized set of x-registers, and
will probe the kernel to see if the f-registers are readable. If they
are readable then we currently assume that the f-registers are the
same size as the x-registers as I don't know of a good way to probe
the f-register length. This will obviously need fixing in future.
As of Linux 4.19 there is no ptrace support for reading the
f-registers, this should appear in 4.20, so right now we only return
target descriptions without f-registers.
gdb/ChangeLog:
* riscv-linux-nat.c: Add 'inferior.h' and 'target-descriptions.h'
header files.
(riscv_linux_nat_target::read_description): New method.
---
gdb/ChangeLog | 6 ++++++
gdb/riscv-linux-nat.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/gdb/riscv-linux-nat.c b/gdb/riscv-linux-nat.c
index d51f6e30218..f0705bc763f 100644
--- a/gdb/riscv-linux-nat.c
+++ b/gdb/riscv-linux-nat.c
@@ -21,6 +21,8 @@
#include "gregset.h"
#include "linux-nat.h"
#include "riscv-tdep.h"
+#include "inferior.h"
+#include "target-descriptions.h"
#include "elf/common.h"
@@ -34,6 +36,9 @@ public:
/* Add our register access methods. */
void fetch_registers (struct regcache *regcache, int regnum) override;
void store_registers (struct regcache *regcache, int regnum) override;
+
+ /* Read suitable target description. */
+ const struct target_desc *read_description () override;
};
static riscv_linux_nat_target the_riscv_linux_nat_target;
@@ -155,6 +160,39 @@ fill_fpregset (const struct regcache *regcache, prfpregset_t *fpregs,
regcache->raw_collect (RISCV_CSR_FCSR_REGNUM, &fpregs->__d.__fcsr);
}
+/* Return a target description for the current target. */
+
+const struct target_desc *
+riscv_linux_nat_target::read_description ()
+{
+ struct riscv_gdbarch_features features;
+ struct iovec iov;
+ elf_fpregset_t regs;
+ int tid;
+
+ /* Figuring out xlen is easy. */
+ features.xlen = sizeof (elf_greg_t);
+
+ tid = inferior_ptid.lwp ();
+
+ iov.iov_base = ®s;
+ iov.iov_len = sizeof (regs);
+
+ /* Can we fetch the f-registers? */
+ if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET,
+ (PTRACE_TYPE_ARG3) &iov) == -1)
+ features.flen = 0; /* No f-registers. */
+ else
+ {
+ /* TODO: We need a way to figure out the actual length of the
+ f-registers. We could have 64-bit x-registers, with 32-bit
+ f-registers. For now, just assumed xlen and flen match. */
+ features.flen = features.xlen;
+ }
+
+ return riscv_create_target_description (features);
+}
+
/* Fetch REGNUM (or all registers if REGNUM == -1) from the target
into REGCACHE using PTRACE_GETREGSET. */
--
2.14.5
next prev parent reply other threads:[~2018-11-29 16:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-28 22:50 [RFC] " Andrew Burgess
2018-11-28 23:37 ` Jim Wilson
2018-11-29 2:23 ` Jim Wilson
2018-11-29 16:50 ` [PATCH 1/4] gdb/riscv: Make some target description functions constant Andrew Burgess
2018-11-29 16:50 ` Andrew Burgess [this message]
2018-11-29 22:22 ` [PATCH 4/4] gdb/riscv: Add read_description method for riscv_linux_nat_target Jim Wilson
2018-11-29 16:50 ` [PATCH 3/4] gdb/riscv: Create each unique target description only once Andrew Burgess
2018-11-29 18:12 ` Pedro Alves
2018-11-29 19:17 ` Andrew Burgess
2018-11-29 22:32 ` Andrew Burgess
2018-11-30 17:07 ` Pedro Alves
2018-11-29 16:50 ` [PATCH 2/4] gdb/riscv: Add equality operators to riscv_gdb_features Andrew Burgess
2018-11-29 16:50 ` [PATCH 0/4] Re: gdb/riscv: Add read_description method for riscv_linux_nat_target Andrew Burgess
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=39fcb759028c9fe3b17c8fdd2469a7238f231296.1543509416.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=jhb@FreeBSD.org \
--cc=jimw@sifive.com \
--cc=palmer@sifive.com \
/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).