public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/7] Move have_ptrace_getregset to linux-low.c
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
@ 2015-07-31 15:16 ` Yao Qi
  2015-07-31 15:17 ` [PATCH 7/7] Mention multi-arch debugging support in NEWS Yao Qi
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:16 UTC (permalink / raw)
  To: gdb-patches

This patch moves variable have_ptrace_getregset from linux-x86-low.c
to linux-low.c, so that arm can use it too.

gdb/gdbserver:

2015-07-28  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-low.c (have_ptrace_getregset): Move it to ...
	* linux-low.c: ... here.
	* linux-low.h (have_ptrace_getregset): Declare it.
---
 gdb/gdbserver/linux-low.c     | 3 +++
 gdb/gdbserver/linux-low.h     | 2 ++
 gdb/gdbserver/linux-x86-low.c | 3 ---
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 9bc9fa3..0986bcc 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -139,6 +139,9 @@ typedef struct
 } Elf64_auxv_t;
 #endif
 
+/* Does the current host support PTRACE_GETREGSET?  */
+int have_ptrace_getregset = -1;
+
 /* LWP accessors.  */
 
 /* See nat/linux-nat.h.  */
diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h
index 5a3697b..24fb015 100644
--- a/gdb/gdbserver/linux-low.h
+++ b/gdb/gdbserver/linux-low.h
@@ -373,3 +373,5 @@ int thread_db_handle_monitor_command (char *);
 int thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
 			       CORE_ADDR load_module, CORE_ADDR *address);
 int thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp);
+
+extern int have_ptrace_getregset;
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index ec2d906..73fe6cd 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -1142,9 +1142,6 @@ int have_ptrace_getfpxregs =
 #endif
 ;
 
-/* Does the current host support PTRACE_GETREGSET?  */
-static int have_ptrace_getregset = -1;
-
 /* Get Linux/x86 target description from running target.  */
 
 static const struct target_desc *
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 5/7] Disable Z0 packet on aarch64 on multi-arch debugging
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
                   ` (4 preceding siblings ...)
  2015-07-31 15:17 ` [PATCH 4/7] Get and set PC correctly on aarch64 in multi-arch Yao Qi
@ 2015-07-31 15:17 ` Yao Qi
  2015-07-31 15:17 ` [PATCH 2/7] New regs_info for aarch32 Yao Qi
  2015-08-03 14:00 ` [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Pedro Alves
  7 siblings, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:17 UTC (permalink / raw)
  To: gdb-patches

In multi-arch debugging, if GDB sends Z0 packet, GDBserver should be
able to do several things below:

 - choose the right breakpoint instruction to insert according to the
   information available, such as 'kind' in Z0 packet and address,

 - choose the right breakpoint instruction to check memory writes and
   validate inserted memory breakpoint

 - be aware of different breakpoint instructions in $ARCH_breakpoint_at.

unfortunately GDBserver can't do them now.  Although x86 GDBserver
supports multi-arch, it doesn't need to support them above because
breakpoint instruction on i686 and x86_64 is the same.  However,
breakpoint instructions on aarch64 and arm (arm mode, thumb1, and thumb2)
are different.

I tried to teach aarch64 GDBserver backend to be really
multi-arch-capable in the following ways,

 - linux_low_target return the right breakpoint instruction according to
   the 'kind' in Z0 packet, and insert_memory_breakpoint can do the right
   thing.
 - once breakpoint is inserted, the breakpoint data and length is recorded
   in each breakpoint object, so that validate_breakpoint and
   check_mem_write can get the right breakpoint instruction from each
   breakpoint object, rather than from global variable breakpoint_data.
 - linux_low_target needs another hook function for pc increment after
   hitting a breakpoint.
 - let set_breakpoint_at, which is widely used for tracepoint, use the
   'default' breakpoint instruction.  We can always use aarch64 breakpoint
   instruction since arm doesn't support tracepoint yet.

looks it is not a small piece of work, so I decide to disable Z0 packet
on multi-arch, which means aarch64 GDBserver only supports Z0 packet
if it is started to debug only one process (extended protocol is not
used) and process target description is 64-bit.

gdb/gdbserver:

2015-07-28  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_supports_z_point_type): Return
	0 for Z_PACKET_SW_BP if it may be used in multi-arch debugging.
	* server.c (extended_protocol): Remove "static".
	* server.h (extended_protocol): Declare it.
---
 gdb/gdbserver/linux-aarch64-low.c | 16 ++++++++++++++++
 gdb/gdbserver/server.c            |  2 +-
 gdb/gdbserver/server.h            |  1 +
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 3512ce9..90d2b43 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -364,6 +364,22 @@ aarch64_supports_z_point_type (char z_type)
   switch (z_type)
     {
     case Z_PACKET_SW_BP:
+      {
+	if (!extended_protocol && is_64bit_tdesc ())
+	  {
+	    /* Only enable Z0 packet in non-multi-arch debugging.  If
+	       extended protocol is used, don't enable Z0 packet because
+	       GDBserver may attach to 32-bit process.  */
+	    return 1;
+	  }
+	else
+	  {
+	    /* Disable Z0 packet so that GDBserver doesn't have to handle
+	       different breakpoint instructions (aarch64, arm, thumb etc)
+	       in multi-arch debugging.  */
+	    return 0;
+	  }
+      }
     case Z_PACKET_HW_BP:
     case Z_PACKET_WRITE_WP:
     case Z_PACKET_READ_WP:
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 2918770..f15b7be 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -49,7 +49,7 @@ ptid_t general_thread;
 
 int server_waiting;
 
-static int extended_protocol;
+int extended_protocol;
 static int response_needed;
 static int exit_requested;
 
diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h
index 09a5624..9080151 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -87,6 +87,7 @@ extern int multi_process;
 extern int report_fork_events;
 extern int report_vfork_events;
 extern int non_stop;
+extern int extended_protocol;
 
 /* True if the "swbreak+" feature is active.  In that case, GDB wants
    us to report whether a trap is explained by a software breakpoint
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 2/7] New regs_info for aarch32
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
                   ` (5 preceding siblings ...)
  2015-07-31 15:17 ` [PATCH 5/7] Disable Z0 packet on aarch64 on multi-arch debugging Yao Qi
@ 2015-07-31 15:17 ` Yao Qi
  2015-08-03 13:58   ` Pedro Alves
  2015-08-03 14:00 ` [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Pedro Alves
  7 siblings, 1 reply; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:17 UTC (permalink / raw)
  To: gdb-patches

This patch adds a new regs_info regs_info_aarch32 for aarch32, which
can be used by both aarch64 and arm backend.

gdb/gdbserver:

2015-07-28  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_tgtobj): Add linux-aarch32-low.o.
	* linux-aarch32-low.c: New file.
	* linux-aarch32-low.h: New file.
	* linux-arm-low.c (arm_fill_gregset): Move it to
	linux-aarch32-low.c.
	(arm_store_gregset), arm_fill_vfpregset): Likewise.
	(arm_store_vfpregset): Likewise.
	(arm_arch_setup): Check if PTRACE_GETREGSET works.
	(regs_info): Rename to regs_info_arm.
	(arm_regs_info): Return regs_info_aarch32 if
	have_ptrace_getregset is 1 and target description isn't
	iwmmxt.
	(initialize_low_arch): Don't call
	init_registers_arm_with_vfpv2, init_registers_arm_with_vfpv3,
	and init_registers_arm_with_neon.  Call
	initialize_low_arch_aarch32 instead.
---
 gdb/gdbserver/configure.srv       |   1 +
 gdb/gdbserver/linux-aarch32-low.c | 141 ++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/linux-aarch32-low.h |  32 +++++++++
 gdb/gdbserver/linux-arm-low.c     | 108 +++++++----------------------
 4 files changed, 199 insertions(+), 83 deletions(-)
 create mode 100644 gdb/gdbserver/linux-aarch32-low.c
 create mode 100644 gdb/gdbserver/linux-aarch32-low.h

diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 9a04aac..1a8361a 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -62,6 +62,7 @@ case "${target}" in
 			srv_regobj="${srv_regobj} arm-with-vfpv3.o"
 			srv_regobj="${srv_regobj} arm-with-neon.o"
 			srv_tgtobj="$srv_linux_obj linux-arm-low.o"
+			srv_tgtobj="$srv_tgtobj linux-aarch32-low.o"
 			srv_xmlfiles="arm-with-iwmmxt.xml"
 			srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv2.xml"
 			srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv3.xml"
