I have a native extension compiled as a dynamic library and loaded by the main program.
In the native extension there is below code that causes SEGV while Nim is running GC for data allocated. The same code would run fine if put in the main program.
discard VM.eval("(ns N)")
Traceback (most recent call last)
/Users/gcao/proj/gene/src/genex/http.nim(176) init
/Users/gcao/proj/gene/src/gene/interpreter_base.nim(167) eval
/Users/gcao/.choosenim/toolchains/nim-1.4.8/lib/system.nim(937) eval
/Users/gcao/.choosenim/toolchains/nim-1.4.8/lib/system/arc.nim(169) nimDestroyAndDispose
/Users/gcao/.choosenim/toolchains/nim-1.4.8/lib/system/orc.nim(413) nimDecRefIsLastCyclicDyn
/Users/gcao/.choosenim/toolchains/nim-1.4.8/lib/system/orc.nim(394) rememberCycle
/Users/gcao/.choosenim/toolchains/nim-1.4.8/lib/system/orc.nim(128) unregisterCycle
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
I'm trying to debug this issue. Based on the stack trace, there might be cyclic references. My data type does allow cyclic references. However in the code above, it probably will not create a real cyclic reference.
The first thing I want to figure out is which data/variable is being recycled. I've enabled debugger but don't get much information out of the debugger other than a stack with a lot of "optimized out".
I tried to pass a C flag "-O0" but it is ignored because the command has "-g3 -Og".
How should I approach fixing this issue?
Any help is much appreciated!
Based on the stack trace, there might be cyclic references.
Run it through valgrind and ignore the stack traces and debuggers, they are highly ineffective tools when you cannot rule out some other unrelated memory corruptions elsewhere. Compile with -d:useMalloc.
Thank you. I just tried Nim 1.6.0 and got same error.
Traceback (most recent call last)
/Users/gcao/proj/gene/src/genex/http.nim(268) init
/Users/gcao/proj/gene/src/gene/interpreter_base.nim(172) eval
/Users/gcao/proj/gene/src/gene/interpreter_base.nim(169) eval
/Users/gcao/.choosenim/toolchains/nim-1.6.0/lib/system.nim(1002) eval
/Users/gcao/.choosenim/toolchains/nim-1.6.0/lib/system/orc.nim(483) nimDecRefIsLastCyclicDyn
/Users/gcao/.choosenim/toolchains/nim-1.6.0/lib/system/orc.nim(466) rememberCycle
/Users/gcao/.choosenim/toolchains/nim-1.6.0/lib/system/orc.nim(146) unregisterCycle
SIGSEGV: Illegal storage access. (Attempt to read from nil?)