0

I'm working on an Erlang wrapper over a 3rd party C library on Ubuntu Linux on x86, so I'm creating a NIF. Sometimes my code (I think) crashes, resulting in a core file. Unfortunately the stacktrace is not really helpful:

(gdb) bt
#0  0x00007fc22229968a in ?? ()
#1  0x0000000060e816d8 in ?? ()
#2  0x0000000007cd48b0 in ?? ()
#3  0x00007fc228031410 in ?? ()
#4  0x00007fc228040b80 in ?? ()
#5  0x00007fc228040c50 in ?? ()
#6  0x00007fc22223de0b in ?? ()
#7  0x0000000000000000 in ?? ()

even though I built my NIF .so file with debug info:

ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=b70dd1f2450f5c0e9980c8396aaad2e1cd29024c, with debug_info, not stripped

The beam also has debug info:

ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=e0a5dba6507b8c2b333faebc89fbc6ea2f7263b9, for GNU/Linux 3.2.0, with debug_info, not stripped

However, info sharedlibrary doesn't show neither the NIF nor the 3rd party lib:

(gdb) info sharedlibrary 
From                To                  Syms Read   Shared Object Library
0x00007fc28942ed50  0x00007fc289432004  Yes         /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0
0x00007fc289429220  0x00007fc28942a179  Yes         /lib/x86_64-linux-gnu/libdl.so.2
0x00007fc2892e83c0  0x00007fc28938ef18  Yes         /lib/x86_64-linux-gnu/libm.so.6
0x00007fc2892b76a0  0x00007fc2892c517c  Yes         /lib/x86_64-linux-gnu/libtinfo.so.6
0x00007fc28928dae0  0x00007fc28929d4d5  Yes         /lib/x86_64-linux-gnu/libpthread.so.0
0x00007fc2890b9630  0x00007fc28922e20d  Yes         /lib/x86_64-linux-gnu/libc.so.6
0x00007fc289657100  0x00007fc289679674  Yes (*)     /lib64/ld-linux-x86-64.so.2
0x00007fc24459c040  0x00007fc2445ab8ad  Yes         /home/nar/otp/23.3.4.2/lib/crypto-4.9.0.2/priv/lib/crypto.so
0x00007fc2239e3000  0x00007fc223b7c800  Yes (*)     /lib/x86_64-linux-gnu/libcrypto.so.1.1
0x00007fc2896500e0  0x00007fc28965028c  Yes         /home/nar/otp/23.3.4.2/lib/crypto-4.9.0.2/priv/lib/crypto_callback.so
0x00007fc289649380  0x00007fc28964bc1c  Yes         /home/nar/otp/23.3.4.2/lib/asn1-5.0.15/priv/lib/asn1rt_nif.so
0x00007fc289638720  0x00007fc28963bd70  Yes         /lib/x86_64-linux-gnu/librt.so.1

I found this answer mentioning that "The Erlang VM doesn't load NIF libraries with global symbols exposed". Could this be the reason why I don't see the symbols? Is there a way to tell gdb to look up symbols from my .so file?

user2414208
  • 425
  • 6
  • 19

1 Answers1

0

I built the Erlang VM with debug enabled (I used kerl to build and set KERL_BUILD_DEBUG_VM to true), then started the erlang with the -debug option. This way some asserts were seem to be enabled in the code, they crashed and that lead to me to the bugs in my code. Since then I don't have the crashes.

user2414208
  • 425
  • 6
  • 19