[erlang-questions] How to track down intermittent segfaults in a threaded NIF

Scott Ribe scott_ribe@REDACTED
Tue May 29 16:42:34 CEST 2018


> On May 29, 2018, at 8:33 AM, Igor Clark <igor.clark@REDACTED> wrote:
> 
> From what I can tell from its docs, I could either do that in Xcode, or using gdb, right? I have no clue how I'd go about running the BEAM inside Xcode, especially booting my application and NIF code, and I've got a lot to learn about how to connect any of this with rebar3 and releases. Do you run BEAM in Xcode or directly with gdb/lldb?

Actually, all you have to do is export those environment variables in whatever environment you launch, not just Xcode or gdb.

At launch, they barf some descriptive info to stdout (or stderr?), so if you can figure out where the beam sends that and monitor it, you should see confirmation that they're in effect:


SHR-MacBook-Pro:~ sribe$ export MallocStackLogging=1
SHR-MacBook-Pro:~ sribe$ ls
ls(32181,0x7fff88acb380) malloc: stack logs being written into /tmp/stack-logs.32181.104a26000.ls.6dB2BT.index
ls(32181,0x7fff88acb380) malloc: recording malloc and VM allocation stacks to disk using standard recorder
Applications			Dropbox				Public				eclipse				fsaclctl
Desktop				Library				Sites				eclipse-workspace		perf_demo
Desktop Folder			Movies				TheFindByContentFolder		elixir-basics-workshop		pgdata
Documents			Music				Trash				elixir-fire-brigade-workshop
Downloads			Pictures			_rvm				elixirconf_workshop
ls(32181,0x7fff88acb380) malloc: stack logs deleted from /tmp/stack-logs.32181.104a26000.ls.6dB2BT.index
SHR-MacBook-Pro:~ sribe$


Barring that, you could always insert a deliberate overrun in your NIF's initialization and check that it immediately crashes with an access violation.

--
Scott Ribe
scott_ribe@REDACTED
https://www.linkedin.com/in/scottribe/







More information about the erlang-questions mailing list