Skip to content

Commit 9c24353

Browse files
dcpleunggalak
authored andcommitted
xtensa: intel_s1000: update to GDB 8.3.1
The intel_s1000 SoC (and the corresponding intel_s1000_crb board) uses Tensilica's own xt-ocd for debugging, which works well with Tensilica's own xt-gdb but based on an older version. To make upstream GDB 8.3 work with xt-ocd, the following modifications are needed: () Introduce an option to use the remote target register number instead of the sequential number as defined in xtensa-config.c. This affects read/write of registers as xt-ocd maps registers to their target number. QEMU, on the other hand, uses the sequential number. Therefore only turns on this option when building GDB for intel_s1000. () Registers that cannot be retrieved are marked unavailable instead of erroring out. There are priviledged registers which can only be retrieved with custom protocol used by xt-gdb. Upstream GDB does not support this. So instead of error out and stopping register retrieval, simply mark those registers as unavailable and continue reading remaining registers. () Add an option to not use 'g' packet. When GDB sends a 'g' packet to retrieve a group of registers, xt-ocd does not produce responses expected by upstream GDB, and GDB simply goes into an infinite loop hoping a correct response would eventually come. So this option is introduced to mark all as not in 'g' packet so GDB would use 'p/P' packets to read/write registers. Fixes #188 Signed-off-by: Daniel Leung <[email protected]>
1 parent 9655290 commit 9c24353

6 files changed

+612
-1
lines changed

