Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 02/11] New aarch32-linux-nat.c
Date: Wed, 01 Jul 2015 13:58:00 -0000	[thread overview]
Message-ID: <1435759111-22856-3-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1435759111-22856-1-git-send-email-yao.qi@linaro.org>

This patch is to move all the code about transferring
regcache <-> byte buffer for arm (aarch32) to a separate file
aarch32-linux-nat.c.  Then, in the following patch, aarch64 code
can use it to do multi-arch debugging.  This is a refactory patch.

gdb:

2015-06-24  Yao Qi  <yao.qi@linaro.org>

	* aarch32-linux-nat.c: New file.
	* aarch32-linux-nat.h: New file.
	* arm-linux-nat.c: Include aarch32-linux-nat.h.
	(fetch_regs): Move code to aarch32-linux-nat.c.  Call
	aarch32_gp_regcache_supply.
	(store_regs): Move code to aarch32-linux-nat.c.  Call
	aarch32_gp_regcache_collect.
	(fetch_vfp_regs): Move code to aarch32-linux-nat.c.  Call
	aarch32_vfp_regcache_supply.
	(store_vfp_regs): Move code to aarch32-linux-nat.c.  Call
	aarch32_vfp_regcache_collect.
	* config/arm/linux.mh (NATDEPFILES): Add aarch32-linux-nat.o.
---
 gdb/aarch32-linux-nat.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/aarch32-linux-nat.h | 29 +++++++++++++++
 gdb/arm-linux-nat.c     | 46 +++++------------------
 gdb/config/arm/linux.mh |  2 +-
 4 files changed, 138 insertions(+), 38 deletions(-)
 create mode 100644 gdb/aarch32-linux-nat.c
 create mode 100644 gdb/aarch32-linux-nat.h

diff --git a/gdb/aarch32-linux-nat.c b/gdb/aarch32-linux-nat.c
new file mode 100644
index 0000000..3147399
--- /dev/null
+++ b/gdb/aarch32-linux-nat.c
@@ -0,0 +1,99 @@
+/* Copyright (C) 1999-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 "defs.h"
+
+#include "regcache.h"
+#include "arm-tdep.h"
+#include "arm-linux-tdep.h"
+
+#include "aarch32-linux-nat.h"
+
+/* Supply GP registers contents, stored in REGS, to REGCACHE.  ARM_APCS_32
+   is true if the 32-bit mode is in use, otherwise, it is false.  */
+
+void
+aarch32_gp_regcache_supply (struct regcache *regcache, uint32_t *regs,
+			    int arm_apcs_32)
+{
+  int regno;
+
+  for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
+    regcache_raw_supply (regcache, regno, &regs[regno]);
+
+  if (arm_apcs_32)
+    regcache_raw_supply (regcache, ARM_PS_REGNUM, &regs[ARM_CPSR_GREGNUM]);
+  else
+    regcache_raw_supply (regcache, ARM_PS_REGNUM, &regs[ARM_PC_REGNUM]);
+
+  regs[ARM_PC_REGNUM] = gdbarch_addr_bits_remove
+			  (get_regcache_arch (regcache), regs[ARM_PC_REGNUM]);
+  regcache_raw_supply (regcache, ARM_PC_REGNUM, &regs[ARM_PC_REGNUM]);
+}
+
+/* Collect GP registers from REGCACHE to buffer REGS.  ARM_APCS_32 is
+   true if the 32-bit mode is in use, otherwise, it is false.  */
+
+void
+aarch32_gp_regcache_collect (const struct regcache *regcache, uint32_t *regs,
+			     int arm_apcs_32)
+{
+  int regno;
+
+  for (regno = ARM_A1_REGNUM; regno <= ARM_PC_REGNUM; regno++)
+    {
+      if (REG_VALID == regcache_register_status (regcache, regno))
+	regcache_raw_collect (regcache, regno, &regs[regno]);
+    }
+
+  if (arm_apcs_32
+      && REG_VALID == regcache_register_status (regcache, ARM_PS_REGNUM))
+    regcache_raw_collect (regcache, ARM_PS_REGNUM,
+			  &regs[ARM_CPSR_GREGNUM]);
+}
+
+/* Supply VFP registers contents, stored in REGS, to REGCACHE.
+   VFP_REGISTER_COUNT is the number of VFP registers.  */
+
+void
+aarch32_vfp_regcache_supply (struct regcache *regcache, gdb_byte *regs,
+			     const int vfp_register_count)
+{
+  int regno;
+
+  for (regno = 0; regno < vfp_register_count; regno++)
+    regcache_raw_supply (regcache, regno + ARM_D0_REGNUM,
+			 regs + regno * 8);
+
+  regcache_raw_supply (regcache, ARM_FPSCR_REGNUM,
+		       regs + 32 * 8);
+}
+
+/* Collect VFP registers from REGCACHE to buffer REGS.
+   VFP_REGISTER_COUNT is the number VFP registers.  */
+
+void
+aarch32_vfp_regcache_collect (const struct regcache *regcache, gdb_byte *regs,
+			      const int vfp_register_count)
+{
+  int regno;
+
+  for (regno = 0; regno < vfp_register_count; regno++)
+    regcache_raw_collect (regcache, regno + ARM_D0_REGNUM, regs + regno * 8);
+
+  regcache_raw_collect (regcache, ARM_FPSCR_REGNUM, regs + 32 * 8);
+}
diff --git a/gdb/aarch32-linux-nat.h b/gdb/aarch32-linux-nat.h
new file mode 100644
index 0000000..1b7ff83e
--- /dev/null
+++ b/gdb/aarch32-linux-nat.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 1999-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void aarch32_gp_regcache_supply (struct regcache *regcache, uint32_t *regs,
+				 int arm_apcs_32);
+
+void aarch32_gp_regcache_collect (const struct regcache *regcache,
+				  uint32_t *regs, int arm_apcs_32);
+
+void aarch32_vfp_regcache_supply (struct regcache *regcache, gdb_byte *regs,
+				  const int vfp_register_count);
+
+void aarch32_vfp_regcache_collect (const struct regcache *regcache,
+				   gdb_byte *regs,
+				   const int vfp_register_count);
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
index 5a8880f..aca0461 100644
--- a/gdb/arm-linux-nat.c
+++ b/gdb/arm-linux-nat.c
@@ -29,6 +29,7 @@
 
 #include "arm-tdep.h"
 #include "arm-linux-tdep.h"