diff --git a/gdb/gdbserver/linux-aarch32-low.c b/gdb/gdbserver/linux-aarch32-low.c
new file mode 100644
index 0000000..0ca40c3
--- /dev/null
+++ b/gdb/gdbserver/linux-aarch32-low.c
@@ -0,0 +1,141 @@
+/* Copyright (C) 1995-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 "server.h"
+#include "arch/arm.h"
+#include "linux-low.h"
+#include "linux-aarch32-low.h"
+
+#include <sys/ptrace.h>
+/* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
+   On Bionic elf.h and linux/elf.h have conflicting definitions.  */
+#ifndef ELFMAG0
+#include <elf.h>
+#endif
+
+/* Collect GP registers from REGCACHE to buffer BUF.  */
+
+void
+arm_fill_gregset (struct regcache *regcache, void *buf)
+{
+  int i;
+  uint32_t *regs = buf;
+
+  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
+    collect_register (regcache, i, &regs[i]);
+
+  collect_register (regcache, ARM_PS_REGNUM, &regs[16]);
+}
+
+/* Supply GP registers contents, stored in BUF, to REGCACHE.  */
+
+void
+arm_store_gregset (struct regcache *regcache, const void *buf)
+{
+  int i;
+  char zerobuf[8];
+  const uint32_t *regs = buf;
+
+  memset (zerobuf, 0, 8);
+  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
+    supply_register (regcache, i, &regs[i]);
+
+  for (; i < ARM_PS_REGNUM; i++)
+    supply_register (regcache, i, zerobuf);
+
+  supply_register (regcache, ARM_PS_REGNUM, &regs[16]);
+}
+
+/* Collect VFP registers from REGCACHE to buffer BUF.  */
+
+void
+arm_fill_vfpregset (struct regcache *regcache, void *buf)
+{
+  int i, num, base;
+
+  if (regcache->tdesc == tdesc_arm_with_neon
+      || regcache->tdesc == tdesc_arm_with_vfpv3)
+    num = 32;
+  else if (regcache->tdesc == tdesc_arm_with_vfpv2)
+    num = 16;
+  else
+    return;
+
+  base = find_regno (regcache->tdesc, "d0");
+  for (i = 0; i < num; i++)
+    collect_register (regcache, base + i, (char *) buf + i * 8);
+
+  collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
+}
+
+/* Supply VFP registers contents, stored in BUF, to REGCACHE.  */
+
+void
+arm_store_vfpregset (struct regcache *regcache, const void *buf)
+{
+  int i, num, base;
+
+  if (regcache->tdesc == tdesc_arm_with_neon
+      || regcache->tdesc == tdesc_arm_with_vfpv3)
+    num = 32;
+  else if (regcache->tdesc == tdesc_arm_with_vfpv2)
+    num = 16;
+  else
+    return;
+
+  base = find_regno (regcache->tdesc, "d0");
+  for (i = 0; i < num; i++)
+    supply_register (regcache, base + i, (char *) buf + i * 8);
+
+  supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
+}
+
+/* Register sets with using PTRACE_GETREGSET.  */
+
+static struct regset_info aarch32_regsets[] = {
+  { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS, 18 * 4,
+    GENERAL_REGS,
+    arm_fill_gregset, arm_store_gregset },
+  { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_ARM_VFP, 32 * 8 + 4,
+    EXTENDED_REGS,
+    arm_fill_vfpregset, arm_store_vfpregset },
+  { 0, 0, 0, -1, -1, NULL, NULL }
+};
+
+static struct regsets_info aarch32_regsets_info =
+  {
+    aarch32_regsets, /* regsets */
+    0, /* num_regsets */
+    NULL, /* disabled_regsets */
+  };
+
+struct regs_info regs_info_aarch32 =
+  {
+    NULL, /* regset_bitmap */
+    NULL, /* usrregs */
+    &aarch32_regsets_info
+  };
+
+void
+initialize_low_arch_aarch32 (void)
+{
+  init_registers_arm_with_vfpv2 ();
+  init_registers_arm_with_vfpv3 ();
+  init_registers_arm_with_neon ();
+
+  initialize_regsets_info (&aarch32_regsets_info);
+}
diff --git a/gdb/gdbserver/linux-aarch32-low.h b/gdb/gdbserver/linux-aarch32-low.h
new file mode 100644
index 0000000..49bd5c3
--- /dev/null
+++ b/gdb/gdbserver/linux-aarch32-low.h
@@ -0,0 +1,32 @@
+/* Copyright (C) 1995-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/>.  */
+
+extern struct regs_info regs_info_aarch32;
+
+void arm_fill_gregset (struct regcache *regcache, void *buf);
+void arm_store_gregset (struct regcache *regcache, const void *buf);
+void arm_fill_vfpregset (struct regcache *regcache, void *buf);
+void arm_store_vfpregset (struct regcache *regcache, const void *buf);
+
+void initialize_low_arch_aarch32 (void);
+
+void init_registers_arm_with_vfpv2 (void);
+extern const struct target_desc *tdesc_arm_with_vfpv2;
+void init_registers_arm_with_vfpv3 (void);
+extern const struct target_desc *tdesc_arm_with_vfpv3;
+void init_registers_arm_with_neon (void);
+extern const struct target_desc *tdesc_arm_with_neon;
diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
index 3c5956b..6aebd29 100644
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -19,7 +19,9 @@
 #include "server.h"
 #include "linux-low.h"
 #include "arch/arm.h"
+#include "linux-aarch32-low.h"
 
+#include <sys/uio.h>
 /* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
    On Bionic elf.h and linux/elf.h have conflicting definitions.  */
 #ifndef ELFMAG0
@@ -35,15 +37,6 @@ extern const struct target_desc *tdesc_arm;
 void init_registers_arm_with_iwmmxt (void);
 extern const struct target_desc *tdesc_arm_with_iwmmxt;
 
-void init_registers_arm_with_vfpv2 (void);
-extern const struct target_desc *tdesc_arm_with_vfpv2;
-
-void init_registers_arm_with_vfpv3 (void);
-extern const struct target_desc *tdesc_arm_with_vfpv3;
-
-void init_registers_arm_with_neon (void);
-extern const struct target_desc *tdesc_arm_with_neon;
-
 #ifndef PTRACE_GET_THREAD_AREA
 #define PTRACE_GET_THREAD_AREA 22
 #endif
@@ -150,35 +143,6 @@ arm_cannot_fetch_register (int regno)
 }
 
 static void
-arm_fill_gregset (struct regcache *regcache, void *buf)
-{
-  int i;
-  uint32_t *regs = buf;
-
-  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
-    collect_register (regcache, i, &regs[i]);
-
-  collect_register (regcache, ARM_PS_REGNUM, &regs[16]);
-}
-
-static void
-arm_store_gregset (struct regcache *regcache, const void *buf)
-{
-  int i;
-  char zerobuf[8];
-  const uint32_t *regs = buf;
-
-  memset (zerobuf, 0, 8);
-  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
-    supply_register (regcache, i, &regs[i]);
-
-  for (; i < ARM_PS_REGNUM; i++)
-    supply_register (regcache, i, zerobuf);
-
-  supply_register (regcache, ARM_PS_REGNUM, &regs[16]);
-}
-
-static void
 arm_fill_wmmxregset (struct regcache *regcache, void *buf)
 {
   int i;
@@ -212,46 +176,6 @@ arm_store_wmmxregset (struct regcache *regcache, const void *buf)
 		     (char *) buf + 16 * 8 + i * 4);
 }
 
-static void
-arm_fill_vfpregset (struct regcache *regcache, void *buf)
-{
-  int i, num, base;
-
-  if (regcache->tdesc == tdesc_arm_with_neon
-      || regcache->tdesc == tdesc_arm_with_vfpv3)
-    num = 32;
-  else if (regcache->tdesc == tdesc_arm_with_vfpv2)
-    num = 16;
-  else
-    return;
-
-  base = find_regno (regcache->tdesc, "d0");
-  for (i = 0; i < num; i++)
-    collect_register (regcache, base + i, (char *) buf + i * 8);
-
-  collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
-}
-
-static void
-arm_store_vfpregset (struct regcache *regcache, const void *buf)
-{
-  int i, num, base;
-
-  if (regcache->tdesc == tdesc_arm_with_neon
-      || regcache->tdesc == tdesc_arm_with_vfpv3)
-    num = 32;
-  else if (regcache->tdesc == tdesc_arm_with_vfpv2)
-    num = 16;
-  else
-    return;
-
-  base = find_regno (regcache->tdesc, "d0");
-  for (i = 0; i < num; i++)
-    supply_register (regcache, base + i, (char *) buf + i * 8);
-
-  supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
-}
-
 extern int debug_threads;
 
 static CORE_ADDR
@@ -888,9 +812,24 @@ arm_read_description (void)
 static void
 arm_arch_setup (void)
 {
+  int tid = lwpid_of (current_thread);
+  int gpregs[18];
+  struct iovec iov;
+
   current_process ()->tdesc = arm_read_description ();
+
+  iov.iov_base = gpregs;
+  iov.iov_len = sizeof (gpregs);
+
+  /* Check if PTRACE_GETREGSET works.  */
+  if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov) == 0)
+    have_ptrace_getregset = 1;
+  else
+    have_ptrace_getregset = 0;
 }
 
