From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hksSB0taZGd85SIAWB0awg (envelope-from ) for ; Thu, 19 Dec 2024 12:39:23 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=gLwYWaeD; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1019B1E097; Thu, 19 Dec 2024 12:39:23 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E66361E091 for ; Thu, 19 Dec 2024 12:39:21 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 834793858D38 for ; Thu, 19 Dec 2024 17:39:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 834793858D38 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=gLwYWaeD Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id EFA4A3858D21 for ; Thu, 19 Dec 2024 17:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFA4A3858D21 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EFA4A3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734629869; cv=none; b=her4J1ll3Z7BtUeJ7Z0jLjBuMp0C1zxPjsKbxHELyys27ZiZE17PDcGVgeGBbwLcmWJV2zI35FevtEglRXA6yMF/cCwaxepxk0xPaeIO898lzb4sJSXhIMs42wKZ2dRSDszZEJH0YIe96kRBrVSjn+kCDSPm/MBgGu8sQlIftAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734629869; c=relaxed/simple; bh=PR4P4GSekjxPStKSm8GTGZEuzrsacXgNEKlWMoavrBY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=DFS2s/ty5XaAUNTi7dcWVwzeNokQaaZxsEZ4dNwaRZ/Hp+EscDPSn9Or7wuvJjDnf2pWyr076PUUhek3Hns0owHAlc3kU0E70AwrPfG+xh4LTVc6GUAEfSrSqzL5zcYeMxbJuxCgydhdPIn50tySwaz25FC+PCp0Ov7gYWiEJ6k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFA4A3858D21 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2164b1f05caso10460945ad.3 for ; Thu, 19 Dec 2024 09:37:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1734629868; x=1735234668; darn=sourceware.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mjMzkNsFG18GPqhHIArdocUnybJsboo16X/FhTbIISY=; b=gLwYWaeD2TUon5AD/X1YBpo+DXpqkUE1iRzLD8aqL1cArAX19j8SpgnK19rX+89aiw Swc1V3/pnr9fDs3gJul4dmdxV/rL2zINGrgPnnGujYAHAnwzfRjJ0zom6jdk00ZNP/6W MzRwzBAvsgMBY85Mg0LSgq1BZoUQJl9qFNmHr19Y8snO66Y1IAK8MznYkuBcWILSjtoW Ewij5qzySaH4VkAlUhH0QMRG9OHugd8hpkc4tezd5C91PCHKJoJbnudT4daIb0vfBo6U Jv30YVHuzbeg4sk3EueRX2YGtMuDEhw6OtLtMONM4vH53QU/jRQNP1gDqNkuDeMNg4bX zJoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734629868; x=1735234668; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mjMzkNsFG18GPqhHIArdocUnybJsboo16X/FhTbIISY=; b=flq6JBuMFDMJTvKNEYRBU+HgqyfiEkXoRu9BTX0VaMNBa9RxxaWHoW9eFn/bLsa53E nBBcn0+JTxkklVK0Co2PptLQ6ITNKWFuJDw6YD6QaWvY6bCsuXGja8hJGmfLcaTVml6q DdWLcPYu4lf4c55bw7EGCZ/uq8Dyk5WofxB13SL3NeZZQKmr9us4JwuZSfzTEULGPiK/ g8OlsAFFWMBYXLnp8LkUUu/0WJnWPcRJFjSBQxhhGJ1/aSlUn5NXWJdI5o4In9sGeAHP IWvk6w2dcpEzNE1B9bo1u9nL/Vd1HY+tWFp+fglQiJTu8pw6WZI4jk+eUlPuxcKaqe5V vJjw== X-Forwarded-Encrypted: i=1; AJvYcCXYusgr/0lk7aPVDvPQTilSkI/xFGuIMest4OSXjqg0UrC9gMWmqAsPI3D/cAQ/mJaMxfYiRQS7P82gPw==@sourceware.org X-Gm-Message-State: AOJu0YwpaBAZvj2wvHDWbnTKiyOeJgfv8JOl9SIkUMlW7kW6+toBu7yu VWpQKveWUiA9nUmzYHp7Ybl6HoNM2+T76IVvkoJzKFjDu2vKxpQMbJ84yf4A1bInrLtn9MaK2/Y SDSAOg/EWNfD0c8L7nHoF+ydLkN9KEr12qt2TAg== X-Gm-Gg: ASbGncvieDaCQrSx4Xop6vC+0GCynIXj45Y+HWztQXmyM19kAH3JrviE+X/PLTgB04b gsbVpcWs8RwlZ3WsIUZcVy9OAQY37xuBAPipTsw== X-Google-Smtp-Source: AGHT+IFsY8QXbmxMl+BSVk94+F5sY5x1z3fTKxTee5aRyeS/AN1x09HF836595pIB3628qnygx7N4h1ClhMzBnB2gGQ= X-Received: by 2002:a17:90b:51c6:b0:2ee:3cc1:793b with SMTP id 98e67ed59e1d1-2f2e9388a51mr9875949a91.26.1734629867919; Thu, 19 Dec 2024 09:37:47 -0800 (PST) MIME-Version: 1.0 References: <20241216-fix_objdump_partial_insn-v2-1-8de88a115dbc@rivosinc.com> In-Reply-To: <20241216-fix_objdump_partial_insn-v2-1-8de88a115dbc@rivosinc.com> From: Nelson Chu Date: Fri, 20 Dec 2024 01:37:37 +0800 Message-ID: Subject: Re: [PATCH v2] RISC-V: Fix disassembly of partial instructions To: Charlie Jenkins Cc: jiawei , gdb-patches , Binutils , Jan Beulich , Andrew Burgess Content-Type: multipart/alternative; boundary="0000000000001833970629a2fd27" X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org --0000000000001833970629a2fd27 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Some minor GNU coding styles as follows. Also cc Jan and Andrew, hope they still have time in their busy schedules can help to see if there are some side effects. Thanks Nelson On Tue, Dec 17, 2024 at 6:23=E2=80=AFAM Charlie Jenkins wrote: > As of commit e43d8768d909 ("RISC-V: Fix disassemble fetch fail return > value.") partial instructions are no longer disassembled. While that > commit fixed the behavior of print_insn_riscv() returning the arbitrary > status value upon failure, it caused the behavior of dumping > instructions to change. Allow partial instructions to be disassembled > once again and only return -1 if no part of the instruction was able to > be disassembled. > > Fixes: e43d8768d909 ("RISC-V: Fix disassemble fetch fail return value.") > Signed-off-by: Charlie Jenkins > --- > When testing linux perf, I noticed that this behavior of objdump has > changed. Before this patch and running `perf test` on riscv the > following test fails due to objdump not returning all of the expected > bytes. > > Bytes read differ from those read by objdump > buf1 (dso): > 0x97 0xf7 0x11 0x00 0x93 0x87 0xc7 0x7c 0x22 0x85 0x7c 0xec 0xef 0x50 0x8= 0 > 0x12 > 0xa6 0x85 0xce 0x86 0x4a 0x86 0x22 0x85 0xef 0x50 0x40 0x40 0xa2 0x84 0x1= d > 0xc9 > 0x7c 0x58 0x85 0x8b 0x85 0xc3 0x1c 0x40 0xa1 0x8b 0x89 0xcf 0x83 0x27 0x0= 4 > 0x0c > 0x63 0x51 0xf0 0x04 0x97 0xf7 0x11 0x00 0x93 0x87 0x07 0x45 0xbe 0x86 0x5= 8 > 0x70 > 0x74 0xec 0x7c 0xf3 0xa2 0x70 0x02 0x74 0x42 0x69 0xa2 0x69 0x26 0x85 0xe= 2 > 0x64 > 0x45 0x61 0x82 0x80 0x22 0x85 0xef 0x50 0x50 0x52 0x22 0x85 0xef 0x00 0xb= 1 > 0x39 > 0xa2 0x70 0x02 0x74 0x81 0x44 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 0x64 0x4= 5 > 0x61 > 0x82 0x80 0x97 0x06 0x12 0x00 0x93 0x86 0xa6 0x8a 0x97 0xf7 0x11 0x00 0x9= 3 > 0x87 > > buf2 (objdump): > 0x97 0xf7 0x11 0x00 0x93 0x87 0xc7 0x7c 0x22 0x85 0x7c 0xec 0xef 0x50 0x8= 0 > 0x12 > 0xa6 0x85 0xce 0x86 0x4a 0x86 0x22 0x85 0xef 0x50 0x40 0x40 0xa2 0x84 0x1= d > 0xc9 > 0x7c 0x58 0x85 0x8b 0x85 0xc3 0x1c 0x40 0xa1 0x8b 0x89 0xcf 0x83 0x27 0x0= 4 > 0x0c > 0x63 0x51 0xf0 0x04 0x97 0xf7 0x11 0x00 0x93 0x87 0x07 0x45 0xbe 0x86 0x5= 8 > 0x70 > 0x74 0xec 0x7c 0xf3 0xa2 0x70 0x02 0x74 0x42 0x69 0xa2 0x69 0x26 0x85 0xe= 2 > 0x64 > 0x45 0x61 0x82 0x80 0x22 0x85 0xef 0x50 0x50 0x52 0x22 0x85 0xef 0x00 0xb= 1 > 0x39 > 0xa2 0x70 0x02 0x74 0x81 0x44 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 0x64 0x4= 5 > 0x61 > 0x82 0x80 0x97 0x06 0x12 0x00 0x93 0x86 0xa6 0x8a 0x97 0xf7 0x11 0x00 0xa= d > 0x00 > > ---- end(-1) ---- > 24: Object code reading : FAILED! > > After this patch, this test case no longer fails, as objdump returns the > expected values. > --- > Changes in v2: > - Fix comment spacing (Jiawei) > - Link to v1: > https://lore.kernel.org/r/20241213-fix_objdump_partial_insn-v1-1-7a4963e6= 55d5@rivosinc.com > --- > opcodes/riscv-dis.c | 51 > ++++++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 46 insertions(+), 5 deletions(-) > > diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c > index > 101380f93aafbd528ba0020371f0c43a85f41bd1..492135d4642a29d86757ba0d2ec8261= dab66275f > 100644 > --- a/opcodes/riscv-dis.c > +++ b/opcodes/riscv-dis.c > @@ -1308,6 +1308,14 @@ riscv_disassemble_data (bfd_vma memaddr > ATTRIBUTE_UNUSED, > (*info->fprintf_styled_func) > (info->stream, dis_style_immediate, "0x%04x", (unsigned) data); > break; > + case 3: > + info->bytes_per_line =3D 7; > + (*info->fprintf_styled_func) > + (info->stream, dis_style_assembler_directive, ".word"); > + (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t"); > + (*info->fprintf_styled_func) > + (info->stream, dis_style_immediate, "0x%06x", (unsigned) data); > + break; > case 4: > info->bytes_per_line =3D 8; > (*info->fprintf_styled_func) > @@ -1360,13 +1368,28 @@ riscv_init_disasm_info (struct disassemble_info > *info) > return true; > } > > +/* Fetch an instruction. If only a partial instruction is able to be > fetched, > + return the number of accessible bytes. */ > + > +static bfd_vma > +fetch_insn (bfd_vma memaddr, bfd_byte *packet, bfd_vma dump_size, struct > disassemble_info *info, volatile int *status) > over 80 char per line. > +{ > + do > + { > + *status =3D (*info->read_memory_func) (memaddr, packet, dump_size, > info); > + } > + while(*status !=3D 0 && dump_size-- > 1); > Need space between while and left '(' > + > + return dump_size; > +} > + > int > print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) > { > bfd_byte packet[RISCV_MAX_INSN_LEN]; > insn_t insn =3D 0; > - bfd_vma dump_size; > - int status; > + volatile bfd_vma dump_size, bytes_fetched; > + volatile int status; > Not sure if it needed to be volatile or not. > enum riscv_seg_mstate mstate; > int (*riscv_disassembler) (bfd_vma, insn_t, const bfd_byte *, > struct disassemble_info *); > @@ -1398,24 +1421,42 @@ print_insn_riscv (bfd_vma memaddr, struct > disassemble_info *info) > else > { > /* Get the first 2-bytes to check the lenghth of instruction. */ > - status =3D (*info->read_memory_func) (memaddr, packet, 2, info); > + bytes_fetched =3D fetch_insn(memaddr, packet, 2, info, &status); > Need space after the function fetch_insn. > if (status !=3D 0) > { > (*info->memory_error_func) (status, memaddr, info); > return -1; > } > + else if (bytes_fetched !=3D 2) > + { > + /* Only the first byte was able to be read. Dump the partial > + instruction. */ > Two spaces after '.' > + dump_size =3D bytes_fetched; > + info->bytes_per_chunk =3D dump_size; > + riscv_disassembler =3D riscv_disassemble_data; > + goto print; > Indent, seems to miss a space. > + } > insn =3D (insn_t) bfd_getl16 (packet); > dump_size =3D riscv_insn_length (insn); > riscv_disassembler =3D riscv_disassemble_insn; > } > > - /* Fetch the instruction to dump. */ > - status =3D (*info->read_memory_func) (memaddr, packet, dump_size, info= ); > + bytes_fetched =3D fetch_insn(memaddr, packet, dump_size, info, &status= ); > Need space after the function fetch_insn. > + > if (status !=3D 0) > { > (*info->memory_error_func) (status, memaddr, info); > return -1; > } > + else if (bytes_fetched !=3D dump_size) > + { > + dump_size =3D bytes_fetched; > + info->bytes_per_chunk =3D dump_size; > + riscv_disassembler =3D riscv_disassemble_data; > + } > + > +print: > Indent, one space needed for the label. > + > insn =3D (insn_t) bfd_get_bits (packet, dump_size * 8, false); > > return (*riscv_disassembler) (memaddr, insn, packet, info); > > --- > base-commit: 978324718990b6b371d4eeeba02cfe13a0ebf120 > change-id: 20241121-fix_objdump_partial_insn-94e236f3db38 > -- > - Charlie > > --0000000000001833970629a2fd27 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Some minor GNU coding styles as follows.=C2=A0 Also c= c Jan and Andrew, hope they still have time in their busy schedules can hel= p to see if there are some side effects.

