From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 115433896825 for ; Tue, 12 Jan 2021 16:56:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 115433896825 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x433.google.com with SMTP id r3so3265844wrt.2 for ; Tue, 12 Jan 2021 08:56:29 -0800 (PST) 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; bh=LqA5LiaxQJ3CFPDAmRNV3/9UwHLSOBtPLX5ZJWLVgpo=; b=UtCDok6FoNtXXouhXvPXV4JPlMfZ2U2G6ZNR9SQ734jQB4OG7Gv/JwRjY7yM+oFSRr jZp6bBIG5rK1wQ1/7ubOS8qQtmmEUkPnmYWMtDcnlH0Hr3Pbeihl1vk3L/pigibeiPwp UtjnZFjwRI6TShtBMZxKeuB+fNN4GVl84v099OqjteDIREQdeIxWDP8pwUk0C/u/gZ7D iC9OZLhTJQtlAGzDrJRFpNoR3gOezab8wjDb7JMWgToOxqB5WDe9HO1Kp4aHlJIuf/cv kCi36Cckpi4agyvyd9UKNzrEnNHOC1G54HIe9UKHFTPuXr6QiStsi6aLI5ycC2okrU8w jOfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LqA5LiaxQJ3CFPDAmRNV3/9UwHLSOBtPLX5ZJWLVgpo=; b=JU+AYZ3hAt9R+H2PnGqEYmBozONIFkEmyDhuQqtS/cGliE4uLspFLoKrvx9he2kJZ3 NE8NvO9xdFhKXUWuF537uVKhQf89RAuuNxyWVAesBZq7GS+8PbUVhHoAeiVi/Cwh7XPG z70bj2NZLXxzekiZkGpofEHHxl8owqBC6DAMPhnq0f8z2Lnn2peLSM4F75BlXErty9k3 t8vZUgVY+HVWpbzNWNh9vdMNVkhmMq+Zj8jjIVbYDFjoiOQPrKEik95Fgw28TDp76HGW zAzjxCwelutYreG+/qfXxyYCXgvNrRVVMxU/5R+iHADaNLAhD5HBn4BLx1GcV0uL/2pe VjnQ== X-Gm-Message-State: AOAM533XT4p06G9Zv+PwgbQkl8PJp+E4bxdhCaFDz0p1fVb/aK7/g0E7 CiAQ/phWJigw+/tWLm3BP6qvVw== X-Google-Smtp-Source: ABdhPJzHhNdtyx8M3qc597cSnooMDK3euTGf3kLg3Wm8D1HR3+Bna19E6TRO4IBAsb1seeXPY9kCpA== X-Received: by 2002:a5d:62c7:: with SMTP id o7mr5168326wrv.257.1610470588147; Tue, 12 Jan 2021 08:56:28 -0800 (PST) Received: from localhost (host86-166-129-230.range86-166.btcentralplus.com. [86.166.129.230]) by smtp.gmail.com with ESMTPSA id b9sm5391098wmd.32.2021.01.12.08.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 08:56:27 -0800 (PST) Date: Tue, 12 Jan 2021 16:56:26 +0000 From: Andrew Burgess To: Simon Marchi Cc: Jan Vrany , gdb@sourceware.org Subject: Re: How to get past ebreak instruction on RISC-V Message-ID: <20210112165626.GA266063@embecosm.com> References: <8c7f5386d98b278267611a9a78aea0a0cb5966f3.camel@fit.cvut.cz> <78fcfd1f-4beb-85c2-acf0-c0231fd8c3e7@polymtl.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <78fcfd1f-4beb-85c2-acf0-c0231fd8c3e7@polymtl.ca> X-Operating-System: Linux/5.8.13-100.fc31.x86_64 (x86_64) X-Uptime: 16:44:06 up 34 days, 21:28, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jan 2021 16:56:30 -0000 * Simon Marchi via Gdb [2021-01-12 11:15:37 -0500]: > > > On 2021-01-12 11:07 a.m., Jan Vrany wrote: > > Hi, > > > > I'm working on RISC-V compiler. To ease debugging of compiled code > > I'm inserting `ebreak` instruction to interesting place (entry/exit > > points or as a placeholder for unimplemented features). > > > > For example, the code might look like: > > > > (gdb) disas 0x0000003FD6A36024, 0x0000003FD6A36048 > > Dump of assembler code from 0x3fd6a36024 to 0x3fd6a36048: > > => 0x0000003fd6a36024: ebreak > > 0x0000003fd6a36028: sd ra,-8(s11) > > 0x0000003fd6a3602c: addi s11,s11,-16 > > 0x0000003fd6a36030: ld t3,80(s10) > > 0x0000003fd6a36034: addiw a0,zero,42 > > 0x0000003fd6a36038: addi s11,s11,16 > > 0x0000003fd6a3603c: ret > > 0x0000003fd6a36040: blt s11,t3,0x3fd6a36000 > > 0x0000003fd6a36044: ebreak > > End of assembler dump. > > (gdb) > > > > When compiled function is (attempted to) run, it stops on `ebreak` > > as expected: > > > > Thread 2 "main" received signal SIGTRAP, Trace/breakpoint trap. > > [Switching to Thread 0x3ff7e681e0 (LWP 428777)] > > 0x0000003fd6a36024 in ?? () > > > > How can I get past the `ebreak` so I can `stepi` thought the following > > instructions and debug? Thanks! > > I suppose you could do "set $pc = 0x3fd6a36028". But really this is > something that GDB should be doing automatically, adjusting the PC > after hitting that style of breakpoint. If you place a breakpoint at the location of the ebreak then GDB will spot that there is already an ebreak there and will do the right thing. That is, it will treat it like a breakpoint, including being able to step over the breakpoint correctly, but will not get confused by the fact that there's no "real" instruction to execute at this address. Here's a sample session: (gdb) target sim Connected to the simulator. (gdb) load Loading section .text, size 0x20 lma 0x10054 Start address 0x10054 Transfer rate: 256 bits in <1 sec. (gdb) x/10i 0x10054 0x10054 <_start>: nop 0x10058 <_start+4>: nop 0x1005c <_start+8>: nop 0x10060 <_start+12>: ebreak 0x10064 <_start+16>: nop 0x10068 <_start+20>: nop 0x1006c <_start+24>: nop 0x10070 <_start+28>: ebreak 0x10074: unimp 0x10076: unimp (gdb) break *0x10060 Breakpoint 1 at 0x10060 (gdb) r Starting program: /home/andrew/projects/riscv-gdb/tmp/test.x Breakpoint 1, 0x00010060 in _start () (gdb) c Continuing. Program received signal SIGTRAP, Trace/breakpoint trap. 0x00010070 in _start () (gdb) x/10i 0x10054 0x10054 <_start>: nop 0x10058 <_start+4>: nop 0x1005c <_start+8>: nop 0x10060 <_start+12>: ebreak 0x10064 <_start+16>: nop 0x10068 <_start+20>: nop 0x1006c <_start+24>: nop => 0x10070 <_start+28>: ebreak 0x10074: unimp 0x10076: unimp (gdb) Thanks, Andrew