Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix for #1990 (#2020)
Browse files Browse the repository at this point in the history
* Fixed copying values from variables in debug mode

* fixed missing evaluateName for array type

* Fixed evaluateName

* Formeatting

* Incorporated review comments

* Changed fqn -> fullyQualifiedName

* Slight refactoring
  • Loading branch information
karthikraobr authored and ramya-rao-a committed Nov 1, 2018
1 parent c2edc4f commit cb6257a
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ interface DebugVariable {
cap: number;
children: DebugVariable[];
unreadable: string;
fullyQualifiedName: string;
}

interface ListGoroutinesOut {
Expand Down Expand Up @@ -808,6 +809,7 @@ class GoDebugSession extends DebugSession {
}
const locals = this.delve.isApiV1 ? <DebugVariable[]>out : (<ListVarsOut>out).Variables;
verbose('locals', locals);
this.addFullyQualifiedName(locals);
let listLocalFunctionArgsIn = { goroutineID: this.debugState.currentGoroutine.id, frame: args.frameId };
this.delve.call<DebugVariable[] | ListFunctionArgsOut>('ListFunctionArgs', this.delve.isApiV1 ? [listLocalFunctionArgsIn] : [{ scope: listLocalFunctionArgsIn, cfg: this.delve.loadConfig }], (err, outArgs) => {
if (err) {
Expand All @@ -816,6 +818,7 @@ class GoDebugSession extends DebugSession {
}
const args = this.delve.isApiV1 ? <DebugVariable[]>outArgs : (<ListFunctionArgsOut>outArgs).Args;
verbose('functionArgs', args);
this.addFullyQualifiedName(args);
let vars = args.concat(locals);

let scopes = new Array<Scope>();
Expand All @@ -829,8 +832,10 @@ class GoDebugSession extends DebugSession {
len: 0,
cap: 0,
children: vars,
unreadable: ''
unreadable: '',
fullyQualifiedName: '',
};

scopes.push(new Scope('Local', this._variableHandles.create(localVariables), false));
response.body = { scopes };

Expand All @@ -850,7 +855,7 @@ class GoDebugSession extends DebugSession {
let initdoneIndex = -1;
for (let i = 0; i < globals.length; i++) {
globals[i].name = globals[i].name.substr(packageName.length + 1);
if (initdoneIndex === -1 && globals[i].name === this.initdone) {
if (initdoneIndex === -1 && globals[i].name === this.initdone) {
initdoneIndex = i;
}
}
Expand All @@ -869,7 +874,8 @@ class GoDebugSession extends DebugSession {
len: 0,
cap: 0,
children: globals,
unreadable: ''
unreadable: '',
fullyQualifiedName: '',
};
scopes.push(new Scope('Global', this._variableHandles.create(globalVariables), false));
this.sendResponse(response);
Expand Down Expand Up @@ -922,6 +928,12 @@ class GoDebugSession extends DebugSession {
variablesReference: 0
};
} else {
if (v.children[0].children.length > 0) {
v.children[0].fullyQualifiedName = v.fullyQualifiedName;
v.children[0].children.forEach(child => {
child.fullyQualifiedName = v.fullyQualifiedName + '.' + child.name;
});
}
return {
result: '<' + v.type + '>',
variablesReference: v.children[0].children.length > 0 ? this._variableHandles.create(v.children[0]) : 0
Expand Down Expand Up @@ -965,6 +977,7 @@ class GoDebugSession extends DebugSession {
return {
name: '[' + i + ']',
value: result,
evaluateName: vari.fullyQualifiedName + '[' + i + ']',
variablesReference
};
});
Expand All @@ -979,15 +992,20 @@ class GoDebugSession extends DebugSession {
variables.push({
name: mapKey.result,
value: mapValue.result,
evaluateName: vari.fullyQualifiedName + '[' + mapKey.result + ']',
variablesReference: mapValue.variablesReference
});
}
} else {
variables = vari.children.map((v, i) => {
let { result, variablesReference } = this.convertDebugVariableToProtocolVariable(v, i);
if (v.fullyQualifiedName === undefined) {
v.fullyQualifiedName = vari.fullyQualifiedName + '.' + v.name;
}
return {
name: v.name,
value: result,
evaluateName: v.fullyQualifiedName,
variablesReference
};
});
Expand Down Expand Up @@ -1140,6 +1158,15 @@ class GoDebugSession extends DebugSession {
verbose('EvaluateResponse');
});
}

private addFullyQualifiedName(variables: DebugVariable[]) {
variables.forEach(local => {
local.fullyQualifiedName = local.name;
local.children.forEach(child => {
child.fullyQualifiedName = local.name;
});
});
}
}

function random(low: number, high: number): number {
Expand Down

0 comments on commit cb6257a

Please sign in to comment.