Thanks
Nelson

On Tue, Dec 17, 2024 at 6:23=E2=80=AFAM= Charlie Jenkins <charlie@rivosi= nc.com> wrote:
As of commit e43d8768d909 ("RISC-V: Fix disassemble fetch fail r= eturn
value.") partial instructions are no longer disassembled. While that commit fixed the behavior of print_insn_riscv() returning the arbitrary
status value upon failure, it caused the behavior of dumping
instructions to change. Allow partial instructions to be disassembled
once again and only return -1 if no part of the instruction was able to
be disassembled.

Fixes: e43d8768d909 ("RISC-V: Fix disassemble fetch fail return value.= ")
Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
---
When testing linux perf, I noticed that this behavior of objdump has
changed. Before this patch and running `perf test` on riscv the
following test fails due to objdump not returning all of the expected
bytes.

Bytes read differ from those read by objdump
buf1 (dso):
0x97 0xf7 0x11 0x00 0x93 0x87 0xc7 0x7c 0x22 0x85 0x7c 0xec 0xef 0x50 0x80 = 0x12
0xa6 0x85 0xce 0x86 0x4a 0x86 0x22 0x85 0xef 0x50 0x40 0x40 0xa2 0x84 0x1d = 0xc9
0x7c 0x58 0x85 0x8b 0x85 0xc3 0x1c 0x40 0xa1 0x8b 0x89 0xcf 0x83 0x27 0x04 = 0x0c
0x63 0x51 0xf0 0x04 0x97 0xf7 0x11 0x00 0x93 0x87 0x07 0x45 0xbe 0x86 0x58 = 0x70
0x74 0xec 0x7c 0xf3 0xa2 0x70 0x02 0x74 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 = 0x64
0x45 0x61 0x82 0x80 0x22 0x85 0xef 0x50 0x50 0x52 0x22 0x85 0xef 0x00 0xb1 = 0x39
0xa2 0x70 0x02 0x74 0x81 0x44 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 0x64 0x45 = 0x61
0x82 0x80 0x97 0x06 0x12 0x00 0x93 0x86 0xa6 0x8a 0x97 0xf7 0x11 0x00 0x93 = 0x87

buf2 (objdump):
0x97 0xf7 0x11 0x00 0x93 0x87 0xc7 0x7c 0x22 0x85 0x7c 0xec 0xef 0x50 0x80 = 0x12
0xa6 0x85 0xce 0x86 0x4a 0x86 0x22 0x85 0xef 0x50 0x40 0x40 0xa2 0x84 0x1d = 0xc9
0x7c 0x58 0x85 0x8b 0x85 0xc3 0x1c 0x40 0xa1 0x8b 0x89 0xcf 0x83 0x27 0x04 = 0x0c
0x63 0x51 0xf0 0x04 0x97 0xf7 0x11 0x00 0x93 0x87 0x07 0x45 0xbe 0x86 0x58 = 0x70
0x74 0xec 0x7c 0xf3 0xa2 0x70 0x02 0x74 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 = 0x64
0x45 0x61 0x82 0x80 0x22 0x85 0xef 0x50 0x50 0x52 0x22 0x85 0xef 0x00 0xb1 = 0x39
0xa2 0x70 0x02 0x74 0x81 0x44 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 0x64 0x45 = 0x61
0x82 0x80 0x97 0x06 0x12 0x00 0x93 0x86 0xa6 0x8a 0x97 0xf7 0x11 0x00 0xad = 0x00

---- end(-1) ----
=C2=A024: Object code reading=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 : FAILED!

After this patch, this test case no longer fails, as objdump returns the expected values.
---
Changes in v2:
- Fix comment spacing (Jiawei)
- Link to v1: https://lore.kernel.org/r/20241213-fix_objdump_partial_insn-v1-1-7a4963= e655d5@rivosinc.com
---
=C2=A0opcodes/riscv-dis.c | 51 ++++++++++++++++++++++++++++++++++++++++++++= ++-----
=C2=A01 file changed, 46 insertions(+), 5 deletions(-)

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 101380f93aafbd528ba0020371f0c43a85f41bd1..492135d4642a29d86757ba0d2ec= 8261dab66275f 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -1308,6 +1308,14 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UN= USED,
=C2=A0 =C2=A0 =C2=A0 =C2=A0(*info->fprintf_styled_func)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (info->stream, dis_style_immediate, "0x= %04x", (unsigned) data);
=C2=A0 =C2=A0 =C2=A0 =C2=A0break;
+=C2=A0 =C2=A0 case 3:
+=C2=A0 =C2=A0 =C2=A0 info->bytes_per_line =3D 7;
+=C2=A0 =C2=A0 =C2=A0 (*info->fprintf_styled_func)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(info->stream, dis_style_assembler_directive= , ".word");
+=C2=A0 =C2=A0 =C2=A0 (*info->fprintf_styled_func) (info->stream, dis= _style_text, "\t");
+=C2=A0 =C2=A0 =C2=A0 (*info->fprintf_styled_func)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(info->stream, dis_style_immediate, "0x= %06x", (unsigned) data);
+=C2=A0 =C2=A0 =C2=A0 break;
=C2=A0 =C2=A0 =C2=A0case 4:
=C2=A0 =C2=A0 =C2=A0 =C2=A0info->bytes_per_line =3D 8;
=C2=A0 =C2=A0 =C2=A0 =C2=A0(*info->fprintf_styled_func)
@@ -1360,13 +1368,28 @@ riscv_init_disasm_info (struct disassemble_info *in= fo)
=C2=A0 =C2=A0return true;
=C2=A0}

