Nasal library/debug: Difference between revisions

Jump to navigation Jump to search
Add documentation for class Breakpoint
No edit summary
(Add documentation for class Breakpoint)
Line 342: Line 342:
}
}
A(130);
A(130);
}}
== Class Breakpoint (available since 2019.1) ==
The breakpoint class is for selective backtracing. Putting a debug.backtrace() into some nasal code could flood the console / log especially if you do not (yet) know where that code is used.
Using a breakpoint gives you better control when to do backtraces and how often via the property browser at runtime.
You have to give "tokens" to you breakpoint which are consumed on each hit of the breakpoint, one per trace. No more tokens, no more traces done until you give more tokens.
For example, if you wish to trace some API call, you can insert a breakpoint into the API code at the point of interest and monitor the number of hits in the property browser.
After FG has started, you can open a property browser and go to /_debug/nas/bp-myLabel
Set tokens to a positive integer to start tracing. Each hit will consume one token and perform one backtrace.
To start tracing again, just set tokens again to the number of traces you wish to perform.
=== new() ===
{{Nasal doc
|syntax = Breakpoint.new(label, [dump_locals = 1]);
|text = create a breakpoint object
|param1 = label
|param1text = a string to name the breakpoint, used in property path and in output
|param2 = dump_locals
|param2text = 0 or 1, passed to backtrace to control printing of namespaces (variables)
|example1 = var myBP = debug.Breakpoint.new("myLabel", 0);
}}
=== enable() ===
{{Nasal doc
|syntax = myBP.enable([tokens = 1]);
|text = enable tracing
|param1 = tokens
|param1text = number of traces allowed; each hit will consume one token, tokens < 1 means no more traces. Tokens can be also set via the property browser at runtime.
}}
=== disable() ===
{{Nasal doc
|syntax = myBP.disable();
|text = Disable traceing by setting tokens to zero.
}}
=== getHits() ===
{{Nasal doc
|syntax = myBP.getHits();
|text = Get total number of hits. This may differ from the number of backtraces done.
}}
=== hit() ===
{{Nasal doc
|syntax = myBP.hit();
|text = Put this at the place in your code where you want to do the trace.
}}
}}


{{Nasal namespaces}}
{{Nasal namespaces}}
295

edits

Navigation menu