This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Don't rewind PC for GHC generated frames
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: Bartosz Nitka <niteria at gmail dot com>, <gdb-patches at sourceware dot org>
- Date: Thu, 1 Feb 2018 16:21:54 -0500
- Subject: Re: [PATCH] Don't rewind PC for GHC generated frames
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=simon dot marchi at ericsson dot com;
- References: <CAOSxnRgHDYy6pz0NqBxcC9Mrq2eMm4UdLAkAc63uibTJFe-rsg@mail.gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On 2018-02-01 01:54 PM, Bartosz Nitka wrote:
> GHC - the Haskell compiler generates code that violates one of
> GDB's assumptions.
>
> GDB assumes that the address in a frame was generated by the call
> instruction and that it is the address of the call instruction
> plus 1 (I'm rephrasing the comment in get_frame_address_in_block).
> So to get the real address, one has to substract 1. This is doubly
> beneficial because some functions are "noreturn" and don't have
> further instructions after call, so GDB would be looking at gibberish.
> All in all, this is good for C-like languages.
>
> GHC generates completely different code. It uses jumps instead of call
> and manages the stack itself. Furthermore every piece of code is preceeded
> by some metadata called the Info Table. If we substract from the
> program counter it ends up pointing to the metadata, which is undesirable.
> GHC has a workaround for this [1] that works most of the time, it basically
> lies in the DWARF data and extends the function one byte backwards.
> That helps with making unwinding succeed most of the time, but then the
> address is also used for looking up symbols and they can't be resolved.
>
> This change disables program counter rewinding for GHC generated compilation
> units.
>
> Some additional context can be found here [2].
>
> [1] https://phabricator.haskell.org/diffusion/GHC/browse/master/compiler/nativeGen/Dwarf/Types.hs;e9ae0cae9eb6a340473b339b5711ae76c6bdd045$399-417
> [2] https://ghc.haskell.org/trac/ghc/wiki/DWARF
Hi Bartosz,
I am unable to apply your patch, it seems that your mail client messed
up the formatting (among other things, replaced some tabs with spaces).
Would it be possible for you to send it using git-send-email? There are
instructions on setting up git-send-email with gmail here, if needed:
https://www.kernel.org/pub/software/scm/git/docs/git-send-email.html
Thanks,
Simon