@@ -149,6 +149,7 @@ interface DebugThread {
149
149
pc : number ;
150
150
goroutineID : number ;
151
151
function ?: DebugFunction ;
152
+ ReturnValues : DebugVariable [ ] ;
152
153
}
153
154
154
155
interface StacktraceOut {
@@ -1572,21 +1573,63 @@ export class GoDebugSession extends LoggingDebugSession {
1572
1573
1573
1574
protected evaluateRequest ( response : DebugProtocol . EvaluateResponse , args : DebugProtocol . EvaluateArguments ) : void {
1574
1575
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 ] ) ;
1581
1581
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 ) ;
1587
1631
} ) ;
1588
- }
1589
- ) ;
1632
+ return returnValue ;
1590
1633
}
1591
1634
1592
1635
protected setVariableRequest (
0 commit comments