From: Luis Machado <lgustavo@codesourcery.com>
To: "'gdb-patches@sourceware.org'" <gdb-patches@sourceware.org>
Subject: [PATCH] Relax ARM prologue unwinder assumption
Date: Thu, 05 Feb 2015 19:07:00 -0000 [thread overview]
Message-ID: <54D3BF52.5070709@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2304 bytes --]
Just recently i ran into a problem with a bare metal ARM target where
GDB would not allow some registers to be changed after the PC was
manually set to some other value.
In reality the target had just started and one of its cores, out of
four, was running the program, but the other ones were in some random state.
The PC of one of the other 3 cores was then adjusted to point to a known
function address.
GDB's reaction to this change is to invalidate the regcache and frame
and build a brand new chain and cache, while trying to retain the
previously selected frame - #0 in this case.
What i noticed is that GDB was selecting frame #1 instead of #0 due to
unfortunate coincidences with both frames' SP's being 0. And we can't
modify some registers on non-innermost frames for obvious reasons.
Here's a brief log of what happens:
[Switching to thread 2 (Thread 2)]
#0 0x0093ff10 in ?? ()
(gdb) set $pc=functioncore2
(gdb) bt
#0 functioncore2 () at test.c:32
#1 0x0000fc44 in ?? ()
(gdb) frame
#1 0x0000fc44 in ?? ()
(gdb) set $sp=0x2030
Attempt to assign to an unmodifiable value.
I tracked this problem down to this old
(https://sourceware.org/ml/gdb-patches/2003-08/msg00526.html) piece of
code in arm-tdep.c:arm_prologue_this_id:
/* If we've hit a wall, stop. */
if (cache->prev_sp == 0)
return;
Due to the SP being 0 for this specific core, GDB returns early and does
not set the frame's PC to the new value. That means we have a frame with
PC==0x0 and SP==0x0, which ends up matching frame #1 in our case. But
this is obviously wrong.
I looked up the patch that introduced this chunk of code and did not
find any reasonable explanation for this check. Though it may make sense
for non-bare metal targets, a bare-metal board attached to a probe can
be stopped at any random place, so we should be able to set its
registers freely without worrying about unwinding assumptions. This is
generic code after all. I understand a valid workaround is to make sure
the proper frame is selected, but GDB should be smart enough not to
confuse things. Therefore this "wall" described in the comment seems too
strict to be in generic code.
The attached patch removes this restriction and does not cause any
regressions for ARM bare metal, but i'd like feedback.
[-- Attachment #2: arm_prologue.diff --]
[-- Type: text/x-patch, Size: 687 bytes --]
2015-02-05 Luis Machado <lgustavo@codesourcery.com>
* arm-tdep.c (arm_prologue_this_id): Remove check for the stack
pointer being 0.
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 8e9552a..771cbeb 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -2042,10 +2042,6 @@ arm_prologue_this_id (struct frame_info *this_frame,
if (pc <= gdbarch_tdep (get_frame_arch (this_frame))->lowest_pc)
return;
- /* If we've hit a wall, stop. */
- if (cache->prev_sp == 0)
- return;
-
/* Use function start address as part of the frame ID. If we cannot
identify the start address (due to missing symbol information),
fall back to just using the current PC. */
next reply other threads:[~2015-02-05 19:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-05 19:07 Luis Machado [this message]
2015-02-06 15:25 ` Pedro Alves
2015-02-09 14:51 ` Luis Machado
2015-02-10 9:38 ` Pedro Alves
2015-02-10 11:52 ` 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=54D3BF52.5070709@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/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