|
@ -655,7 +655,7 @@ function Interface() { |
|
|
var proto = Interface.prototype, |
|
|
var proto = Interface.prototype, |
|
|
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak', |
|
|
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak', |
|
|
'requireConnection', 'killChild', 'trySpawn', |
|
|
'requireConnection', 'killChild', 'trySpawn', |
|
|
'controlEval', 'debugEval'], |
|
|
'controlEval', 'debugEval', 'print'], |
|
|
synonym = { |
|
|
synonym = { |
|
|
'run': 'r', |
|
|
'run': 'r', |
|
|
'cont': 'c', |
|
|
'cont': 'c', |
|
@ -708,20 +708,23 @@ Interface.prototype.resume = function(silent) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Interface.prototype.handleBreak = function(r) { |
|
|
// Output
|
|
|
var expected = this.paused !== 0; |
|
|
Interface.prototype.print = function(text) { |
|
|
|
|
|
process.stdout.cursorTo(0); |
|
|
|
|
|
process.stdout.clearLine(1); |
|
|
|
|
|
process.stdout.write(text + '\n'); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Interface.prototype.handleBreak = function(r) { |
|
|
this.pause(); |
|
|
this.pause(); |
|
|
|
|
|
|
|
|
this.client.currentSourceLine = r.sourceLine; |
|
|
this.client.currentSourceLine = r.sourceLine; |
|
|
this.client.currentFrame = 0; |
|
|
this.client.currentFrame = 0; |
|
|
this.client.currentScript = r.script.name; |
|
|
this.client.currentScript = r.script.name; |
|
|
|
|
|
|
|
|
if (!expected) { |
|
|
this.print(SourceInfo(r) + '\n' + |
|
|
console.log(''); |
|
|
SourceUnderline(r.sourceLineText, r.sourceColumn)); |
|
|
} |
|
|
|
|
|
console.log(SourceInfo(r)); |
|
|
|
|
|
console.log(SourceUnderline(r.sourceLineText, r.sourceColumn)); |
|
|
|
|
|
this.resume(); |
|
|
this.resume(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -801,7 +804,7 @@ function leftPad(n) { |
|
|
|
|
|
|
|
|
// Print help message
|
|
|
// Print help message
|
|
|
Interface.prototype.help = function() { |
|
|
Interface.prototype.help = function() { |
|
|
console.log(helpMessage); |
|
|
this.print(helpMessage); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -837,7 +840,7 @@ Interface.prototype.version = function() { |
|
|
|
|
|
|
|
|
this.pause(); |
|
|
this.pause(); |
|
|
this.client.reqVersion(function(v) { |
|
|
this.client.reqVersion(function(v) { |
|
|
process.stdout.write(v); |
|
|
self.print(v); |
|
|
self.resume(); |
|
|
self.resume(); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
@ -872,9 +875,9 @@ Interface.prototype.list = function() { |
|
|
pointer += '='; |
|
|
pointer += '='; |
|
|
} |
|
|
} |
|
|
pointer += '>'; |
|
|
pointer += '>'; |
|
|
console.log(pointer + ' ' + lines[i]); |
|
|
self.print(pointer + ' ' + lines[i]); |
|
|
} else { |
|
|
} else { |
|
|
console.log(leftPad(lineno) + ' ' + lines[i]); |
|
|
self.print(leftPad(lineno) + ' ' + lines[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
self.resume(); |
|
|
self.resume(); |
|
@ -891,24 +894,25 @@ Interface.prototype.backtrace = function() { |
|
|
self.pause(); |
|
|
self.pause(); |
|
|
client.fullTrace(function(bt) { |
|
|
client.fullTrace(function(bt) { |
|
|
if (bt.totalFrames == 0) { |
|
|
if (bt.totalFrames == 0) { |
|
|
console.log('(empty stack)'); |
|
|
self.print('(empty stack)'); |
|
|
} else { |
|
|
} else { |
|
|
var text = ''; |
|
|
var trace = [], |
|
|
var firstFrameNative = bt.frames[0].script.isNative; |
|
|
firstFrameNative = bt.frames[0].script.isNative; |
|
|
for (var i = 0; i < bt.frames.length; i++) { |
|
|
for (var i = 0; i < bt.frames.length; i++) { |
|
|
var frame = bt.frames[i]; |
|
|
var frame = bt.frames[i]; |
|
|
if (!firstFrameNative && frame.script.isNative) break; |
|
|
if (!firstFrameNative && frame.script.isNative) break; |
|
|
|
|
|
|
|
|
text += '#' + i + ' '; |
|
|
var text = '#' + i + ' '; |
|
|
if (frame.func.inferredName && frame.func.inferredName.length > 0) { |
|
|
if (frame.func.inferredName && frame.func.inferredName.length > 0) { |
|
|
text += frame.func.inferredName + ' '; |
|
|
text += frame.func.inferredName + ' '; |
|
|
} |
|
|
} |
|
|
text += require('path').basename(frame.script.name) + ':'; |
|
|
text += require('path').basename(frame.script.name) + ':'; |
|
|
text += (frame.line + 1) + ':' + (frame.column + 1); |
|
|
text += (frame.line + 1) + ':' + (frame.column + 1); |
|
|
text += '\n'; |
|
|
|
|
|
|
|
|
trace.push(text); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(text); |
|
|
self.print(trace.join('\n')); |
|
|
} |
|
|
} |
|
|
self.resume(); |
|
|
self.resume(); |
|
|
}); |
|
|
}); |
|
@ -920,7 +924,7 @@ Interface.prototype.scripts = function(displayNatives) { |
|
|
this.requireConnection(); |
|
|
this.requireConnection(); |
|
|
|
|
|
|
|
|
var client = this.client; |
|
|
var client = this.client; |
|
|
var text = ''; |
|
|
var scripts = []; |
|
|
|
|
|
|
|
|
this.pause(); |
|
|
this.pause(); |
|
|
for (var id in client.scripts) { |
|
|
for (var id in client.scripts) { |
|
@ -929,12 +933,14 @@ Interface.prototype.scripts = function(displayNatives) { |
|
|
if (displayNatives || |
|
|
if (displayNatives || |
|
|
script.name == client.currentScript || |
|
|
script.name == client.currentScript || |
|
|
!script.isNative) { |
|
|
!script.isNative) { |
|
|
text += script.name == client.currentScript ? '* ' : ' '; |
|
|
scripts.push( |
|
|
text += require('path').basename(script.name) + '\n'; |
|
|
(script.name == client.currentScript ? '* ' : ' ') + |
|
|
|
|
|
require('path').basename(script.name) |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
console.log(text); |
|
|
this.print(scripts.join('\n')); |
|
|
this.resume(); |
|
|
this.resume(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -1005,7 +1011,7 @@ Interface.prototype.breakpoints = function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
this.client.listbreakpoints(function(res) { |
|
|
this.client.listbreakpoints(function(res) { |
|
|
if (res.success) { |
|
|
if (res.success) { |
|
|
console.log(res.body); |
|
|
self.print(res.body); |
|
|
} else { |
|
|
} else { |
|
|
throw Error(res.message || 'Some error happened'); |
|
|
throw Error(res.message || 'Some error happened'); |
|
|
} |
|
|
} |
|
@ -1027,7 +1033,7 @@ Interface.prototype.repl = function() { |
|
|
|
|
|
|
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
console.log('Press Ctrl + C to leave debug repl'); |
|
|
self.print('Press Ctrl + C to leave debug repl'); |
|
|
|
|
|
|
|
|
// Don't display any default messages
|
|
|
// Don't display any default messages
|
|
|
var listeners = this.repl.rli.listeners('SIGINT'); |
|
|
var listeners = this.repl.rli.listeners('SIGINT'); |
|
@ -1107,7 +1113,7 @@ Interface.prototype.trySpawn = function(cb) { |
|
|
|
|
|
|
|
|
client.on('close', function() { |
|
|
client.on('close', function() { |
|
|
self.pause() |
|
|
self.pause() |
|
|
console.log('program terminated'); |
|
|
self.print('program terminated'); |
|
|
self.resume(); |
|
|
self.resume(); |
|
|
self.client = null; |
|
|
self.client = null; |
|
|
self.killChild(); |
|
|
self.killChild(); |
|
@ -1116,8 +1122,7 @@ Interface.prototype.trySpawn = function(cb) { |
|
|
|
|
|
|
|
|
client.on('unhandledResponse', function(res) { |
|
|
client.on('unhandledResponse', function(res) { |
|
|
self.pause(); |
|
|
self.pause(); |
|
|
console.log('\r\nunhandled res:'); |
|
|
self.print('\nunhandled res:' + JSON.stringify(res)); |
|
|
console.log(res); |
|
|
|
|
|
self.resume(); |
|
|
self.resume(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|