From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102647 invoked by alias); 20 Sep 2018 00:40:51 -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 102635 invoked by uid 89); 20 Sep 2018 00:40:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=BREAK, H*f:sk:CAFyWVa, H*i:sk:CAFyWVa X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Sep 2018 00:40:47 +0000 Received: from John-Baldwins-MacBook-Pro-2.local (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 9D7DC10B670; Wed, 19 Sep 2018 20:40:45 -0400 (EDT) Subject: Re: [PATCH 2/4] Fall back to a default value of 0 for the MISA register. To: Jim Wilson References: <20180919231950.22634-1-jhb@FreeBSD.org> <20180919231950.22634-3-jhb@FreeBSD.org> Cc: gdb-patches@sourceware.org, Andrew Burgess , Palmer Dabbelt From: John Baldwin Message-ID: <0081bdf8-04cb-f6b7-d80a-d9a878d0a3ab@FreeBSD.org> Date: Thu, 20 Sep 2018 00:40:00 -0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00722.txt.bz2 On 9/19/18 5:09 PM, Jim Wilson wrote: > On Wed, Sep 19, 2018 at 4:20 PM John Baldwin wrote: >> MISA is a machine-mode register in RISC-V which may or may not be >> available to supervisor operating systems. Rather than requiring >> targets to always provide a fake MISA value, fallback to 0 for now. >> (The Linux native target currently always provides a fake value of 0 >> for MISA.) > > The linux target provides a fake value for misa because gdb is a side > project for me, and I haven't had time to add ptrace support for it > yet. Too many binutils and gcc problems I need to fix first. > > I think providing a default misa value in riscv-tdep.c is a mistake. > One major problem is with the use of compressed breakpoints. Consider > the case where the target has compressed instruction support, the C > library was compiled to use compressed instructions, and the user > program was compiled without compressed instruction support. If we > can't read misa, then we check the program ELF headers, see that there > is no compressed instruction support, and start using 4-byte > breakpoints. Storing a 4 byte breakpoint into a library compiled with > compressed instructions means that we will be clobbering instructions > and things start breaking badly. I ran into this earlier before > fixing some bugs in the breakpoint support in riscv-tdep.c. Glibc > provides a stub function for gdb support that happens to be exactly 2 > bytes long. Storing a 4-byte breakpoint there clobbers the first > instruction of the next function, which happens to be an important > function for program startup, which means we get an illegal > instruction error before even reaching main which is very confusing. > > If we can read misa, then we don't have this problem, as we will > always know if the hardware supports compressed breakpoints, and we > can avoid this problem. If we can't read misa, then we will have to > check the ELF headers of every shared library used by a program, > including the interpreter ld.so, to see if any of them use compressed > instructions. We will also have to check every library loaded at > run-time via dlload. This seems like a hassle. Another option might > be to try to execute a 2-byte breakpoint to see if it works or not, > and then use compressed breakpoints if they work, but this also seems > like a hassle. Reading misa seems like the easy solution, all I need > is a linux kernel patch to add ptrace support for reading it. If we > have access to misa, then we also know whether FP registers are > present, and their size, which is also important info that we can't > easily get any other way. misa is roughly equivalent to x86 cpuid. I > don't know of any reason why misa wouldn't be available to the OS. > > I suppose another option here might be the auxvec/hwcap info. Maybe > info about compressed instructions and FP support can be passed from > the kernel to the user program this way, and then maybe gdb can get > the info from there, if gdb has some way to read and parse > auxvec/hwcap info passed to the user program. GDB certainly can examine AT_ values (it already has to read AT_BASE to find the runtime linker and from there the list of shared libraries, etc.). For some things like F vs D vs Q we probably want to have different target descriptions (this is how x86 manages x86 vs SSE vs AVX) and have the native target's ::read_description method return a suitable description. Whether or not 'C' is present is a bit more subtle as it isn't something you could infer just from a register being present or not. On the other hand, for breakpoints, I wonder if a more straightforward approach would be to examine the opcode of the existing instruction and use that to decide which breakpoint to use? That is, read the first byte of the existing instruction and if the low 2 bits indicate a 16-bit instruction use C.BREAK and otherwise use BREAK? -- John Baldwin                                                                            Â