From patchwork Tue Jul 10 11:58:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 28291 Received: (qmail 53001 invoked by alias); 10 Jul 2018 11:58:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 52900 invoked by uid 89); 10 Jul 2018 11:58:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*RU:209.85.221.65, Hx-spam-relays-external:209.85.221.65 X-HELO: mail-wr1-f65.google.com Received: from mail-wr1-f65.google.com (HELO mail-wr1-f65.google.com) (209.85.221.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jul 2018 11:58:54 +0000 Received: by mail-wr1-f65.google.com with SMTP id c4-v6so1636689wrs.12 for ; Tue, 10 Jul 2018 04:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=DEV4w4K6HLChfqeo/jzTAKb7MS8KVRF1IrcYG0Mp+sA=; b=S74rzA8iUC5sRRtYNk3BSv62VfxKuwHGxi6Z86LbAsJqNOg2HWRGesVmKJ+d++wPuH +aVuDLEK4SEiko/Z7RM/dwKuyNadcI1+L+adOBQzHde9SAP3wZ7JWw+4qPGgUbmXWvcA LUucLAD5I+qSPZZktYjcDl/gMI/PwqKGgLIXLBgYmgZT+Trkw5pGIwxpdCRaFy7Rd6Fu vNYdkLlOupt4bFEiaOIN1TEWlhLy81QLaR/MYZfNiuk+84KhunHsJSB9RU9i/nYU3YrG VNPm58StCOaCPIHRuWlRQ2HiiPmcrzhqsT/8DKQxIofJgOZdDoi0S20FkkutvVbVjiye 8Hqg== Return-Path: Received: from localhost (host86-164-199-62.range86-164.btcentralplus.com. [86.164.199.62]) by smtp.gmail.com with ESMTPSA id z7-v6sm10168248wrh.85.2018.07.10.04.58.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jul 2018 04:58:51 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/2] gdb/riscv: Fix assertion in inferior call code Date: Tue, 10 Jul 2018 12:58:43 +0100 Message-Id: <8c49aa89abb92516dfc3507b540f736ca6339c0c.1531223299.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes An assertion when setting up arguments for an inferior call checks the size of the argument against xlen. However, if xlen and flen are different sizes, and the argument is being placed into a floating pointer register then we should be comparing against flen not xlen. This issue shows up as an assertion failure when running on an rv32g target with a binary compiled using the rv32f abi and making an inferior call involving large floating point arguments, for example the test gdb.base/infcall-nested-structs.exp. gdb/ChangeLog: * riscv-tdep.c (riscv_is_fp_regno_p): New function. (riscv_register_reggroup_p): Use new function, remove unneeded parenthesis. (riscv_push_dummy_call): Extend assert to compare against xlen or flen based on register type. --- gdb/ChangeLog | 8 ++++++++ gdb/riscv-tdep.c | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index e2be993eaf0..25a8fda29c4 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -413,6 +413,15 @@ riscv_has_fp_abi (struct gdbarch *gdbarch) return (gdbarch_tdep (gdbarch)->abi.fields.float_abi != 0); } +/* Return true if REGNO is a floating pointer register. */ + +static bool +riscv_is_fp_regno_p (int regno) +{ + return (regno >= RISCV_FIRST_FP_REGNUM + && regno <= RISCV_LAST_FP_REGNUM); +} + /* Implement the breakpoint_kind_from_pc gdbarch method. */ static int @@ -787,10 +796,10 @@ riscv_register_reggroup_p (struct gdbarch *gdbarch, int regnum, return 0; } else if (reggroup == float_reggroup) - return ((regnum >= RISCV_FIRST_FP_REGNUM && regnum <= RISCV_LAST_FP_REGNUM) - || (regnum == RISCV_CSR_FCSR_REGNUM - || regnum == RISCV_CSR_FFLAGS_REGNUM - || regnum == RISCV_CSR_FRM_REGNUM)); + return (riscv_is_fp_regno_p (regnum) + || regnum == RISCV_CSR_FCSR_REGNUM + || regnum == RISCV_CSR_FFLAGS_REGNUM + || regnum == RISCV_CSR_FRM_REGNUM); else if (reggroup == general_reggroup) return regnum < RISCV_FIRST_FP_REGNUM; else if (reggroup == restore_reggroup || reggroup == save_reggroup) @@ -2154,7 +2163,9 @@ riscv_push_dummy_call (struct gdbarch *gdbarch, { gdb_byte tmp [sizeof (ULONGEST)]; - gdb_assert (second_arg_length <= call_info.xlen); + gdb_assert ((riscv_is_fp_regno_p (info->argloc[1].loc_data.regno) + && second_arg_length <= call_info.flen) + || second_arg_length <= call_info.xlen); memset (tmp, 0, sizeof (tmp)); memcpy (tmp, second_arg_data, second_arg_length); regcache->cooked_write (info->argloc[1].loc_data.regno, tmp);