Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
limit the number of locals transmitted by the scopes request; fixes m…
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed May 16, 2016
1 parent 3b9cce1 commit 624d700
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 29 deletions.
29 changes: 29 additions & 0 deletions src/node/debugInjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
return content;
};
} catch (error) {
// since overriding 'serializeReferencedObjects' is optional, we can silently ignore the error.
}

/**
Expand Down Expand Up @@ -213,4 +214,32 @@
}
return result;
};

/**
* This override trims the maximum number of local variables to 'maxLocals'.
*/
DebugCommandProcessor.prototype.dispatch_['vscode_scopes'] = function(request, response) {
var result = this.scopesRequest_(request, response);
if (!result) {
var maxLocals = request.arguments.maxLocals;
var scopes = response.body.scopes;
for (var i = 0; i < scopes.length-1; i++) {
const details = scopes[i].details_.details_;
if (details[0] === 1) { // locals
const locals = details[1];
const names = Object.keys(locals);
if (names.length > maxLocals) {
var locals2 = {};
for (var j = 0; j < maxLocals; j++) {
var name = names[j];
locals2[name] = locals[name];
}
details[1] = locals2;
}
response.body.vscode_locals = names.length; // remember original number of locals
}
}
}
return result;
};
}()
64 changes: 35 additions & 29 deletions src/node/nodeDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,16 @@ export class NodeDebugSession extends DebugSession {

//--- scopes request ------------------------------------------------------------------------------------------------------

private static SCOPE_NAMES = [
localize({ key: 'scope.global', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Global"),
localize({ key: 'scope.local', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Local"),
localize({ key: 'scope.with', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "With"),
localize({ key: 'scope.closure', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Closure"),
localize({ key: 'scope.catch', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Catch"),
localize({ key: 'scope.block', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Block"),
localize({ key: 'scope.script', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Script")
];

protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {

const frame = this._frameHandles.get(args.frameId);
Expand All @@ -1719,44 +1729,40 @@ export class NodeDebugSession extends DebugSession {
const frameIx = frame.index;
const frameThis = this._getValueFromCache(frame.receiver);

const scopesArgs: any = {
frame_index: frameIx,
frameNumber: frameIx
}
let cmd = 'scopes';

if (this._nodeInjectionAvailable) {
cmd = 'vscode_scopes';
scopesArgs.maxLocals = this._chunkSize;
}

this.log('va', `scopesRequest: scope ${frameIx}`);
this._node.command2('scopes', { frame_index: frameIx, frameNumber: frameIx }).then(response => {
this._node.command2(cmd, scopesArgs).then(scopesResponse => {

this._cacheRefs(response);
this._cacheRefs(scopesResponse);

const scopes : any[] = response.body.scopes;
const scopes : any[] = scopesResponse.body.scopes;

return Promise.all(scopes.map(scope => {
const type: number = scope.type;
const extra = type === 1 ? frameThis : null;
const expensive = type === 0; // global scope is expensive
let expensive = type === 0; // global scope is expensive

let scopeName: string;
switch (type) {
case 0:
scopeName = localize({ key: 'scope.global', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Global");
break;
case 1:
scopeName = localize({ key: 'scope.local', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Local");
break;
case 2:
scopeName = localize({ key: 'scope.with', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "With");
break;
case 3:
scopeName = localize({ key: 'scope.closure', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Closure");
break;
case 4:
scopeName = localize({ key: 'scope.catch', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Catch");
break;
case 5:
scopeName = localize({ key: 'scope.block', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Block");
break;
case 6:
scopeName = localize({ key: 'scope.script', comment: ['https://github.com/Microsoft/vscode/issues/4569'] }, "Script");
break;
default:
scopeName = localize('scope.unknown', "Unknown Scope Type: {0}", type);
break;
if (type >= 0 && type < NodeDebugSession.SCOPE_NAMES.length) {
if (type === 1 && typeof scopesResponse.body.vscode_locals === 'number') {
expensive = true;
scopeName = localize({ key: 'scope.local.with.count', comment: ['https://github.com/Microsoft/vscode/issues/4569'] },
"Local ({0} of {1})", scopesArgs.maxLocals, scopesResponse.body.vscode_locals);
} else {
scopeName = NodeDebugSession.SCOPE_NAMES[type];
}
} else {
scopeName = localize('scope.unknown', "Unknown Scope Type: {0}", type);
}

return this._resolveValues( [ scope.object ] ).then(resolved => {
Expand Down

0 comments on commit 624d700

Please sign in to comment.