Hey,
during development of a tool using Nim i experienced some errors in the form of "SIGSEGV: Illegal storage access". I was able to "fix" them by re-structuring my code, but i feel not very good with this. Maybe i am doing something fundamentally wrong, that leads to this error.
I would like to know if there are any advices how i can track those errors down. The hint "Try to compile with -d:useSysAssert -d:useGcAssert for details." i got was not useful at all, because when compiling with those flags my app just hangs forever ...
thanks very much in advance,
harald
No, i did not compile with "-d:release" and i got indeed a stack trace. The strange thing in my case is, that the error occured as soon as i was compiling with "-d:ssl" and the error occured in a line, where i am doing for example:
let search_path = [
"/etc/" & app_name,
getHomeDir() & "/." & app_name & "/" & app_name & ".rc",
getHomeDir() & "/." & app_name & ".rc"
]
This thing worked perfectly fine when not compiling with SSL enabled. Doing a:
let home = getHomeDir()
and using "home" in "search_path" instead, fixed the problem in this case. On the other hand: i tried to write a little test-case with only few lines of code for testing and demonstrating the issue, and of course the test-case worked without any problems with ssl enabled or disabled.
So i think the stack-trace in my case is just misleading and the error must be somewhere else in my code ... but i do not know, how i can track it down ...
In the example above i tried to use
let app_name = expandFilename(getAppFilename())
But then the SIGSEGV error occured in that line ... just setting a fixed value for app_name led to the SIGSEGV error in "search_path" in the line i used getHomeDir() ... I am sorry, if that might be confusing ... :)
Btw.: if you are interested to have a look at my tool, let me know -- it's just 300 lines and will be open-sourced anyway ...
Sounds like a memory corruption error - you try compiling with '-gc:markAndSweep' option to find the actual point of error.
Does your code call any ssl related procedures?
I am on Mac OS X 10.10, i've tried with both nim 0.10.2 and the latest nim from github. BUT: i just noticed, that it seems to be a platform specific problem: i just tried with an Ubuntu Linux 14.04.02 and nim 0.10.2 and i cannot reproduce the issue ... this is really bad for me i think :-(. So the following seems to only apply to Mac OS X:
Yes, the code calls ssl related procedures, but the error occurs before any of those procedures are called. For the error to reproduce, compile it with "nim -d:ssl rmate.nim" ... just run the resulting executable, no need to specify any command-line flags ... the tool should print the usage information, if the SIGSEGV error does not occur. This one works as expected:
https://github.com/aurora/rmate-nim/blob/ssl/src/rmate.nim
and this one produces the SIGSEGV:
https://github.com/aurora/rmate-nim/blob/SIGSEGV/src/rmate.nim
The trace is:
Traceback (most recent call last)
rmate.nim(95) rmate
os.nim(1610) getHomeDir
os.nim(1154) getEnv
os.nim(1143) findEnvVar
gc.nim(465) newObj
gc.nim(440) rawNewObj
alloc.nim(577) rawAlloc
SIGSEGV: Illegal storage access. (Try to compile with -d:useSysAssert -d:useGcAssert for details.)
You can see the diff here: