From: John Baldwin <jhb@FreeBSD.org>
To: Jim Wilson <jimw@sifive.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] RISC-V: Don't allow unaligned breakpoints.
Date: Thu, 01 Nov 2018 22:05:00 -0000 [thread overview]
Message-ID: <e4fa69a6-aa80-b7ad-7ec6-62ec80888720@FreeBSD.org> (raw)
In-Reply-To: <20181101214139.27196-1-jimw@sifive.com>
On 11/1/18 2:41 PM, Jim Wilson wrote:
> Some hardware doesn't support unaligned accesses, and a bare metal target
> may not have an unaligned access trap handler. So if the PC is 2-byte
> aligned, then use a 2-byte breakpoint to avoid unaligned accesses.
>
> Tested on native RV64GC Linux with gdb testsuite and cross on spike
> simulator and openocd with riscv-tests/debug.
>
> gdb/
> * riscv-tdep.c (riscv_breakpoint_kind_from_pc): New local unaligned_p.
> Set if pcptr if unaligned. Return 2 if unaligned_p true. Update
> debugging messages.
> ---
> gdb/riscv-tdep.c | 31 +++++++++++++++++++++++--------
> 1 file changed, 23 insertions(+), 8 deletions(-)
>
> diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
> index 4b5f38a877..9c6872d021 100644
> --- a/gdb/riscv-tdep.c
> +++ b/gdb/riscv-tdep.c
> @@ -415,18 +415,33 @@ riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
> {
> if (use_compressed_breakpoints == AUTO_BOOLEAN_AUTO)
> {
> + bool unaligned_p = false;
> gdb_byte buf[1];
>
> - /* Read the opcode byte to determine the instruction length. */
> - read_code (*pcptr, buf, 1);
> + /* Some targets don't support unaligned reads. If the instruction
> + address is unaligned, use a compressed breakpoint. */
> + if (*pcptr & 0x2)
> + unaligned_p = true;
> + else
> + {
> + /* Read the opcode byte to determine the instruction length. */
> + read_code (*pcptr, buf, 1);
> + }
>
> if (riscv_debug_breakpoints)
> - fprintf_unfiltered
> - (gdb_stdlog,
> - "Using %s for breakpoint at %s (instruction length %d)\n",
> - riscv_insn_length (buf[0]) == 2 ? "C.EBREAK" : "EBREAK",
> - paddress (gdbarch, *pcptr), riscv_insn_length (buf[0]));
> - if (riscv_insn_length (buf[0]) == 2)
> + {
> + const char *bp = (unaligned_p || riscv_insn_length (buf[0]) == 2
> + ? "C.EBREAK" : "EBREAK");
> +
> + fprintf_unfiltered (gdb_stdlog, "Using %s for breakpoint at %s ",
> + bp, paddress (gdbarch, *pcptr));
> + if (unaligned_p)
> + fprintf_unfiltered (gdb_stdlog, "(unaligned address)\n");
> + else
> + fprintf_unfiltered (gdb_stdlog, "(instruction length %d)\n",
> + riscv_insn_length (buf[0]));
> + }
> + if (unaligned_p || riscv_insn_length (buf[0]) == 2)
> return 2;
> else
> return 4;
This looks good to me. Not sure if you want to explicitly add something to
the comment that an unaligned PC is only valid if C is supported, so we
know C.EBREAK is safe to use with an unaligned PC?
--
John Baldwin
                                                                           Â
next prev parent reply other threads:[~2018-11-01 22:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-01 21:41 Jim Wilson
2018-11-01 22:05 ` John Baldwin [this message]
2018-11-01 23:37 ` Jim Wilson
2018-11-01 23:46 ` Andrew Burgess
2018-11-02 0:27 ` Jim Wilson
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=e4fa69a6-aa80-b7ad-7ec6-62ec80888720@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=gdb-patches@sourceware.org \
--cc=jimw@sifive.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