albertodemichelis / squirrel

Official repository for the programming language Squirrel
http://www.squirrel-lang.org
MIT License
894 stars 148 forks source link

Any reason to SQVM::CallDebugHook do not raise error ? #238

Open mingodad opened 3 years ago

mingodad commented 3 years ago

I'm trying to debug an script that seems to enter an infinite loop and one way that I'm experimenting to find out is to set a debughook and raise an exception after ncalls have been done to see the stack trace to help figure out what's the problem, but throwing an exception inside the debughook does nothing, looking through the code I found that it's because the debughook is called with raiseerror set to false.

There is any reason for that ?

I changed the raiseerror to true and now I can get the stack trace, although the program do not stop but it's ok while debuging.

void SQVM::CallDebugHook(SQInteger type,SQInteger forcedline)
{
    _debughook = false;
    SQFunctionProto *func=_closure(ci->_closure)->_function;
    if(_debughook_native) {
        const SQChar *src = sq_type(func->_sourcename) == OT_STRING?_stringval(func->_sourcename):NULL;
        const SQChar *fname = sq_type(func->_name) == OT_STRING?_stringval(func->_name):NULL;
        SQInteger line = forcedline?forcedline:func->GetLine(ci->_ip);
        _debughook_native(this,type,src,line,fname);
    }
    else {
        SQObjectPtr creg;
        SQInteger nparams=5;
        Push(_roottable); Push(type); Push(func->_sourcename); Push(forcedline?forcedline:func->GetLine(ci->_ip)); Push(func->_name);
        Call(_debughook_closure,nparams,_top-nparams,creg,SQTrue);
        Pop(nparams);
    }
    _debughook = true;
}
local call_count = 0;
local function myDebugHook(event_type,sourcefile,line,funcname)
{
    //print(call_count);
    if((++call_count % 5000000) == 0) throw("too many calls " + call_count);
}

setdebughook(myDebugHook);
enabledebuginfo(true); //to get line by line
albertodemichelis commented 3 years ago

That's the expected behavior. If the debug hook throws the script doesn't stop.

mingodad commented 3 years ago

In my point of view It's a strange behavior when debugging. Anyway thank you for reply !