From: James Yang <James.Yang@freescale.com>
To: <benh@kernel.crashing.org>, <scottwood@freescale.com>
Cc: James Yang <James.Yang@freescale.com>, linuxppc-dev@lists.ozlabs.org
Subject: [RFC][PATCH 2/2] powerpc/booke: revert PTRACE_SINGLEBLOCK to BookE behavior
Date: Fri, 5 Jul 2013 17:11:05 -0500 [thread overview]
Message-ID: <1373062265-4267-3-git-send-email-James.Yang@freescale.com> (raw)
In-Reply-To: <1373062265-4267-1-git-send-email-James.Yang@freescale.com>
A BookE branch taken debug exception followed by a single step does not
accurately simulate Server's branch execute debug exception. BookE's
branch taken debug exception stops before the branch is to be executed
and only happens if the branch will actually be taken. Server's branch
execute trace exception stops on the instruction after the branch
executes, regardless of whether or not the branch redirected the program
counter.
The existing PTRACE_SINGLEBLOCK support for BookE hardcodes a single
step after the branch taken exception is taken in order to simulate
Server's behavior, but this misses fall-through branch instructions
(i.e., branches that are NOT taken). Also, the si_code became masked as
TRAP_TRACE instead of TRAP_BRANCH.
This patch provides native support for the BookE branch taken debug
exception's behavior: PTRACE_SINGLEBLOCK stops with a SIGTRAP before a
branch-that-would-be-taken would execute. Userspace software will be
able to examine the process state upon catching the SIGTRAP, and it
will need to issue a PTRACE_SINGLESTEP or PTRACE_CONT to resume program
execution past the branch.
Signed-off-by: James Yang <James.Yang@freescale.com>
---
arch/powerpc/kernel/traps.c | 40 +++++++++++++++++++++++++++-------------
1 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index c3ceaa2..5837d7f 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -1518,12 +1518,21 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)
{
current->thread.dbsr = debug_status;
- /* Hack alert: On BookE, Branch Taken stops on the branch itself, while
- * on server, it stops on the target of the branch. In order to simulate
- * the server behaviour, we thus restart right away with a single step
- * instead of stopping here when hitting a BT
+ /* BookE's Branch Taken Debug Exception stops on the branch iff the
+ * branch is resolved to be taken. No exception occurs if the branch
+ * is not taken (no exception if the branch does not redirect the PC).
+ * This is unlike Classic/Server's behavior where the exception occurs
+ * after the branch executes, regardless of whether or not the branch
+ * redirected the PC.
+ *
+ * The past behavior of this function was to simulate Classic/Server's
+ * behavior by performing a single-step upon a branch taken exception.
+ * However, the simulation is not accurate because fall-through non-
+ * taken branches would not result in a SIGTRAP. Also, that SIGTRAP's
+ * si_code would be reported as a TRAP_TRACE instead of a TRAP_BRANCH.
*/
- if (debug_status & DBSR_BT) {
+
+ if (debug_status & DBSR_BT) { /* Branch Taken */
regs->msr &= ~MSR_DE;
/* Disable BT */
@@ -1531,20 +1540,25 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)
/* Clear the BT event */
mtspr(SPRN_DBSR, DBSR_BT);
- /* Do the single step trick only when coming from userspace */
- if (user_mode(regs)) {
- current->thread.dbcr0 &= ~DBCR0_BT;
- current->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
- regs->msr |= MSR_DE;
- return;
- }
-
if (notify_die(DIE_SSTEP, "block_step", regs, 5,
5, SIGTRAP) == NOTIFY_STOP) {
return;
}
+
if (debugger_sstep(regs))
return;
+
+ if (user_mode(regs)) {
+ current->thread.dbcr0 &= ~DBCR0_BT;
+ if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0,
+ current->thread.dbcr1))
+ regs->msr |= MSR_DE;
+ else
+ /* Make sure the IDM bit is off */
+ current->thread.dbcr0 &= ~DBCR0_IDM;
+ }
+
+ _exception(SIGTRAP, regs, TRAP_BRANCH, regs->nip);
} else if (debug_status & DBSR_IC) { /* Instruction complete */
regs->msr &= ~MSR_DE;
--
1.7.0.4
next prev parent reply other threads:[~2013-07-05 22:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-05 22:11 [RFC][PATCH 0/2] powerpc/booke: PTRACE_SINGLEBLOCK support for BookE James Yang
2013-07-05 22:11 ` [RFC][PATCH 1/2] powerpc/booke: extend PTRACE_SINGLEBLOCK for BookE Branch Taken Debug James Yang
2013-07-09 16:53 ` Scott Wood
2013-07-05 22:11 ` James Yang [this message]
2013-07-06 0:21 ` [RFC][PATCH 2/2] powerpc/booke: revert PTRACE_SINGLEBLOCK to BookE behavior Benjamin Herrenschmidt
2013-07-06 5:01 ` James Yang
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=1373062265-4267-3-git-send-email-James.Yang@freescale.com \
--to=james.yang@freescale.com \
--cc=benh@kernel.crashing.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=scottwood@freescale.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 NNTP newsgroup(s).