This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC, arm M-profile] unbreak compatibility with some remote servers
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 20 Apr 2011 20:27:27 +0100
- Subject: [RFC, arm M-profile] unbreak compatibility with some remote servers
This patch back from August:
(Add support for ARMv7M devices.)
<http://sourceware.org/ml/gdb-patches/2010-08/msg00225.html>
unfortunately broke compatibility with existing remote stubs
that supported M-profile devices, but that were not feeding
GDB xml registers descriptions.
The problem is that after the patch, when an M-profile program
is loaded, GDB selects a target description that includes
registers, based on the ELF file. The M-profile register set
is smaller than the traditional/historical arm register set,
that includes the FPA registers (f0-f7, fps), between
register 16 and 24.
Before that patch:
(gdb) maint print remote-registers
Name Nr Rel Offset Size Type Rmt Nr g/G Offset
r0 0 0 0 4 uint32_t 0 0
r1 1 1 4 4 uint32_t 1 4
r2 2 2 8 4 uint32_t 2 8
r3 3 3 12 4 uint32_t 3 12
r4 4 4 16 4 uint32_t 4 16
r5 5 5 20 4 uint32_t 5 20
r6 6 6 24 4 uint32_t 6 24
r7 7 7 28 4 uint32_t 7 28
r8 8 8 32 4 uint32_t 8 32
r9 9 9 36 4 uint32_t 9 36
r10 10 10 40 4 uint32_t 10 40
r11 11 11 44 4 uint32_t 11 44
r12 12 12 48 4 uint32_t 12 48
sp 13 13 52 4 *1 13 52
lr 14 14 56 4 uint32_t 14 56
pc 15 15 60 4 *1 15 60
f0 16 16 64 12 _arm_ext 16 64
f1 17 17 76 12 _arm_ext 17 76
f2 18 18 88 12 _arm_ext 18 88
f3 19 19 100 12 _arm_ext 19 100
f4 20 20 112 12 _arm_ext 20 112
f5 21 21 124 12 _arm_ext 21 124
f6 22 22 136 12 _arm_ext 22 136
f7 23 23 148 12 _arm_ext 23 148
fps 24 24 160 4 uint32_t 24 160
cpsr 25 25 164 4 uint32_t 25 164
'' 26 26 168 0 int0_t
'' 27 27 168 0 int0_t
After that patch:
(gdb) maint print remote-registers
Name Nr Rel Offset Size Type Rmt Nr g/G Offset
r0 0 0 0 4 uint32_t 0 0
r1 1 1 4 4 uint32_t 1 4
r2 2 2 8 4 uint32_t 2 8
r3 3 3 12 4 uint32_t 3 12
r4 4 4 16 4 uint32_t 4 16
r5 5 5 20 4 uint32_t 5 20
r6 6 6 24 4 uint32_t 6 24
r7 7 7 28 4 uint32_t 7 28
r8 8 8 32 4 uint32_t 8 32
r9 9 9 36 4 uint32_t 9 36
r10 10 10 40 4 uint32_t 10 40
r11 11 11 44 4 uint32_t 11 44
r12 12 12 48 4 uint32_t 12 48
sp 13 13 52 4 *1 13 52
lr 14 14 56 4 uint32_t 14 56
pc 15 15 60 4 *1 15 60
'' 16 16 64 1 void
'' 17 17 65 1 void
'' 18 18 66 1 void
'' 19 19 67 1 void
'' 20 20 68 1 void
'' 21 21 69 1 void
'' 22 22 70 1 void
'' 23 23 71 1 void
'' 24 24 72 4 uint32_t
xpsr 25 25 76 4 uint32_t 25 64
Notice that the FPA registers are gone (because they don't exist on
M-profile devices), and that xpsr is expected at offset 64, rather
than where cpsr would be before the patch, which was at offset 164 (and
where such stubs naturally place xpsr).
This results in _'g' packet reply is too long_ errors on connection
against stubs that are using the former layout.
The patch switches to using the g-packet-guess registration
mechanism instead, to guess which register layout the target
is expecting, if the target doesn't provide it's own description,
and, adds a guess size that selects a new target description
that handles stubs that support M-profile targets, and are
still assuming a register layout with the FPA registers. The
description leaves those registers unnamed, so they are
not user visible:
(gdb) maint print remote-registers
Name Nr Rel Offset Size Type Rmt Nr g/G Offset
r0 0 0 0 4 long 0 0
r1 1 1 4 4 long 1 4
r2 2 2 8 4 long 2 8
r3 3 3 12 4 long 3 12
r4 4 4 16 4 long 4 16
r5 5 5 20 4 long 5 20
r6 6 6 24 4 long 6 24
r7 7 7 28 4 long 7 28
r8 8 8 32 4 long 8 32
r9 9 9 36 4 long 9 36
r10 10 10 40 4 long 10 40
r11 11 11 44 4 long 11 44
r12 12 12 48 4 long 12 48
sp 13 13 52 4 *1 13 52
lr 14 14 56 4 long 14 56
pc 15 15 60 4 *1 15 60
'' 16 16 64 0 int0_t
'' 17 17 64 0 int0_t
'' 18 18 64 0 int0_t
'' 19 19 64 0 int0_t
'' 20 20 64 0 int0_t
'' 21 21 64 0 int0_t
'' 22 22 64 0 int0_t
'' 23 23 64 0 int0_t
'' 24 24 64 0 int0_t
xpsr 25 25 64 4 long 25 164
'' 26 26 68 0 int0_t
'' 27 27 68 0 int0_t
'' 28 28 68 0 int0_t
'' 29 29 68 0 int0_t
'' 30 30 68 0 int0_t
'' 31 31 68 0 int0_t
'' 32 32 68 0 int0_t
'' 33 33 68 0 int0_t
'' 34 34 68 0 int0_t
'' 35 35 68 0 int0_t
'' 36 36 68 0 int0_t
'' 37 37 68 0 int0_t
'' 38 38 68 0 int0_t
'' 39 39 68 0 int0_t
'' 40 40 68 0 int0_t
'' 41 41 68 0 int0_t
'' 42 42 68 0 int0_t
'' 43 43 68 0 int0_t
'' 44 44 68 0 int0_t
'' 45 45 68 0 int0_t
'' 46 46 68 0 int0_t
'' 47 47 68 0 int0_t
'' 48 48 68 0 int0_t
'' 49 49 68 0 int0_t
'' 50 50 68 0 int0_t
'' 51 51 68 0 int0_t
'' 52 52 68 0 int0_t
'' 53 53 68 0 int0_t
'' 54 54 68 0 int0_t
'' 55 55 68 0 int0_t
'' 56 56 68 0 int0_t
'' 57 57 68 0 int0_t
'' 58 58 68 0 int0_t
'' 59 59 68 0 int0_t
'' 60 60 68 0 int0_t
'' 61 61 68 0 int0_t
'' 62 62 68 0 int0_t
'' 63 63 68 0 int0_t
'' 64 64 68 0 int0_t
'' 65 65 68 0 int0_t
'' 66 66 68 0 int0_t
'' 67 67 68 0 int0_t
'' 68 68 68 0 int0_t
'' 69 69 68 0 int0_t
'' 70 70 68 0 int0_t
'' 71 71 68 0 int0_t
'' 72 72 68 0 int0_t
'' 73 73 68 0 int0_t
'' 74 74 68 0 int0_t
'' 75 75 68 0 int0_t
'' 76 76 68 0 int0_t
'' 77 77 68 0 int0_t
'' 78 78 68 0 int0_t
'' 79 79 68 0 int0_t
'' 80 80 68 0 int0_t
'' 81 81 68 0 int0_t
'' 82 82 68 0 int0_t
'' 83 83 68 0 int0_t
'' 84 84 68 0 int0_t
'' 85 85 68 0 int0_t
'' 86 86 68 0 int0_t
'' 87 87 68 0 int0_t
'' 88 88 68 0 int0_t
'' 89 89 68 0 int0_t
'' 90 90 68 0 int0_t
'' 91 91 68 12 _arm_ext 16 64
'' 92 92 80 12 _arm_ext 17 76
'' 93 93 92 12 _arm_ext 18 88
'' 94 94 104 12 _arm_ext 19 100
'' 95 95 116 12 _arm_ext 20 112
'' 96 96 128 12 _arm_ext 21 124
'' 97 97 140 12 _arm_ext 22 136
'' 98 98 152 12 _arm_ext 23 148
'' 99 99 164 4 long 24 160
*1: Register type's name NULL.
(gdb)
So from the user's perspective, nothing changes in the register
set, and GDB unbreaks backward compatibility with some
remote servers.
Comments appreciated.
Pedro Alves
2011-04-20 Pedro Alves <pedro@codesourcery.com>
gdb/
* arm-tdep.c: Include "remote.h" and
"features/arm-with-m-fpa-layout.c".
(arm_register_g_packet_guesses): New function.
(arm_gdbarch_init): Don't force a target description with
registers when the executable is detected as M-profile. Instead
set gdbarch->tdep->is_m. Register `g' packet guesses.
(_initialize_arm_tdep): Initialize the new target description.
* features/arm-with-m-fpa-layout.xml: New description.
* features/arm-with-m-fpa-layout.c: New, generated.
---
gdb/arm-tdep.c | 31 ++++++++++++++++++++++
gdb/features/arm-with-m-fpa-layout.c | 44 ++++++++++++++++++++++++++++++++
gdb/features/arm-with-m-fpa-layout.xml | 45 +++++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+), 1 deletion(-)
Index: src/gdb/arm-tdep.c
===================================================================
--- src.orig/gdb/arm-tdep.c 2011-04-20 19:53:29.735273006 +0100
+++ src/gdb/arm-tdep.c 2011-04-20 20:15:15.295272998 +0100
@@ -41,6 +41,7 @@
#include "dwarf2-frame.h"
#include "gdbtypes.h"
#include "prologue-value.h"
+#include "remote.h"
#include "target-descriptions.h"
#include "user-regs.h"
#include "observer.h"
@@ -56,6 +57,7 @@
#include "vec.h"
#include "features/arm-with-m.c"
+#include "features/arm-with-m-fpa-layout.c"
static int arm_debug;
@@ -8098,6 +8100,30 @@ arm_register_reggroup_p (struct gdbarch
}
+static void
+arm_register_g_packet_guesses (struct gdbarch *gdbarch)
+{
+ if (gdbarch_tdep (gdbarch)->is_m)
+ {
+ /* If we know from the executable this is an M-profile target,
+ cater for remote targets whose register set layout is the
+ same as the FPA layout. */
+ register_remote_g_packet_guess (gdbarch,
+ /* r0-r12,sp,lr,pc; f0-f7; fps,cpsr */
+ (16 * 4) + (8 * 16) + (2 * 4),
+ tdesc_arm_with_m_fpa_layout);
+
+ /* The regular M-profile layout. */
+ register_remote_g_packet_guess (gdbarch,
+ /* r0-r12,sp,lr,pc; xpsr */
+ (16 * 4) + 4,
+ tdesc_arm_with_m);
+ }
+
+ /* Otherwise we don't have a useful guess. */
+}
+
+
/* Initialize the current architecture based on INFO. If possible,
re-use an architecture from ARCHES, which is a list of
architectures already created during this debugging session.
@@ -8231,7 +8257,7 @@ arm_gdbarch_init (struct gdbarch_info in
&& (attr_arch == TAG_CPU_ARCH_V6_M
|| attr_arch == TAG_CPU_ARCH_V6S_M
|| attr_profile == 'M'))
- tdesc = tdesc_arm_with_m;
+ is_m = 1;
#endif
}
@@ -8488,6 +8514,8 @@ arm_gdbarch_init (struct gdbarch_info in
tdep->have_neon_pseudos = have_neon_pseudos;
tdep->have_neon = have_neon;
+ arm_register_g_packet_guesses (gdbarch);
+
/* Breakpoints. */
switch (info.byte_order_for_code)
{
@@ -8724,6 +8752,7 @@ _initialize_arm_tdep (void)
/* Initialize the standard target descriptions. */
initialize_tdesc_arm_with_m ();
+ initialize_tdesc_arm_with_m_fpa_layout ();
/* Get the number of possible sets of register names defined in opcodes. */
num_disassembly_options = get_arm_regname_num_options ();
Index: src/gdb/features/arm-with-m-fpa-layout.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/features/arm-with-m-fpa-layout.c 2011-04-20 20:15:15.295272998 +0100
@@ -0,0 +1,44 @@
+/* THIS FILE IS GENERATED. Original: arm-with-m-fpa-layout.xml */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+struct target_desc *tdesc_arm_with_m_fpa_layout;
+static void
+initialize_tdesc_arm_with_m_fpa_layout (void)
+{
+ struct target_desc *result = allocate_target_description ();
+ struct tdesc_feature *feature;
+ struct tdesc_type *field_type, *type;
+
+ feature = tdesc_create_feature (result, "org.gnu.gdb.arm.m-profile");
+ tdesc_create_reg (feature, "r0", 0, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r2", 2, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r3", 3, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r4", 4, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r5", 5, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r6", 6, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r7", 7, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r8", 8, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r9", 9, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r10", 10, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r11", 11, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "r12", 12, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "sp", 13, 1, NULL, 32, "data_ptr");
+ tdesc_create_reg (feature, "lr", 14, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "pc", 15, 1, NULL, 32, "code_ptr");
+ tdesc_create_reg (feature, "", 16, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 17, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 18, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 19, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 20, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 21, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 22, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 23, 1, NULL, 96, "arm_fpa_ext");
+ tdesc_create_reg (feature, "", 24, 1, NULL, 32, "int");
+ tdesc_create_reg (feature, "xpsr", 25, 1, NULL, 32, "int");
+
+ tdesc_arm_with_m_fpa_layout = result;
+}
Index: src/gdb/features/arm-with-m-fpa-layout.xml
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/features/arm-with-m-fpa-layout.xml 2011-04-20 20:15:15.295272998 +0100
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+
+ Copying and distribution of this file, with or without modification,
+ are permitted in any medium without royalty provided the copyright
+ notice and this notice are preserved. -->
+
+<!-- A target description for an M-profile device, for stubs that
+ transfer registers using the historical fpa layout. -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<target>
+<feature name="org.gnu.gdb.arm.m-profile">
+ <reg name="r0" bitsize="32"/>
+ <reg name="r1" bitsize="32"/>
+ <reg name="r2" bitsize="32"/>
+ <reg name="r3" bitsize="32"/>
+ <reg name="r4" bitsize="32"/>
+ <reg name="r5" bitsize="32"/>
+ <reg name="r6" bitsize="32"/>
+ <reg name="r7" bitsize="32"/>
+ <reg name="r8" bitsize="32"/>
+ <reg name="r9" bitsize="32"/>
+ <reg name="r10" bitsize="32"/>
+ <reg name="r11" bitsize="32"/>
+ <reg name="r12" bitsize="32"/>
+ <reg name="sp" bitsize="32" type="data_ptr"/>
+ <reg name="lr" bitsize="32"/>
+ <reg name="pc" bitsize="32" type="code_ptr"/>
+
+ <!-- Slack for unused FPA registers (f0-f7 + fps).
+ See arm-fpa.xml. -->
+ <reg name="" bitsize="96" type="arm_fpa_ext" regnum="16"/>
+ <reg name="" bitsize="96" type="arm_fpa_ext"/>
+ <reg name="" bitsize="96" type="arm_fpa_ext"/>
+ <reg name="" bitsize="96" type="arm_fpa_ext"/>
+ <reg name="" bitsize="96" type="arm_fpa_ext"/>
+ <reg name="" bitsize="96" type="arm_fpa_ext"/>
+ <reg name="" bitsize="96" type="arm_fpa_ext"/>
+ <reg name="" bitsize="96" type="arm_fpa_ext"/>
+ <reg name="" bitsize="32"/>
+
+ <reg name="xpsr" bitsize="32" regnum="25"/>
+</feature>
+</target>