Hey I'm new to nim and have an issue where my code fails with the following error, only when I compile with -d:release
SIGSEGV: Illegal storage access.
Any ideas how I can debug this?
Arrr, from my understanding he told us that his code is running fine when compiled without -d:release but crashes due to nil access when compiled in release mode. So I can not see how your comment can really help him.
scobra, for me "in" test for seq of strings work fine with Nim v 0.19 both in debug and release mode. So I guess that you are doing some dirty low level operations with cast or addr or similar unsecure operations. So your code may be buggy, but the bug does not show always. So investigate your code carefully, or show us a complete, compiling code example that shows the mentioned error.
I have not recreated a trivial case so unfortunately there's a bit more to the code and setting it up for yourself might be a bit of a pain as you will need a matrix.org account as it's a bot for that.
Anyway the error occurs on the following line: https://github.com/fxcqz/gouda4/blob/master/src/modules/core.nim#L50
A Message is created from parsing the json of a POST request using httpclient (using -d:ssl), you can see it here: https://github.com/fxcqz/gouda4/blob/master/src/matrix.nim#L72
I appreciate that this is not easy to debug for someone else so don't go to too much effort. I don't have access to the code right now so I can't make any progress debugging until later.
Aha, yes that was the issue, here is a minimal case:
import json
import unicode
echo "{\"a\":[]}".parseJson["a"]["a"].getStr.toLower
Raises AssertionError without -d:release and SIGSEGV with it. Thanks all.
Fine error message without -d_release for Nim v0.19:
$ ./t
t.nim(4) t
json.nim(426) []
system.nim(3790) failedAssertImpl
system.nim(3783) raiseAssert
system.nim(2830) sysFatal
Error: unhandled exception: /home/stefan/Nim/lib/pure/json.nim(426, 9) `node.kind == JObject` [AssertionError]
So some work for json or unicode module maintainers -- reason may be that internal string handling has changed for Nim > 0.18
Release version mean it's version that has intensively tested.
You need to import segfault module to catch segfault as NilAccessError
Interesting, that does work, thanks. From a contextual stand point though I think `{}` makes more sense than an import + try block.
Regarding the level of testing, yes I suppose this is true - my issue was I wasn't even seeing an assertion error in the debug mode binary (not sure why), and I wouldn't generally expect stdlib code to segfault, especially because the error does not help at all.