+/* Fetch an instruction. If only a partial instruction is able to be fetch= ed,
+=C2=A0 =C2=A0return the number of accessible bytes.=C2=A0 */
+
+static bfd_vma
+fetch_insn (bfd_vma memaddr, bfd_byte *packet, bfd_vma dump_size, struct d= isassemble_info *info, volatile int *status)

over 80 char per line.
=C2=A0
+{
+=C2=A0 do
+=C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 *status =3D (*info->read_memory_func) (memaddr, pa= cket, dump_size, info);
+=C2=A0 =C2=A0 }
+=C2=A0 while(*status !=3D 0 && dump_size-- > 1);

Need space between while and left '('
=C2=A0
+
+=C2=A0 return dump_size;
+}
+
=C2=A0int
=C2=A0print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
=C2=A0{
=C2=A0 =C2=A0bfd_byte packet[RISCV_MAX_INSN_LEN];
=C2=A0 =C2=A0insn_t insn =3D 0;
-=C2=A0 bfd_vma dump_size;
-=C2=A0 int status;
+=C2=A0 volatile bfd_vma dump_size, bytes_fetched;
+=C2=A0 volatile int status;

Not sure i= f it needed to be volatile or not.
=C2=A0
=C2=A0 =C2=A0enum riscv_seg_mstate mstate;
=C2=A0 =C2=A0int (*riscv_disassembler) (bfd_vma, insn_t, const bfd_byte *,<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct disassemble_info *);
@@ -1398,24 +1421,42 @@ print_insn_riscv (bfd_vma memaddr, struct disassemb= le_info *info)
=C2=A0 =C2=A0else
=C2=A0 =C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Get the first 2-bytes to check the lenghth of= instruction.=C2=A0 */
-=C2=A0 =C2=A0 =C2=A0 status =3D (*info->read_memory_func) (memaddr, pac= ket, 2, info);
+=C2=A0 =C2=A0 =C2=A0 bytes_fetched =3D fetch_insn(memaddr, packet, 2, info= , &status);

Need space after the fu= nction fetch_insn.
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0if (status !=3D 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (*info->memory_error_func) (status, m= emaddr, info);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -1;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 else if (bytes_fetched !=3D 2)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Only the first byte was able to be re= ad. Dump the partial
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 instruction.=C2=A0 */

Two spaces after '.'
=C2=A0
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dump_size =3D bytes_fetched;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0info->bytes_per_chunk =3D dump_size;<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0riscv_disassembler =3D riscv_disassemble= _data;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto print;

Indent, seems to miss a space.
=C2=A0
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0insn =3D (insn_t) bfd_getl16 (packet);
=C2=A0 =C2=A0 =C2=A0 =C2=A0dump_size =3D riscv_insn_length (insn);
=C2=A0 =C2=A0 =C2=A0 =C2=A0riscv_disassembler =3D riscv_disassemble_insn; =C2=A0 =C2=A0 =C2=A0}

-=C2=A0 /* Fetch the instruction to dump.=C2=A0 */
-=C2=A0 status =3D (*info->read_memory_func) (memaddr, packet, dump_size= , info);
+=C2=A0 bytes_fetched =3D fetch_insn(memaddr, packet, dump_size, info, &= ;status);

Need space after the function= fetch_insn.
=C2=A0
+
=C2=A0 =C2=A0if (status !=3D 0)
=C2=A0 =C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0(*info->memory_error_func) (status, memaddr, = info);
=C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;
=C2=A0 =C2=A0 =C2=A0}
+=C2=A0 else if (bytes_fetched !=3D dump_size)
+=C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 dump_size =3D bytes_fetched;
+=C2=A0 =C2=A0 =C2=A0 info->bytes_per_chunk =3D dump_size;
+=C2=A0 =C2=A0 =C2=A0 riscv_disassembler =3D riscv_disassemble_data;
+=C2=A0 =C2=A0 }
+
+print:

Indent, one space needed for th= e label.
=C2=A0
+
=C2=A0 =C2=A0insn =3D (insn_t) bfd_get_bits (packet, dump_size * 8, false);=

=C2=A0 =C2=A0return (*riscv_disassembler) (memaddr, insn, packet, info);
---
base-commit: 978324718990b6b371d4eeeba02cfe13a0ebf120
change-id: 20241121-fix_objdump_partial_insn-94e236f3db38
--
- Charlie

--0000000000001833970629a2fd27--