[Debug BEAM VM] How can I debug Segmentation fault from 3rd party lib?

Hello,

first a bit of context:

I am using Elixir with Kafka extensively.

Lib for connecting to Kafka I am using is GitHub - silviucpp/erlkaf: Erlang kafka driver based on librdkafka

It depends on a well known C++ Kafka driver GitHub - edenhill/librdkafka: The Apache Kafka C/C++ library

librdkafka works great most of the time, but sometimes on startup it throws Segmentation fault errors, and I would like to debug the C++ code.

Question:

Is there a way to compile the BEAM VM with C debug flags and connect it to some C debugger (prob not gdb but something for LLVM, right?)

I am using Mac with i7 Intel proc, installed Erlang and Elixir with asdf.

Tnx in advance,
Vlx

If I’m reading the docs right, asdf uses kerl under the hood, so you should be able to pass kerl options when installing:

$ export KERL_BUILD_DEBUG_VM="true"
$ asdf install erlang <version>

You should then be able to use cerl -debug -lldb to start LLDB with the debug emulator.

3 Likes

False alarm, I mistakenly used openssl@3 for compile

uuuugh, now my asdf installation doesn’t work. OpenSSL issues

$ echo $KERL_BUILD_DEBUG_VM
true
$ echo $KERL_CONFIGURE_OPTIONS 
--without-javac --with-ssl=/usr/local/opt/openssl@3
$ asdf install erlang 24.1.7 
asdf_24.1.7 is not a kerl-managed Erlang/OTP installation
No build named asdf_24.1.7
Downloading 24.1.7 to /Users/y/.asdf/plugins/erlang/kerl-home/archives...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   654  100   654    0     0   6812      0 --:--:-- --:--:-- --:--:--  6812
100  102M  100  102M    0     0  27.9M      0  0:00:03  0:00:03 --:--:-- 37.0M
Extracting source code
Building Erlang/OTP 24.1.7 (asdf_24.1.7), please wait...
APPLICATIONS DISABLED (See: /Users/y/.asdf/plugins/erlang/kerl-home/builds/asdf_24.1.7/otp_build_24.1.7.log)
 * jinterface     : Java compiler disabled by user

Build failed.
#   define OSSL_DEPRECATEDIN_3_0                OSSL_DEPRECATED(3.0)
                                                ^
/usr/local/opt/openssl@3/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED'
#     define OSSL_DEPRECATED(since) __attribute__((deprecated))
                                                   ^
25 warnings generated.
make[3]: *** [opt] Error 2
make[2]: *** [opt] Error 2
make[1]: *** [opt] Error 2
make: *** [libs] Error 2

I successfully compiled erlang with debug flags, thank you very much!

Now I am really struggling with runnig the Elixir app in interactive mode (iex -S mix) and connecting it to the lldb

I suppose I should run the lldb first, then run BEAM machine and then point it to the Elixir project to run it?

Sorry, I’m afraid I can’t be of much help with the Elixir side of things. :frowning: