From: "Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>
To: <gdb-patches@sourceware.org>
Cc: luis.machado@arm.com, vanekt@volny.cz,
"Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>
Subject: [PATCH 3/3] gdb/arm: PR 29738 Cache value for stack pointers for dwarf2 frames
Date: Fri, 4 Nov 2022 15:44:41 +0100 [thread overview]
Message-ID: <20221104144438.2786801-4-torbjorn.svensson@foss.st.com> (raw)
In-Reply-To: <20221104144438.2786801-1-torbjorn.svensson@foss.st.com>
Without this patch, the number of calls to arm_dwarf2_prev_register
would grow in a too rapid way when the number of frames increase.
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
gdb/arm-tdep.c | 141 +++++++++++++++++++++++--------------------------
1 file changed, 66 insertions(+), 75 deletions(-)
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index c011b2aa973..a6fb660bcbc 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -3992,78 +3992,6 @@ arm_dwarf2_prev_register (frame_info_ptr this_frame, void **this_cache,
cpsr = reconstruct_t_bit (gdbarch, lr, cpsr);
return frame_unwind_got_constant (this_frame, regnum, cpsr);
}
- else if (arm_is_alternative_sp_register (tdep, regnum))
- {
- /* Handle the alternative SP registers on Cortex-M. */
- bool override_with_sp_value = false;
- CORE_ADDR val;
-
- if (tdep->have_sec_ext)
- {
- CORE_ADDR sp
- = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
- CORE_ADDR msp_s
- = get_frame_register_unsigned (this_frame,
- tdep->m_profile_msp_s_regnum);
- CORE_ADDR msp_ns
- = get_frame_register_unsigned (this_frame,
- tdep->m_profile_msp_ns_regnum);
- CORE_ADDR psp_s
- = get_frame_register_unsigned (this_frame,
- tdep->m_profile_psp_s_regnum);
- CORE_ADDR psp_ns
- = get_frame_register_unsigned (this_frame,
- tdep->m_profile_psp_ns_regnum);
-
- bool is_msp = (regnum == tdep->m_profile_msp_regnum)
- && (msp_s == sp || msp_ns == sp);
- bool is_msp_s = (regnum == tdep->m_profile_msp_s_regnum)
- && (msp_s == sp);
- bool is_msp_ns = (regnum == tdep->m_profile_msp_ns_regnum)
- && (msp_ns == sp);
- bool is_psp = (regnum == tdep->m_profile_psp_regnum)
- && (psp_s == sp || psp_ns == sp);
- bool is_psp_s = (regnum == tdep->m_profile_psp_s_regnum)
- && (psp_s == sp);
- bool is_psp_ns = (regnum == tdep->m_profile_psp_ns_regnum)
- && (psp_ns == sp);
-
- override_with_sp_value = is_msp || is_msp_s || is_msp_ns
- || is_psp || is_psp_s || is_psp_ns;
-
- }
- else if (tdep->is_m)
- {
- CORE_ADDR sp
- = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
- CORE_ADDR msp
- = get_frame_register_unsigned (this_frame,
- tdep->m_profile_msp_regnum);
- CORE_ADDR psp
- = get_frame_register_unsigned (this_frame,
- tdep->m_profile_psp_regnum);
-
- bool is_msp = (regnum == tdep->m_profile_msp_regnum) && (sp == msp);
- bool is_psp = (regnum == tdep->m_profile_psp_regnum) && (sp == psp);
-
- override_with_sp_value = is_msp || is_psp;
- }
-
- if (override_with_sp_value)
- {
- /* Use value of SP from previous frame. */
- frame_info_ptr prev_frame = get_prev_frame (this_frame);
- if (prev_frame)
- val = get_frame_register_unsigned (prev_frame, ARM_SP_REGNUM);
- else
- val = get_frame_base (this_frame);
- }
- else
- /* Use value for the register from previous frame. */
- val = get_frame_register_unsigned (this_frame, regnum);
-
- return frame_unwind_got_constant (this_frame, regnum, val);
- }
internal_error (_("Unexpected register %d"), regnum);
}
@@ -5202,9 +5130,72 @@ arm_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
reg->how = DWARF2_FRAME_REG_CFA;
else if (arm_is_alternative_sp_register (tdep, regnum))
{
- /* Handle the alternative SP registers on Cortex-M. */
- reg->how = DWARF2_FRAME_REG_FN;
- reg->loc.fn = arm_dwarf2_prev_register;
+ /* Identify what stack pointers that are synced with sp. */
+ bool override_with_sp_value = false;
+
+ if (tdep->have_sec_ext)
+ {
+ CORE_ADDR sp
+ = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
+
+ CORE_ADDR msp_s
+ = get_frame_register_unsigned (this_frame,
+ tdep->m_profile_msp_s_regnum);
+ CORE_ADDR msp_ns
+ = get_frame_register_unsigned (this_frame,
+ tdep->m_profile_msp_ns_regnum);
+ CORE_ADDR psp_s
+ = get_frame_register_unsigned (this_frame,
+ tdep->m_profile_psp_s_regnum);
+ CORE_ADDR psp_ns
+ = get_frame_register_unsigned (this_frame,
+ tdep->m_profile_psp_ns_regnum);
+
+ bool is_msp = (regnum == tdep->m_profile_msp_regnum)
+ && (msp_s == sp || msp_ns == sp);
+ bool is_msp_s = (regnum == tdep->m_profile_msp_s_regnum)
+ && (msp_s == sp);
+ bool is_msp_ns = (regnum == tdep->m_profile_msp_ns_regnum)
+ && (msp_ns == sp);
+ bool is_psp = (regnum == tdep->m_profile_psp_regnum)
+ && (psp_s == sp || psp_ns == sp);
+ bool is_psp_s = (regnum == tdep->m_profile_psp_s_regnum)
+ && (psp_s == sp);
+ bool is_psp_ns = (regnum == tdep->m_profile_psp_ns_regnum)
+ && (psp_ns == sp);
+
+ override_with_sp_value = is_msp || is_msp_s || is_msp_ns
+ || is_psp || is_psp_s || is_psp_ns;
+
+ }
+ else if (tdep->is_m)
+ {
+ CORE_ADDR sp
+ = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
+
+ CORE_ADDR msp
+ = get_frame_register_unsigned (this_frame,
+ tdep->m_profile_msp_regnum);
+ CORE_ADDR psp
+ = get_frame_register_unsigned (this_frame,
+ tdep->m_profile_psp_regnum);
+
+ bool is_msp = (regnum == tdep->m_profile_msp_regnum) && (sp == msp);
+ bool is_psp = (regnum == tdep->m_profile_psp_regnum) && (sp == psp);
+
+ override_with_sp_value = is_msp || is_psp;
+ }
+
+ if (override_with_sp_value)
+ {
+ /* Use the CFA value for this stack pointer register. */
+ reg->how = DWARF2_FRAME_REG_CFA;
+ }
+ else
+ {
+ /* This frame does not have any update for this stack pointer. */
+ reg->how = DWARF2_FRAME_REG_SAME_VALUE;
+ }
}
}
--
2.25.1
next prev parent reply other threads:[~2022-11-04 14:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 14:44 [PATCH 0/3] gdb/arm: Fixes for Cortex-M stack unwinding Torbjörn SVENSSON
2022-11-04 14:44 ` [PATCH 1/3] gdb/arm: Update active msp/psp when switching stack Torbjörn SVENSSON
2022-11-04 14:44 ` [PATCH 2/3] gdb/arm: Ensure that stack pointers are in sync Torbjörn SVENSSON
2022-11-04 17:31 ` Tomas Vanek
2022-11-07 17:27 ` Torbjorn SVENSSON
2022-11-04 14:44 ` Torbjörn SVENSSON [this message]
2022-11-11 9:15 ` [PATCH 3/3] gdb/arm: PR 29738 Cache value for stack pointers for dwarf2 frames Luis Machado
2022-11-11 10:27 ` Tomas Vanek
2022-11-12 19:54 ` Torbjorn SVENSSON
2022-11-14 10:46 ` Luis Machado
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=20221104144438.2786801-4-torbjorn.svensson@foss.st.com \
--to=torbjorn.svensson@foss.st.com \
--cc=gdb-patches@sourceware.org \
--cc=luis.machado@arm.com \
--cc=vanekt@volny.cz \
/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).