+#include "aarch32-linux-nat.h"
 
 #include <elf/common.h>
 #include <sys/user.h>
@@ -212,20 +213,7 @@ fetch_regs (struct regcache *regcache)
       return;
     }
 
-  for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
-    regcache_raw_supply (regcache, regno, (char *) &regs[regno]);
-
-  if (arm_apcs_32)
-    regcache_raw_supply (regcache, ARM_PS_REGNUM,
-			 (char *) &regs[ARM_CPSR_GREGNUM]);
-  else
-    regcache_raw_supply (regcache, ARM_PS_REGNUM,
-			 (char *) &regs[ARM_PC_REGNUM]);
-
-  regs[ARM_PC_REGNUM] = gdbarch_addr_bits_remove
-			  (get_regcache_arch (regcache), regs[ARM_PC_REGNUM]);
-  regcache_raw_supply (regcache, ARM_PC_REGNUM,
-		       (char *) &regs[ARM_PC_REGNUM]);
+  aarch32_gp_regcache_supply (regcache, (uint32_t *) regs, arm_apcs_32);
 }
 
 static void
@@ -256,15 +244,7 @@ store_regs (const struct regcache *regcache)
       return;
     }
 
-  for (regno = ARM_A1_REGNUM; regno <= ARM_PC_REGNUM; regno++)
-    {
-      if (REG_VALID == regcache_register_status (regcache, regno))
-	regcache_raw_collect (regcache, regno, (char *) &regs[regno]);
-    }
-
-  if (arm_apcs_32 && REG_VALID == regcache_register_status (regcache, ARM_PS_REGNUM))
-    regcache_raw_collect (regcache, ARM_PS_REGNUM,
-			 (char *) &regs[ARM_CPSR_GREGNUM]);
+  aarch32_gp_regcache_collect (regcache, (uint32_t *) regs, arm_apcs_32);
 
   if (have_ptrace_getregset == TRIBOOL_TRUE)
     {
@@ -370,7 +350,7 @@ store_wmmx_regs (const struct regcache *regcache)
 static void
 fetch_vfp_regs (struct regcache *regcache)
 {
-  char regbuf[VFP_REGS_SIZE];
+  gdb_byte regbuf[VFP_REGS_SIZE];
   int ret, regno, tid;
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
@@ -395,18 +375,14 @@ fetch_vfp_regs (struct regcache *regcache)
       return;
     }
 
-  for (regno = 0; regno < tdep->vfp_register_count; regno++)
-    regcache_raw_supply (regcache, regno + ARM_D0_REGNUM,
-			 (char *) regbuf + regno * 8);
-
-  regcache_raw_supply (regcache, ARM_FPSCR_REGNUM,
-		       (char *) regbuf + 32 * 8);
+  aarch32_vfp_regcache_supply (regcache, regbuf,
+			       tdep->vfp_register_count);
 }
 
 static void
 store_vfp_regs (const struct regcache *regcache)
 {
-  char regbuf[VFP_REGS_SIZE];
+  gdb_byte regbuf[VFP_REGS_SIZE];
   int ret, regno, tid;
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
@@ -431,12 +407,8 @@ store_vfp_regs (const struct regcache *regcache)
       return;
     }
 
