Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion include/daScript/builtin/debugapi_gen.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,10 @@ protected:
__fn_onBeforeVariables = 9,
__fn_onVariable = 10,
__fn_onAfterCall = 11,
__fn_onCorruptStack = 12,
};
protected:
int _das_class_method_offset[12];
int _das_class_method_offset[13];
public:
DapiStackWalker_Adapter ( const StructInfo * info ) {
_das_class_method_offset[__fn_canWalkArguments] = info->fields[2]->offset;
Expand All @@ -1240,6 +1241,7 @@ public:
_das_class_method_offset[__fn_onBeforeVariables] = info->fields[11]->offset;
_das_class_method_offset[__fn_onVariable] = info->fields[12]->offset;
_das_class_method_offset[__fn_onAfterCall] = info->fields[13]->offset;
_das_class_method_offset[__fn_onCorruptStack] = info->fields[14]->offset;
}
__forceinline Func get_canWalkArguments ( void * self ) const {
return getDasClassMethod(self,_das_class_method_offset[__fn_canWalkArguments]);
Expand Down Expand Up @@ -1349,5 +1351,14 @@ public:
(__context__,nullptr,__funcCall__,
self,pp);
}
__forceinline Func get_onCorruptStack ( void * self ) const {
return getDasClassMethod(self,_das_class_method_offset[__fn_onCorruptStack]);
}
__forceinline void invoke_onCorruptStack ( Context * __context__, Func __funcCall__, void * self, Prologue const & pp ) const {
das_invoke_function<void>::invoke
<void *,Prologue const &>
(__context__,nullptr,__funcCall__,
self,pp);
}
};

1 change: 1 addition & 0 deletions include/daScript/simulate/simulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ namespace das
virtual void onBeforeVariables ( ) { }
virtual void onVariable ( FuncInfo *, LocalVariableInfo *, void *, bool ) { }
virtual bool onAfterCall ( Prologue * ) { return true; }
virtual void onCorruptStack ( Prologue * ) { }
};
typedef smart_ptr<StackWalker> StackWalkerPtr;

Expand Down
2 changes: 1 addition & 1 deletion modules/dasLLVM
1 change: 1 addition & 0 deletions src/builtin/debugger.das
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class DapiStackWalker {
def abstract onBeforeVariables : void
def abstract onVariable(inf : FuncInfo; vinfo : LocalVariableInfo; arg : void?; inScope : bool) : void
def abstract onAfterCall(pp : Prologue) : bool
def abstract onCorruptStack(pp : Prologue) : void
}

def make_stack_walker(classPtr) : smart_ptr<StackWalker> {
Expand Down
7 changes: 7 additions & 0 deletions src/builtin/debugger.das.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,13 @@ static unsigned char debugger_das[] = {
0x3a,0x20,0x50,0x72,0x6f,0x6c,0x6f,0x67,
0x75,0x65,0x29,0x20,0x3a,0x20,0x62,0x6f,
0x6f,0x6c,0x0a,
0x20,0x20,0x20,0x20,0x64,0x65,0x66,0x20,
0x61,0x62,0x73,0x74,0x72,0x61,0x63,0x74,
0x20,0x6f,0x6e,0x43,0x6f,0x72,0x72,0x75,
0x70,0x74,0x53,0x74,0x61,0x63,0x6b,0x28,
0x70,0x70,0x20,0x3a,0x20,0x50,0x72,0x6f,
0x6c,0x6f,0x67,0x75,0x65,0x29,0x20,0x3a,
0x20,0x76,0x6f,0x69,0x64,0x0a,
0x7d,0x0a,
0x0a,
0x64,0x65,0x66,0x20,0x6d,0x61,0x6b,0x65,
Expand Down
31 changes: 27 additions & 4 deletions src/builtin/module_builtin_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ namespace debugapi {
return true;
}
}
virtual void onCorruptStack ( Prologue * pp ) override {
if ( auto fnOnCorruptStack = get_onCorruptStack(classPtr) ) {
invoke_onCorruptStack(context,fnOnCorruptStack,classPtr,*pp);
}
}
protected:
void * classPtr;
Context * context;
Expand Down Expand Up @@ -825,7 +830,7 @@ namespace debugapi {
#if DAS_ENABLE_STACK_WALK
char * sp = context.stack.ap();
int32_t depth = 0;
while ( sp < context.stack.top() ) {
while ( sp < context.stack.top() ) {
Prologue * pp = (Prologue *) sp;
Block * block = nullptr;
FuncInfo * info = nullptr;
Expand All @@ -840,7 +845,16 @@ namespace debugapi {
info = pp->info;
}
}
sp += info ? info->stackSize : pp->stackSize;
auto incr = info ? info->stackSize : pp->stackSize;
if ( incr >= context.stack.size() || incr<sizeof(Prologue) ) {
// corrupted stack
break;
}
sp += incr;
if ( sp > context.stack.top() ) {
// corrupted stack
break;
}
depth ++;
}
return depth;
Expand All @@ -854,7 +868,7 @@ namespace debugapi {
#if DAS_ENABLE_STACK_WALK
char * sp = context.stack.ap();
const LineInfo * lineAt = &at;
while ( sp < context.stack.top() ) {
while ( sp < context.stack.top() ) {
Prologue * pp = (Prologue *) sp;
Block * block = nullptr;
FuncInfo * info = nullptr;
Expand All @@ -869,6 +883,11 @@ namespace debugapi {
info = pp->info;
}
}
auto incr = info ? info->stackSize : pp->stackSize;
if ( incr >= context.stack.size() || incr<sizeof(Prologue) ) {
walker->onCorruptStack(pp);
break;
}
walker->onBeforeCall(pp,SP);
if ( !info ) {
walker->onCallAOT(pp,pp->fileName);
Expand Down Expand Up @@ -909,7 +928,11 @@ namespace debugapi {
}
}
lineAt = info ? pp->line : nullptr;
sp += info ? info->stackSize : pp->stackSize;
sp += incr;
if ( sp > context.stack.top() ) {
walker->onCorruptStack(pp);
break;
}
if ( !walker->onAfterCall(pp) ) break;
}
#else
Expand Down
5 changes: 4 additions & 1 deletion src/simulate/simulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,10 @@ namespace das
}
virtual bool onAfterCall ( Prologue * ) override {
return !stackTopOnly;
}
}
virtual void onCorruptStack (Prologue * ) override {
ssw << "!!! stack corrupted, aborting stack walk !!!\n";
}
public:
bool showArguments = true;
bool showLocalVariables = true;
Expand Down