Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 14ac9e4

Browse files
author
Matt Loring
committed
Enable maxExpandFrames config option
1 parent 82bb2b8 commit 14ac9e4

File tree

3 files changed

+63
-18
lines changed

3 files changed

+63
-18
lines changed

config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ module.exports = {
4646

4747
// Only collect locals and arguments on a few top frames. For the rest
4848
// only collect the source location
49-
// TODO: implement this
50-
//maxExpandFrames: 5,
49+
maxExpandFrames: 5,
5150

5251
// To reduce the overall capture time, limit the number of properties
5352
// gathered on large object. A value of 0 disables the limit.

lib/state.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,30 @@ module.exports = {
2323

2424
var assert = require('assert');
2525
var semver = require('semver');
26+
var util = require('util');
2627

2728
var StatusMessage = require('./apiclasses.js').StatusMessage;
2829

2930
var BUFFER_FULL_MESSAGE_INDEX = 0;
3031
var NATIVE_PROPERTY_MESSAGE_INDEX = 1;
3132
var GETTER_MESSAGE_INDEX = 2;
33+
var ARG_LOCAL_LIMIT_MESSAGE_INDEX = 3;
34+
35+
var MESSAGE_TABLE = [];
36+
MESSAGE_TABLE[BUFFER_FULL_MESSAGE_INDEX] =
37+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
38+
'Max data size reached', true) };
39+
MESSAGE_TABLE[NATIVE_PROPERTY_MESSAGE_INDEX] =
40+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
41+
'Native properties are not available', true) };
42+
MESSAGE_TABLE[GETTER_MESSAGE_INDEX] =
43+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
44+
'Properties with getters are not available', true) };
45+
MESSAGE_TABLE[ARG_LOCAL_LIMIT_MESSAGE_INDEX] =
46+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
47+
'Locals and arguments are only displayed for the ' +
48+
'top `config.capture.maxExpandFrames` stack frames.',
49+
true) };
3250

3351
// TODO: document this file
3452

@@ -83,17 +101,8 @@ function StateResolver(execState, expressions, config) {
83101
this.evaluatedExpressions_ = [];
84102
this.totalSize_ = 0;
85103

86-
this.rawVariableTable_ = [ null, null, null ];
87-
this.resolvedVariableTable_ = [];
88-
this.resolvedVariableTable_[BUFFER_FULL_MESSAGE_INDEX] =
89-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
90-
'Max data size reached', true) };
91-
this.resolvedVariableTable_[NATIVE_PROPERTY_MESSAGE_INDEX] =
92-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
93-
'Native properties are not available', true) };
94-
this.resolvedVariableTable_[GETTER_MESSAGE_INDEX] =
95-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
96-
'Properties with getters are not available', true) };
104+
this.resolvedVariableTable_ = util._extend([], MESSAGE_TABLE);
105+
this.rawVariableTable_ = MESSAGE_TABLE.map(function() { return null; });
97106
}
98107

99108

@@ -122,7 +131,7 @@ StateResolver.prototype.capture = function() {
122131
}
123132

124133
// Now resolve the variables
125-
var index = 3; // skip the sentinel values
134+
var index = MESSAGE_TABLE.length; // skip the sentinel values
126135
while (index < that.rawVariableTable_.length && // NOTE: length changes in loop
127136
that.totalSize_ < that.config_.capture.maxDataSize) {
128137
assert(!that.resolvedVariableTable_[index]); // shouldn't have it resolved yet
@@ -177,7 +186,8 @@ StateResolver.prototype.resolveFrames_ = function() {
177186
for (var i = 0; i < this.state_.frameCount(); i++) {
178187
var frame = this.state_.frame(i);
179188
if (this.shouldFrameBeResolved_(frame)) {
180-
frames.push(this.resolveFrame_(frame));
189+
var resolveVars = i < this.config_.capture.maxExpandFrames;
190+
frames.push(this.resolveFrame_(frame, resolveVars));
181191
}
182192
}
183193
return frames;
@@ -242,13 +252,20 @@ StateResolver.prototype.isPathInNodeModulesDirectory_ = function(path) {
242252
};
243253

244254

245-
StateResolver.prototype.resolveFrame_ = function(frame) {
246-
var args = this.resolveArgumentList_(frame);
255+
StateResolver.prototype.resolveFrame_ = function(frame, resolveVars) {
256+
var args = resolveVars ? this.resolveArgumentList_(frame) : [{
257+
name: 'arguments_not_available',
258+
varTableIndex: ARG_LOCAL_LIMIT_MESSAGE_INDEX
259+
}];
260+
var locals = resolveVars ? this.resolveLocalsList_(frame, args) : [{
261+
name: 'locals_not_available',
262+
varTableIndex: ARG_LOCAL_LIMIT_MESSAGE_INDEX
263+
}];
247264
return {
248265
function: this.resolveFunctionName_(frame.func()),
249266
location: this.resolveLocation_(frame),
250267
arguments: args,
251-
locals: this.resolveLocalsList_(frame, args)
268+
locals: locals
252269
};
253270
};
254271

test/test-v8debugapi.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,35 @@ describe('v8debugapi', function() {
307307
});
308308
});
309309

310+
it('should resolve correct frame count', function(done) {
311+
// clone a clean breakpointInFoo
312+
var bp = {id: breakpointInFoo.id, location: breakpointInFoo.location};
313+
var oldCount = config.capture.maxExpandFrames;
314+
config.capture.maxExpandFrames = 0;
315+
api.set(bp, function(err) {
316+
assert.ifError(err);
317+
api.wait(bp, function(err) {
318+
assert.ifError(err);
319+
assert.ok(bp.stackFrames);
320+
assert.ok(bp.variableTable);
321+
322+
var topFrame = bp.stackFrames[0];
323+
assert.ok(topFrame);
324+
assert.equal(topFrame['function'], 'foo');
325+
assert.equal(topFrame.arguments.length, 1);
326+
var argsVal = bp.variableTable[topFrame.arguments[0].varTableIndex];
327+
assert(argsVal.status.isError);
328+
assert.equal(topFrame.locals.length, 1);
329+
var localsVal = bp.variableTable[topFrame.locals[0].varTableIndex];
330+
assert(localsVal.status.isError);
331+
api.clear(bp);
332+
config.capture.maxExpandFrames = oldCount;
333+
done();
334+
});
335+
process.nextTick(function() {foo(2);});
336+
});
337+
});
338+
310339
it('should capture state with watch expressions', function(done) {
311340
// clone a clean breakpointInFoo
312341
var bp = {

0 commit comments

Comments
 (0)