Created
May 23, 2013 02:38
-
-
Save pmuellr/5632450 to your computer and use it in GitHub Desktop.
trace JavaScript using v8's --expose-debug-as= option
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
#!/usr/bin/env node | |
// run with `node --expose-debug-as=Debug fileName.js` | |
// traces all the code run after dummyFunc() invoked | |
// see v8/src/debug-debugger.js for some of the impl of the API | |
var debug = Debug.Debug | |
//------------------------------------------------------------------------------ | |
function dummyFunc() {} | |
//------------------------------------------------------------------------------ | |
function listener(event, execState, eventData, data) { | |
if (event != debug.DebugEvent.Break) return | |
var script = eventData.func().script().name() | |
var line = eventData.sourceLine() | |
var col = eventData.sourceColumn() | |
var location = script + ":" + line + ":" + col | |
var funcName = eventData.func().name() | |
if (funcName != "") { | |
location += " " + funcName + "()" | |
} | |
console.log(location) | |
execState.prepareStep(debug.StepAction.StepIn) | |
} | |
//------------------------------------------------------------------------------ | |
function doSomething() { | |
for (var i=0; i<10; i++) { | |
console.log(i) | |
} | |
} | |
//------------------------------------------------------------------------------ | |
debug.setListener(listener) | |
debug.setBreakPoint(dummyFunc, 0, 0) | |
dummyFunc() | |
doSomething() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment