From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1844) id D312D3858C2C; Wed, 15 Jun 2022 14:09:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D312D3858C2C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Yvan Roux To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/arm: Track msp and psp X-Act-Checkin: binutils-gdb X-Git-Author: Yvan Roux X-Git-Refname: refs/heads/master X-Git-Oldrev: fe642a5b1411502000af9d169122522065dff9ca X-Git-Newrev: 0d12d61b9a646f317d9793492971c9a28f83b754 Message-Id: <20220615140939.D312D3858C2C@sourceware.org> Date: Wed, 15 Jun 2022 14:09:39 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2022 14:09:39 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0d12d61b9a64= 6f317d9793492971c9a28f83b754 commit 0d12d61b9a646f317d9793492971c9a28f83b754 Author: Yvan Roux Date: Wed Jun 15 16:01:46 2022 +0200 gdb/arm: Track msp and psp =20 For Arm Cortex-M33 with security extensions, there are 4 different stack pointers (msp_s, msp_ns, psp_s, psp_ns). To be compatible with earlier Cortex-M derivates, the msp and psp registers are aliases for one of the 4 real stack pointer registers. =20 These are the combinations that exist: sp -> msp -> msp_s sp -> msp -> msp_ns sp -> psp -> psp_s sp -> psp -> psp_ns =20 This means that when the GDB client is to show the value of "msp", the value should always be equal to either "msp_s" or "msp_ns". Same goes for "psp". =20 To add a bit more context; GDB does not really use the register msp (or psp) internally, but they are part of the set of registers which are provided by the target.xml file. As a result, they will be part of the set of registers printed by the "info r" command. =20 Without this particular patch, GDB will hit the assert in the bottom of arm_cache_get_sp_register function. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29121 =20 Signed-off-by: Torbj=C3=B6rn SVENSSON Signed-off-by: Yvan Roux Diff: --- gdb/arm-tdep.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 7c36133a091..38ce85e9cbc 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -288,6 +288,8 @@ struct arm_prologue_cache =20 /* Active stack pointer. */ int active_sp_regnum; + int active_msp_regnum; + int active_psp_regnum; =20 /* The frame base for this frame is just prev_sp - frame size. FRAMESIZE is the distance from the frame pointer to the @@ -345,11 +347,23 @@ arm_cache_init (struct arm_prologue_cache *cache, str= uct frame_info *frame) =20 if (tdep->have_sec_ext) { + CORE_ADDR msp_val =3D get_frame_register_unsigned (frame, tdep->m_pr= ofile_msp_regnum); + CORE_ADDR psp_val =3D get_frame_register_unsigned (frame, tdep->m_pr= ofile_psp_regnum); + arm_cache_init_sp (tdep->m_profile_msp_s_regnum, &cache->msp_s, cach= e, frame); arm_cache_init_sp (tdep->m_profile_psp_s_regnum, &cache->psp_s, cach= e, frame); arm_cache_init_sp (tdep->m_profile_msp_ns_regnum, &cache->msp_ns, ca= che, frame); arm_cache_init_sp (tdep->m_profile_psp_ns_regnum, &cache->psp_ns, ca= che, frame); =20 + if (msp_val =3D=3D cache->msp_s) + cache->active_msp_regnum =3D tdep->m_profile_msp_s_regnum; + else if (msp_val =3D=3D cache->msp_ns) + cache->active_msp_regnum =3D tdep->m_profile_msp_ns_regnum; + if (psp_val =3D=3D cache->psp_s) + cache->active_psp_regnum =3D tdep->m_profile_psp_s_regnum; + else if (psp_val =3D=3D cache->psp_ns) + cache->active_psp_regnum =3D tdep->m_profile_psp_ns_regnum; + /* Use MSP_S as default stack pointer. */ if (cache->active_sp_regnum =3D=3D ARM_SP_REGNUM) cache->active_sp_regnum =3D tdep->m_profile_msp_s_regnum; @@ -384,6 +398,10 @@ arm_cache_get_sp_register (struct arm_prologue_cache *= cache, return cache->psp_s; if (regnum =3D=3D tdep->m_profile_psp_ns_regnum) return cache->psp_ns; + if (regnum =3D=3D tdep->m_profile_msp_regnum) + return arm_cache_get_sp_register (cache, tdep, cache->active_msp_regnum); + if (regnum =3D=3D tdep->m_profile_psp_regnum) + return arm_cache_get_sp_register (cache, tdep, cache->active_psp_regnum); } else if (tdep->is_m) {