From patchwork Thu Jul 4 21:07:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 33596 Received: (qmail 63949 invoked by alias); 4 Jul 2019 21:08:06 -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 63940 invoked by uid 89); 4 Jul 2019 21:08:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 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.1 spammy=H*RU:sk:host86-, HX-Spam-Relays-External:sk:host86-, H*r:sk:host86- X-HELO: mail-wr1-f67.google.com Received: from mail-wr1-f67.google.com (HELO mail-wr1-f67.google.com) (209.85.221.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 Jul 2019 21:08:04 +0000 Received: by mail-wr1-f67.google.com with SMTP id a10so6729033wrp.9 for ; Thu, 04 Jul 2019 14:08:03 -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; bh=jGtNN574DAqJqkn6cJYvLcpbXESlOjX31WSyWzcj2UQ=; b=U6rqXoI6y3X83OC1nLn5n+7IhIlRYeSqIm7Bm5oLXRf4wdkz4h45gJ4CqG4WWQPnx/ NEZPqF4vb1Tmx9yx2OUIGctGwYY51uyqjzQPnRm9raluGjUmi2FuWh5v5yuQo8sxGQNj FSiI+itJmrP9uT250AeD+C0vwMQKRrb96DA7bxXolrnWnlF4uQkZvz7VHrRqMkfZ8yli QyYt3RYTJ6dfx1T91YDjDLU4pr6seX2Sr+G+rbs3eFqdKFdzNwdRhLeYBjgUKaFxwwl8 KPnhk+dvhRrIqfgbWyQPzmK93Sz/YJ4b9UUx6VRj6lF4K7IoPSmUd/CJY5JGeXVWV/wD Q62Q== Return-Path: Received: from localhost (host86-128-12-99.range86-128.btcentralplus.com. [86.128.12.99]) by smtp.gmail.com with ESMTPSA id r12sm9933397wrt.95.2019.07.04.14.08.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jul 2019 14:08:01 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Jim Wilson , Palmer Dabbelt , John Baldwin , Andrew Burgess Subject: [PATCH] gdb/riscv: Don't use default bfd to define required features Date: Thu, 4 Jul 2019 22:07:58 +0100 Message-Id: <20190704210758.22920-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes When we initialise a gdbarch object we perform a check to try and detect if the user is doing something silly; trying to run an RV64 binary on an RV32 target. To perform this check we compare the xlen from the target description with the xlen specified in the headers on the ELF being debugged. If there is no ELF being debugged then we (currently) try to use the bfd_arch_info from the gdbarch_info object, which will have been set to the default architecture if no bfd is currently being debugged. For RISC-V the default architecture is RV64. What this means is that if a user tries to connect to an RV32 target without specifying the BFD to debug then GDB will assume RV64. The sanity check mentioned above will failed (xlen difference) and GDB will throw an error. The error causes GDB to disconnect from the remote target. After this commit GDB no longer relies on the default bfd architecture. If the user tries to connect without specifying the bfd then GDB will simply make use of the xlen extracted from the target description in order to find or create a suitable gdbarch object. gdb/ChangeLog: * riscv-tdep.c (riscv_features_from_gdbarch_info): Don't modify required features based on default bfd type when no specific bfd is present. --- gdb/ChangeLog | 6 ++++++ gdb/riscv-tdep.c | 12 ------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index bae987cf66b..828beea7e2b 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -2917,18 +2917,6 @@ riscv_features_from_gdbarch_info (const struct gdbarch_info info) else if (e_flags & EF_RISCV_FLOAT_ABI_SINGLE) features.flen = 4; } - else - { - const struct bfd_arch_info *binfo = info.bfd_arch_info; - - if (binfo->bits_per_word == 32) - features.xlen = 4; - else if (binfo->bits_per_word == 64) - features.xlen = 8; - else - internal_error (__FILE__, __LINE__, _("unknown bits_per_word %d"), - binfo->bits_per_word); - } return features; }