[Haskell-cafe] Tips for debugging seg. faults?
Viktor Dukhovni
ietf-dane at dukhovni.org
Sat Jun 19 22:46:53 UTC 2021
On Sat, Jun 19, 2021 at 12:53:35PM -0700, David Banas wrote:
> Does anyone have any helpful tips for debugging seg. faults in a
> Haskell program that calls out to a C library, via the FFI?
The question would ideally be more specific. What kind of data is being
passed to the C FFI function? The most common issue is that the
structure passed may no longer have any live references on the Haskell
side, and may be freed before the C FFI is done with it.
Thus functions like `withForeignPtr` which try to make sure the the
referenced memory is not released too early.
Buffer pointers should be to pinned memory, ...
Sure, build your program with "-Og -g -ggdb3" and use "gdb" to see more
context for the crash, but typically the problem is a simple misuse of
pointers that are not guaranteed to be valid.
Therefore, what is the FFI signature, and how is it called?
--
Viktor.
More information about the Haskell-Cafe
mailing list