debug
Tools for finding a bug: assertions, a hand-kept call stack, tracing and timing.
import debug
The debug package holds a few simple tools for when the program is not doing the right thing. Assert checks a condition that should always hold. Enter and Exit build a call stack by hand, so you know where in the program you are. The timers show which part is slow.
Functions
Assert
func Assert(cond: bool, msg: str)import debug
func child():
debug.Enter("child")
println debug.Depth()
println debug.Stack()
debug.Exit()
end
func main:
debug.Enter("root")
child()
debug.Exit()
println debug.Depth()
debug.Assert(1 + 1 == 2, "the arithmetic holds")
debug.AssertNotNil(debug.MemStats() as void*, "the memory statistics")
debug.EnableTrace(true)
println debug.TraceEnabled()
debug.Trace("a trace message")
debug.StartTimer("loop")
mut total := 0
repeat 1000 in i:
total += i
end
println total, debug.StopTimer("loop") >= 0.0
if total < 0:
debug.Break()
end
endAssertNotNil
func AssertNotNil(p: void*, msg: str)The example for this item is shown with the ones above: debug-Enter.salam
Enter
func Enter(frame: str)The example for this item is shown with the ones above: debug-Enter.salam
Exit
func Exit()The example for this item is shown with the ones above: debug-Enter.salam
Stack
func Stack(): strroot > child.The example for this item is shown with the ones above: debug-Enter.salam
Depth
func Depth(): intThe example for this item is shown with the ones above: debug-Enter.salam
EnableTrace
func EnableTrace(enabled: bool)The example for this item is shown with the ones above: debug-Enter.salam
TraceEnabled
func TraceEnabled(): boolThe example for this item is shown with the ones above: debug-Enter.salam
Trace
func Trace(msg: str)[TRACE] label.The example for this item is shown with the ones above: debug-Enter.salam
StartTimer
func StartTimer(name: str)The example for this item is shown with the ones above: debug-Enter.salam
StopTimer
func StopTimer(name: str): f64The example for this item is shown with the ones above: debug-Enter.salam
Break
func Break()The example for this item is shown with the ones above: debug-Enter.salam
MemStats
func MemStats(): strThe example for this item is shown with the ones above: debug-Enter.salam