mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Split auciliary code into reusable parts for debugging.
This commit is contained in:
parent
ae2b1dc778
commit
b93deee276
@ -6,6 +6,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SQUIRREL_API void sqstd_dumptypename(HSQUIRRELVM v, SQInteger idx, const SQChar *name, SQPRINTFUNCTION pf);
|
||||
SQUIRREL_API void sqstd_dumpstack(HSQUIRRELVM v, SQInteger bottom, SQInteger top, SQPRINTFUNCTION pf);
|
||||
|
||||
SQUIRREL_API void sqstd_seterrorhandlers(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sqstd_printcallstack(HSQUIRRELVM v);
|
||||
|
||||
|
@ -5,53 +5,29 @@
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
void sqstd_dumptypename(HSQUIRRELVM v, SQInteger idx, const SQChar *name, SQPRINTFUNCTION pf)
|
||||
{
|
||||
SQPRINTFUNCTION pf = sq_geterrorfunc(v);
|
||||
if(pf) {
|
||||
SQStackInfos si;
|
||||
SQInteger i;
|
||||
SQFloat f;
|
||||
const SQChar *s;
|
||||
SQInteger level=1; //1 is to skip this function that is level 0
|
||||
const SQChar *name=0;
|
||||
SQInteger seq=0;
|
||||
pf(v,_SC("\nCALLSTACK\n"));
|
||||
while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
|
||||
{
|
||||
const SQChar *fn=_SC("unknown");
|
||||
const SQChar *src=_SC("unknown");
|
||||
if(si.funcname)fn=si.funcname;
|
||||
if(si.source)src=si.source;
|
||||
pf(v,_SC("*FUNCTION [%s()] %s line [%d]\n"),fn,src,si.line);
|
||||
level++;
|
||||
}
|
||||
level=0;
|
||||
pf(v,_SC("\nLOCALS\n"));
|
||||
|
||||
for(level=0;level<10;level++){
|
||||
seq=0;
|
||||
while((name = sq_getlocal(v,level,seq)))
|
||||
{
|
||||
seq++;
|
||||
switch(sq_gettype(v,-1))
|
||||
switch(sq_gettype(v,idx))
|
||||
{
|
||||
case OT_NULL:
|
||||
pf(v,_SC("[%s] NULL\n"),name);
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
sq_getinteger(v,-1,&i);
|
||||
pf(v,_SC("[%s] %d\n"),name,i);
|
||||
break;
|
||||
case OT_FLOAT:
|
||||
sq_getfloat(v,-1,&f);
|
||||
case OT_INTEGER: {
|
||||
SQInteger i;
|
||||
sq_getinteger(v,idx,&i);
|
||||
pf(v,_SC("[%s] " _PRINT_INT_FMT "\n"),name,i);
|
||||
} break;
|
||||
case OT_FLOAT: {
|
||||
SQFloat f;
|
||||
sq_getfloat(v,idx,&f);
|
||||
pf(v,_SC("[%s] %.14g\n"),name,f);
|
||||
break;
|
||||
} break;
|
||||
case OT_USERPOINTER:
|
||||
pf(v,_SC("[%s] USERPOINTER\n"),name);
|
||||
break;
|
||||
case OT_STRING:
|
||||
sq_getstring(v,-1,&s);
|
||||
const SQChar *s;
|
||||
sq_getstring(v,idx,&s);
|
||||
pf(v,_SC("[%s] \"%s\"\n"),name,s);
|
||||
break;
|
||||
case OT_TABLE:
|
||||
@ -86,12 +62,50 @@ void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
break;
|
||||
case OT_BOOL:{
|
||||
SQBool bval;
|
||||
sq_getbool(v,-1,&bval);
|
||||
sq_getbool(v,idx,&bval);
|
||||
pf(v,_SC("[%s] %s\n"),name,bval == SQTrue ? _SC("true"):_SC("false"));
|
||||
}
|
||||
break;
|
||||
default: assert(0); break;
|
||||
}
|
||||
}
|
||||
void sqstd_dumpstack(HSQUIRRELVM v, SQInteger bottom, SQInteger top, SQPRINTFUNCTION pf)
|
||||
{
|
||||
SQChar b[16];
|
||||
while (bottom <= top)
|
||||
{
|
||||
scsprintf(b, sizeof(b), _PRINT_INT_FMT, bottom);
|
||||
sqstd_dumptypename(v, bottom++, b, pf);
|
||||
}
|
||||
}
|
||||
|
||||
void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
{
|
||||
SQPRINTFUNCTION pf = sq_geterrorfunc(v);
|
||||
if(pf) {
|
||||
SQStackInfos si;
|
||||
SQInteger level=1; //1 is to skip this function that is level 0
|
||||
const SQChar *name=0;
|
||||
SQInteger seq=0;
|
||||
pf(v,_SC("\nCALLSTACK\n"));
|
||||
while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
|
||||
{
|
||||
const SQChar *fn=_SC("unknown");
|
||||
const SQChar *src=_SC("unknown");
|
||||
if(si.funcname)fn=si.funcname;
|
||||
if(si.source)src=si.source;
|
||||
pf(v,_SC("*FUNCTION [%s()] %s line [%d]\n"),fn,src,si.line);
|
||||
level++;
|
||||
}
|
||||
level=0;
|
||||
pf(v,_SC("\nLOCALS\n"));
|
||||
|
||||
for(level=0;level<10;level++){
|
||||
seq=0;
|
||||
while((name = sq_getlocal(v,level,seq)))
|
||||
{
|
||||
seq++;
|
||||
sqstd_dumptypename(v,-1,name, pf);
|
||||
sq_pop(v,1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user