From patchwork Thu Dec 21 11:11:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaydeep Patil X-Patchwork-Id: 82666 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 803AD3858C2A for ; Thu, 21 Dec 2023 11:12:16 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mx08-00376f01.pphosted.com (mx08-00376f01.pphosted.com [91.207.212.86]) by sourceware.org (Postfix) with ESMTPS id 35C173858C52 for ; Thu, 21 Dec 2023 11:12:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35C173858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=imgtec.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=imgtec.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 35C173858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=91.207.212.86 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703157123; cv=none; b=T+jqsDcZFeLxR6bs01k2mrSyFVEgiOKMdqtaSorSapKBelHeWq59c4WXB68NEJGEuYDhNyRaDbNgPsar5xVg+qVRT3AkekmEd74y7OIAsc5Xjhq0b6MyYcrXck/+zUFuMskoQCI52rkes1lP58wL2iCiV66ka38FOl9q8RnshJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703157123; c=relaxed/simple; bh=46le165ZkaquqmTeFb72kEQj4H++UZPQ+kPETKfNMx4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZQz2jZRpwU7c+yVddD4bCD1WAEVGnzRp783Sm7CbB0RdfCW65p/Pc+VEyORNcP/12uuLPVyZw9mehjMoNaHXP2H2RlhwL4WswfHxx5xa5JYfcc22v6NIOUK5P3qG1GbxuprPGMvNwmxU6Gj4OL1y/bhANmn3c/p3y76bIMFwTh8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0168888.ppops.net [127.0.0.1]) by mx08-00376f01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BL90AEf021506; Thu, 21 Dec 2023 11:11:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imgtec.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= dk201812; bh=JRSCacYUZYV6UoWoCCPxmS6QGSMwvR1GDedaZ0nShaE=; b=dF7 qOFQv62fq3j793Gkk7LhOfjqKmo5y6xwXuPDVEd/zNL7NpKHwigAU2Dsvil+GBZF NU0AINncZm6Ehx1Z6ipdJbSnKeB7amW6LYwASFRxncx71i9OrOOHOem7Fb6Zm1d7 6xAN2C2/RKWhY6BTca1WkrFV6BNg771OVCj2mTjmxkGDtRTyk1fDmrUC/HP/oAKw Q3Ccu8xtReiISsGbAu/uczL8q8YX7Ni7/GpBLGfj8reSLKQhn4T/bw9pXGcfAk8H NyKVTOpvtzgCXwojaxJ6WG/kg9+Gly2hU07YKpY7Wz8VzPHMeHGNCBeAQouSwcDy E9MR5QoHzBh5JLxJHXA== Received: from hhmail05.hh.imgtec.org ([217.156.249.195]) by mx08-00376f01.pphosted.com (PPS) with ESMTPS id 3v2kvm22v3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 21 Dec 2023 11:11:50 +0000 (GMT) Received: from hhjpatil.hh.imgtec.org (10.100.136.70) by HHMAIL05.hh.imgtec.org (10.100.10.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 21 Dec 2023 11:11:49 +0000 From: To: CC: , , , , Subject: [PATCH v4 1/2] [sim/riscv] Fix crash during instruction decoding Date: Thu, 21 Dec 2023 11:11:38 +0000 Message-ID: <20231221111139.26341-2-jaydeep.patil@imgtec.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231221111139.26341-1-jaydeep.patil@imgtec.com> References: <20231221111139.26341-1-jaydeep.patil@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.100.136.70] X-ClientProxiedBy: HHMAIL05.hh.imgtec.org (10.100.10.120) To HHMAIL05.hh.imgtec.org (10.100.10.120) X-EXCLAIMER-MD-CONFIG: 15a78312-3e47-46eb-9010-2e54d84a9631 X-Proofpoint-GUID: tX_TeY9Fe34w4bIVdwmiZK8V2xEQB8UD X-Proofpoint-ORIG-GUID: tX_TeY9Fe34w4bIVdwmiZK8V2xEQB8UD X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org From: Jaydeep Patil The match_never() function has been removed and thus step_once() crashes during instruction decoding. Fixed it by checking for null pointer before invoking function attached to match_func member of riscv_opcode structure. --- opcodes/riscv-dis.c | 2 +- sim/riscv/sim-main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 68674380797..a89ebdd32ac 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -818,7 +818,7 @@ riscv_disassemble_insn (bfd_vma memaddr, if (op->pinfo == INSN_MACRO) continue; /* Does the opcode match? */ - if (! (op->match_func) (op, word)) + if (! op->match_func || ! (op->match_func) (op, word)) continue; /* Is this a pseudo-instruction and may we print it as such? */ if (no_aliases && (op->pinfo & INSN_ALIAS)) diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c index afdfcf50656..8a23d2aa1f9 100644 --- a/sim/riscv/sim-main.c +++ b/sim/riscv/sim-main.c @@ -1041,7 +1041,7 @@ void step_once (SIM_CPU *cpu) for (; op->name; op++) { /* Does the opcode match? */ - if (! op->match_func (op, iw)) + if (! op->match_func || ! op->match_func (op, iw)) continue; /* Is this a pseudo-instruction and may we print it as such? */ if (op->pinfo & INSN_ALIAS)