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

Commit

Permalink
debug: use unique stack frame id, fix local variables, evaluation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xiphon committed Nov 16, 2018
1 parent f26c88f commit 342bc86
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ class GoDebugSession extends DebugSession {
private delve: Delve;
private localPathSeparator: string;
private remotePathSeparator: string;
private stackFrameHandles: Handles<[number, number]>;
private packageInfo = new Map<string, string>();
private launchArgs: LaunchRequestArguments;

Expand All @@ -538,6 +539,7 @@ class GoDebugSession extends DebugSession {
this.debugState = null;
this.delve = null;
this.breakpoints = new Map<string, DebugBreakpoint[]>();
this.stackFrameHandles = new Handles<[number, number]>();

const logPath = path.join(os.tmpdir(), 'vscode-go-debug.txt');
logger.init(e => this.sendEvent(e), logPath, isServer);
Expand Down Expand Up @@ -773,7 +775,8 @@ class GoDebugSession extends DebugSession {
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void {
verbose('StackTraceRequest');
// delve does not support frame paging, so we ask for a large depth
let stackTraceIn = { id: args.threadId, depth: this.delve.stackTraceDepth };
const goroutineId = args.threadId;
let stackTraceIn = { id: goroutineId, depth: this.delve.stackTraceDepth };
if (!this.delve.isApiV1) {
Object.assign(stackTraceIn, { full: false, cfg: this.delve.loadConfig });
}
Expand All @@ -784,18 +787,19 @@ class GoDebugSession extends DebugSession {
}
const locations = this.delve.isApiV1 ? <DebugLocation[]>out : (<StacktraceOut>out).Locations;
verbose('locations', locations);
let stackFrames = locations.map((location, i) =>
new StackFrame(
i,
let stackFrames = locations.map((location, frameId) => {
const uniqueStackFrameId = this.stackFrameHandles.create([goroutineId, frameId]);
return new StackFrame(
uniqueStackFrameId,
location.function ? location.function.name : '<unknown>',
location.file === '<autogenerated>' ? null : new Source(
basename(location.file),
this.toLocalPath(location.file)
),
location.line,
0
)
);
);
});
if (args.startFrame > 0) {
stackFrames = stackFrames.slice(args.startFrame);
}
Expand All @@ -810,7 +814,8 @@ class GoDebugSession extends DebugSession {

protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
verbose('ScopesRequest');
const listLocalVarsIn = { goroutineID: this.debugState.currentGoroutine.id, frame: args.frameId };
const [goroutineId, frameId] = this.stackFrameHandles.get(args.frameId);
const listLocalVarsIn = { goroutineID: goroutineId, frame: frameId };
this.delve.call<DebugVariable[] | ListVarsOut>('ListLocalVars', this.delve.isApiV1 ? [listLocalVarsIn] : [{ scope: listLocalVarsIn, cfg: this.delve.loadConfig }], (err, out) => {
if (err) {
logError('Failed to list local variables - ' + err.toString());
Expand All @@ -819,7 +824,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 };
let listLocalFunctionArgsIn = { goroutineID: goroutineId, frame: frameId };
this.delve.call<DebugVariable[] | ListFunctionArgsOut>('ListFunctionArgs', this.delve.isApiV1 ? [listLocalFunctionArgsIn] : [{ scope: listLocalFunctionArgsIn, cfg: this.delve.loadConfig }], (err, outArgs) => {
if (err) {
logError('Failed to list function args - ' + err.toString());
Expand Down Expand Up @@ -1144,9 +1149,10 @@ class GoDebugSession extends DebugSession {

protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
verbose('EvaluateRequest');
const [goroutineId, frameId] = this.stackFrameHandles.get(args.frameId);
const scope = {
goroutineID: this.debugState.currentGoroutine.id,
frame: args.frameId
goroutineID: goroutineId,
frame: frameId
};
let evalSymbolArgs = this.delve.isApiV1 ? {
symbol: args.expression,
Expand Down

0 comments on commit 342bc86

Please sign in to comment.