gdb/hppa: guess g packet size

Message ID 20240228202028.1517040-1-svens@stackframe.org
State New
Headers
Series gdb/hppa: guess g packet size |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Testing failed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Sven Schnelle Feb. 28, 2024, 8:20 p.m. UTC
  With qemu supporting 64 bit now, add some code to determine the
register size of a hppa remote target. This first checks the
PROPERTY_GP32/PROPERTY_GP64 flags in target_desc, and uses
bfd_arch_info as fallback.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
---
 gdb/hppa-tdep.c | 47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)
  

Comments

Sven Schnelle March 18, 2024, 5:30 p.m. UTC | #1
svens@stackframe.org (Sven Schnelle) writes:

> With qemu supporting 64 bit now, add some code to determine the
> register size of a hppa remote target. This first checks the
> PROPERTY_GP32/PROPERTY_GP64 flags in target_desc, and uses
> bfd_arch_info as fallback.
>
> Signed-off-by: Sven Schnelle <svens@stackframe.org>
> ---
>  gdb/hppa-tdep.c | 47 ++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 42 insertions(+), 5 deletions(-)

Gentle ping?

Thanks!
Sven
  

Patch

diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 30128bafac4..d501e8470b6 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -34,6 +34,8 @@ 
 #include "frame-unwind.h"
 #include "frame-base.h"
 
+#include "remote.h"
+#include "target-descriptions.h"
 #include "gdbcore.h"
 #include "gdbcmd.h"
 #include "gdbtypes.h"
@@ -43,6 +45,14 @@ 
 
 static bool hppa_debug = false;
 
+/* Properties (for struct target_desc) describing the g/G packet
+   layout.  */
+#define PROPERTY_GP32 "internal: transfers-32bit-registers"
+#define PROPERTY_GP64 "internal: transfers-64bit-registers"
+
+struct target_desc *hppa_tdesc32;
+struct target_desc *hppa_tdesc64;
+
 /* Some local constants.  */
 static const int hppa32_num_regs = 128;
 static const int hppa64_num_regs = 96;
@@ -2978,6 +2988,17 @@  hppa_skip_trampoline_code (const frame_info_ptr &frame, CORE_ADDR pc)
 
    -- chastain 2003-12-18  */
 
+static void
+hppa_register_g_packet_guesses (struct gdbarch *gdbarch)
+{
+  /* If the size matches the set of 32-bit or 64-bit integer registers,
+     assume that's what we've got.  */
+  register_remote_g_packet_guess (gdbarch, hppa32_num_regs * 4, hppa_tdesc32);
+  register_remote_g_packet_guess (gdbarch, hppa64_num_regs * 8, hppa_tdesc64);
+
+  /* Otherwise we don't have a useful guess.  */
+}
+
 static struct gdbarch *
 hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 {
@@ -2991,14 +3012,24 @@  hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     = gdbarch_alloc (&info, gdbarch_tdep_up (new hppa_gdbarch_tdep));
   hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
-  /* Determine from the bfd_arch_info structure if we are dealing with
-     a 32 or 64 bits architecture.  If the bfd_arch_info is not available,
-     then default to a 32bit machine.  */
-  if (info.bfd_arch_info != NULL)
+  /* Determine from the target description if we are dealing with
+     a 32 or 64 bits architecture. If the target description is not
+     available, then check whether bfd_arch_info could be used.
+     Otherwise default to a 32bit machine.
+  */
+  if (info.target_desc != NULL) {
+    if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL)
+      tdep->bytes_per_address = 8;
+    else if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL)
+      tdep->bytes_per_address = 4;
+  } else if (info.bfd_arch_info != NULL) {
     tdep->bytes_per_address =
       info.bfd_arch_info->bits_per_address / info.bfd_arch_info->bits_per_byte;
-  else
+  } else {
     tdep->bytes_per_address = 4;
+  }
+
+  hppa_register_g_packet_guesses (gdbarch);
 
   tdep->find_global_pointer = hppa_find_global_pointer;
 
@@ -3125,6 +3156,12 @@  _initialize_hppa_tdep ()
 {
   gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep);
 
+  hppa_tdesc32 = allocate_target_description ().release ();
+  set_tdesc_property (hppa_tdesc32, PROPERTY_GP32, "");
+
+  hppa_tdesc64 = allocate_target_description ().release ();
+  set_tdesc_property (hppa_tdesc64, PROPERTY_GP64, "");
+
   add_cmd ("unwind", class_maintenance, unwind_command,
 	   _("Print unwind table entry at given address."),
 	   &maintenanceprintlist);