+/* Register sets without using PTRACE_GETREGSET.  */
+
 static struct regset_info arm_regsets[] = {
   { PTRACE_GETREGS, PTRACE_SETREGS, 0, 18 * 4,
     GENERAL_REGS,
@@ -917,7 +856,7 @@ static struct usrregs_info arm_usrregs_info =
     arm_regmap,
   };
 
-static struct regs_info regs_info =
+static struct regs_info regs_info_arm =
   {
     NULL, /* regset_bitmap */
     &arm_usrregs_info,
@@ -927,7 +866,11 @@ static struct regs_info regs_info =
 static const struct regs_info *
 arm_regs_info (void)
 {
-  return &regs_info;
+  if (have_ptrace_getregset == 1
+      && current_process ()->tdesc != tdesc_arm_with_iwmmxt)
+    return &regs_info_aarch32;
+  else
+    return &regs_info_arm;
 }
 
 struct linux_target_ops the_low_target = {
@@ -973,9 +916,8 @@ initialize_low_arch (void)
   /* Initialize the Linux target descriptions.  */
   init_registers_arm ();
   init_registers_arm_with_iwmmxt ();
-  init_registers_arm_with_vfpv2 ();
-  init_registers_arm_with_vfpv3 ();
-  init_registers_arm_with_neon ();
+
+  initialize_low_arch_aarch32 ();
 
   initialize_regsets_info (&arm_regsets_info);
 }
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 7/7] Mention multi-arch debugging support in NEWS
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
  2015-07-31 15:16 ` [PATCH 1/7] Move have_ptrace_getregset to linux-low.c Yao Qi
@ 2015-07-31 15:17 ` Yao Qi
  2015-08-19  8:26   ` Yao Qi
  2015-09-04 14:30   ` Yao Qi
  2015-07-31 15:17 ` [PATCH 6/7] Disable tracepoint support for aarch32 Yao Qi
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:17 UTC (permalink / raw)
  To: gdb-patches

gdb:

2015-07-31  Yao Qi  <yao.qi@linaro.org>

	* NEWS: Mention the aarch64 multi-arch debugging support.
---
 gdb/NEWS | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index 7ce9758..dd834b9 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -5,6 +5,10 @@
 
 * Support for tracepoints on aarch64-linux was added in GDBserver.
 
+* Multi-architecture debugging is supported on AArch64 GNU/Linux.
+  GDB now is able to debug both AArch64 applications and ARM applications
+  at the same time.
+
 *** Changes in GDB 7.10
 
 * Support for process record-replay and reverse debugging on aarch64*-linux*
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging
@ 2015-07-31 15:17 Yao Qi
  2015-07-31 15:16 ` [PATCH 1/7] Move have_ptrace_getregset to linux-low.c Yao Qi
                   ` (7 more replies)
  0 siblings, 8 replies; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:17 UTC (permalink / raw)
  To: gdb-patches

This patch series is to enable Aarch64 GDBserver debug arm program.

Patch 1 is to make variable have_ptrace_getregset shared for all linux
targets, so that patch 2 can use it.  Patch 2 adds a new regs_info
specific to aarch32, which will be used by patch 3.  This new regs_info
can also be used by some arm-linux targets if kernel support
ptrace_getregset.

Patch 3 is the major part of this series, which teach GDBserver uses
arm target description and regs_info if the target program is 32-bit.
Patch 4 is to handle the different size of PC value in multi-arch, which
is the same as what we are doing on x86 multi-arch.

Patch 5 disables Z0 packets on aarch64 for multi-arch debugging,
otherwise GDBserver has to know how to choose the right breakpoint
instructions for aarch64, arm, and arm thumb mode (thumb and thumb2).
See more details from the patch.

Nowadays, tracepoint is not supported for arm, so we need to disable
tracepoint support in aarch64 GDBserver if the target thread is 32-bit.
This is what patch 6 does.

Note that multi-thread debugging and HW watchpoint are still not
supported, because of some kernel issues.  My description in this
patch https://sourceware.org/ml/gdb-patches/2015-07/msg00029.html
is still valid.

After some kernel patches for multi-arch are committed, I'll enable
multi-thread debugging and HW watchpoint support in both GDB and
GDBserver.  That is my plan next step.

*** BLURB HERE ***

Yao Qi (7):
  Move have_ptrace_getregset to linux-low.c
  New regs_info for aarch32
  Use arm target description and regs_info for 32-bit file on aarch64
    GDBserver
  Get and set PC correctly on aarch64 in multi-arch
  Disable Z0 packet on aarch64 on multi-arch debugging
  Disable tracepoint support for aarch32
  Mention multi-arch debugging support in NEWS

 gdb/NEWS                          |   4 +
 gdb/gdbserver/configure.srv       |   5 ++
 gdb/gdbserver/linux-aarch32-low.c | 152 ++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/linux-aarch32-low.h |  36 +++++++++
 gdb/gdbserver/linux-aarch64-low.c | 100 ++++++++++++++++++++++---
 gdb/gdbserver/linux-arm-low.c     | 108 +++++++--------------------
 gdb/gdbserver/linux-low.c         |   3 +
 gdb/gdbserver/linux-low.h         |   2 +
 gdb/gdbserver/linux-x86-low.c     |   3 -
 gdb/gdbserver/server.c            |   2 +-
 gdb/gdbserver/server.h            |   1 +
 11 files changed, 318 insertions(+), 98 deletions(-)
 create mode 100644 gdb/gdbserver/linux-aarch32-low.c
 create mode 100644 gdb/gdbserver/linux-aarch32-low.h

-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 3/7] Use arm target description and regs_info for 32-bit file on aarch64 GDBserver
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
                   ` (2 preceding siblings ...)
  2015-07-31 15:17 ` [PATCH 6/7] Disable tracepoint support for aarch32 Yao Qi
@ 2015-07-31 15:17 ` Yao Qi
  2015-08-04 13:44   ` Yao Qi
  2015-07-31 15:17 ` [PATCH 4/7] Get and set PC correctly on aarch64 in multi-arch Yao Qi
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:17 UTC (permalink / raw)
  To: gdb-patches

This patch teaches aarch64-linux GDBserver use 32-bit arm target
description and regs_info if the elf file is 32-bit.

gdb/gdbserver:

2015-07-31  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (case aarch64*-*-linux*): Append arm-with-neon.o
	to srv_regobj and append arm-core.xml arm-vfpv3.xml and
	arm-with-neon.xml to srv_xmlfiles.
	* linux-aarch32-low.c (arm_fill_vfpregset) [__aarch64__]: Add
	assert and set num to 32.
	(arm_store_vfpregset) [__aarch64__]: Likewise.
	(initialize_low_arch_aarch32) [!__aarch64__] Call
	init_registers_arm_with_vfpv2 and
	init_registers_arm_with_vfpv3.
	* linux-aarch32-low.h [!__aarch64__]: Declare
	init_registers_arm_with_vfpv2, tdesc_arm_with_vfpv2,
	init_registers_arm_with_vfpv3 and tdesc_arm_with_vfpv3.
	* linux-aarch64-low.c: Include linux-aarch32-low.h.
	(is_64bit_tdesc): New function.
	(tdesc_arm_with_neon): Declare
	(aarch64_linux_read_description): New function.
	(aarch64_arch_setup): Call aarch64_linux_read_description.
	(regs_info): Rename to regs_info_aarch64.
	(aarch64_regs_info): Return right regs_info.
	(initialize_low_arch): Call initialize_low_arch_aarch32.
---
 gdb/gdbserver/configure.srv       |  4 ++++
 gdb/gdbserver/linux-aarch32-low.c | 13 +++++++++++-
 gdb/gdbserver/linux-aarch32-low.h |  4 ++++
 gdb/gdbserver/linux-aarch64-low.c | 42 ++++++++++++++++++++++++++++++++++++---
 4 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 1a8361a..0b18d1d 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -49,11 +49,15 @@ srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-wa
 case "${target}" in
   aarch64*-*-linux*)
 			srv_regobj="aarch64.o"
+			srv_regobj="${srv_regobj} arm-with-neon.o"
 			srv_tgtobj="linux-aarch64-low.o aarch64-linux-hw-point.o"
+			srv_tgtobj="$srv_tgtobj linux-aarch32-low.o"
 			srv_tgtobj="${srv_tgtobj} $srv_linux_obj"
 			srv_xmlfiles="aarch64.xml"
 			srv_xmlfiles="${srv_xmlfiles} aarch64-core.xml"
 			srv_xmlfiles="${srv_xmlfiles} aarch64-fpu.xml"
+			srv_xmlfiles="${srv_xmlfiles} arm-core.xml arm-vfpv3.xml"
+			srv_xmlfiles="${srv_xmlfiles} arm-with-neon.xml"
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
 			;;
