[erlang-questions] how can I debug errors in linked-in drivers or nif loaded as shared library?

193 views
Skip to first unread message

caox

unread,
Dec 24, 2010, 4:09:59 AM12/24/10
to erlang-q...@erlang.org
hi

I got a segmentation fault and a core.dump file when tested my linked-in driver. How could I debug it with gdb?
For an executable c file, we can just call 'gdb a.out core.dump'. How can I do this for a .so file loaded by erlang?
Thanks.
________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questio...@erlang.org

Attila Rajmund Nohl

unread,
Dec 24, 2010, 6:39:32 AM12/24/10
to erlang-q...@erlang.org
2010/12/24, caox <ca...@lightpole.net>:

> hi
>
> I got a segmentation fault and a core.dump file when tested my linked-in
> driver. How could I debug it with gdb?
> For an executable c file, we can just call 'gdb a.out core.dump'. How can I
> do this for a .so file loaded by erlang?

If I remember correctly, you should use the path to the erl binary in
place of 'a.out'.

Kevin A. Smith

unread,
Dec 24, 2010, 8:59:56 AM12/24/10
to caox, erlang-q...@erlang.org
I've edited the erl script which comes with the standard Erlang release to allow easy use of GDB for just such situations:

if [ ! -z "$USE_GDB" ]; then
gdb $BINDIR/erlexec --args $BINDIR/erlexec ${1+"$@"}
else
exec $BINDIR/erlexec ${1+"$@"}
fi

#exec $BINDIR/erlexec ${1+"$@"}

Define the env var "USE_GDB" before launching Erlang and you'll get a debugger prompt when your NIF/driver crashes. GDB's backtrace command is especially helpful :-)

Credit to Dave Smith @ Basho for originally suggesting this approach.

--Kevin

caox

unread,
Dec 25, 2010, 10:45:02 AM12/25/10
to Kevin A. Smith, erlang-q...@erlang.org
thanks a lot. I will try it.
Reply all
Reply to author
Forward
0 new messages