Debugging and Profiling
40.1 Debugging
echo/debugEcho (allowed in func), repr(x), dump x (std/sugar), fmt"{x=}".
Native debugging:
nim-gdb wrapper script. VS Code + CodeLLDB with --debugger:native.
Sanitizers: AddressSanitizer, UndefinedBehaviorSanitizer, ThreadSanitizer via --passC/--passL + -d:useMalloc.
Valgrind with -d:useMalloc.
Compile-time debugging: static: echo, macros.treeRepr, expandMacros, --expandMacro:name, --expandArc:proc.
nim c --debugger:native -d:nimDebugDlOpen app.nim
gdb ./app # use Nim's gdb pretty-printers: tools/debug/nim-gdb.py
lldb ./app40.2 Profiling
Built-in sampling profiler: --profiler:on --stackTrace:on + import nimprof.
Memory profiler: --profiler:off -d:memProfiler.
External: perf (Linux), Valgrind callgrind / KCachegrind, Instruments (macOS), VTune, Hotspot, Tracy (via the nimtracy package).
Benchmarking: benchy, criterion (nim-criterion), std/monotimes for manual timing.