diff --git a/gdb/gdbserver/linux-aarch32-low.c b/gdb/gdbserver/linux-aarch32-low.c
index 0ca40c3..d39dfac 100644
--- a/gdb/gdbserver/linux-aarch32-low.c
+++ b/gdb/gdbserver/linux-aarch32-low.c
@@ -67,6 +67,10 @@ arm_fill_vfpregset (struct regcache *regcache, void *buf)
 {
   int i, num, base;
 
+#ifdef __aarch64__
+  gdb_assert (regcache->tdesc == tdesc_arm_with_neon);
+  num = 32;
+#else
   if (regcache->tdesc == tdesc_arm_with_neon
       || regcache->tdesc == tdesc_arm_with_vfpv3)
     num = 32;
@@ -74,6 +78,7 @@ arm_fill_vfpregset (struct regcache *regcache, void *buf)
     num = 16;
   else
     return;
+#endif
 
   base = find_regno (regcache->tdesc, "d0");
   for (i = 0; i < num; i++)
@@ -88,7 +93,10 @@ void
 arm_store_vfpregset (struct regcache *regcache, const void *buf)
 {
   int i, num, base;
-
+#ifdef __aarch64__
+  gdb_assert (regcache->tdesc == tdesc_arm_with_neon);
+  num = 32;
+#else
   if (regcache->tdesc == tdesc_arm_with_neon
       || regcache->tdesc == tdesc_arm_with_vfpv3)
     num = 32;
@@ -96,6 +104,7 @@ arm_store_vfpregset (struct regcache *regcache, const void *buf)
     num = 16;
   else
     return;
+#endif
 
   base = find_regno (regcache->tdesc, "d0");
   for (i = 0; i < num; i++)
@@ -133,8 +142,10 @@ struct regs_info regs_info_aarch32 =
 void
 initialize_low_arch_aarch32 (void)
 {
+#ifndef __aarch64__
   init_registers_arm_with_vfpv2 ();
   init_registers_arm_with_vfpv3 ();
+#endif
   init_registers_arm_with_neon ();
 
   initialize_regsets_info (&aarch32_regsets_info);
diff --git a/gdb/gdbserver/linux-aarch32-low.h b/gdb/gdbserver/linux-aarch32-low.h
index 49bd5c3..72e5d37 100644
--- a/gdb/gdbserver/linux-aarch32-low.h
+++ b/gdb/gdbserver/linux-aarch32-low.h
@@ -24,9 +24,13 @@ void arm_store_vfpregset (struct regcache *regcache, const void *buf);
 
 void initialize_low_arch_aarch32 (void);
 
+#ifndef __aarch64__
 void init_registers_arm_with_vfpv2 (void);
 extern const struct target_desc *tdesc_arm_with_vfpv2;
+
 void init_registers_arm_with_vfpv3 (void);
 extern const struct target_desc *tdesc_arm_with_vfpv3;
+#endif
+
 void init_registers_arm_with_neon (void);
 extern const struct target_desc *tdesc_arm_with_neon;
diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 3a47521..e4a41ce 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -22,6 +22,7 @@
 #include "server.h"
 #include "linux-low.h"
 #include "nat/aarch64-linux-hw-point.h"
+#include "linux-aarch32-low.h"
 #include "elf/common.h"
 
 #include <signal.h>
@@ -69,6 +70,16 @@ struct arch_process_info
   struct aarch64_debug_reg_state debug_reg_state;
 };
 
+/* Return true if the size of register 0 is 8 byte.  */
+
+static int
+is_64bit_tdesc (void)
+{
+  struct regcache *regcache = get_thread_regcache (current_thread, 0);
+
+  return register_size (regcache->tdesc, 0) == 8;
+}
+
 /* Implementation of linux_target_ops method "cannot_store_register".  */
 
 static int
@@ -582,12 +593,32 @@ aarch64_linux_prepare_to_resume (struct lwp_info *lwp)
     }
 }
 
+/* Return the right target description according to the ELF file of
+   current thread.  */
+
+static const struct target_desc *
+aarch64_linux_read_description (void)
+{
+  unsigned int machine;
+  int is_elf64;
+  int tid;
+
+  tid = lwpid_of (current_thread);
+
+  is_elf64 = linux_pid_exe_is_elf_64_file (tid, &machine);
+
+  if (is_elf64)
+    return tdesc_aarch64;
+  else
+    return tdesc_arm_with_neon;
+}
+
 /* Implementation of linux_target_ops method "arch_setup".  */
 
 static void
 aarch64_arch_setup (void)
 {
-  current_process ()->tdesc = tdesc_aarch64;
+  current_process ()->tdesc = aarch64_linux_read_description ();
 
   aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread));
 }
@@ -611,7 +642,7 @@ static struct regsets_info aarch64_regsets_info =
     NULL, /* disabled_regsets */
   };
 
-static struct regs_info regs_info =
+static struct regs_info regs_info_aarch64 =
   {
     NULL, /* regset_bitmap */
     NULL, /* usrregs */
@@ -623,7 +654,10 @@ static struct regs_info regs_info =
 static const struct regs_info *
 aarch64_regs_info (void)
 {
-  return &regs_info;
+  if (is_64bit_tdesc ())
+    return &regs_info_aarch64;
+  else
+    return &regs_info_aarch32;
 }
 
 /* Implementation of linux_target_ops method "supports_tracepoints".  */
@@ -682,5 +716,7 @@ initialize_low_arch (void)
 {
   init_registers_aarch64 ();
 
+  initialize_low_arch_aarch32 ();
+
   initialize_regsets_info (&aarch64_regsets_info);
 }
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 6/7] Disable tracepoint support for aarch32
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
  2015-07-31 15:16 ` [PATCH 1/7] Move have_ptrace_getregset to linux-low.c Yao Qi
  2015-07-31 15:17 ` [PATCH 7/7] Mention multi-arch debugging support in NEWS Yao Qi
@ 2015-07-31 15:17 ` Yao Qi
  2015-07-31 15:17 ` [PATCH 3/7] Use arm target description and regs_info for 32-bit file on aarch64 GDBserver Yao Qi
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:17 UTC (permalink / raw)
  To: gdb-patches

We only support tracepoint for aarch64.  Although arm program can run
on aarch64, GDBserver doesn't support tracepoint for it.

gdb/gdbserver:

2015-07-31  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_supports_tracepoints): Return 0
	if current_thread is 32 bit.
---
 gdb/gdbserver/linux-aarch64-low.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 90d2b43..da472ae 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -701,7 +701,13 @@ aarch64_regs_info (void)
 static int
 aarch64_supports_tracepoints (void)
 {
-  return 1;
+  if (current_thread == NULL)
+    return 1;
+  else
+    {
+      /* We don't support tracepoints on aarch32 now.  */
+      return is_64bit_tdesc ();
+    }
 }
 
 /* Implementation of linux_target_ops method "supports_range_stepping".  */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 4/7] Get and set PC correctly on aarch64 in multi-arch
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
                   ` (3 preceding siblings ...)
  2015-07-31 15:17 ` [PATCH 3/7] Use arm target description and regs_info for 32-bit file on aarch64 GDBserver Yao Qi
@ 2015-07-31 15:17 ` Yao Qi
  2015-07-31 15:17 ` [PATCH 5/7] Disable Z0 packet on aarch64 on multi-arch debugging Yao Qi
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-07-31 15:17 UTC (permalink / raw)
  To: gdb-patches

gdb/gdbserver:

2015-07-31  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_get_pc): Get PC register on
	both aarch64 and aarch32.
	(aarch64_set_pc): Likewise.
---
 gdb/gdbserver/linux-aarch64-low.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index e4a41ce..3512ce9 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -155,12 +155,24 @@ extern int debug_threads;
 static CORE_ADDR
 aarch64_get_pc (struct regcache *regcache)
 {
-  unsigned long pc;
+  if (register_size (regcache->tdesc, 0) == 8)
+    {
+      unsigned long pc;
+
+      collect_register_by_name (regcache, "pc", &pc);
+      if (debug_threads)
+	debug_printf ("stop pc is %08lx\n", pc);
+      return pc;
+    }
+  else
+    {
+      unsigned int pc;
 
-  collect_register_by_name (regcache, "pc", &pc);
-  if (debug_threads)
-    debug_printf ("stop pc is %08lx\n", pc);
-  return pc;
+      collect_register_by_name (regcache, "pc", &pc);
+      if (debug_threads)
+	debug_printf ("stop pc is %04x\n", pc);
+      return pc;
+    }
 }
 
 /* Implementation of linux_target_ops method "set_pc".  */
@@ -168,8 +180,16 @@ aarch64_get_pc (struct regcache *regcache)
 static void
 aarch64_set_pc (struct regcache *regcache, CORE_ADDR pc)
 {
-  unsigned long newpc = pc;
-  supply_register_by_name (regcache, "pc", &newpc);
+  if (register_size (regcache->tdesc, 0) == 8)
+    {
+      unsigned long newpc = pc;
+      supply_register_by_name (regcache, "pc", &newpc);
+    }
+  else
+    {
+      unsigned int newpc = pc;
+      supply_register_by_name (regcache, "pc", &newpc);
+    }
 }
 
 #define aarch64_breakpoint_len 4
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-07-31 15:17 ` [PATCH 2/7] New regs_info for aarch32 Yao Qi
@ 2015-08-03 13:58   ` Pedro Alves
  2015-08-03 16:34     ` Yao Qi
  0 siblings, 1 reply; 21+ messages in thread
From: Pedro Alves @ 2015-08-03 13:58 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 07/31/2015 04:16 PM, Yao Qi wrote:
> @@ -973,9 +916,8 @@ initialize_low_arch (void)
>    /* Initialize the Linux target descriptions.  */
>    init_registers_arm ();
>    init_registers_arm_with_iwmmxt ();

Why weren't these moved as well?  At first,

> -  init_registers_arm_with_vfpv2 ();
> -  init_registers_arm_with_vfpv3 ();
> -  init_registers_arm_with_neon ();
> +
> +  initialize_low_arch_aarch32 ();

I thought that this was because aarch64 doesn't
do the old iwmmxt, but then in the following patch you
have this anyway:

>  void
>  initialize_low_arch_aarch32 (void)
>  {
> +#ifndef __aarch64__
>    init_registers_arm_with_vfpv2 ();
>    init_registers_arm_with_vfpv3 ();
> +#endif
>    init_registers_arm_with_neon ();
>

So I don't understand when/where to initialize arm32
descriptions going forward.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging
  2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
                   ` (6 preceding siblings ...)
  2015-07-31 15:17 ` [PATCH 2/7] New regs_info for aarch32 Yao Qi
@ 2015-08-03 14:00 ` Pedro Alves
  2015-08-04 13:41   ` Yao Qi
  7 siblings, 1 reply; 21+ messages in thread
From: Pedro Alves @ 2015-08-03 14:00 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

Hi Yao,

Apart from the comment I sent to patch #2, this
all looks good to me.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-08-03 13:58   ` Pedro Alves
@ 2015-08-03 16:34     ` Yao Qi
  2015-08-03 17:11       ` Pedro Alves
  0 siblings, 1 reply; 21+ messages in thread
