Skip to content

Commit

Permalink
Fix top-level function missing in call stack dump
Browse files Browse the repository at this point in the history
Printing call stack may be performed not only by call of the
native function, but possibly also by such tools as debugger.
In this case the top-level function in call stack is an actual
script function being executed and should not be skipped.
So start stack traversal from level 0 and check if the top
is a script or a native function and include the script one
into output.
  • Loading branch information
VasiliyRyabtsev committed Sep 22, 2021
1 parent 8182bae commit a944cc8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sqstdlib/sqstdaux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ static void collect_stack_sting(HSQUIRRELVM v, PrintFunc pf)
SQInteger i;
SQFloat f;
const SQChar *s;
SQInteger level=1; //1 is to skip this function that is level 0
SQInteger level=0;
const SQChar *name=0;
SQInteger seq=0;
pf(v,_SC("\nCALLSTACK\n"));
while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
{
if (si.line < 0 && level == 0) { // skip top native function
++level;
continue;
}

const SQChar *fn=_SC("unknown");
const SQChar *src=_SC("unknown");
if(si.funcname)fn=si.funcname;
Expand Down

0 comments on commit a944cc8

Please sign in to comment.