From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ppKnE7P5Nmg2xTcAWB0awg (envelope-from ) for ; Wed, 28 May 2025 07:55:31 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=Rnwu/db6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4294F1E11C; Wed, 28 May 2025 07:55:31 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.0 required=5.0 tests=ARC_SIGNED,ARC_VALID, BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 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 2D95A1E102 for ; Wed, 28 May 2025 07:55:28 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C50A938515DA for ; Wed, 28 May 2025 11:55:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C50A938515DA Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=Rnwu/db6 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by sourceware.org (Postfix) with ESMTPS id 4AFD9385DDED for ; Wed, 28 May 2025 11:54:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AFD9385DDED Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=partner.samsung.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=partner.samsung.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4AFD9385DDED Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748433293; cv=none; b=dNBnoayjnpm3G8LoCtvDOLHoZpCA6q+qE01qSELCZNTbmSFH7TERvE419YBtrGPi9cThUqI5Y8Gfm+ZVCJWh+e7oTyFm+ZstholAhksw9DSotkL+Huxq68YCjA6yBXIkEIMFkyRm3O+RB6+tqGZxqMsRevZe+TRmqEL9Y4FF7vc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748433293; c=relaxed/simple; bh=wwI3svcvPwJrf/AJ8ddKPL4eilWr45MBxzeLfesFYg8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fKTE1GIwDSy0moebEXwrDlN1tALJpTP+JJdQ4D9ciG+E1Klx9B0VuxMfmql505XAOknAfznW2w7Ba2GhA2ssCZwCqGtJ/Wa26v4ZZS0e5OiN0qk6LAS2Hk/CYkI3Qg4KVWvmV8seDEH1C8+6DgF1Jgx8bszDwncKKXAgT8HIHQ4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AFD9385DDED Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20250528115450euoutp02180b74e32a6e830f73a28278658ab781~DrtBy26601260212602euoutp02J for ; Wed, 28 May 2025 11:54:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20250528115450euoutp02180b74e32a6e830f73a28278658ab781~DrtBy26601260212602euoutp02J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1748433290; bh=coby3KzQwxyHTz4JVX1zThhMAa7ZYzaz4n+VXKX61uw=; h=From:To:Cc:Subject:Date:References:From; b=Rnwu/db6FUp28nqd8mf60Iui4vAyjl5aUm/Rg32FTAbogNSuoO4ZHgVD8r0+Ixg3G N0+eJRN9DeiyoLmgwRn1Xk+CRT8NHaykQZFkZ+BInkdqWCMQKI7cGT/irp1Dpq9xYs Sdc99cwKERilKrhOMbYlNvhe3Yo4ukn+EPJ3/Rys= Received: from eusmtip1.samsung.com (unknown [203.254.199.221]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20250528115450eucas1p1e57249bb51f4b7f41741772f60186468~DrtBgvMOC1108711087eucas1p1j; Wed, 28 May 2025 11:54:50 +0000 (GMT) Received: from blue.pikula.net (unknown [106.210.135.145]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20250528115449eusmtip1443c60954662915bb9f1cc7abd1c0c0d~DrtBKC1i42391723917eusmtip1A; Wed, 28 May 2025 11:54:49 +0000 (GMT) From: =?UTF-8?q?Marek=20Piku=C5=82a?= To: gdb-patches@sourceware.org Cc: s.rutka@samsung.com, palmer@dabbelt.com, andrew@sifive.com, jim.wilson.gcc@gmail.com, nelson@rivosinc.com, f.wasil@samsung.com, =?UTF-8?q?Marek=20Piku=C5=82a?= Subject: [PATCH v2] RISC-V: Fix ISA string detection for disassembly Date: Wed, 28 May 2025 13:54:47 +0200 Message-ID: <20250528115447.2750177-1-m.pikula@partner.samsung.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMS-MailID: 20250528115450eucas1p1e57249bb51f4b7f41741772f60186468 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20250528115450eucas1p1e57249bb51f4b7f41741772f60186468 X-EPHeader: CA X-CMS-RootMailID: 20250528115450eucas1p1e57249bb51f4b7f41741772f60186468 References: 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 Commit 3f61a38 introduced a regression where the ISA string was no longer detected based on the ELF header. The mechanism was changed from directly referencing `abfd` to using `disassembler_info->section`, which was not properly initialized for RISC-V. The previous implementation ignored the object in scope, leading to issues such as failing to decode RVV instructions when a library was compiled as `rv64gcv` and the main application as `rv64gc`. This patch resolves both problems by initializing `disassembler_info->section` with the object currently in scope, ensuring correct ISA string detection during disassembly. Signed-off-by: Marek PikuĊ‚a --- gdb/riscv-tdep.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 8998a297315..01e5dd00153 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -4163,6 +4163,19 @@ riscv_gnu_triplet_regexp (struct gdbarch *gdbarch) return "riscv(32|64)?"; } +/* Implement the "print_insn" gdbarch method. */ +static int +riscv_print_insn (bfd_vma addr, struct disassemble_info *info) +{ + /* Initialize the BFD section to enable ISA string detection depending on the + object in scope. */ + struct obj_section *s = find_pc_section (addr); + if (s != nullptr) + info->section = s->the_bfd_section; + + return default_print_insn (addr, info); +} + /* Implementation of `gdbarch_stap_is_single_operand', as defined in gdbarch.h. */ @@ -4429,6 +4442,9 @@ riscv_gdbarch_init (struct gdbarch_info info, disassembler_options_riscv ()); set_gdbarch_disassembler_options (gdbarch, &riscv_disassembler_options); + /* Disassembler print_insn. */ + set_gdbarch_print_insn (gdbarch, riscv_print_insn); + /* SystemTap Support. */ set_gdbarch_stap_is_single_operand (gdbarch, riscv_stap_is_single_operand); set_gdbarch_stap_register_indirection_prefixes -- 2.49.0