From: Pedro Franco de Carvalho <pedromfc@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Cc: uweigand@de.ibm.com
Subject: [PATCH v2 2/8] [PowerPC] Consolidate wordsize getter between native and gdbserver
Date: Mon, 21 May 2018 20:46:00 -0000 [thread overview]
Message-ID: <20180521204458.19070-2-pedromfc@linux.vnet.ibm.com> (raw)
In-Reply-To: <20180521204458.19070-1-pedromfc@linux.vnet.ibm.com>
This patch moves the native target wordsize getter for ppc linux to
nat/ so that it can be used to simplify ppc_arch_setup in
gdbserver. The ptrace call used to get MSR for this is ultimately the
same as before, but it is no longer necessary to create a temporary
regcache to call fetch_inferior_registers.
gdb/ChangeLog:
yyyy-mm-dd Pedro Franco de Carvalho <pedromfc@linux.vnet.ibm.com>
* configure.nat <linux powerpc>: Add ppc-linux.o to NATDEPFILES.
* ppc-linux-nat.c (ppc_linux_target_wordsize): Move to
nat/ppc-linux.c.
(ppc_linux_nat_target::auxv_parse): Get thread id tid. Call
ppc_linux_target_wordsize with tid.
(ppc_linux_nat_target::read_description): Call ppc_linux_target
wordsize with tid.
* nat/ppc-linux.c: Include nat/gdb_ptrace.h.
(ppc64_64bit_inferior_p): Add static and inline specifiers.
(ppc_linux_target_wordsize): Move here from ppc-linux-nat.c. Add
tid parameter. Remove static specifier.
* nat/ppc-linux.h (ppc64_64bit_inferior_p): Remove declaration.
(ppc_linux_target_wordsize): New declaration.
gdb/gdbserver/ChangeLog:
yyyy-mm-dd Pedro Franco de Carvalho <pedromfc@linux.vnet.ibm.com>
* linux-ppc-low.c (ppc_arch_setup): Remove code for getting the
wordsize of the inferior. Call ppc_linux_target_wordsize.
---
gdb/configure.nat | 2 +-
gdb/gdbserver/linux-ppc-low.c | 32 ++++++--------------------------
gdb/nat/ppc-linux.c | 22 +++++++++++++++++++++-
gdb/nat/ppc-linux.h | 7 ++-----
gdb/ppc-linux-nat.c | 32 +++++++-------------------------
5 files changed, 37 insertions(+), 58 deletions(-)
diff --git a/gdb/configure.nat b/gdb/configure.nat
index 6b0f44fede..bcaeaf4583 100644
--- a/gdb/configure.nat
+++ b/gdb/configure.nat
@@ -264,7 +264,7 @@ case ${gdb_host} in
;;
powerpc)
# Host: PowerPC, running Linux
- NATDEPFILES="${NATDEPFILES} ppc-linux-nat.o"
+ NATDEPFILES="${NATDEPFILES} ppc-linux-nat.o ppc-linux.o"
;;
s390)
# Host: S390, running Linux
diff --git a/gdb/gdbserver/linux-ppc-low.c b/gdb/gdbserver/linux-ppc-low.c
index 5361baf72a..30fcd4115a 100644
--- a/gdb/gdbserver/linux-ppc-low.c
+++ b/gdb/gdbserver/linux-ppc-low.c
@@ -620,36 +620,16 @@ ppc_arch_setup (void)
{
const struct target_desc *tdesc;
struct ppc_linux_features features = ppc_linux_no_features;
+ int tid = lwpid_of (current_thread);
- features.wordsize = 4;
-
-#ifdef __powerpc64__
- long msr;
- struct regcache *regcache;
-
- /* On a 64-bit host, assume 64-bit inferior process with no
- AltiVec registers. Reset ppc_hwcap to ensure that the
- collect_register call below does not fail. */
- tdesc = tdesc_powerpc_64l;
- current_process ()->tdesc = tdesc;
- ppc_hwcap = 0;
-
- regcache = new_register_cache (tdesc);
- fetch_inferior_registers (regcache, find_regno (tdesc, "msr"));
- collect_register_by_name (regcache, "msr", &msr);
- free_register_cache (regcache);
- if (ppc64_64bit_inferior_p (msr))
- {
- features.wordsize = 8;
- }
-#endif
+ features.wordsize = ppc_linux_target_wordsize (tid);
if (features.wordsize == 4)
- {
- /* OK, we have a 32-bit inferior. */
tdesc = tdesc_powerpc_32l;
- current_process ()->tdesc = tdesc;
- }
+ else
+ tdesc = tdesc_powerpc_64l;
+
+ current_process ()->tdesc = tdesc;
/* The value of current_process ()->tdesc needs to be set for this
call. */
diff --git a/gdb/nat/ppc-linux.c b/gdb/nat/ppc-linux.c
index 7ab6551316..1796ceb751 100644
--- a/gdb/nat/ppc-linux.c
+++ b/gdb/nat/ppc-linux.c
@@ -17,6 +17,7 @@
#include "common-defs.h"
#include "ppc-linux.h"
+#include "nat/gdb_ptrace.h"
#include <elf.h>
#ifdef HAVE_GETAUXVAL
@@ -53,7 +54,7 @@ ppc64_host_hwcap (unsigned long *valp)
#endif /* HAVE_GETAUXVAL */
}
-int
+static inline int
ppc64_64bit_inferior_p (long msr)
{
unsigned long ppc_host_hwcap = 0;
@@ -73,3 +74,22 @@ ppc64_64bit_inferior_p (long msr)
}
#endif
+
+int
+ppc_linux_target_wordsize (int tid)
+{
+ int wordsize = 4;
+
+ /* Check for 64-bit inferior process. This is the case when the host is
+ 64-bit, and in addition the top bit of the MSR register is set. */
+#ifdef __powerpc64__
+ long msr;
+
+ errno = 0;
+ msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0);
+ if (errno == 0 && ppc64_64bit_inferior_p (msr))
+ wordsize = 8;
+#endif
+
+ return wordsize;
+}
diff --git a/gdb/nat/ppc-linux.h b/gdb/nat/ppc-linux.h
index 76a5d181df..3d4d4fdc56 100644
--- a/gdb/nat/ppc-linux.h
+++ b/gdb/nat/ppc-linux.h
@@ -82,10 +82,7 @@
#define PTRACE_SETEVRREGS 21
#endif
-#ifdef __powerpc64__
-/* Return whether the inferior is 64bit or not by checking certain bit
- in MSR. */
-int ppc64_64bit_inferior_p (long msr);
-#endif
+/* Return the wordsize of the target, either 4 or 8 bytes. */
+int ppc_linux_target_wordsize (int tid);
#endif
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index e49a482c09..7e96032d4c 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -2368,35 +2368,17 @@ fill_fpregset (const struct regcache *regcache,
fpregsetp, sizeof (*fpregsetp));
}
-static int
-ppc_linux_target_wordsize (void)
-{
- int wordsize = 4;
-
- /* Check for 64-bit inferior process. This is the case when the host is
- 64-bit, and in addition the top bit of the MSR register is set. */
-#ifdef __powerpc64__
- long msr;
-
- int tid = ptid_get_lwp (inferior_ptid);
- if (tid == 0)
- tid = ptid_get_pid (inferior_ptid);
-
- errno = 0;
- msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0);
- if (errno == 0 && ppc64_64bit_inferior_p (msr))
- wordsize = 8;
-#endif
-
- return wordsize;
-}
-
int
ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
gdb_byte *endptr, CORE_ADDR *typep,
CORE_ADDR *valp)
{
- int sizeof_auxv_field = ppc_linux_target_wordsize ();
+ int tid = ptid_get_lwp (inferior_ptid);
+ if (tid == 0)
+ tid = ptid_get_pid (inferior_ptid);
+
+ int sizeof_auxv_field = ppc_linux_target_wordsize (tid);
+
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
gdb_byte *ptr = *readptr;
@@ -2437,7 +2419,7 @@ ppc_linux_nat_target::read_description ()
struct ppc_linux_features features = ppc_linux_no_features;
- features.wordsize = ppc_linux_target_wordsize ();
+ features.wordsize = ppc_linux_target_wordsize (tid);
unsigned long hwcap = ppc_linux_get_hwcap ();
--
2.13.6
next prev parent reply other threads:[~2018-05-21 20:46 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-10 19:59 [PATCH 0/8] [PowerPC] Miscellaneous fixes for register access Pedro Franco de Carvalho
2018-05-10 19:59 ` [PATCH 4/8] [PowerPC] Consolidate linux vector regset sizes Pedro Franco de Carvalho
2018-05-16 16:35 ` Ulrich Weigand
2018-05-10 19:59 ` [PATCH 3/8] [PowerPC] Disable regsets using zero sizes in gdbserver Pedro Franco de Carvalho
2018-05-16 16:17 ` Ulrich Weigand
2018-05-10 19:59 ` [PATCH 1/8] [PowerPC] Consolidate linux target description selection Pedro Franco de Carvalho
2018-05-16 14:05 ` Ulrich Weigand
2018-05-16 22:50 ` Pedro Franco de Carvalho
2018-05-17 8:28 ` Ulrich Weigand
2018-05-10 20:00 ` [PATCH 8/8] [PowerPC] Recognize isa205 in linux core files Pedro Franco de Carvalho
2018-05-16 15:53 ` Ulrich Weigand
2018-05-16 23:32 ` Pedro Franco de Carvalho
2018-05-17 10:22 ` Ulrich Weigand
2018-05-21 20:46 ` Pedro Franco de Carvalho
2018-05-22 12:48 ` Ulrich Weigand
2018-05-22 14:33 ` Pedro Franco de Carvalho
2018-05-10 20:33 ` [PATCH 2/8] [PowerPC] Consolidate wordsize getter between native and gdbserver Pedro Franco de Carvalho
2018-05-16 15:54 ` Ulrich Weigand
2018-05-10 20:33 ` [PATCH 6/8] [PowerPC] Fix VSX registers in linux core files Pedro Franco de Carvalho
2018-05-16 14:18 ` Ulrich Weigand
2018-05-10 21:46 ` [PATCH 5/8] [PowerPC] Fix access to VSCR in linux targets Pedro Franco de Carvalho
2018-05-16 14:06 ` Ulrich Weigand
2018-05-17 21:25 ` Pedro Franco de Carvalho
2018-05-18 15:37 ` Ulrich Weigand
2018-05-21 20:46 ` Pedro Franco de Carvalho
2018-05-22 12:56 ` Ulrich Weigand
2018-05-10 22:25 ` [PATCH 7/8] [PowerPC] Fix inclusion of dfp pseudoregs in tdep Pedro Franco de Carvalho
2018-05-16 14:18 ` Ulrich Weigand
2018-05-21 20:46 ` [PATCH v2 1/8] [PowerPC] Consolidate linux target description selection Pedro Franco de Carvalho
2018-05-21 20:46 ` Pedro Franco de Carvalho [this message]
2018-05-22 12:56 ` [PATCH v2 2/8] [PowerPC] Consolidate wordsize getter between native and gdbserver Ulrich Weigand
2018-05-21 20:46 ` [PATCH v2 3/8] [PowerPC] Disable regsets using zero sizes in gdbserver Pedro Franco de Carvalho
2018-05-22 12:48 ` Ulrich Weigand
2018-05-21 20:46 ` [PATCH v2 4/8] [PowerPC] Consolidate linux vector regset sizes Pedro Franco de Carvalho
2018-05-22 12:48 ` Ulrich Weigand
2018-05-21 23:45 ` [PATCH v2 5/8] [PowerPC] Fix access to VSCR in linux targets Pedro Franco de Carvalho
2018-05-22 12:56 ` Ulrich Weigand
2018-05-21 23:55 ` [PATCH v2 8/8] [PowerPC] Recognize isa205 in linux core files Pedro Franco de Carvalho
2018-05-22 13:34 ` Ulrich Weigand
2018-05-21 23:56 ` [PATCH v2 7/8] [PowerPC] Fix inclusion of dfp pseudoregs in tdep Pedro Franco de Carvalho
2018-05-22 12:56 ` Ulrich Weigand
2018-05-22 0:54 ` [PATCH v2 6/8] [PowerPC] Fix VSX registers in linux core files Pedro Franco de Carvalho
2018-05-22 13:46 ` Ulrich Weigand
2018-05-22 12:48 ` [PATCH v2 1/8] [PowerPC] Consolidate linux target description selection Ulrich Weigand
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=20180521204458.19070-2-pedromfc@linux.vnet.ibm.com \
--to=pedromfc@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=uweigand@de.ibm.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