Added `stackTraceLimit` configuration, fixes #96.

The new option `stackTraceLimit`, like the corresponding option in
Chrome, allows us to specify how many stack frames we want when
stopped at a breakpoint. It can be set as high as you like.
Negative numbers will cause an error.

The default number of frames is set to 50 to prevent possible
performance issues; if you wish to capture all frames, no matter the
consequences, set this option to a high number, like `99999`.
This commit is contained in:
ssafejava 2013-09-24 13:21:24 +08:00 коммит произвёл Miroslav Bajtos
Родитель 295dea39a8
Коммит 21e8230ac0
9 изменённых файлов: 73 добавлений и 31 удалений

Просмотреть файл

@ -2,16 +2,18 @@ var convert = require('./convert'),
CallFramesProvider = require('./CallFramesProvider').CallFramesProvider;
/**
* @param {Object} config
* @param {FrontendClient} frontendClient
* @param {DebuggerClient} debuggerClient
* @param {ScriptManager} scriptManager
* @constructor
*/
function BreakEventHandler(frontendClient, debuggerClient, scriptManager) {
function BreakEventHandler(config, frontendClient, debuggerClient, scriptManager) {
this._config = config;
this._frontendClient = frontendClient;
this._debuggerClient = debuggerClient;
this._scriptManager = scriptManager;
this._callFramesProvider = new CallFramesProvider(debuggerClient);
this._callFramesProvider = new CallFramesProvider(config, debuggerClient);
this._registerDebuggerEventHandlers();
}

Просмотреть файл

@ -3,7 +3,12 @@ var async = require('async'),
var SCOPE_ID_MATCHER = /^scope:(\d+):(\d+)$/;
function CallFramesProvider(debuggerClient) {
/**
* @param {Object} config
* @param {DebuggerClient} debuggerClient
*/
function CallFramesProvider(config, debuggerClient) {
this._config = config;
this._debuggerClient = debuggerClient;
}
@ -13,7 +18,9 @@ CallFramesProvider.prototype = {
this._debuggerClient.request(
'backtrace',
{
inlineRefs: true
inlineRefs: true,
fromFrame: 0,
toFrame: this._config.stackTraceLimit
},
function(err, responseBody, responseRefs) {
if (err) {

Просмотреть файл

@ -3,6 +3,13 @@ var RuntimeAgent = require('./RuntimeAgent').RuntimeAgent,
NetworkAgent = require('./NetworkAgent').NetworkAgent,
DebuggerAgent = require('./DebuggerAgent').DebuggerAgent;
/**
* @param {Object} config
* @param {FrontendClient} frontendClient
* @param {DebuggerClient} debuggerClient
* @param {BreakEventHandler} breakEventHandler
* @param {ScriptManager} scriptManager
*/
function FrontendCommandHandler(config,
frontendClient,
debuggerClient,
@ -31,7 +38,7 @@ FrontendCommandHandler.prototype = {
this._scriptManager)
);
this._registerAgent('Runtime', new RuntimeAgent(this._debuggerClient));
this._registerAgent('Runtime', new RuntimeAgent(this._config, this._debuggerClient));
this._registerAgent(
'Page',

Просмотреть файл

@ -4,12 +4,13 @@ var convert = require('./convert.js'),
CallFramesProvider = require('./CallFramesProvider.js').CallFramesProvider;
/**
* @param {Object} config
* @param {DebuggerClient} debuggerClient
* @constructor
*/
function RuntimeAgent(debuggerClient) {
function RuntimeAgent(config, debuggerClient) {
this._debuggerClient = debuggerClient;
this._callFramesProvider = new CallFramesProvider(debuggerClient);
this._callFramesProvider = new CallFramesProvider(config, debuggerClient);
}
RuntimeAgent.prototype = {

Просмотреть файл

@ -40,7 +40,7 @@ var conversions = {
printHelpAndExit: function(value) {
if (value) {
console.log('Usage: node-inspector [options]');
console.log(' Option Default Description');
console.log(' Option Default Description');
Object.keys(definitions).map(function(key) {
definitions[key].desc && console.log(definitions[key].desc);
});
@ -74,36 +74,41 @@ var conversions = {
};
var definitions = {
'help': {
desc: '--help | | Print information about options',
desc: '--help | | Print information about options',
convert: conversions.printHelpAndExit,
defaultValue: false
},
'web-port': {
desc: '--web-port | 8080 | Port to host the inspector',
desc: '--web-port | 8080 | Port to host the inspector',
convert: conversions.stringToInt,
defaultValue: 8080
},
'web-host': {
desc: '--web-host | 127.0.0.1 | Host to listen on',
desc: '--web-host | 127.0.0.1 | Host to listen on',
convert: conversions.checkIfNull,
defaultValue: null
},
'debug-port': {
desc: '--debug-port | 5858 | Port to connect to the debugging app',
desc: '--debug-port | 5858 | Port to connect to the debugging app',
convert: conversions.stringToInt,
defaultValue: 5858
},
'save-live-edit': {
desc: '--save-live-edit | false | Save live edit changes to disk' +
'\t\t\t | | (update the edited files)',
desc: '--save-live-edit | false | Save live edit changes to disk\n' +
' | | (update the edited files)',
convert: conversions.stringToBoolean,
defaultValue: false
},
'hidden': {
desc: '--hidden | [] | Array of files to hide from the UI' +
'\t\t\t | | Breakpoints in these files will be ignored',
desc: '--hidden | [] | Array of files to hide from the UI\n' +
' | | (breakpoints in these files will be ignored)',
convert: conversions.stringToArray,
defaultValue: []
},
'stack-trace-limit': {
desc: '--stack-trace-limit | 50 | Number of stack frames to show on a breakpoint',
convert: conversions.stringToInt,
defaultValue: 50
}
};

Просмотреть файл

@ -53,6 +53,7 @@ exports.create = function(debuggerPort, config) {
);
breakEventHandler = new BreakEventHandler(
config,
frontendClient,
debuggerClient,
scriptManager

Просмотреть файл

@ -164,14 +164,16 @@ so that sources earlier in this list override later ones.
List of predefined options:
```
Option Default Description
--help | | Print information about options
--web-port | 8080 | Port to host the inspector
--web-host | 127.0.0.1 | Host to listen on
--debug-port | 5858 | Port to connect to the debugging app
--save-live-edit | false | Save live edit changes to disk (update the edited files)
--hidden | [] | Array of files to hide from the UI
| | Breakpoints in these files will be ignored
Option Default Description
--help | | Print information about options
--web-port | 8080 | Port to host the inspector
--web-host | 127.0.0.1 | Host to listen on
--debug-port | 5858 | Port to connect to the debugging app
--save-live-edit | false | Save live edit changes to disk
| | (update the edited files)
--hidden | [] | Array of files to hide from the UI
| | (breakpoints in these files will be ignored)
--stack-trace-limit | 50 | Number of stack frames to show on a breakpoint
```
## FAQ / WTF

Просмотреть файл

@ -1,5 +1,6 @@
var expect = require('chai').expect,
launcher = require('./helpers/launcher.js'),
config = require('../config'),
CallFramesProvider = require('../lib/CallFramesProvider').CallFramesProvider;
describe('CallFramesProvider', function() {
@ -7,7 +8,7 @@ describe('CallFramesProvider', function() {
it('gets stack trace', function(done) {
launcher.runOnBreakInFunction(function(debuggerClient) {
var provider = new CallFramesProvider(debuggerClient);
var provider = new CallFramesProvider(config, debuggerClient);
provider.fetchCallFrames(function(error, callFrames) {
if (error !== undefined && error !== null) {
done(error);
@ -57,6 +58,21 @@ describe('CallFramesProvider', function() {
});
});
});
it('retrieves specified number of stack traces when configured', function(done) {
launcher.runOnBreakInFunction(function(debuggerClient) {
var provider = new CallFramesProvider({stackTraceLimit: 1}, debuggerClient);
provider.fetchCallFrames(function(error, callFrames) {
if (error !== undefined && error !== null) {
done(error);
return;
}
expect(callFrames).to.have.length(1);
done();
});
});
});
});
function assertFrame(expected, actual, frameName) {

Просмотреть файл

@ -1,5 +1,6 @@
var expect = require('chai').expect,
launcher = require('./helpers/launcher.js'),
config = require('../config'),
CallFramesProvider = require('../lib/CallFramesProvider').CallFramesProvider,
RuntimeAgent = require('../lib/RuntimeAgent.js').RuntimeAgent;
@ -12,8 +13,8 @@ describe('RuntimeAgent', function() {
var MYFUNC_LOCAL_SCOPE_ID = 'scope:0:0';
launcher.runOnBreakInFunction(function(debuggerClient) {
var callFramesProvider = new CallFramesProvider(debuggerClient),
agent = new RuntimeAgent(debuggerClient);
var callFramesProvider = new CallFramesProvider(config, debuggerClient),
agent = new RuntimeAgent(config, debuggerClient);
// request call frames so that scope properties are initialized
callFramesProvider.fetchCallFrames(function(cferror) {
@ -64,7 +65,7 @@ describe('RuntimeAgent', function() {
it('returns object properties with metadata', function(done) {
launcher.runInspectObject(function(debuggerClient, inspectedObjectId) {
var agent = new RuntimeAgent(debuggerClient);
var agent = new RuntimeAgent(config, debuggerClient);
agent.getProperties(
{
objectId: inspectedObjectId,
@ -97,7 +98,7 @@ describe('RuntimeAgent', function() {
it('returns empty result for unsupported getProperties() call', function(done) {
launcher.runInspectObject(function(debuggerClient, inspectedObjectId) {
var agent = new RuntimeAgent(debuggerClient);
var agent = new RuntimeAgent(config, debuggerClient);
agent.getProperties(
{
objectId: inspectedObjectId,
@ -116,7 +117,7 @@ describe('RuntimeAgent', function() {
it('calls function on an object to get completions', function(done) {
launcher.runOnBreakInFunction(function(debuggerClient) {
var agent = new RuntimeAgent(debuggerClient);
var agent = new RuntimeAgent(config, debuggerClient);
debuggerClient.fetchObjectId(agent, 'console', function(consoleObjectId) {
agent.callFunctionOn(
@ -197,7 +198,7 @@ describe('RuntimeAgent', function() {
launcher.runInspectObject(function(client, objectId) {
debuggerClient = client;
inspectedObjectId = objectId;
agent = new RuntimeAgent(debuggerClient);
agent = new RuntimeAgent(config, debuggerClient);
done();
});
}