Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Charlie Jenkins <charlie@rivosinc.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: gdb-patches <gdb-patches@sourceware.org>,
	Binutils <binutils@sourceware.org>, jiawei <jiawei@iscas.ac.cn>,
	Nelson Chu <nelson@rivosinc.com>,
	Andrew Burgess <aburgess@redhat.com>
Subject: Re: [PATCH 1/2] RISC-V: Fix abort when displaying .dword
Date: Wed, 12 Feb 2025 16:52:34 -0800	[thread overview]
Message-ID: <Z61CUjciK84ekc07@ghost> (raw)
In-Reply-To: <f0cc84b4-5712-4c45-a641-5fd6219b60de@suse.com>

On Wed, Feb 12, 2025 at 09:06:43AM +0100, Jan Beulich wrote:
> On 12.02.2025 06:08, Charlie Jenkins wrote:
> > In the normal case an instruction won't be split into 5, 6, or 7 byte
> > sections. However a .dword disassembled with -D can cause an instruction
> > to split across the 6 byte boundary. 6 byte instructions were not
> > supported so riscv_disassemble_data() would abort.
> > 
> > Forcing instructions to be at most 4 bytes causes other unintented
> > side-effects, so instead add entries to the switch statement to handle
> > instructions that are 5, 6, or 7 bytes.
> > 
> > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> > Fixes: 6a04e8230707 ("RISC-V: Fix display of partial instructions")
> > ---
> >  opcodes/riscv-dis.c | 29 ++++++++++++++++++++++++++++-
> >  1 file changed, 28 insertions(+), 1 deletion(-)
> > 
> > diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
> > index 367004d3341e46a5f72253cd70c7c2941912e84d..21bcbd32c7f226d13f1637ad192d8fe3c52e0d7a 100644
> > --- a/opcodes/riscv-dis.c
> > +++ b/opcodes/riscv-dis.c
> > @@ -1325,6 +1325,33 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
> >  	(info->stream, dis_style_immediate, "0x%08lx",
> >  	 (unsigned long) data);
> >        break;
> > +    case 5:
> > +      info->bytes_per_line = 8;
> > +      (*info->fprintf_styled_func)
> > +	(info->stream, dis_style_assembler_directive, ".dword");
> > +      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
> > +      (*info->fprintf_styled_func)
> > +	(info->stream, dis_style_immediate, "0x%010lx",
> > +	 (unsigned long) data);
> 
> This isn't going to have the intended effect on a 32-bit host.
> 
> > +      break;
> > +    case 6:
> > +      info->bytes_per_line = 8;
> > +      (*info->fprintf_styled_func)
> > +	(info->stream, dis_style_assembler_directive, ".dword");
> > +      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
> > +      (*info->fprintf_styled_func)
> > +	(info->stream, dis_style_immediate, "0x%012lx",
> > +	 (unsigned long) data);
> > +      break;
> > +    case 7:
> > +      info->bytes_per_line = 8;
> > +      (*info->fprintf_styled_func)
> > +	(info->stream, dis_style_assembler_directive, ".dword");
> > +      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
> > +      (*info->fprintf_styled_func)
> > +	(info->stream, dis_style_immediate, "0x%014lx",
> > +	 (unsigned long) data);
> > +      break;
> 
> While this follows what's done in the 3-byte case, I don't consider this
> (or the 3-byte logic) correct. When I see .dword, I expect what's printed
> covers full 8 bytes. Imo fake .<N>byte directives (which the assembler
> doesn't recognize for non-power-of-2 N) would be more logical to use.

That's a good point. I think the simplest thing to do would be to have
.short/.word/.dword for the 2/4/8 cases and then for anything outside of
that print .<N>byte. Similar to what is done with insn with printing
.insn <size>, <insn> when it is not identified.

- Charlie

> 
> Also, question to the maintainers: Can we perhaps stop this unnecessary
> decoration of indirect function calls? E.g. (taking part of the above)
> 
>     case 5:
>       info->bytes_per_line = 8;
>       info->fprintf_styled_func
> 	(info->stream, dis_style_assembler_directive, ".dword");
>       info->fprintf_styled_func (info->stream, dis_style_text, "\t");
>       info->fprintf_styled_func
> 	(info->stream, dis_style_immediate, "0x%010lx",
> 	 (unsigned long) data);
>       break;
> 
> has been perfectly fine to write for several decades, and is imo quite
> a bit easier to read.
> 
> > @@ -1332,7 +1359,7 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
> >        (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
> >        (*info->fprintf_styled_func)
> >  	(info->stream, dis_style_immediate, "0x%016llx",
> > -	 (unsigned long long) data);
> > +	 (unsigned long) data);
> 
> This can't be correct; the compiler will complain about format specifier
> disagreeing with type of the value to format, on 32-bit hosts.
> 
> Jan

  parent reply	other threads:[~2025-02-13  0:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  5:08 [PATCH 0/2] RISC-V: Fix abort when displaying data and add test Charlie Jenkins
2025-02-12  5:08 ` [PATCH 1/2] RISC-V: Fix abort when displaying .dword Charlie Jenkins
2025-02-12  5:27   ` Jiawei
2025-02-12  7:25   ` Alan Modra
2025-02-12  8:06   ` Jan Beulich
2025-02-12  8:57     ` Nelson Chu
2025-02-12 10:06       ` Jan Beulich
2025-02-12 22:15         ` Maciej W. Rozycki
2025-02-13  0:51           ` Charlie Jenkins
2025-02-13  0:52     ` Charlie Jenkins [this message]
2025-02-12  5:08 ` [PATCH 2/2] RISC-V: Add testcase for 6 byte instruction Charlie Jenkins
2025-02-12  5:20 ` [PATCH 0/2] RISC-V: Fix abort when displaying data and add test Nelson Chu

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=Z61CUjciK84ekc07@ghost \
    --to=charlie@rivosinc.com \
    --cc=aburgess@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=jiawei@iscas.ac.cn \
    --cc=nelson@rivosinc.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