From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4947 invoked by alias); 1 Nov 2018 23:46:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 4933 invoked by uid 89); 1 Nov 2018 23:46:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.1 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= X-HELO: mail-wr1-f68.google.com Received: from mail-wr1-f68.google.com (HELO mail-wr1-f68.google.com) (209.85.221.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Nov 2018 23:46:23 +0000 Received: by mail-wr1-f68.google.com with SMTP id n5-v6so162202wrw.12 for ; Thu, 01 Nov 2018 16:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9avABDVPsSP2LlLBaoUon5xklBEkvfz29P46Bf+XoqU=; b=L0ChPMxO89xv8kMQluFPDasiTr+PbDy9JwLtaXhuXLz9L2Hn8Wr3nnmHtgUMtVldYA 8M93expiPLQKs/3kLf90kMcE3OkK/GJjKzq/dtlfqgQOSr7mnocMzcuwd+8cCYsElC8o bYhusupQZH23O1r1t1s82yrTdy2q+VJ10ni9bxVuVpbgYKOYRGvCEXNwIN39w7pw1GeT dcduUcrvQc9hTrhyksysYCrHOQTk4e+aN6QihyR6MIS3dmaW/bZjA2NFJ4EaWFHi6UHe eYeNeUZJrwd6cABqzfo31BDQcJbgjjaG5Cc4umtHCo7Ktm8vv/GU81/F/8NVtkc6i13N cpzA== Return-Path: Received: from localhost (host81-148-252-35.range81-148.btcentralplus.com. [81.148.252.35]) by smtp.gmail.com with ESMTPSA id x18-v6sm8386819wrs.50.2018.11.01.16.46.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 16:46:20 -0700 (PDT) Date: Thu, 01 Nov 2018 23:46:00 -0000 From: Andrew Burgess To: Jim Wilson Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] RISC-V: Don't allow unaligned breakpoints. Message-ID: <20181101234618.GD16539@embecosm.com> References: <20181101214139.27196-1-jimw@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181101214139.27196-1-jimw@sifive.com> X-Fortune: Too many little pins on CPU confusing it, bend back and forth until 10-20% are neatly removed. Do _not_ leave metal bits visible! X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes X-SW-Source: 2018-11/txt/msg00017.txt.bz2 * Jim Wilson [2018-11-01 14:41:39 -0700]: > Some hardware doesn't support unaligned accesses, and a bare metal target > may not have an unaligned access trap handler. So if the PC is 2-byte > aligned, then use a 2-byte breakpoint to avoid unaligned accesses. > > Tested on native RV64GC Linux with gdb testsuite and cross on spike > simulator and openocd with riscv-tests/debug. > > gdb/ > * riscv-tdep.c (riscv_breakpoint_kind_from_pc): New local unaligned_p. > Set if pcptr if unaligned. Return 2 if unaligned_p true. Update > debugging messages. Looks good to me. Thanks, Andrew > --- > gdb/riscv-tdep.c | 31 +++++++++++++++++++++++-------- > 1 file changed, 23 insertions(+), 8 deletions(-) > > diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c > index 4b5f38a877..9c6872d021 100644 > --- a/gdb/riscv-tdep.c > +++ b/gdb/riscv-tdep.c > @@ -415,18 +415,33 @@ riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) > { > if (use_compressed_breakpoints == AUTO_BOOLEAN_AUTO) > { > + bool unaligned_p = false; > gdb_byte buf[1]; > > - /* Read the opcode byte to determine the instruction length. */ > - read_code (*pcptr, buf, 1); > + /* Some targets don't support unaligned reads. If the instruction > + address is unaligned, use a compressed breakpoint. */ > + if (*pcptr & 0x2) > + unaligned_p = true; > + else > + { > + /* Read the opcode byte to determine the instruction length. */ > + read_code (*pcptr, buf, 1); > + } > > if (riscv_debug_breakpoints) > - fprintf_unfiltered > - (gdb_stdlog, > - "Using %s for breakpoint at %s (instruction length %d)\n", > - riscv_insn_length (buf[0]) == 2 ? "C.EBREAK" : "EBREAK", > - paddress (gdbarch, *pcptr), riscv_insn_length (buf[0])); > - if (riscv_insn_length (buf[0]) == 2) > + { > + const char *bp = (unaligned_p || riscv_insn_length (buf[0]) == 2 > + ? "C.EBREAK" : "EBREAK"); > + > + fprintf_unfiltered (gdb_stdlog, "Using %s for breakpoint at %s ", > + bp, paddress (gdbarch, *pcptr)); > + if (unaligned_p) > + fprintf_unfiltered (gdb_stdlog, "(unaligned address)\n"); > + else > + fprintf_unfiltered (gdb_stdlog, "(instruction length %d)\n", > + riscv_insn_length (buf[0])); > + } > + if (unaligned_p || riscv_insn_length (buf[0]) == 2) > return 2; > else > return 4; > -- > 2.17.1 >