configs/xtensa_intel_s1000.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ CT_CC_GCC_EXTRA_CONFIG_ARRAY="--with-gnu-ld --with-gnu-as --enable-initfini-arra
4242
CT_CC_LANG_CXX=y
4343
CT_CC_GCC_LIBSTDCXX_NANO=y
4444
CT_DEBUG_GDB=y
45-
CT_GDB_V_7_6=y
45+
CT_GDB_V_8_3=y
46+
CT_GDB_CROSS_EXTRA_CONFIG_ARRAY="--enable-xtensa-use-target-regnum --disable-xtensa-remote-g-packet"
4647
CT_ISL_V_0_18=y
4748
CT_LIBICONV_NEEDED=y
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
From db7169daa3c7159873510de97c3cfb271004cbd2 Mon Sep 17 00:00:00 2001
2+
From: Daniel Leung <[email protected]>
3+
Date: Fri, 6 Mar 2020 11:06:32 -0800
4+
Subject: [PATCH 4/8] gdb: regenerate configure file
5+
6+
configure is out-of-sync...
7+
8+
Signed-off-by: Daniel Leung <[email protected]>
9+
---
10+
gdb/configure | 14 +++++++++++++-
11+
gdb/gdbserver/configure | 14 +++++++++++++-
12+
gdb/testsuite/configure | 14 +++++++++++++-
13+
3 files changed, 39 insertions(+), 3 deletions(-)
14+
15+
diff --git a/gdb/configure b/gdb/configure
16+
index 866564fbe6..352a56c6a2 100755
17+
--- a/gdb/configure
18+
+++ b/gdb/configure
19+
@@ -825,6 +825,7 @@ infodir
20+
docdir
21+
oldincludedir
22+
includedir
23+
+runstatedir
24+
localstatedir
25+
sharedstatedir
26+
sysconfdir
27+
@@ -958,6 +959,7 @@ datadir='${datarootdir}'
28+
sysconfdir='${prefix}/etc'
29+
sharedstatedir='${prefix}/com'
30+
localstatedir='${prefix}/var'
31+
+runstatedir='${localstatedir}/run'
32+
includedir='${prefix}/include'
33+
oldincludedir='/usr/include'
34+
docdir='${datarootdir}/doc/${PACKAGE}'
35+
@@ -1210,6 +1212,15 @@ do
36+
| -silent | --silent | --silen | --sile | --sil)
37+
silent=yes ;;
38+
39+
+ -runstatedir | --runstatedir | --runstatedi | --runstated \
40+
+ | --runstate | --runstat | --runsta | --runst | --runs \
41+
+ | --run | --ru | --r)
42+
+ ac_prev=runstatedir ;;
43+
+ -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
44+
+ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
45+
+ | --run=* | --ru=* | --r=*)
46+
+ runstatedir=$ac_optarg ;;
47+
+
48+
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
49+
ac_prev=sbindir ;;
50+
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
51+
@@ -1347,7 +1358,7 @@ fi
52+
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
53+
datadir sysconfdir sharedstatedir localstatedir includedir \
54+
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
55+
- libdir localedir mandir
56+
+ libdir localedir mandir runstatedir
57+
do
58+
eval ac_val=\$$ac_var
59+
# Remove trailing slashes.
60+
@@ -1500,6 +1511,7 @@ Fine tuning of the installation directories:
61+
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
62+
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
63+
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
64+
+ --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
65+
--libdir=DIR object code libraries [EPREFIX/lib]
66+
--includedir=DIR C header files [PREFIX/include]
67+
--oldincludedir=DIR C header files for non-gcc [/usr/include]
68+
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
69+
index 1ddbd6b27e..1d298fa824 100755
70+
--- a/gdb/gdbserver/configure
71+
+++ b/gdb/gdbserver/configure
72+
@@ -697,6 +697,7 @@ infodir
73+
docdir
74+
oldincludedir
75+
includedir
76+
+runstatedir
77+
localstatedir
78+
sharedstatedir
79+
sysconfdir
80+
@@ -784,6 +785,7 @@ datadir='${datarootdir}'
81+
sysconfdir='${prefix}/etc'
82+
sharedstatedir='${prefix}/com'
83+
localstatedir='${prefix}/var'
84+
+runstatedir='${localstatedir}/run'
85+
includedir='${prefix}/include'
86+
oldincludedir='/usr/include'
87+
docdir='${datarootdir}/doc/${PACKAGE}'
88+
@@ -1036,6 +1038,15 @@ do
89+
| -silent | --silent | --silen | --sile | --sil)
90+
silent=yes ;;
91+
92+
+ -runstatedir | --runstatedir | --runstatedi | --runstated \
93+
+ | --runstate | --runstat | --runsta | --runst | --runs \
94+
+ | --run | --ru | --r)
95+
+ ac_prev=runstatedir ;;
96+
+ -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
97+
+ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
98+
+ | --run=* | --ru=* | --r=*)
99+
+ runstatedir=$ac_optarg ;;
100+
+
101+
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
102+
ac_prev=sbindir ;;
103+
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
104+
@@ -1173,7 +1184,7 @@ fi
105+
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
106+
datadir sysconfdir sharedstatedir localstatedir includedir \
107+
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
108+
- libdir localedir mandir
109+
+ libdir localedir mandir runstatedir
110+
do
111+
eval ac_val=\$$ac_var
112+
# Remove trailing slashes.
113+
@@ -1326,6 +1337,7 @@ Fine tuning of the installation directories:
114+
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
115+
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
116+
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
117+
+ --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
118+
--libdir=DIR object code libraries [EPREFIX/lib]
119+
--includedir=DIR C header files [PREFIX/include]
120+
--oldincludedir=DIR C header files for non-gcc [/usr/include]
121+
diff --git a/gdb/testsuite/configure b/gdb/testsuite/configure
122+
index cc00f8dfa8..dae183eae9 100755
123+
--- a/gdb/testsuite/configure
124+
+++ b/gdb/testsuite/configure
125+
@@ -671,6 +671,7 @@ infodir
126+
docdir
127+
oldincludedir
128+
includedir
129+
+runstatedir
130+
localstatedir
131+
sharedstatedir
132+
sysconfdir
133+
@@ -743,6 +744,7 @@ datadir='${datarootdir}'
134+
sysconfdir='${prefix}/etc'
135+
sharedstatedir='${prefix}/com'
136+
localstatedir='${prefix}/var'
137+
+runstatedir='${localstatedir}/run'
138+
includedir='${prefix}/include'
139+
oldincludedir='/usr/include'
140+
docdir='${datarootdir}/doc/${PACKAGE}'
141+
@@ -995,6 +997,15 @@ do
142+
| -silent | --silent | --silen | --sile | --sil)
143+
silent=yes ;;
144+
145+
+ -runstatedir | --runstatedir | --runstatedi | --runstated \
146+
+ | --runstate | --runstat | --runsta | --runst | --runs \
147+
+ | --run | --ru | --r)
148+
+ ac_prev=runstatedir ;;
149+
+ -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
150+
+ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
151+
+ | --run=* | --ru=* | --r=*)
152+
+ runstatedir=$ac_optarg ;;
153+
+
154+
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
155+
ac_prev=sbindir ;;
156+
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
157+
@@ -1132,7 +1143,7 @@ fi
158+
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
159+
datadir sysconfdir sharedstatedir localstatedir includedir \
160+
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
161+
- libdir localedir mandir
162+
+ libdir localedir mandir runstatedir
163+
do
164+
eval ac_val=\$$ac_var
165+
# Remove trailing slashes.
166+
@@ -1285,6 +1296,7 @@ Fine tuning of the installation directories:
167+
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
168+
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
169+
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
170+
+ --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
171+
--libdir=DIR object code libraries [EPREFIX/lib]
172+
--includedir=DIR C header files [PREFIX/include]
173+
--oldincludedir=DIR C header files for non-gcc [/usr/include]
174+
--
175+
2.24.1
176+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From 88cfe105614a576580bc3f36ee1f0d91cd37b781 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 5/8] 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 36136e3e3e..c8c5b32c74 100644
18+
--- a/gdb/remote.c
19+
+++ b/gdb/remote.c
20+
@@ -7933,6 +7933,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+
@@ -7956,6 +7957,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.24.1
46+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
From 5665931ee51625c9a29a41d845011be67ded7e54 Mon Sep 17 00:00:00 2001
2+
From: Daniel Leung <[email protected]>
3+
Date: Thu, 5 Mar 2020 14:00:07 -0800
4+
Subject: [PATCH 6/8] gdb: xtensa: use remote target register number...
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 352a56c6a2..e873b109ca 100755
19+
--- a/gdb/configure
20+
+++ b/gdb/configure
21+
@@ -900,6 +900,7 @@ enable_sim
22+
enable_gdbserver
23+
with_babeltrace
24+
with_libbabeltrace_prefix
25+
+enable_xtensa_use_target_regnum
26+
enable_unit_tests
27+
'
28+
ac_precious_vars='build_alias
29+
@@ -1579,6 +1580,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+
@@ -17822,6 +17825,23 @@ $as_echo "$as_me: WARNING: babeltrace is missing or unusable; GDB is unable to r
39+
fi
40+
fi
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+
# If nativefile (NAT_FILE) is not set in configure.nat, we link to an
60+
# empty version.
61+
62+
diff --git a/gdb/configure.ac b/gdb/configure.ac
63+
index 0805827adf..56b004448f 100644
64+
--- a/gdb/configure.ac
65+
+++ b/gdb/configure.ac
66+
@@ -2260,6 +2260,20 @@ else
67+
fi
68+
fi
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+
# If nativefile (NAT_FILE) is not set in configure.nat, we link to an
85+
# empty version.
86+
87+
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
88+
index fcec9961ee..48f1005e9e 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.24.1
124+

0 commit comments

Comments
 (0)