Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Created May 23, 2013 02:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmuellr/5632450 to your computer and use it in GitHub Desktop.
Save pmuellr/5632450 to your computer and use it in GitHub Desktop.
trace JavaScript using v8's --expose-debug-as= option
#!/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