From: Luis Machado <luis.machado@arm.com>
To: "Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>,
gdb-patches@sourceware.org
Subject: Re: [PATCH v2] gdb/arm: Stop unwinding on error, but do not assert
Date: Thu, 13 Oct 2022 10:46:10 +0100 [thread overview]
Message-ID: <bdbe86cc-b1ba-dabe-898b-31e1c2b490a9@arm.com> (raw)
In-Reply-To: <20221013091740.645783-1-torbjorn.svensson@foss.st.com>
Hi,
On 10/13/22 10:17, Torbjörn SVENSSON wrote:
> 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.
>
> Without this patch, gdb would assert if this errornous state was
> detected.
>
Could you please attach an example of the change in the commit message? What it does before
and after the change?
> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
> ---
> gdb/arm-tdep.c | 35 +++++++++++++++++++++++++++++------
> 1 file changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 041e6afefed..afcbce478c2 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -3591,9 +3591,13 @@ arm_m_exception_cache (frame_info_ptr this_frame)
> ULONGEST fpcar;
>
> /* 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 "
> + "unwind is impossible."));
> + return NULL;
NULL -> nullptr everywhere.
> + }
>
> /* Read FPCAR register. */
> if (!safe_read_memory_unsigned_integer (FPCAR, ARM_INT_REGISTER_SIZE,
> @@ -3669,9 +3673,15 @@ 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_REGNUM]
> + .addr (), ARM_INT_REGISTER_SIZE,
> + byte_order, &xpsr))
> + {
> + warning (_("Could not fetch required XPSR content. Further unwind "
> + "is impossible."));
> + return NULL;
> + }
> +
> if (bit (xpsr, 9) != 0)
> {
> CORE_ADDR new_sp = arm_cache_get_prev_sp_value (cache, tdep) + 4;
> @@ -3703,6 +3713,14 @@ arm_m_exception_this_id (frame_info_ptr this_frame,
> *this_cache = arm_m_exception_cache (this_frame);
> cache = (struct arm_prologue_cache *) *this_cache;
>
> + /* Unwind of this frame is not possible. Return outer_frame_id to stop the
> + unwinding. */
> + if (cache == NULL)
> + {
> + *this_id = outer_frame_id;
> + return;
> + }
> +
> /* Our frame ID for a stub frame is the current SP and LR. */
> arm_gdbarch_tdep *tdep
> = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
> @@ -3725,6 +3743,11 @@ arm_m_exception_prev_register (frame_info_ptr this_frame,
> *this_cache = arm_m_exception_cache (this_frame);
> cache = (struct arm_prologue_cache *) *this_cache;
>
> + /* It's not allowed to call prev_register when this_id has returned the
> + outer_frame_id. The arm_m_exception_cache function will return NULL when
> + the frame cannot be properly unwinded. */
> + gdb_assert (cache != NULL);
> +
It does seem safe to assume this function won't be called if there is no frame_id. So I agree this would be
a GDB bug and needs an assertion here.
> /* The value was already reconstructed into PREV_SP. */
> arm_gdbarch_tdep *tdep
> = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
next prev parent reply other threads:[~2022-10-13 9:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 9:17 Torbjörn SVENSSON
2022-10-13 9:46 ` Luis Machado [this message]
2022-10-13 11:21 ` Pedro Alves
2022-10-13 12:24 ` Torbjorn SVENSSON
2022-10-13 13:25 ` Pedro Alves
2022-10-13 13:11 ` Luis Machado
2022-10-13 13:41 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bdbe86cc-b1ba-dabe-898b-31e1c2b490a9@arm.com \
--to=luis.machado@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=torbjorn.svensson@foss.st.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).