From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7897) id 6E792385696E; Fri, 14 Oct 2022 13:06:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E792385696E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665752810; bh=vH7r8uKXcWIBLsG9KC6xPwgkyO1OrqFCpT+lepTKybE=; h=From:To:Subject:Date:From; b=GwISuPbx7goTNFSUzka+IwFk+MzIiyrLMeiKhNpDxEXuJO8ubhrGA8aPvA+RGWmp1 1DZ9O8F/IFZkc8clDphk/5Jf3X/0HGwsgkYSdJxhd2DyYvJVgVpd1XShV6KjjxEoXu hwDg5Fwl7IL3Ox7U8IwwsxxwPOpo8bHQGA+xyh4Y= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Torbjorn Svensson To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/arm: Stop unwinding on error, but do not assert X-Act-Checkin: binutils-gdb X-Git-Author: =?utf-8?q?Torbj=C3=B6rn_SVENSSON?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 5abb5d3f67d6469cbb21978df09187f1ae93f5ea X-Git-Newrev: ce6c3d253b97961801bc045d10b7fd022578fd03 Message-Id: <20221014130650.6E792385696E@sourceware.org> Date: Fri, 14 Oct 2022 13:06:50 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dce6c3d253b97= 961801bc045d10b7fd022578fd03 commit ce6c3d253b97961801bc045d10b7fd022578fd03 Author: Torbj=C3=B6rn SVENSSON Date: Thu Oct 6 16:15:56 2022 +0200 gdb/arm: Stop unwinding on error, but do not assert =20 When it's impossible to read the FPCCR and XPSR, the unwinding is unpredictable as the it's not possible to determine the correct frame size or padding. The only sane thing to do in this condition is to stop the unwinding. =20 Example session without this patch: =20 (gdb) bt #0 SVC_Handler () at .../GPIO/GPIO_EXTI/Src/stm32f4xx_it.c:112 .../gdb/arm-tdep.c:3594: internal-error: arm_m_exception_cache: Asser= tion `safe_read_memory_unsigned_integer (FPCCR, ARM_INT_REGISTER_SIZE, byte= _order, &fpccr)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- 0x5583bfb2a157 gdb_internal_backtrace_1 ... --------------------- =20 This is a bug, please report it. For instructions, see: . =20 Aborted (core dumped) =20 Example session with this patch: =20 (gdb) bt #0 SVC_Handler () at .../GPIO/GPIO_EXTI/Src/stm32f4xx_it.c:112 warning: Could not fetch required FPCCR content. Further unwind is i= mpossible. #1 (gdb) =20 Reviewed-by: Pedro Alves Signed-off-by: Torbj=C3=B6rn SVENSSON Diff: --- gdb/arm-tdep.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 041e6afefed..fa6b08e4a54 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3591,9 +3591,14 @@ arm_m_exception_cache (frame_info_ptr this_frame) ULONGEST fpcar; =20 /* Read FPCCR register. */ - gdb_assert (safe_read_memory_unsigned_integer (FPCCR, - ARM_INT_REGISTER_SIZE, - byte_order, &fpccr)); + if (!safe_read_memory_unsigned_integer (FPCCR, ARM_INT_REGISTER_SIZE, + byte_order, &fpccr)) + { + warning (_("Could not fetch required FPCCR content. Further " + "unwinding is impossible.")); + arm_cache_set_active_sp_value (cache, tdep, 0); + return cache; + } =20 /* Read FPCAR register. */ if (!safe_read_memory_unsigned_integer (FPCAR, ARM_INT_REGISTER_SIZE, @@ -3669,9 +3674,16 @@ arm_m_exception_cache (frame_info_ptr this_frame) aligner between the top of the 32-byte stack frame and the previous context's stack pointer. */ ULONGEST xpsr; - gdb_assert (safe_read_memory_unsigned_integer (cache->saved_regs[ - ARM_PS_REGNUM].addr (), 4, - byte_order, &xpsr)); + if (!safe_read_memory_unsigned_integer (cache->saved_regs[ARM_PS_REG= NUM] + .addr (), ARM_INT_REGISTER_SIZE, + byte_order, &xpsr)) + { + warning (_("Could not fetch required XPSR content. Further " + "unwinding is impossible.")); + arm_cache_set_active_sp_value (cache, tdep, 0); + return cache; + } + if (bit (xpsr, 9) !=3D 0) { CORE_ADDR new_sp =3D arm_cache_get_prev_sp_value (cache, tdep) + 4; @@ -3689,6 +3701,27 @@ arm_m_exception_cache (frame_info_ptr this_frame) phex (lr, ARM_INT_REGISTER_SIZE)); } =20 +/* Implementation of the stop_reason hook for arm_m_exception frames. */ + +static enum unwind_stop_reason +arm_m_exception_frame_unwind_stop_reason (frame_info_ptr this_frame, + void **this_cache) +{ + struct arm_prologue_cache *cache; + arm_gdbarch_tdep *tdep + =3D gdbarch_tdep (get_frame_arch (this_frame)); + + if (*this_cache =3D=3D NULL) + *this_cache =3D arm_m_exception_cache (this_frame); + cache =3D (struct arm_prologue_cache *) *this_cache; + + /* If we've hit a wall, stop. */ + if (arm_cache_get_prev_sp_value (cache, tdep) =3D=3D 0) + return UNWIND_OUTERMOST; + + return UNWIND_NO_REASON; +} + /* Implementation of function hook 'this_id' in 'struct frame_uwnind'. */ =20 @@ -3798,7 +3831,7 @@ struct frame_unwind arm_m_exception_unwind =3D { "arm m exception", SIGTRAMP_FRAME, - default_frame_unwind_stop_reason, + arm_m_exception_frame_unwind_stop_reason, arm_m_exception_this_id, arm_m_exception_prev_register, NULL,