From: Yao Qi @ 2015-08-03 16:34 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches



On 03/08/15 14:58, Pedro Alves wrote:
> Why weren't these moved as well?  At first,
>
>> >-  init_registers_arm_with_vfpv2 ();
>> >-  init_registers_arm_with_vfpv3 ();
>> >-  init_registers_arm_with_neon ();
>> >+
>> >+  initialize_low_arch_aarch32 ();
> I thought that this was because aarch64 doesn't
> do the old iwmmxt, but then in the following patch you
> have this anyway:

Yes, aarch64 doesn't support iwmmxt.

>
>> >  void
>> >  initialize_low_arch_aarch32 (void)
>> >  {
>> >+#ifndef __aarch64__
>> >    init_registers_arm_with_vfpv2 ();
>> >    init_registers_arm_with_vfpv3 ();
>> >+#endif
>> >    init_registers_arm_with_neon ();
>> >
> So I don't understand when/where to initialize arm32
> descriptions going forward.

Sorry, I am not sure I understand your question.

initialize_low_arch_aarch32 is called from
linux-arm-low.c and linux-aarch64-low.c for arm and aarch64
target respectively.  For aarch64, we initialize arm_with_neon
while for arm, we initialize arm_with_vfpv2 and arm_with_vfpv3
additionally.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-08-03 16:34     ` Yao Qi
@ 2015-08-03 17:11       ` Pedro Alves
  2015-08-04  9:52         ` Yao Qi
  0 siblings, 1 reply; 21+ messages in thread
From: Pedro Alves @ 2015-08-03 17:11 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 08/03/2015 05:34 PM, Yao Qi wrote:
> 
> 
> On 03/08/15 14:58, Pedro Alves wrote:
>> Why weren't these moved as well?  At first,
>>
>>>> -  init_registers_arm_with_vfpv2 ();
>>>> -  init_registers_arm_with_vfpv3 ();
>>>> -  init_registers_arm_with_neon ();
>>>> +
>>>> +  initialize_low_arch_aarch32 ();
>> I thought that this was because aarch64 doesn't
>> do the old iwmmxt, but then in the following patch you
>> have this anyway:
> 
> Yes, aarch64 doesn't support iwmmxt.
> 
>>
>>>>  void
>>>>  initialize_low_arch_aarch32 (void)
>>>>  {
>>>> +#ifndef __aarch64__
>>>>    init_registers_arm_with_vfpv2 ();
>>>>    init_registers_arm_with_vfpv3 ();
>>>> +#endif
>>>>    init_registers_arm_with_neon ();
>>>>
>> So I don't understand when/where to initialize arm32
>> descriptions going forward.
> 
> Sorry, I am not sure I understand your question.
> 
> initialize_low_arch_aarch32 is called from
> linux-arm-low.c and linux-aarch64-low.c for arm and aarch64
> target respectively.  For aarch64, we initialize arm_with_neon
> while for arm, we initialize arm_with_vfpv2 and arm_with_vfpv3
> additionally.
> 

Let me try putting it another way then.

Why are some init_registers_arm_XXX calls done in
linux-aarch32-low.c:initialize_low_arch_aarch32 but others
in linux-arm-low.c:initialize_low_arch?

If we already end up with __aarch64__ #ifdefs, shouldn't the resulting
code end like this?

  void
  initialize_low_arch_aarch32 (void)
  {
#ifndef __aarch64__
    init_registers_arm ();
    init_registers_arm_with_iwmmxt ();
    init_registers_arm_with_vfpv2 ();
    init_registers_arm_with_vfpv3 ();
#endif
    init_registers_arm_with_neon ();
  }

Isn't aarch32 the term used for all 32-bit execution state,
including pre-ARMv8?  Otherwise, going forward, what is the
guideline to know where to put a new
init_registers_arm_xxx call?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-08-03 17:11       ` Pedro Alves
@ 2015-08-04  9:52         ` Yao Qi
  2015-08-04 10:11           ` Pedro Alves
  2015-08-11 19:40           ` Joel Brobecker
  0 siblings, 2 replies; 21+ messages in thread
From: Yao Qi @ 2015-08-04  9:52 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, gdb-patches

Pedro Alves <palves@redhat.com> writes:

> Let me try putting it another way then.
>
> Why are some init_registers_arm_XXX calls done in
> linux-aarch32-low.c:initialize_low_arch_aarch32 but others
> in linux-arm-low.c:initialize_low_arch?
>
> If we already end up with __aarch64__ #ifdefs, shouldn't the resulting
> code end like this?
>
>   void
>   initialize_low_arch_aarch32 (void)
>   {
> #ifndef __aarch64__
>     init_registers_arm ();
>     init_registers_arm_with_iwmmxt ();
>     init_registers_arm_with_vfpv2 ();
>     init_registers_arm_with_vfpv3 ();
> #endif
>     init_registers_arm_with_neon ();
>   }
>
> Isn't aarch32 the term used for all 32-bit execution state,
> including pre-ARMv8?  Otherwise, going forward, what is the
> guideline to know where to put a new
> init_registers_arm_xxx call?

aarch32 means armv7+neon, so ideally we only need call
init_registers_arm_with_neon for aarch32.  However, arm_store_vfpregset
and arm_fill_vfpregset need to check tdesc_arm_with_vfpv3 and
tdesc_arm_with_vfpv2, so we need to call init_registers_arm_with_vfpv2
and init_registers_arm_with_vfpv3 to init them.  That is the reason I
call them inside initialize_low_arch_aarch32.

I agree the "#ifndef __aarch64__" is confusing, and let me remove that
block out of initialize_low_arch_aarch32.  The patch below is updated to
initialize arm_with_neon target description in
linux-aarch32-low.c:initialize_low_arch_aarch32, and leave vfpv2 and
vfpv3 target descriptions inside linux-arm-low.c.  This is cleaner than
the previous version.    As a result, patch 3/7 is cleaner too, because
"#ifndef __aarch64__" is not needed anymore.

The guideline of adding new arm targets in my mind is if new arm target
can be run on aarch32 (32-bit mode on aarch64), it should be initialized
in initialize_low_arch_aarch32.  If new arm target can't be run on
32-bit mode on aarch64, it should be initialized in
linux-arm-low.c:initialize_low_arch.

-- 
Yao (齐尧)

Subject: [PATCH 2/7] New regs_info for aarch32

This patch adds a new regs_info regs_info_aarch32 for aarch32, which
can be used by both aarch64 and arm backend.

gdb/gdbserver:

2015-08-04  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_tgtobj): Add linux-aarch32-low.o.
	* linux-aarch32-low.c: New file.
	* linux-aarch32-low.h: New file.
	* linux-arm-low.c (arm_fill_gregset): Move it to
	linux-aarch32-low.c.
	(arm_store_gregset): Likewise.
	(arm_fill_vfpregset): Call arm_fill_vfpregset_num
	(arm_store_vfpregset): Call arm_store_vfpregset_num.
	(arm_arch_setup): Check if PTRACE_GETREGSET works.
	(regs_info): Rename to regs_info_arm.
	(arm_regs_info): Return regs_info_aarch32 if
	have_ptrace_getregset is 1 and target description is
	arm_with_neon or arm_with_vfpv3.
	(initialize_low_arch): Don't call init_registers_arm_with_neon.
	Call initialize_low_arch_aarch32 instead.
---
 gdb/gdbserver/configure.srv       |   1 +
 gdb/gdbserver/linux-aarch32-low.c | 140 ++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/linux-aarch32-low.h |  29 ++++++++
 gdb/gdbserver/linux-arm-low.c     |  78 +++++++++------------
 4 files changed, 201 insertions(+), 47 deletions(-)
 create mode 100644 gdb/gdbserver/linux-aarch32-low.c
 create mode 100644 gdb/gdbserver/linux-aarch32-low.h

diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 9a04aac..1a8361a 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -62,6 +62,7 @@ case "${target}" in
 			srv_regobj="${srv_regobj} arm-with-vfpv3.o"
 			srv_regobj="${srv_regobj} arm-with-neon.o"
 			srv_tgtobj="$srv_linux_obj linux-arm-low.o"
+			srv_tgtobj="$srv_tgtobj linux-aarch32-low.o"
 			srv_xmlfiles="arm-with-iwmmxt.xml"
 			srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv2.xml"
 			srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv3.xml"
diff --git a/gdb/gdbserver/linux-aarch32-low.c b/gdb/gdbserver/linux-aarch32-low.c
new file mode 100644
index 0000000..7f3b985
--- /dev/null
+++ b/gdb/gdbserver/linux-aarch32-low.c
@@ -0,0 +1,140 @@
+/* Copyright (C) 1995-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 "server.h"
+#include "arch/arm.h"
+#include "linux-low.h"
+#include "linux-aarch32-low.h"
+
+#include <sys/ptrace.h>
+/* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
+   On Bionic elf.h and linux/elf.h have conflicting definitions.  */
+#ifndef ELFMAG0
+#include <elf.h>
+#endif
+
+/* Collect GP registers from REGCACHE to buffer BUF.  */
+
+void
+arm_fill_gregset (struct regcache *regcache, void *buf)
+{
+  int i;
+  uint32_t *regs = buf;
+
+  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
+    collect_register (regcache, i, &regs[i]);
+
+  collect_register (regcache, ARM_PS_REGNUM, &regs[16]);
+}
+
+/* Supply GP registers contents, stored in BUF, to REGCACHE.  */
+
+void
+arm_store_gregset (struct regcache *regcache, const void *buf)
+{
+  int i;
+  char zerobuf[8];
+  const uint32_t *regs = buf;
+
+  memset (zerobuf, 0, 8);
+  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
+    supply_register (regcache, i, &regs[i]);
+
+  for (; i < ARM_PS_REGNUM; i++)
+    supply_register (regcache, i, zerobuf);
+
+  supply_register (regcache, ARM_PS_REGNUM, &regs[16]);
+}
+
+/* Collect NUM number of VFP registers from REGCACHE to buffer BUF.  */
+
+void
+arm_fill_vfpregset_num (struct regcache *regcache, void *buf, int num)
+{
+  int i, base;
+
+  gdb_assert (num == 16 || num == 32);
+
+  base = find_regno (regcache->tdesc, "d0");
+  for (i = 0; i < num; i++)
+    collect_register (regcache, base + i, (char *) buf + i * 8);
+
+  collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
+}
+
+/* Supply NUM number of VFP registers contents, stored in BUF, to
+   REGCACHE.  */
+
+void
+arm_store_vfpregset_num (struct regcache *regcache, const void *buf, int num)
+{
+  int i, base;
+
+  gdb_assert (num == 16 || num == 32);
+
+  base = find_regno (regcache->tdesc, "d0");
+  for (i = 0; i < num; i++)
+    supply_register (regcache, base + i, (char *) buf + i * 8);
+
+  supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
+}
+
+static void
+arm_fill_vfpregset (struct regcache *regcache, void *buf)
+{
+  arm_fill_vfpregset_num (regcache, buf, 32);
+}
+
+static void
+arm_store_vfpregset (struct regcache *regcache, const void *buf)
+{
+  arm_store_vfpregset_num (regcache, buf, 32);
+}
+
+/* Register sets with using PTRACE_GETREGSET.  */
+
+static struct regset_info aarch32_regsets[] = {
+  { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS, 18 * 4,
+    GENERAL_REGS,
+    arm_fill_gregset, arm_store_gregset },
+  { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_ARM_VFP, 32 * 8 + 4,
+    EXTENDED_REGS,
+    arm_fill_vfpregset, arm_store_vfpregset },
+  { 0, 0, 0, -1, -1, NULL, NULL }
+};
+
+static struct regsets_info aarch32_regsets_info =
+  {
+    aarch32_regsets, /* regsets */
+    0, /* num_regsets */
+    NULL, /* disabled_regsets */
+  };
+
+struct regs_info regs_info_aarch32 =
+  {
+    NULL, /* regset_bitmap */
+    NULL, /* usrregs */
+    &aarch32_regsets_info
+  };
+
+void
+initialize_low_arch_aarch32 (void)
+{
+  init_registers_arm_with_neon ();
+
+  initialize_regsets_info (&aarch32_regsets_info);
+}
diff --git a/gdb/gdbserver/linux-aarch32-low.h b/gdb/gdbserver/linux-aarch32-low.h
new file mode 100644
index 0000000..6682f0a
--- /dev/null
+++ b/gdb/gdbserver/linux-aarch32-low.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 1995-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/>.  */
+
+extern struct regs_info regs_info_aarch32;
+
+void arm_fill_gregset (struct regcache *regcache, void *buf);
+void arm_store_gregset (struct regcache *regcache, const void *buf);
+void arm_fill_vfpregset_num (struct regcache *regcache, void *buf, int num);
+void arm_store_vfpregset_num (struct regcache *regcache, const void *buf,
+			      int num);
+
+void initialize_low_arch_aarch32 (void);
+
+void init_registers_arm_with_neon (void);
+extern const struct target_desc *tdesc_arm_with_neon;
diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
index 3c5956b..6a27e6e 100644
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -19,7 +19,9 @@
 #include "server.h"
 #include "linux-low.h"
 #include "arch/arm.h"
+#include "linux-aarch32-low.h"
 
+#include <sys/uio.h>
 /* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
    On Bionic elf.h and linux/elf.h have conflicting definitions.  */
 #ifndef ELFMAG0
@@ -41,9 +43,6 @@ extern const struct target_desc *tdesc_arm_with_vfpv2;
 void init_registers_arm_with_vfpv3 (void);
 extern const struct target_desc *tdesc_arm_with_vfpv3;
 
-void init_registers_arm_with_neon (void);
-extern const struct target_desc *tdesc_arm_with_neon;
-
 #ifndef PTRACE_GET_THREAD_AREA
 #define PTRACE_GET_THREAD_AREA 22
 #endif
@@ -150,35 +149,6 @@ arm_cannot_fetch_register (int regno)
 }
 
 static void
-arm_fill_gregset (struct regcache *regcache, void *buf)
-{
-  int i;
-  uint32_t *regs = buf;
-
-  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
-    collect_register (regcache, i, &regs[i]);
-
-  collect_register (regcache, ARM_PS_REGNUM, &regs[16]);
-}
-
-static void
-arm_store_gregset (struct regcache *regcache, const void *buf)
-{
-  int i;
-  char zerobuf[8];
-  const uint32_t *regs = buf;
-
-  memset (zerobuf, 0, 8);
-  for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
-    supply_register (regcache, i, &regs[i]);
-
-  for (; i < ARM_PS_REGNUM; i++)
-    supply_register (regcache, i, zerobuf);
-
-  supply_register (regcache, ARM_PS_REGNUM, &regs[16]);
-}
-
-static void
 arm_fill_wmmxregset (struct regcache *regcache, void *buf)
 {
   int i;
@@ -215,7 +185,7 @@ arm_store_wmmxregset (struct regcache *regcache, const void *buf)
 static void
 arm_fill_vfpregset (struct regcache *regcache, void *buf)
 {
-  int i, num, base;
+  int num;
 
   if (regcache->tdesc == tdesc_arm_with_neon
       || regcache->tdesc == tdesc_arm_with_vfpv3)
@@ -225,17 +195,13 @@ arm_fill_vfpregset (struct regcache *regcache, void *buf)
   else
     return;
 
-  base = find_regno (regcache->tdesc, "d0");
-  for (i = 0; i < num; i++)
-    collect_register (regcache, base + i, (char *) buf + i * 8);
-
-  collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
+  arm_fill_vfpregset_num (regcache, buf, num);
 }
 
 static void
 arm_store_vfpregset (struct regcache *regcache, const void *buf)
 {
-  int i, num, base;
+  int num;
 
   if (regcache->tdesc == tdesc_arm_with_neon
       || regcache->tdesc == tdesc_arm_with_vfpv3)
@@ -245,11 +211,7 @@ arm_store_vfpregset (struct regcache *regcache, const void *buf)
   else
     return;
 
-  base = find_regno (regcache->tdesc, "d0");
-  for (i = 0; i < num; i++)
-    supply_register (regcache, base + i, (char *) buf + i * 8);
-
-  supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
+  arm_store_vfpregset_num (regcache, buf, num);
 }
 
 extern int debug_threads;
@@ -888,9 +850,24 @@ arm_read_description (void)
 static void
 arm_arch_setup (void)
 {
+  int tid = lwpid_of (current_thread);
+  int gpregs[18];
+  struct iovec iov;
+
   current_process ()->tdesc = arm_read_description ();
+
+  iov.iov_base = gpregs;
+  iov.iov_len = sizeof (gpregs);
+
+  /* Check if PTRACE_GETREGSET works.  */
+  if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov) == 0)
+    have_ptrace_getregset = 1;
+  else
+    have_ptrace_getregset = 0;
 }
 
+/* Register sets without using PTRACE_GETREGSET.  */
+
 static struct regset_info arm_regsets[] = {
   { PTRACE_GETREGS, PTRACE_SETREGS, 0, 18 * 4,
     GENERAL_REGS,
@@ -917,7 +894,7 @@ static struct usrregs_info arm_usrregs_info =
     arm_regmap,
   };
 
-static struct regs_info regs_info =
+static struct regs_info regs_info_arm =
   {
     NULL, /* regset_bitmap */
     &arm_usrregs_info,
@@ -927,7 +904,13 @@ static struct regs_info regs_info =
 static const struct regs_info *
 arm_regs_info (void)
 {
-  return &regs_info;
+  const struct target_desc *tdesc = current_process ()->tdesc;
+
+  if (have_ptrace_getregset == 1
+      && (tdesc == tdesc_arm_with_neon || tdesc == tdesc_arm_with_vfpv3))
+    return &regs_info_aarch32;
+  else
+    return &regs_info_arm;
 }
 
 struct linux_target_ops the_low_target = {
@@ -975,7 +958,8 @@ initialize_low_arch (void)
   init_registers_arm_with_iwmmxt ();
   init_registers_arm_with_vfpv2 ();
   init_registers_arm_with_vfpv3 ();
-  init_registers_arm_with_neon ();
+
+  initialize_low_arch_aarch32 ();
 
   initialize_regsets_info (&arm_regsets_info);
 }
-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-08-04  9:52         ` Yao Qi
@ 2015-08-04 10:11           ` Pedro Alves
  2015-08-11 19:40           ` Joel Brobecker
  1 sibling, 0 replies; 21+ messages in thread
From: Pedro Alves @ 2015-08-04 10:11 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 08/04/2015 10:51 AM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>> Let me try putting it another way then.
>>
>> Why are some init_registers_arm_XXX calls done in
>> linux-aarch32-low.c:initialize_low_arch_aarch32 but others
>> in linux-arm-low.c:initialize_low_arch?
>>
>> If we already end up with __aarch64__ #ifdefs, shouldn't the resulting
>> code end like this?
>>
>>   void
>>   initialize_low_arch_aarch32 (void)
>>   {
>> #ifndef __aarch64__
>>     init_registers_arm ();
>>     init_registers_arm_with_iwmmxt ();
>>     init_registers_arm_with_vfpv2 ();
>>     init_registers_arm_with_vfpv3 ();
>> #endif
>>     init_registers_arm_with_neon ();
>>   }
>>
>> Isn't aarch32 the term used for all 32-bit execution state,
>> including pre-ARMv8?  Otherwise, going forward, what is the
>> guideline to know where to put a new
>> init_registers_arm_xxx call?
> 
> aarch32 means armv7+neon, 

Ah.

> so ideally we only need call
> init_registers_arm_with_neon for aarch32.  However, arm_store_vfpregset
> and arm_fill_vfpregset need to check tdesc_arm_with_vfpv3 and
> tdesc_arm_with_vfpv2, so we need to call init_registers_arm_with_vfpv2
> and init_registers_arm_with_vfpv3 to init them.  That is the reason I
> call them inside initialize_low_arch_aarch32.
> 
> I agree the "#ifndef __aarch64__" is confusing, and let me remove that
> block out of initialize_low_arch_aarch32.  The patch below is updated to
> initialize arm_with_neon target description in
> linux-aarch32-low.c:initialize_low_arch_aarch32, and leave vfpv2 and
> vfpv3 target descriptions inside linux-arm-low.c.  This is cleaner than
> the previous version.    As a result, patch 3/7 is cleaner too, because
> "#ifndef __aarch64__" is not needed anymore.
> 

Nice.

> The guideline of adding new arm targets in my mind is if new arm target
> can be run on aarch32 (32-bit mode on aarch64), it should be initialized
> in initialize_low_arch_aarch32.  If new arm target can't be run on
> 32-bit mode on aarch64, it should be initialized in
> linux-arm-low.c:initialize_low_arch.
> 

OK, that makes sense.  This version looks good to me.  Thanks!

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging
  2015-08-03 14:00 ` [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Pedro Alves
@ 2015-08-04 13:41   ` Yao Qi
  0 siblings, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-08-04 13:41 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, gdb-patches

Pedro Alves <palves@redhat.com> writes:

> Apart from the comment I sent to patch #2, this
> all looks good to me.

I've pushed them in except patch #7 which needs doc review.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/7] Use arm target description and regs_info for 32-bit file on aarch64 GDBserver
  2015-07-31 15:17 ` [PATCH 3/7] Use arm target description and regs_info for 32-bit file on aarch64 GDBserver Yao Qi
@ 2015-08-04 13:44   ` Yao Qi
  0 siblings, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-08-04 13:44 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Yao Qi <qiyaoltc@gmail.com> writes:

> This patch teaches aarch64-linux GDBserver use 32-bit arm target
> description and regs_info if the elf file is 32-bit.

This patch is updated together with patch #2.  Here is what I pushed in.

-- 
Yao (齐尧)

Subject: [PATCH] Use arm target description and regs_info for 32-bit file on aarch64 GDBserver

This patch teaches aarch64-linux GDBserver use 32-bit arm target
description and regs_info if the elf file is 32-bit.

gdb/gdbserver:

2015-08-04  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (case aarch64*-*-linux*): Append arm-with-neon.o
	to srv_regobj and append arm-core.xml arm-vfpv3.xml and
	arm-with-neon.xml to srv_xmlfiles.
	* linux-aarch64-low.c: Include linux-aarch32-low.h.
	(is_64bit_tdesc): New function.
	(aarch64_linux_read_description): New function.
	(aarch64_arch_setup): Call aarch64_linux_read_description.
	(regs_info): Rename to regs_info_aarch64.
	(aarch64_regs_info): Return right regs_info.
	(initialize_low_arch): Call initialize_low_arch_aarch32.

diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 0ed70a2..d652bb3 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,18 @@
 2015-08-04  Yao Qi  <yao.qi@linaro.org>
 
+	* configure.srv (case aarch64*-*-linux*): Append arm-with-neon.o
+	to srv_regobj and append arm-core.xml arm-vfpv3.xml and
+	arm-with-neon.xml to srv_xmlfiles.
+	* linux-aarch64-low.c: Include linux-aarch32-low.h.
+	(is_64bit_tdesc): New function.
+	(aarch64_linux_read_description): New function.
+	(aarch64_arch_setup): Call aarch64_linux_read_description.
+	(regs_info): Rename to regs_info_aarch64.
+	(aarch64_regs_info): Return right regs_info.
+	(initialize_low_arch): Call initialize_low_arch_aarch32.
+
+2015-08-04  Yao Qi  <yao.qi@linaro.org>
+
 	* configure.srv (srv_tgtobj): Add linux-aarch32-low.o.
 	* linux-aarch32-low.c: New file.
 	* linux-aarch32-low.h: New file.
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 1a8361a..0b18d1d 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -49,11 +49,15 @@ srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-wa
 case "${target}" in
   aarch64*-*-linux*)
 			srv_regobj="aarch64.o"
