Skip to content

Commit 27d736c

Browse files
committed
2655 Function calls via delve 'call' are not supported
1 parent 603c3de commit 27d736c

File tree

1 file changed

+56
-13
lines changed

1 file changed

+56
-13
lines changed

src/debugAdapter/goDebug.ts

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ interface DebugThread {
149149
pc: number;
150150
goroutineID: number;
151151
function?: DebugFunction;
152+
ReturnValues: DebugVariable[];
152153
}
153154

154155
interface StacktraceOut {
@@ -1572,21 +1573,63 @@ export class GoDebugSession extends LoggingDebugSession {
15721573

15731574
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
15741575
log('EvaluateRequest');
1575-
this.evaluateRequestImpl(args).then(
1576-
(out) => {
1577-
const variable = this.delve.isApiV1 ? <DebugVariable>out : (<EvalOut>out).Variable;
1578-
// #2326: Set the fully qualified name for variable mapping
1579-
variable.fullyQualifiedName = variable.name;
1580-
response.body = this.convertDebugVariableToProtocolVariable(variable);
1576+
const re = new RegExp(/\w+(?=\(.*\))/, 'g');
1577+
if (re.test(args.expression)) {
1578+
this.evaluateCallImpl(args).then(out => {
1579+
const state = this.delve.isApiV1 ? <DebuggerState>out : (<CommandOut>out).State;
1580+
response.body = this.convertDebugVariableToProtocolVariable(state.currentThread.ReturnValues[0]);
15811581
this.sendResponse(response);
1582-
log('EvaluateResponse');
1583-
},
1584-
(err) => {
1585-
this.sendErrorResponse(response, 2009, 'Unable to eval expression: "{e}"', {
1586-
e: err.toString()
1582+
log('EvaluateCallResponse');
1583+
}, err => {
1584+
this.sendErrorResponse(response, 2009, 'Unable to complete call: "{e}"', { e: err.toString() });
1585+
});
1586+
} else {
1587+
this.evaluateRequestImpl(args).then(
1588+
(out) => {
1589+
const variable = this.delve.isApiV1 ? <DebugVariable>out : (<EvalOut>out).Variable;
1590+
// #2326: Set the fully qualified name for variable mapping
1591+
variable.fullyQualifiedName = variable.name;
1592+
response.body = this.convertDebugVariableToProtocolVariable(variable);
1593+
this.sendResponse(response);
1594+
log('EvaluateResponse');
1595+
},
1596+
(err) => {
1597+
this.sendErrorResponse(response, 2009, 'Unable to eval expression: "{e}"', {
1598+
e: err.toString()
1599+
});
1600+
}
1601+
);
1602+
}
1603+
}
1604+
1605+
private evaluateCallImpl(args: DebugProtocol.EvaluateArguments): Thenable<DebuggerState | CommandOut> {
1606+
// default to the topmost stack frame of the current goroutine
1607+
let goroutineId = -1;
1608+
let frameId = 0;
1609+
// args.frameId won't be specified when evaluating global vars
1610+
if (args.frameId) {
1611+
[goroutineId, frameId] = this.stackFrameHandles.get(args.frameId);
1612+
}
1613+
const scope = {
1614+
goroutineID: goroutineId,
1615+
frame: frameId
1616+
};
1617+
const evalSymbolArgs = this.delve.isApiV1 ? {
1618+
symbol: args.expression,
1619+
scope
1620+
} : {
1621+
Expr: args.expression,
1622+
Scope: scope,
1623+
Cfg: this.delve.loadConfig,
1624+
Unsafe: true
1625+
};
1626+
const returnValue = this.delve.callPromise<DebuggerState | CommandOut>('Command',
1627+
[{ name: 'call', returnInfoLoadConfig: this.delve.loadConfig, expr: evalSymbolArgs.Expr, unsafe: false, goroutineID: scope.goroutineID }]).then(val => val,
1628+
err => {
1629+
logError('Failed to call function: ', JSON.stringify(evalSymbolArgs.Expr, null, ' '), '\n\rCall error:', err.toString());
1630+
return Promise.reject(err);
15871631
});
1588-
}
1589-
);
1632+
return returnValue;
15901633
}
15911634

15921635
protected setVariableRequest(

0 commit comments

Comments
 (0)