-  for (regno = 0; regno < tdep->vfp_register_count; regno++)
-    regcache_raw_collect (regcache, regno + ARM_D0_REGNUM,
-			  (char *) regbuf + regno * 8);
-
-  regcache_raw_collect (regcache, ARM_FPSCR_REGNUM,
-			(char *) regbuf + 32 * 8);
+  aarch32_vfp_regcache_collect (regcache, regbuf,
+				tdep->vfp_register_count);
 
   if (have_ptrace_getregset == TRIBOOL_TRUE)
     {
diff --git a/gdb/config/arm/linux.mh b/gdb/config/arm/linux.mh
index f0c5967..003ca1f 100644
--- a/gdb/config/arm/linux.mh
+++ b/gdb/config/arm/linux.mh
@@ -2,7 +2,7 @@
 
 NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o arm-linux-nat.o \
-	proc-service.o linux-thread-db.o \
+	aarch32-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
 	linux-waitpid.o linux-personality.o linux-namespaces.o
 NAT_CDEPS = $(srcdir)/proc-service.list
-- 
1.9.1


  parent reply	other threads:[~2015-07-01 13:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-01 13:58 [PATCH 00/11] Aarch64 linux GDB native multi-arch debugging (part 1) Yao Qi
2015-07-01 13:58 ` [PATCH 08/11] New proc is_aarch64_target Yao Qi
2015-07-01 14:10   ` Andreas Schwab
2015-07-01 14:19     ` Yao Qi
2015-07-01 14:39       ` Andreas Schwab
2015-07-01 13:58 ` [PATCH 04/11] Set architecture to arm in arm-*.xml files Yao Qi
2015-07-01 13:58 ` [PATCH 07/11] New proc is_aarch32_target Yao Qi
2015-07-01 13:58 ` Yao Qi [this message]
2015-07-01 13:58 ` [PATCH 01/11] Remove {fetch,store}_fpregister and {fetch,store}_register Yao Qi
2015-07-01 13:59 ` [PATCH 09/11] [gdbserver] Rename supports_conditional_breakpoints to supports_hardware_single_step Yao Qi
2015-07-01 13:59 ` [PATCH 10/11] Reply s and S vCont actions if target supports hardware single step Yao Qi
2015-07-01 13:59 ` [PATCH 03/11] Native debug arm program by aarch64 GDB Yao Qi
2015-07-01 13:59 ` [PATCH 11/11] New target_ops hook to_can_do_single_step Yao Qi
2015-07-01 16:43   ` Pedro Alves
2015-07-02  8:56     ` Yao Qi
2015-07-02  9:09       ` Pedro Alves
2015-07-01 13:59 ` [PATCH 05/11] Adjust gdb.multi tests for aarch64 Yao Qi
2015-07-01 13:59 ` [PATCH 06/11] Enable multi-arch test in catch-syscall.exp on aarch64 Yao Qi
2015-07-01 17:00 ` [PATCH 00/11] Aarch64 linux GDB native multi-arch debugging (part 1) Pedro Alves
2015-07-01 18:54   ` Pedro Alves
2015-07-02  9:05   ` Yao Qi
2015-07-07 16:13   ` Yao Qi

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=1435759111-22856-3-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.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