+			srv_regobj="${srv_regobj} arm-with-neon.o"
 			srv_tgtobj="linux-aarch64-low.o aarch64-linux-hw-point.o"
+			srv_tgtobj="$srv_tgtobj linux-aarch32-low.o"
 			srv_tgtobj="${srv_tgtobj} $srv_linux_obj"
 			srv_xmlfiles="aarch64.xml"
 			srv_xmlfiles="${srv_xmlfiles} aarch64-core.xml"
 			srv_xmlfiles="${srv_xmlfiles} aarch64-fpu.xml"
+			srv_xmlfiles="${srv_xmlfiles} arm-core.xml arm-vfpv3.xml"
+			srv_xmlfiles="${srv_xmlfiles} arm-with-neon.xml"
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
 			;;
diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 3a47521..e4a41ce 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -22,6 +22,7 @@
 #include "server.h"
 #include "linux-low.h"
 #include "nat/aarch64-linux-hw-point.h"
+#include "linux-aarch32-low.h"
 #include "elf/common.h"
 
 #include <signal.h>
@@ -69,6 +70,16 @@ struct arch_process_info
   struct aarch64_debug_reg_state debug_reg_state;
 };
 
+/* Return true if the size of register 0 is 8 byte.  */
+
+static int
+is_64bit_tdesc (void)
+{
+  struct regcache *regcache = get_thread_regcache (current_thread, 0);
+
+  return register_size (regcache->tdesc, 0) == 8;
+}
+
 /* Implementation of linux_target_ops method "cannot_store_register".  */
 
 static int
