-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debugger test. Record the stack depth before the debugger callbac…
…k is made. Remove the stack context before exiting GC free zone.
- Loading branch information
Showing
8 changed files
with
260 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
class App | ||
{ | ||
public static var hasRunBreakMe = false; | ||
public static var hasRunBreakMe2 = false; | ||
|
||
function breakMe() | ||
{ | ||
hasRunBreakMe = true; | ||
} | ||
|
||
function breakMe2() hasRunBreakMe2 = true; | ||
|
||
|
||
public function new() | ||
{ | ||
breakMe(); | ||
breakMe2(); | ||
Lines.lineStep(); | ||
} | ||
|
||
public static function main() | ||
{ | ||
TestDebugger.setup(); | ||
|
||
new App(); | ||
|
||
if (!TestDebugger.finished) | ||
{ | ||
Sys.println("Not all breakpoints triggered"); | ||
Sys.exit(-1); | ||
} | ||
else if (!TestDebugger.ok) | ||
{ | ||
Sys.println("Some debugger checks failed"); | ||
Sys.exit(-1); | ||
} | ||
else | ||
{ | ||
Sys.println("All good!"); | ||
} | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Lines // line 1 | ||
{ // line 2 | ||
public static var line = -1; // line 3 | ||
// line 4 | ||
public static function lineStep() // line 5 | ||
{ // line 6 | ||
line = 7; // line 7; | ||
callFunction(); // 8 | ||
line = 9; // line 9; | ||
callFunction(); // 10 | ||
// 11 | ||
line = 12; // 12 | ||
} // line 13 | ||
// 14 | ||
public static function callFunction() // 15 | ||
{ // 16 | ||
// 17 | ||
line = 18; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import cpp.vm.Debugger; | ||
import cpp.vm.Thread; | ||
|
||
typedef DebuggerContext = { className : String, | ||
functionName : String, | ||
fileName : String, | ||
lineNumber : Int }; | ||
|
||
typedef DebuggerTest = { setup:Void->Void, | ||
test:DebuggerContext->Bool, | ||
name:String, | ||
resume:Int->Void }; | ||
|
||
class TestDebugger | ||
{ | ||
public static var ok = true; | ||
public static var finished = false; | ||
static var jobs:Array<DebuggerTest>; | ||
static var currentTest:DebuggerContext->Bool; | ||
static var currentName:String; | ||
static var currentResume:Void->Void; | ||
|
||
|
||
public static function setup() | ||
{ | ||
Debugger.enableCurrentThreadDebugging(false); | ||
var mainThread = Thread.current(); | ||
cpp.vm.Thread.create( function() { | ||
startDebugger(); | ||
mainThread.sendMessage("setup"); | ||
}); | ||
|
||
var message = Thread.readMessage(true); | ||
Sys.println("Debugger : " + message); | ||
Debugger.enableCurrentThreadDebugging(true); | ||
|
||
} | ||
|
||
static function handleThreadEvent(threadNumber : Int, event : Int, | ||
stackFrame : Int, | ||
className : String, | ||
functionName : String, | ||
fileName : String, lineNumber : Int) | ||
{ | ||
if (event==Debugger.THREAD_STOPPED) | ||
{ | ||
var ctx = { className:className, functionName:functionName, fileName:fileName, lineNumber:lineNumber }; | ||
|
||
if (!currentTest(ctx)) | ||
{ | ||
ok = false; | ||
Sys.println('Test failed : $currentName - got $ctx'); | ||
Sys.exit(-1); | ||
} | ||
else | ||
{ | ||
nextTest(threadNumber); | ||
} | ||
} | ||
} | ||
|
||
static function cont(id:Int) | ||
{ | ||
Debugger.continueThreads(-1,1); | ||
} | ||
|
||
static function step(id:Int) | ||
{ | ||
Debugger.stepThread(id,Debugger.STEP_INTO,1); | ||
} | ||
|
||
|
||
static function stepOver(id:Int) | ||
{ | ||
Debugger.stepThread(id,Debugger.STEP_OVER,1); | ||
} | ||
|
||
|
||
static function stepOut(id:Int) | ||
{ | ||
Debugger.stepThread(id,Debugger.STEP_OUT,1); | ||
} | ||
|
||
static function nextTest(threadId:Int) | ||
{ | ||
var test = jobs.shift(); | ||
if (test==null) | ||
{ | ||
finished = true; | ||
currentName = null; | ||
currentTest = null; | ||
currentResume = null; | ||
Debugger.setEventNotificationHandler(null); | ||
cont(-1); | ||
} | ||
else | ||
{ | ||
currentName = test.name; | ||
currentTest = test.test; | ||
test.setup(); | ||
Sys.println(' $currentName...'); | ||
test.resume(threadId); | ||
} | ||
} | ||
|
||
|
||
static function startDebugger() | ||
{ | ||
Debugger.setEventNotificationHandler(handleThreadEvent); | ||
jobs = [ | ||
{ setup:function() Debugger.addClassFunctionBreakpoint("App","breakMe"), | ||
test:function(ctx) return !App.hasRunBreakMe, | ||
name:"Set function breakpoint App.breakMe", | ||
resume:cont }, | ||
{ setup:function() Debugger.addClassFunctionBreakpoint("App","breakMe2"), | ||
test:function(ctx) return App.hasRunBreakMe && !App.hasRunBreakMe2, | ||
name:"Set function breakpoint App.breakMe2", | ||
resume:cont}, | ||
{ setup:function() Debugger.addFileLineBreakpoint("Lines.hx",7), | ||
test:function(ctx) return Lines.line==-1, | ||
name:"Set line breakpoint Lines.hx:7", | ||
resume:cont}, | ||
{ setup:function() { }, | ||
test:function(ctx) return Lines.line==7, | ||
name:"Step from Lines.hx:7", | ||
resume:step}, | ||
{ setup:function() { }, | ||
test:function(ctx) return Lines.line==18, | ||
name:"Step over callFunction", | ||
resume:stepOver}, | ||
{ setup:function() { }, | ||
test:function(ctx) return Lines.line==9, | ||
name:"Step over line 9", | ||
resume:step}, | ||
{ setup:function() { }, | ||
test:function(ctx) return Lines.line==9, | ||
name:"step into callFunction", | ||
resume:step}, | ||
{ setup:function() { }, | ||
test:function(ctx) return Lines.line==18, | ||
name:"step out of callFunction", | ||
resume:stepOut }, | ||
{ setup:function() { }, | ||
test:function(ctx) return Lines.line==12, | ||
name:"step out of Lines", | ||
resume:stepOut }, | ||
|
||
|
||
]; | ||
nextTest(-1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-main App | ||
-cpp bin | ||
-D HXCPP_DEBUGGER | ||
-debug |
4a2fbdb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my my my... that sounds like sweetness included 💃
4a2fbdb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
4a2fbdb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes jcward/vscode-hxcpp-debug#49. Thanks!