Debugging, Profiling and Hot Reload
42.1 Debugging
println, eprintln, dump(expr), $dbg (built-in REPL-like debugger at a breakpoint, 0.4.6+), @FILE:@LINE, print_backtrace().
Native debuggers: build with -g (maps to V source lines) or -cg (C lines), then gdb ./app, lldb ./app, or VS Code with CodeLLDB.
Inspect generated C: -keepc -showcc or -o out.c.
Sanitizers: v -cc clang -cflags '-fsanitize=address,undefined' -gc none run app.v. Valgrind with -gc none.
v doctor for environment info when filing compiler bugs.
42.2 Profiling
v -profile profile.txt run app.v # function call counts and times
sort -n -k3 profile.txt | tail
v -prod -cflags -pg app.v # gprof
perf record ./app && perf report # Linux perf (build with -g)42.3 Hot Code Reloading
Great for games and graphics (gg examples support live reloading).
import time
@[live]
fn draw() {
println('Edit me and save, change applied without restart!')
}
fn main() {
for {
draw()
time.sleep(1 * time.second)
}
}v -live run app.v