From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30225 invoked by alias); 19 Nov 2016 01:16:15 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 30210 invoked by uid 89); 19 Nov 2016 01:16:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=Newsome, newsome, hey X-HELO: mail-it0-f54.google.com Received: from mail-it0-f54.google.com (HELO mail-it0-f54.google.com) (209.85.214.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 Nov 2016 01:16:04 +0000 Received: by mail-it0-f54.google.com with SMTP id j191so61121478ita.1 for ; Fri, 18 Nov 2016 17:16:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=6aJ8UILiRC02gcMQHsWDdszp018gjbPUWkDqAX/yUHk=; b=bahzo6g0PwKhnYyFtegjUzCS8cBOO+qS+8dB8P+cgHyqSPrkswBDNbgcQOKfO9P8Iz 4bbz632NZSstOuPjT2SzntxaHfOZSwqf9L3disjdn+D58FlB0FPyeB3+9OomDO9z/VK4 YT/StVZI6S8UWQtEfbgKEtVx6KjaGDHoexQWq4hFiVuzjCI8B9GhwdRsujMWLJxYxQo7 FJ3byfJd9sZ21wLFbg51JwZv4JrLfr2r8MbCKQKVvnAo0zN87KwrqLm+U+JebR7EDXpr lo3oe9SwEV3zH/JmC4keg19+Ec7cO9HuVaAySMlrSCvpYtoQ53LqS8otmVSGqn9lzR08 acvQ== X-Gm-Message-State: AKaTC02gc/yxDtNxlPqYy5f2xZFJ/wlwBzizrKlWuUnI6qtlNFnyJyQU2J2CNmLEoj2OrS0xzXHLIULHPKH0Mw== X-Received: by 10.36.236.3 with SMTP id g3mr1152478ith.4.1479518163283; Fri, 18 Nov 2016 17:16:03 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.174.30 with HTTP; Fri, 18 Nov 2016 17:16:02 -0800 (PST) In-Reply-To: References: From: Ofir Cohen Date: Sat, 19 Nov 2016 01:16:00 -0000 Message-ID: Subject: Re: read target register to decide breakpoint size To: Tim Newsome Cc: gdb Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00031.txt.bz2 Hi, I've been messing with that code lately, and I recall gdb is checking if the instruction is a breakpoint instruction in validate_inserted_breakpoint() function: if (err || memcmp (buf, bp_opcode (bp), bp_size (bp)) != 0) Also, you should check out breakpoint_from_pc callback function (IIRC implemented in target_ops), from [1]: "breakpoint_from_pc. Returns the breakpoint instruction to be used when the PC is at a particular location in memory. For architectures with variable length instructions, the choice of breakpoint instruction may depend on the length of the instruction at the program counter. Returns the instruction sequence and its length. The default value is NULL (undefined). This function should always be defined if GDB is to support breakpointing for this architecture." So IOW gdb is (somewhat) flexible when it comes to determining instruction breakpoints. You should probably initialize the breakpoint size (2/4) at target init stage, cache it within your module and return at runtime the (correct) cached size. Guys on the mailing list can probably elabore more on this, but hey this is a place to start :-). Good luck. Regards, Ofir Cohen [1] http://www.embecosm.com/appnotes/ean3/embecosm-howto-gdb-porting-ean3-issue-2.pdf On 19 November 2016 at 01:44, Tim Newsome wrote: > I'm still working on RISC-V support for gdb. Any given RISC-V core may > support a compressed instruction set (2 bytes per instruction as > opposed to 4). There are corresponding 2-byte and 4-byte breakpoint > instructions. On cores that support the compressed instruction set it > is safe to just always use the 2-byte version, and there is a register > I can read to tell me whether the compressed instruction set is > supported. What I would like to do is read (and cache) that register > when breakpoint size is determined. That seems more robust than making > a decision based on ELF info, which may not reflect what is actually > being executed. > > Is that a good idea? Are there examples of operations that read target > registers to complete? > > Thank you, > Tim