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

debug: use unique stack frame id #2130

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ class GoDebugSession extends LoggingDebugSession {
private delve: Delve;
private localPathSeparator: string;
private remotePathSeparator: string;
private stackFrameHandles: Handles<[number, number]>;
private packageInfo = new Map<string, string>();
private launchArgs: LaunchRequestArguments;
private logLevel: Logger.LogLevel = Logger.LogLevel.Error;
Expand All @@ -565,6 +566,7 @@ class GoDebugSession extends LoggingDebugSession {
this.debugState = null;
this.delve = null;
this.breakpoints = new Map<string, DebugBreakpoint[]>();
this.stackFrameHandles = new Handles<[number, number]>();
}

protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
Expand Down Expand Up @@ -840,7 +842,8 @@ class GoDebugSession extends LoggingDebugSession {
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void {
log('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 @@ -851,18 +854,19 @@ class GoDebugSession extends LoggingDebugSession {
}
const locations = this.delve.isApiV1 ? <DebugLocation[]>out : (<StacktraceOut>out).Locations;
log('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 @@ -877,7 +881,8 @@ class GoDebugSession extends LoggingDebugSession {

protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
log('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 @@ -886,7 +891,7 @@ class GoDebugSession extends LoggingDebugSession {
const locals = this.delve.isApiV1 ? <DebugVariable[]>out : (<ListVarsOut>out).Variables;
log('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 @@ -1166,7 +1171,14 @@ class GoDebugSession extends LoggingDebugSession {
return typeName.substr(i + 1);
}

private cleanupHandles(): void {
this._variableHandles.reset();
this.stackFrameHandles.reset();
}

private handleReenterDebug(reason: string): void {
this.cleanupHandles();

if (this.debugState.exited) {
this.sendEvent(new TerminatedEvent());
log('TerminatedEvent');
Expand Down Expand Up @@ -1305,9 +1317,10 @@ class GoDebugSession extends LoggingDebugSession {
}

private evaluateRequestImpl(args: DebugProtocol.EvaluateArguments): Thenable<EvalOut | DebugVariable> {
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