From: Daniel Jacobowitz <drow@false.org>
To: "Maciej W. Rozycki" <macro@mips.com>
Cc: gdb-patches@sourceware.org, Chris Dearman <chris@mips.com>,
"Maciej W. Rozycki" <macro@linux-mips.org>
Subject: Re: mips-tdep.c: Adjust breakpoints in branch delay slots
Date: Thu, 24 May 2007 18:31:00 -0000 [thread overview]
Message-ID: <20070524183129.GA10094@caradoc.them.org> (raw)
In-Reply-To: <Pine.LNX.4.61.0705241853450.21951@perivale.mips.com>
On Thu, May 24, 2007 at 07:07:46PM +0100, Maciej W. Rozycki wrote:
> +/* Return non-zero if the ADDR instruction has a branch delay slot
> + (i.e. it is a jump or branch instruction). This function was based
> + on mips32_next_pc(). */
> +
> +static int
> +mips32_instruction_has_delay_slot (CORE_ADDR addr)
> +{
> + gdb_byte buf[MIPS_INSN32_SIZE];
> + int status;
> +
> + status = read_memory_nobpt (addr, buf, MIPS_INSN32_SIZE);
> + return !status && mips32_next_pc (addr) != addr + 4;
> +}
That's not what you want. mips32_next_pc calls read_register to
figure out if the branch condition is true, and we don't have any idea
yet (and might not be connected to a target).
> + /* If a breakpoint is set on the instruction in a branch delay slot,
> + GDB gets confused. When the breakpoint is hit, the PC isn't on
> + the instruction in the branch delay slot, the PC will point to
> + the branch instruction. Since the PC doesn't match any known
> + breakpoints, GDB reports a trap exception.
Just checking, but does this happen in a userspace environment like
Linux too?
> + There are two possible fixes for this problem.
> +
> + 1) When the breakpoint gets hit, see if the BD bit is set in the
> + Cause register (which indicates the last exception occurred in a
> + branch delay slot). If the BD bit is set, fix the PC to point to
> + the instruction in the branch delay slot.
> +
> + 2) When the user sets the breakpoint, don't allow him to set the
> + breakpoint on the instruction in the branch delay slot. Instead
> + move the breakpoint to the branch instruction (which will have
> + the same result).
> +
> + The problem with the first solution is that if the user then
> + single-steps the processor, the branch instruction will get
> + skipped (since GDB thinks the PC is on the instruction in the
> + branch delay slot).
> +
> + So, we'll use the second solution. To do this we need to know if
> + the instruction we're trying to set the breakpoint on is in the
> + branch delay slot. */
Abstractly, which of these solutions would you say was better? I bet
we could make the first one work if we tried hard enough. One way
would be to fake the PC, but that's pretty gross. Still, it might be
possible if it was worthwhile.
BTW, see mips_single_step_through_delay, which could probably be
improved. Doesn't its comment about MIPS16 having no delay slots
disagree with this patch? Which is right?
> + /* Make sure we don't scan back before the beginning of the
> + current function, since we may fetch constant data or MIPS32
> + insns that looks like a MIPS16 jump. Of course we might do
> + that anyway if the compiler has moved constants inline. :-( */
This can happen for MIPS32 too at the start of a function. All in all
I'm a little bit nervous about this adjustment, since it will fail
very confusingly if you get unlucky with constant pool data. That's
why I was asking about the alternative solution above.
Oh, and I wholeheartedly agree with Mark about testcases. It
shouldn't be hard to add this to gdb.arch/.
Thanks for the patch!
--
Daniel Jacobowitz
CodeSourcery
next prev parent reply other threads:[~2007-05-24 18:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-24 18:08 Maciej W. Rozycki
2007-05-24 18:21 ` Mark Kettenis
2007-05-24 18:31 ` Daniel Jacobowitz [this message]
[not found] ` <Pine.LNX.4.61.0705251217190.13913@perivale.mips.com>
2007-05-25 12:50 ` Maciej W. Rozycki
2007-05-25 13:16 ` Maciej W. Rozycki
[not found] ` <Pine.LNX.4.61.0705251318500.13913@perivale.mips.com>
2007-05-25 13:19 ` Daniel Jacobowitz
2007-06-15 14:38 ` Maciej W. Rozycki
2007-05-25 13:21 ` Maciej W. Rozycki
2007-05-25 13:26 ` Daniel Jacobowitz
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=20070524183129.GA10094@caradoc.them.org \
--to=drow@false.org \
--cc=chris@mips.com \
--cc=gdb-patches@sourceware.org \
--cc=macro@linux-mips.org \
--cc=macro@mips.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