[RFC,12/15] gdbserver: Add help functions to get arm/thumb mode

Message ID 32fca8843f5c9a19d4f829f089daf4dac6d2e620.1444820235.git.henrik.wallin@windriver.com
State New, archived
Headers

Commit Message

henrik.wallin@windriver.com Oct. 14, 2015, 11:14 a.m. UTC
  From: Henrik Wallin <henrik.wallin@windriver.com>

This adds new function. No users yet.

This is a quick dirty way to ask gdb what the mode is.
The relocate_instruction function is used with a bogus address.
gdb side advances the to address if arm mode, otherwise not.

gdb/ChangeLog:

        * arm-tdep.c (arm_relocate_instruction_func) : Add code
	to handle special case address value.

gdb/gdbserver/ChangeLog:

	* linux-arm-low.c (is_target_arm) : New function.

Signed-off-by: Henrik Wallin <henrik.wallin@windriver.com>
---
 gdb/arm-tdep.c                | 9 ++++++++-
 gdb/gdbserver/linux-arm-low.c | 9 +++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 601d589b8a89..74c58eb91c4d 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -10447,7 +10447,14 @@  arm_relocate_instruction_func (struct relocate_insn *rel)
   rel->byte_order_for_code = gdbarch_byte_order_for_code (rel->gdbarch);
   rel->result = 0;
 
-  if (arm_pc_is_thumb (rel->gdbarch, rel->oldloc))
+  if (rel->oldloc == 0xFFFFFFFF)
+    {
+      uint32_t tmp = read_memory_unsigned_integer (*(rel->to), 4,
+						   rel->byte_order_for_code);
+      if (! arm_pc_is_thumb (rel->gdbarch, tmp))
+	*rel->to += 1;
+    }
+  else if (arm_pc_is_thumb (rel->gdbarch, rel->oldloc))
     {
       uint16_t insn1;
       uint16_t insn2;
diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
index 044e7527a3b0..1853e79bc140 100644
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -917,6 +917,15 @@  arm_regs_info (void)
     return &regs_info_arm;
 }
 
+static int
+is_target_arm (CORE_ADDR to, CORE_ADDR from)
+{
+  CORE_ADDR ptr = to;
+  write_inferior_memory (to, (unsigned char *) &from, 4);
+  relocate_instruction (&ptr, 0xFFFFFFFF);
+  return (to == ptr) ? 0 : 1;
+}
+
 static uint32_t
 mk_t_b_rel (CORE_ADDR from, CORE_ADDR to)
 {