@@ -582,12 +593,32 @@ aarch64_linux_prepare_to_resume (struct lwp_info *lwp)
     }
 }
 
+/* Return the right target description according to the ELF file of
+   current thread.  */
+
+static const struct target_desc *
+aarch64_linux_read_description (void)
+{
+  unsigned int machine;
+  int is_elf64;
+  int tid;
+
+  tid = lwpid_of (current_thread);
+
+  is_elf64 = linux_pid_exe_is_elf_64_file (tid, &machine);
+
+  if (is_elf64)
+    return tdesc_aarch64;
+  else
+    return tdesc_arm_with_neon;
+}
+
 /* Implementation of linux_target_ops method "arch_setup".  */
 
 static void
 aarch64_arch_setup (void)
 {
-  current_process ()->tdesc = tdesc_aarch64;
+  current_process ()->tdesc = aarch64_linux_read_description ();
 
   aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread));
 }
@@ -611,7 +642,7 @@ static struct regsets_info aarch64_regsets_info =
     NULL, /* disabled_regsets */
   };
 
-static struct regs_info regs_info =
+static struct regs_info regs_info_aarch64 =
   {
     NULL, /* regset_bitmap */
     NULL, /* usrregs */
@@ -623,7 +654,10 @@ static struct regs_info regs_info =
 static const struct regs_info *
 aarch64_regs_info (void)
 {
-  return &regs_info;
+  if (is_64bit_tdesc ())
+    return &regs_info_aarch64;
+  else
+    return &regs_info_aarch32;
 }
 
 /* Implementation of linux_target_ops method "supports_tracepoints".  */
@@ -682,5 +716,7 @@ initialize_low_arch (void)
 {
   init_registers_aarch64 ();
 
+  initialize_low_arch_aarch32 ();
+
   initialize_regsets_info (&aarch64_regsets_info);
 }

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-08-04  9:52         ` Yao Qi
  2015-08-04 10:11           ` Pedro Alves
@ 2015-08-11 19:40           ` Joel Brobecker
  2015-08-18 15:21             ` Yao Qi
  1 sibling, 1 reply; 21+ messages in thread
From: Joel Brobecker @ 2015-08-11 19:40 UTC (permalink / raw)
  To: Yao Qi; +Cc: Pedro Alves, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1479 bytes --]

