-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Hunting crashes: The ultimate guide
Ok, so your nice Nim program crashes under various hard-to-reproduce conditions. What can you do about that?
--gc:boehm
--gc:refc
--gc:markAndSweep
Note that if your program does not crash with a different GC, it doesn't imply you found a GC bug! It's just a weak indicator.
- Linux
- MacOS X
- Windows
- i386 (32bit)
- amd64 (64bit)
- arm
-d:release
vs debug mode is the obvious choice, but the Nim GC, allocator and standard library have many more checks you can should enable:
-d:useSysAssert
- enables assertions in the system.nim, especially in Nim's allocator.
-d:useGcAssert
- enables assertions in Nim's GC.
-d:nimBurnFree
- overwrite deallocated memory with 0xff bytes so that "access after free" triggers a segfault.
Even more debugging options can be enabled by editing lib/system/mmdisp.nim
. Most of these have no --define
equivalent, unfortunately.
One problem with corruptions is their non-deterministic nature, in particular heap and stack addresses change from run to run. Define -d:corruption
to enable "cell IDs", so that every "cell" (that is every ref
/string
/seq
) gets a unique ID. It's often interesting to see if the corrupted cell has the same ID from run to run or if it differs. If it differs the bug is non-deterministic. Within the GC writeCell
can be used to output offending cells.
Intro
Getting Started
- Install
- Docs
- Curated Packages
- Editor Support
- Unofficial FAQ
- Nim for C programmers
- Nim for Python programmers
- Nim for TypeScript programmers
- Nim for D programmers
- Nim for Java programmers
- Nim for Haskell programmers
Developing
- Build
- Contribute
- Creating a release
- Compiler module reference
- Consts defined by the compiler
- Debugging the compiler
- GitHub Actions/Travis CI/Circle CI/Appveyor
- GitLab CI setup
- Standard library and the JavaScript backend
Misc