Skip to content

Conversation

idlewan
Copy link
Contributor

@idlewan idlewan commented Nov 10, 2017

When using -d:useNimRtl, stack traces are useless ("No stack traceback available").
This can be verified when compiling this example program in addition to libnimrtl.so:

template fuzzy(x) =
  echo x[] != 9

var p: ptr int
fuzzy p       # will segfault on purpose, however "no stack traceback is available"

Compile with nim c -d:useNimRtl test_segfault.nim and nim c -o:libnimrtl.so nim-repo/lib/nimrtl.nim.
Start (on linux) with LD_LIBRARY_PATH=/path/to/libnimrtl.so ./test_segfault

This happens because two instances of framePtr exist at the same time: one from libnimrtl.so, and one from the test program (I ended up seeing this when printfing my way around and checking the generated c files). There is also two signalHandler present, the one from test_segfault is the one that runs last, apparently.

The right framePtr from libnimrtl.so is updated correctly by nimFrame and other functions, however when for example a segfault happens, the signalHandler from the test program runs, which refer to a nil framePtr.
That framePtr doesn't contain any information on frames, thus why no stack traceback were available.


This change ensure that there is only one signalHander that will be registered, the one from libnimrtl.so, this should also avoid pulling a second nil framePtr by the test program.
The stack traces should now be available and shown when using useNimRtl.

@Araq
Copy link
Member

Araq commented Nov 10, 2017

Wonderful analysis and bugfix!

@Araq Araq merged commit 6a6a2b7 into nim-lang:devel Nov 10, 2017
@idlewan idlewan deleted the fix-stacktrace-nimrtl branch November 10, 2017 10:33
@idlewan idlewan restored the fix-stacktrace-nimrtl branch November 10, 2017 15:25
@idlewan idlewan deleted the fix-stacktrace-nimrtl branch November 10, 2017 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants