Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Add documentation for DebugFrame #6300

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions HelpSource/Classes/DebugFrame.schelp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class:: DebugFrame
summary:: A representation of the call frame
categories:: Core/Kernel

Description::
A representation of the call frame.
Can be used to reconstruct a backtrace by using link::#-caller::.

An instance can be acquired by calling link::Classes/Object#-getBackTrace::.
While this is often not useful due to function inlining,
it is useful when called on an link::Classes/Exception::,
see the implementation of link::Classes/Exception#-reportError:: where a call to link::Classes/Object#-dumpBackTrace:: can be replaced by a call to link::Classes/Object#-getBackTrace:: and a call stack constructed manually.

Instancemethods::

method:: functionDef
Returns a link::Classes/FunctionDef:: or a link::Classes/Method:: of the current function or method.

method:: caller
Returns another link::Classes/DebugFrame:: for the function that called this function.

discussion::
Can be used to make a back trace, but watch out for function inlining.
code::
(
var debugFrame = { 1.0.getBackTrace }.();

while{ debugFrame.isNil.not }{
var def = debugFrame.functionDef;
def.postln;
if(def.isKindOf(Method)){
File.readAllString(def.filenameSymbol.asString)[def.charPos..def.charPos + 200].post;
"...".postln;
} {
def.sourceCode.postln
};
"\n".post;
debugFrame = debugFrame.caller
}
)
::

method:: args
Returns an link::Classes/Array:: of the argument's values, if there are no arguments, returns a link::Classes/Nil::.
This does not contain the argument names, which must be accessed through the link::#-functionDef::.


discussion::
code::
{ thisFunction.getBackTrace }.().args == nil;
{ |a, b, c| thisFunction.getBackTrace }.().args == [nil, nil, nil];
{ |a, b, c = 1| thisFunction.getBackTrace }.().args == [nil, nil, 1];
{ |a, b, c = 1| thisFunction.getBackTrace }.(2, 3, c: 4).args == [2, 3, 4];
::

method:: vars
Same as link::#-args:: but for the variables.
discussion::
code::
{ thisFunction.getBackTrace }.().vars == nil
{ var a; thisFunction.getBackTrace }.().vars == [nil]
{ var a, b = 1; thisFunction.getBackTrace }.().vars == [nil, 1]
::

method:: address
Returns a link::Classes/RawPointer::, rarely useful.

method:: context
Returns another link::Classes/DebugFrame:: of the compiling context, rarely useful.