Skip to content

Commit b920c9f

Browse files
dcpleunggalak
authored andcommitted
xtensa: intel_s1000: update patches for GDB 8.3.1 to GDB 9.2
This updates those patches targeting Xtensa on GDB 8.3.1 so they will work with GDB 9.2. These patches are needed to debug intel_s1000. Signed-off-by: Daniel Leung <[email protected]>
1 parent ef3a4e7 commit b920c9f

4 files changed

+436
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From 5651f5332065c396bbe70e2627fac6d8e9d98a58 Mon Sep 17 00:00:00 2001
2+
From: Daniel Leung <[email protected]>
3+
Date: Thu, 5 Mar 2020 17:20:25 -0800
4+
Subject: [PATCH 3/6] gdb: xtensa: don't error out when registers cannot be
5+
read
6+
7+
On Xtensa, some privileged registers cannot be read using 'p'
8+
packet. So keep these marked as unavailable so GDB can still
9+
fetch other registers instead of stopping at error.
10+
11+
Signed-off-by: Daniel Leung <[email protected]>
12+
---
13+
gdb/remote.c | 10 ++++++++++
14+
1 file changed, 10 insertions(+)
15+
16+
diff --git a/gdb/remote.c b/gdb/remote.c
17+
index 4acaf922d6..9222be6b9f 100644
18+
--- a/gdb/remote.c
19+
+++ b/gdb/remote.c
20+
@@ -7878,6 +7878,7 @@ remote_target::fetch_register_using_p (struct regcache *regcache,
21+
char *buf, *p;
22+
gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
23+
int i;
24+
+ enum bfd_architecture bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
25+
26+
if (packet_support (PACKET_p) == PACKET_DISABLE)
27+
return 0;
28+
@@ -7901,6 +7902,15 @@ remote_target::fetch_register_using_p (struct regcache *regcache,
29+
case PACKET_UNKNOWN:
30+
return 0;
31+
case PACKET_ERROR:
32+
+ /* On Xtensa, some privileged registers cannot be read using 'p'
33+
+ packet. So keep these marked as unavailable so GDB can still
34+
+ fetch other registers instead of stopping at error. */
35+
+ if (bfd_arch == bfd_arch_xtensa)
36+
+ {
37+
+ regcache->raw_supply (reg->regnum, NULL);
38+
+ return 1;
39+
+ }
40+
+
41+
error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
42+
gdbarch_register_name (regcache->arch (),
43+
reg->regnum),
44+
--
45+
2.28.0
46+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
From ebcadd05dc165f3b67524bc9f8255db035249d6b Mon Sep 17 00:00:00 2001
2+
From: Daniel Leung <[email protected]>
3+
Date: Mon, 14 Sep 2020 12:58:46 -0700
4+
Subject: [PATCH 4/6] gdb: xtensa: use remote target register numer...
5+
6+
...instead of the sequential number defined in xtensa-config.c
7+
when retrieving registers from remote target, as the remote
8+
probe maps registers to their target numbers.
9+
10+
Signed-off-by: Daniel Leung <[email protected]>
11+
---
12+
gdb/configure | 20 ++++++++++++++++++++
13+
gdb/configure.ac | 14 ++++++++++++++
14+
gdb/xtensa-tdep.c | 17 +++++++++++++++++
15+
3 files changed, 51 insertions(+)
16+
17+
diff --git a/gdb/configure b/gdb/configure
18+
index b572d414ca..87d62cfa3a 100755
19+
--- a/gdb/configure
20+
+++ b/gdb/configure
21+
@@ -910,6 +910,7 @@ with_babeltrace
22+
with_libbabeltrace_prefix
23+
with_xxhash
24+
with_libxxhash_prefix
25+
+enable_xtensa_use_target_regnum
26+
enable_unit_tests
27+
'
28+
ac_precious_vars='build_alias
29+
@@ -1577,6 +1578,8 @@ Optional Features:
30+
--enable-sim link gdb with simulator
31+
--enable-gdbserver automatically build gdbserver (yes/no/auto, default
32+
is auto)
33+
+ --enable-xtensa-use-target-regnum
34+
+ Use remote target register numbers (Xtensa target)
35+
--enable-unit-tests Enable the inclusion of unit tests when compiling
36+
GDB
37+
38+
@@ -18878,6 +18881,23 @@ $as_echo_n "checking whether to use xxhash... " >&6; }
39+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_xxhash" >&5
40+
$as_echo "$with_xxhash" >&6; }
41+
42+
+# Xtensa to use target register number
43+
+# Check whether --enable-xtensa-use-target-regnum was given.
44+
+if test "${enable_xtensa_use_target_regnum+set}" = set; then :
45+
+ enableval=$enable_xtensa_use_target_regnum; case $enableval in
46+
+ yes | no)
47+
+ enable_xtensa_use_target_regnum=$enableval ;;
48+
+ *)
49+
+ as_fn_error $? "bad value $enableval for --enable-xtensa-use-target-regnum" "$LINENO" 5 ;;
50+
+ esac
51+
+else
52+
+ enable_xtensa_use_target_regnum=no
53+
+fi
54+
+
55+
+if test x"$enable_xtensa_use_target_regnum" = xyes; then
56+
+ CPPFLAGS="$CPPFLAGS -DXTENSA_USE_TGT_REGNUM"
57+
+fi
58+
+
59+
NM_H=
60+
rm -f nm.h
61+
if test "${nativefile}" != ""; then
62+
diff --git a/gdb/configure.ac b/gdb/configure.ac
63+
index ca0da7980c..dac55b943c 100644
64+
--- a/gdb/configure.ac
65+
+++ b/gdb/configure.ac
66+
@@ -2191,6 +2191,20 @@ fi
67+
AC_MSG_CHECKING([whether to use xxhash])
68+
AC_MSG_RESULT([$with_xxhash])
69+
70+
+# Xtensa to use target register number
71+
+AC_ARG_ENABLE(xtensa-use-target-regnum,
72+
+AS_HELP_STRING([--enable-xtensa-use-target-regnum], [Use remote target register numbers (Xtensa target)]),
73+
+ [case $enableval in
74+
+ yes | no)
75+
+ enable_xtensa_use_target_regnum=$enableval ;;
76+
+ *)
77+
+ AC_MSG_ERROR([bad value $enableval for --enable-xtensa-use-target-regnum]) ;;
78+
+ esac],
79+
+ [enable_xtensa_use_target_regnum=no])
80+
+if test x"$enable_xtensa_use_target_regnum" = xyes; then
81+
+ CPPFLAGS="$CPPFLAGS -DXTENSA_USE_TGT_REGNUM"
82+
+fi
83+
+
84+
NM_H=
85+
rm -f nm.h
86+
if test "${nativefile}" != ""; then
87+
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
88+
index d44c5b52c0..7d9e0c7d31 100644
89+
--- a/gdb/xtensa-tdep.c
90+
+++ b/gdb/xtensa-tdep.c
91+
@@ -3145,6 +3145,19 @@ xtensa_derive_tdep (struct gdbarch_tdep *tdep)
92+
tdep->max_register_virtual_size = max_size;
93+
}
94+
95+
+#ifdef XTENSA_USE_TGT_REGNUM
96+
+int
97+
+xtensa_remote_register_number (struct gdbarch *gdbarch, int regnum)
98+
+{
99+
+ /* Return the name stored in the register map. */
100+
+ if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
101+
+ return gdbarch_tdep (gdbarch)->regmap[regnum].target_number;
102+
+
103+
+ internal_error (__FILE__, __LINE__, _("invalid register %d"), regnum);
104+
+ return regnum;
105+
+}
106+
+#endif
107+
+
108+
/* Module "constructor" function. */
109+
110+
extern struct gdbarch_tdep xtensa_tdep;
111+
@@ -3193,6 +3206,10 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
112+
set_gdbarch_register_name (gdbarch, xtensa_register_name);
113+
set_gdbarch_register_type (gdbarch, xtensa_register_type);
114+
115+
+#ifdef XTENSA_USE_TGT_REGNUM
116+
+ set_gdbarch_remote_register_number (gdbarch, xtensa_remote_register_number);
117+
+#endif
118+
+
119+
/* To call functions from GDB using dummy frame. */
120+
set_gdbarch_push_dummy_call (gdbarch, xtensa_push_dummy_call);
121+
122+
--
123+
2.28.0
124+
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
From 733f5079219b6a6edbc63ba5ce7d98a17236656a Mon Sep 17 00:00:00 2001
2+
From: Daniel Leung <[email protected]>
3+
Date: Mon, 14 Sep 2020 13:04:31 -0700
4+
Subject: [PATCH 5/6] gdb: arch to tell whether it supports 'g' packets
5+
6+
This adds a callback to gdbarch so indicate whether
7+
the architecture supports 'g' packets to remote target.
8+
For example, on Xtensa, xt-ocd does not support 'g'
9+
packet. However, the register fetching code keeps on
10+
trying 'g' packet which results in infinite loop. So
11+
this provides a mechanism for architecture to indicate
12+
whether 'g' packet is supported.
13+
14+
Signed-off-by: Daniel Leung <[email protected]>
15+
---
16+
gdb/arch-utils.c | 6 ++++++
17+
gdb/arch-utils.h | 2 ++
18+
gdb/gdbarch.c | 21 +++++++++++++++++++++
19+
gdb/gdbarch.h | 5 +++++
20+
gdb/remote.c | 5 ++++-
21+
5 files changed, 38 insertions(+), 1 deletion(-)
22+
23+
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
24+
index 8d484c78e3..cb4e89dfff 100644
25+
--- a/gdb/arch-utils.c
26+
+++ b/gdb/arch-utils.c
27+
@@ -1004,6 +1004,12 @@ default_get_pc_address_flags (frame_info *frame, CORE_ADDR pc)
28+
return "";
29+
}
30+
31+
+int
32+
+default_remote_supports_g_packet (struct gdbarch *gdbarch)
33+
+{
34+
+ return 1;
35+
+}
36+
+
37+
void
38+
_initialize_gdbarch_utils (void)
39+
{
40+
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
41+
index 3fb9ad317a..1a0df4a86b 100644
42+
--- a/gdb/arch-utils.h
43+
+++ b/gdb/arch-utils.h
44+
@@ -276,4 +276,6 @@ extern ULONGEST default_type_align (struct gdbarch *gdbarch,
45+
extern std::string default_get_pc_address_flags (frame_info *frame,
46+
CORE_ADDR pc);
47+
48+
+int default_remote_supports_g_packet (struct gdbarch *gdbarch);
49+
+
50+
#endif /* ARCH_UTILS_H */
51+
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
52+
index ab9bf1f5f4..636c51fc82 100644
53+
--- a/gdb/gdbarch.c
54+
+++ b/gdb/gdbarch.c
55+
@@ -358,6 +358,7 @@ struct gdbarch
56+
const disasm_options_and_args_t * valid_disassembler_options;
57+
gdbarch_type_align_ftype *type_align;
58+
gdbarch_get_pc_address_flags_ftype *get_pc_address_flags;
59+
+ gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet;
60+
};
61+
62+
/* Create a new ``struct gdbarch'' based on information provided by
63+
@@ -473,6 +474,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
64+
gdbarch->addressable_memory_unit_size = default_addressable_memory_unit_size;
65+
gdbarch->type_align = default_type_align;
66+
gdbarch->get_pc_address_flags = default_get_pc_address_flags;
67+
+ gdbarch->remote_supports_g_packet = default_remote_supports_g_packet;
68+
/* gdbarch_alloc() */
69+
70+
return gdbarch;
71+
@@ -1500,6 +1502,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
72+
fprintf_unfiltered (file,
73+
"gdbarch_dump: xml_syscall_file = %s\n",
74+
pstring (gdbarch->xml_syscall_file));
75+
+ fprintf_unfiltered (file,
76+
+ "gdbarch_dump: remote_supports_g_packet = <%s>\n",
77+
+ host_address_to_string (gdbarch->remote_supports_g_packet));
78+
if (gdbarch->dump_tdep != NULL)
79+
gdbarch->dump_tdep (gdbarch, file);
80+
}
81+
@@ -5156,6 +5161,22 @@ set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch,
82+
gdbarch->get_pc_address_flags = get_pc_address_flags;
83+
}
84+
85+
+int
86+
+gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch)
87+
+{
88+
+ gdb_assert (gdbarch != NULL);
89+
+ gdb_assert (gdbarch->remote_supports_g_packet != NULL);
90+
+ if (gdbarch_debug >= 2)
91+
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_remote_supports_g_packet called\n");
92+
+ return gdbarch->remote_supports_g_packet (gdbarch);
93+
+}
94+
+
95+
+void
96+
+set_gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch,
97+
+ gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet)
98+
+{
99+
+ gdbarch->remote_supports_g_packet = remote_supports_g_packet;
100+
+}
101+
102+
/* Keep a registry of per-architecture data-pointers required by GDB
103+
modules. */
104+
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
105+
index 9f32ac23ab..67612bb93e 100644
106+
--- a/gdb/gdbarch.h
107+
+++ b/gdb/gdbarch.h
108+
@@ -1642,6 +1642,11 @@ extern void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_g
109+
110+
extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
111+
112+
+/* If arch supports 'g' packets */
113+
+
114+
+typedef int (gdbarch_remote_supports_g_packet_ftype) (struct gdbarch *gdbarch);
115+
+extern int gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch);
116+
+extern void set_gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch, gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet);
117+
118+
/* Mechanism for co-ordinating the selection of a specific
119+
architecture.
120+
diff --git a/gdb/remote.c b/gdb/remote.c
121+
index 9222be6b9f..a090228b1c 100644
122+
--- a/gdb/remote.c
123+
+++ b/gdb/remote.c
124+
@@ -1276,6 +1276,7 @@ map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs)
125+
{
126+
int regnum, num_remote_regs, offset;
127+
struct packet_reg **remote_regs;
128+
+ int remote_supports_g_packet;
129+
130+
for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
131+
{
132+
@@ -1305,9 +1306,11 @@ map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs)
133+
[] (const packet_reg *a, const packet_reg *b)
134+
{ return a->pnum < b->pnum; });
135+
136+
+ remote_supports_g_packet = gdbarch_remote_supports_g_packet(gdbarch);
137+
+
138+
for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++)
139+
{
140+
- remote_regs[regnum]->in_g_packet = 1;
141+
+ remote_regs[regnum]->in_g_packet = remote_supports_g_packet;
142+
remote_regs[regnum]->offset = offset;
143+
offset += register_size (gdbarch, remote_regs[regnum]->regnum);
144+
}
145+
--
146+
2.28.0
147+

0 commit comments

Comments
 (0)