debug with GHC FFI?
Tue, 25 Feb 2003 15:31:13 -0000
[ moved to firstname.lastname@example.org ]
> I am using Green Card to make some FFI modules with GHC, but
> sometimes it segfaults in the middle of nowhere, leaving
> no sensible stack trace in gdb.
> I wonder what is the proper way to debug FFI modules written
> in C? Trying to add a "-g" flag doesn't seem help at all...=20
You should be able to debug the normal C code using gdb. If the crash
happens somewhere in Haskell code, then gdb is of less use (unless you
happen to know the details of GHC's execution model). It sounds like in
your case the crash is happening somewhere in Haskell. =20
There are a few possible approaches:
- If it is a callback into Haskell that is crashing, you should
be able to use gdb to find which call into Haskell is
the culprit, which might give you some clues.
- use Debug.Trace.trace in the Haskell code to narrow down the bug.
Ugly, but very useful.
- Robert Ennals is working on a debugger for GHC as part of
his speculative evaluation work. It's very much a
work in progress though, and I haven't tried it myself yet.
It's in ghc/utils/hs-debug on the speceval_2 branch of CVS.