Merge pull request #447 from samisalreadytaken/dev

Update sqdbg
This commit is contained in:
Blixibon 2025-07-28 15:41:18 -05:00 committed by GitHub
commit b652c6f61f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@
// Squirrel Debugger // Squirrel Debugger
// //
#define SQDBG_SV_VER 6 #define SQDBG_SV_VER 7
#include "sqdbg.h" #include "sqdbg.h"
@ -845,14 +845,17 @@ public:
} }
else else
{ {
for ( hnode_t i = 0; i < m_Nodes.Size(); i++ ) for ( hnode_t i = 0; i < m_NodeTags.Size(); i++ )
{ {
node_t &node = m_Nodes[i]; nodetag_t *node = &m_NodeTags[i];
node.calls = 0; __ObjRelease( node->funcsrc );
node.samples = 0.0; __ObjRelease( node->funcname );
node.sampleStart = 0.0;
} }
m_Nodes.Clear();
m_NodeTags.Clear();
m_CallStack.Clear();
for ( int i = 0; i < vm->_callsstacksize; i++ ) for ( int i = 0; i < vm->_callsstacksize; i++ )
{ {
const SQVM::CallInfo &ci = vm->_callsstack[i]; const SQVM::CallInfo &ci = vm->_callsstack[i];
@ -928,9 +931,9 @@ public:
{ {
m_State = kProfPaused; m_State = kProfPaused;
if ( m_CallStack.Size() ) for ( unsigned int i = 0; i < m_CallStack.Size(); i++ )
{ {
hnode_t caller = m_CallStack.Top(); hnode_t caller = m_CallStack[i];
node_t *node = &m_Nodes[caller]; node_t *node = &m_Nodes[caller];
node->samples += sample - node->sampleStart; node->samples += sample - node->sampleStart;
#ifdef _DEBUG #ifdef _DEBUG
@ -938,9 +941,9 @@ public:
#endif #endif
} }
if ( m_GroupStack.Size() ) for ( unsigned int i = 0; i < m_GroupStack.Size(); i++ )
{ {
hgroup_t idx = m_GroupStack.Top(); hgroup_t idx = m_GroupStack[i];
group_t *group = &m_Groups[idx]; group_t *group = &m_Groups[idx];
sample_t dt = sample - group->sampleStart; sample_t dt = sample - group->sampleStart;
group->samples += dt; group->samples += dt;
@ -967,16 +970,16 @@ public:
sample_t sample = Sample(); sample_t sample = Sample();
if ( m_CallStack.Size() ) for ( unsigned int i = 0; i < m_CallStack.Size(); i++ )
{ {
hnode_t caller = m_CallStack.Top(); hnode_t caller = m_CallStack[i];
node_t *node = &m_Nodes[caller]; node_t *node = &m_Nodes[caller];
node->sampleStart = sample; node->sampleStart = sample;
} }
if ( m_GroupStack.Size() ) for ( unsigned int i = 0; i < m_GroupStack.Size(); i++ )
{ {
hgroup_t idx = m_GroupStack.Top(); hgroup_t idx = m_GroupStack[i];
group_t *group = &m_Groups[idx]; group_t *group = &m_Groups[idx];
group->sampleStart = sample; group->sampleStart = sample;
} }
@ -985,7 +988,7 @@ public:
void CallBegin( SQFunctionProto *func ) void CallBegin( SQFunctionProto *func )
{ {
Assert( IsActive() ); Assert( IsActive() || m_State == kProfPaused );
hnode_t caller = m_CallStack.Size() ? m_CallStack.Top() : INVALID_HANDLE; hnode_t caller = m_CallStack.Size() ? m_CallStack.Top() : INVALID_HANDLE;
@ -1287,6 +1290,10 @@ public:
return (int)( buf - bufstart ); return (int)( buf - bufstart );
} }
sample_t sample = ( m_CallStack.Size() && m_State != kProfPaused ) ?
Sample() :
0.0;
vector< node_t > nodes( m_Nodes ); vector< node_t > nodes( m_Nodes );
switch ( type ) switch ( type )
@ -1348,17 +1355,13 @@ public:
{ {
totalSamples += node.samples; totalSamples += node.samples;
} }
// Within the call frame, accumulate children for a rough estimate // Within the call frame, take current time
// This will miss any time spent in the body
// of the function excluding subcalls
else else
{ {
for ( hnode_t j = i; j < nodecount; j++ ) totalSamples += node.samples;
{
const node_t &nj = nodes[j]; if ( m_State != kProfPaused )
if ( nj.caller == node.id ) totalSamples += sample - node.sampleStart;
totalSamples += nj.samples;
}
} }
} }
} }
@ -1603,7 +1606,7 @@ private:
{ {
if ( us > 0.0 ) if ( us > 0.0 )
{ {
int len = scsprintf( buf, size, _SC("%6.2f ns"), us * 1.e3 ); int len = scsprintf( buf, size, _SC("%6.2f ns"), min( us * 1.e3, 999.99 ) );
buf += len; buf += len;
size -= len; size -= len;
} }
@ -2095,6 +2098,7 @@ struct objref_t
DELEGABLE_META, DELEGABLE_META,
CUSTOMMEMBER, CUSTOMMEMBER,
STACK, STACK,
OUTER,
#ifdef SQDBG_SUPPORTS_FUNCPROTO_LIST #ifdef SQDBG_SUPPORTS_FUNCPROTO_LIST
FUNCPROTO, FUNCPROTO,
#endif #endif
@ -7922,6 +7926,18 @@ bool SQDebugServer::Get( const objref_t &obj, SQObjectPtr &value )
} }
} }
return false;
}
case objref_t::OUTER:
{
if ( sq_type(obj.src) == OT_CLOSURE &&
_integer(obj.key) >= 0 &&
_integer(obj.key) < _fp(_closure(obj.src)->_function)->_noutervalues )
{
value = *_outervalptr( _closure(obj.src)->_outervalues[ _integer(obj.key) ] );
return true;
}
return false; return false;
} }
#ifdef SQDBG_SUPPORTS_FUNCPROTO_LIST #ifdef SQDBG_SUPPORTS_FUNCPROTO_LIST
@ -8116,6 +8132,18 @@ bool SQDebugServer::Set( const objref_t &obj, const SQObjectPtr &value )
} }
} }
return false;
}
case objref_t::OUTER:
{
if ( sq_type(obj.src) == OT_CLOSURE &&
_integer(obj.key) >= 0 &&
_integer(obj.key) < _fp(_closure(obj.src)->_function)->_noutervalues )
{
*_outervalptr( _closure(obj.src)->_outervalues[ _integer(obj.key) ] ) = value;
return true;
}
return false; return false;
} }
#ifdef SQDBG_SUPPORTS_FUNCPROTO_LIST #ifdef SQDBG_SUPPORTS_FUNCPROTO_LIST
@ -12108,7 +12136,6 @@ bool SQDebugServer::ArithOp( char op, const SQObjectPtr &lhs, const SQObjectPtr
void SQDebugServer::ConvertPtr( objref_t &obj ) void SQDebugServer::ConvertPtr( objref_t &obj )
{ {
// doesn't convert outer vars
if ( obj.type & ~objref_t::PTR ) if ( obj.type & ~objref_t::PTR )
obj.type = (objref_t::EOBJREF)( obj.type & ~objref_t::PTR ); obj.type = (objref_t::EOBJREF)( obj.type & ~objref_t::PTR );
} }
@ -12512,8 +12539,10 @@ bool SQDebugServer::GetObj_Frame( HSQUIRRELVM vm, const SQVM::CallInfo *ci, cons
const SQOuterVar &var = func->_outervalues[i]; const SQOuterVar &var = func->_outervalues[i];
if ( expression.IsEqualTo( _string(var._name) ) ) if ( expression.IsEqualTo( _string(var._name) ) )
{ {
out.type = objref_t::PTR; out.type = (objref_t::EOBJREF)( objref_t::PTR | objref_t::OUTER );
out.ptr = _outervalptr( pClosure->_outervalues[i] ); out.ptr = _outervalptr( pClosure->_outervalues[i] );
out.src = pClosure;
out.key = (SQInteger)i;
value = *out.ptr; value = *out.ptr;
return true; return true;
} }
@ -20029,7 +20058,6 @@ SQInteger SQDebugServer::SQProfReset( HSQUIRRELVM vm )
tag = _string(arg1); tag = _string(arg1);
break; break;
default: default:
Assert(!"UNREACHABLE");
break; break;
} }
@ -20540,7 +20568,7 @@ void sqdbg_get_debugger_ref( HSQUIRRELVM vm, SQObjectPtr &ref )
#ifdef DEBUG_HOOK_CACHED_SQDBG #ifdef DEBUG_HOOK_CACHED_SQDBG
// Cache the debugger in an unused variable in the VM // Cache the debugger in an unused variable in the VM
// for at least 20% faster access on debug hook // for faster access on debug hook
// compared to registry table access // compared to registry table access
void sqdbg_set_debugger_cached_debughook( HSQUIRRELVM vm, bool state ) void sqdbg_set_debugger_cached_debughook( HSQUIRRELVM vm, bool state )
{ {