Hi Yao,

> 2015-08-04  Yao Qi  <yao.qi@linaro.org>
> 
> 	* configure.srv (srv_tgtobj): Add linux-aarch32-low.o.
> 	* linux-aarch32-low.c: New file.
> 	* linux-aarch32-low.h: New file.
> 	* linux-arm-low.c (arm_fill_gregset): Move it to
> 	linux-aarch32-low.c.
> 	(arm_store_gregset): Likewise.
> 	(arm_fill_vfpregset): Call arm_fill_vfpregset_num
> 	(arm_store_vfpregset): Call arm_store_vfpregset_num.
> 	(arm_arch_setup): Check if PTRACE_GETREGSET works.
> 	(regs_info): Rename to regs_info_arm.
> 	(arm_regs_info): Return regs_info_aarch32 if
> 	have_ptrace_getregset is 1 and target description is
> 	arm_with_neon or arm_with_vfpv3.
> 	(initialize_low_arch): Don't call init_registers_arm_with_neon.
> 	Call initialize_low_arch_aarch32 instead.

This patch is causing a GDBserver build failure on some versions
of GNU/Linux (the version we support is fairly old), but also on
relatively recent versions of Android as well.

The problem is that NT_ARM_VFP is not always defined. I tried
the attached patch, which I was a bit dubious about, but seems
to work ("info float" does not error out, and print a series of zeros),
but I'm not sure whether I'm exercising the code at all. The other
alternative I was thinking of was perhaps to just #ifndef out
the entry in aarch32_regsets that needs NT_ARM_VFP. It might be
cleaner, but I haven't tried it.

gdb/gdbserver/ChangeLog:

        * linux-aarch32-low.c (NT_ARM_VFP): Define if not already defined.

WDYT?

Thanks!
-- 
Joel

[-- Attachment #2: 0001-gdbserver-linux-aarch32-low-build-failure-when-NT_AR.patch --]
[-- Type: text/x-diff, Size: 1203 bytes --]

From 6c3cc336283db01c11a89bdbfdb70cc90a7b5d3e Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Tue, 11 Aug 2015 15:28:19 -0400
Subject: [PATCH] gdbserver/linux-aarch32-low: build failure when NT_ARM_VFP
 not defined

On some older versions of GNU/Linux, gdbserver now fails to build
due to an undefined reference to NT_ARM_VFP. Same issue on Android,
where this macros is undefined until Android API level 21 (Android
5.0 "Lollipop").

This patch modifies linux-aarch32-low.c to define that macros when
not already defined.

gdb/gdbserver/ChangeLog:

        * linux-aarch32-low.c (NT_ARM_VFP): Define if not already defined.
---
 gdb/gdbserver/linux-aarch32-low.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gdb/gdbserver/linux-aarch32-low.c b/gdb/gdbserver/linux-aarch32-low.c
index 7f3b985..5876b13 100644
--- a/gdb/gdbserver/linux-aarch32-low.c
+++ b/gdb/gdbserver/linux-aarch32-low.c
@@ -27,6 +27,12 @@
 #include <elf.h>
 #endif
 
+/* Some older versions of GNU/Linux and Android do not define
+   the following macros.  */
+#ifndef NT_ARM_VFP
+#define NT_ARM_VFP 0x400
+#endif
+
 /* Collect GP registers from REGCACHE to buffer BUF.  */
 
 void
-- 
2.1.4


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-08-11 19:40           ` Joel Brobecker
@ 2015-08-18 15:21             ` Yao Qi
  2015-08-18 22:42               ` Joel Brobecker
  0 siblings, 1 reply; 21+ messages in thread
From: Yao Qi @ 2015-08-18 15:21 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Pedro Alves, gdb-patches

On 11/08/15 20:40, Joel Brobecker wrote:
> This patch is causing a GDBserver build failure on some versions
> of GNU/Linux (the version we support is fairly old), but also on
> relatively recent versions of Android as well.
>
> The problem is that NT_ARM_VFP is not always defined. I tried
> the attached patch, which I was a bit dubious about, but seems
> to work ("info float" does not error out, and print a series of zeros),
> but I'm not sure whether I'm exercising the code at all. The other
> alternative I was thinking of was perhaps to just #ifndef out
> the entry in aarch32_regsets that needs NT_ARM_VFP. It might be
> cleaner, but I haven't tried it.

If kernel doesn't support NT_ARM_VFP, GDBserver
(linux-low.c:regsets_fetch_inferior_registers) can disable this
regset_info.  On the other hand, if kernel is too old to support
PTRACE_GETREGSET, aarch32_regsets won't be used at all.

>
> gdb/gdbserver/ChangeLog:
>
>          * linux-aarch32-low.c (NT_ARM_VFP): Define if not already defined.
>

Patch looks right to me.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] New regs_info for aarch32
  2015-08-18 15:21             ` Yao Qi
@ 2015-08-18 22:42               ` Joel Brobecker
  0 siblings, 0 replies; 21+ messages in thread
From: Joel Brobecker @ 2015-08-18 22:42 UTC (permalink / raw)
  To: Yao Qi; +Cc: Pedro Alves, gdb-patches

> If kernel doesn't support NT_ARM_VFP, GDBserver
> (linux-low.c:regsets_fetch_inferior_registers) can disable this
> regset_info.  On the other hand, if kernel is too old to support
> PTRACE_GETREGSET, aarch32_regsets won't be used at all.
> 
> >
> >gdb/gdbserver/ChangeLog:
> >
> >         * linux-aarch32-low.c (NT_ARM_VFP): Define if not already defined.
> >
> 
> Patch looks right to me.

Thank you, Yao. Patch pushed!

-- 
Joel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 7/7] Mention multi-arch debugging support in NEWS
  2015-07-31 15:17 ` [PATCH 7/7] Mention multi-arch debugging support in NEWS Yao Qi
@ 2015-08-19  8:26   ` Yao Qi
  2015-09-04 14:30   ` Yao Qi
  1 sibling, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-08-19  8:26 UTC (permalink / raw)
  To: eliz; +Cc: gdb-patches

Yao Qi <qiyaoltc@gmail.com> writes:

> gdb:
>
> 2015-07-31  Yao Qi  <yao.qi@linaro.org>
>
> 	* NEWS: Mention the aarch64 multi-arch debugging support.
> ---
>  gdb/NEWS | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 7ce9758..dd834b9 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -5,6 +5,10 @@
>  
>  * Support for tracepoints on aarch64-linux was added in GDBserver.
>  
> +* Multi-architecture debugging is supported on AArch64 GNU/Linux.
> +  GDB now is able to debug both AArch64 applications and ARM applications
> +  at the same time.
> +

Hi Eli,
How about the NEWS entry?

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 7/7] Mention multi-arch debugging support in NEWS
  2015-07-31 15:17 ` [PATCH 7/7] Mention multi-arch debugging support in NEWS Yao Qi
  2015-08-19  8:26   ` Yao Qi
@ 2015-09-04 14:30   ` Yao Qi
  1 sibling, 0 replies; 21+ messages in thread
From: Yao Qi @ 2015-09-04 14:30 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Yao Qi <qiyaoltc@gmail.com> writes:

> 2015-07-31  Yao Qi  <yao.qi@linaro.org>
>
> 	* NEWS: Mention the aarch64 multi-arch debugging support.

I push it in.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2015-09-04 14:30 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-31 15:17 [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Yao Qi
2015-07-31 15:16 ` [PATCH 1/7] Move have_ptrace_getregset to linux-low.c Yao Qi
2015-07-31 15:17 ` [PATCH 7/7] Mention multi-arch debugging support in NEWS Yao Qi
2015-08-19  8:26   ` Yao Qi
2015-09-04 14:30   ` Yao Qi
2015-07-31 15:17 ` [PATCH 6/7] Disable tracepoint support for aarch32 Yao Qi
2015-07-31 15:17 ` [PATCH 3/7] Use arm target description and regs_info for 32-bit file on aarch64 GDBserver Yao Qi
2015-08-04 13:44   ` Yao Qi
2015-07-31 15:17 ` [PATCH 4/7] Get and set PC correctly on aarch64 in multi-arch Yao Qi
2015-07-31 15:17 ` [PATCH 5/7] Disable Z0 packet on aarch64 on multi-arch debugging Yao Qi
2015-07-31 15:17 ` [PATCH 2/7] New regs_info for aarch32 Yao Qi
2015-08-03 13:58   ` Pedro Alves
2015-08-03 16:34     ` Yao Qi
2015-08-03 17:11       ` Pedro Alves
2015-08-04  9:52         ` Yao Qi
2015-08-04 10:11           ` Pedro Alves
2015-08-11 19:40           ` Joel Brobecker
2015-08-18 15:21             ` Yao Qi
2015-08-18 22:42               ` Joel Brobecker
2015-08-03 14:00 ` [PATCH 0/7] Aarch64 linux GDB remote multi-arch debugging Pedro Alves
2015-08-04 13:41   ` Yao Qi

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).