2018-05-04 17:31:45 +00:00
package main
import (
"fmt"
2020-11-12 23:24:31 +00:00
"os"
2018-05-04 17:31:45 +00:00
"runtime"
2018-07-28 19:12:07 +00:00
"strings"
2018-05-04 17:31:45 +00:00
)
2020-11-12 23:24:31 +00:00
var call = "this is a variable named `call`"
2018-05-04 17:31:45 +00:00
func callstacktrace ( ) ( stacktrace string ) {
for skip := 0 ; ; skip ++ {
pc , file , line , ok := runtime . Caller ( skip )
if ! ok {
break
}
fn := runtime . FuncForPC ( pc )
stacktrace += fmt . Sprintf ( "in %s at %s:%d\n" , fn . Name ( ) , file , line )
}
return stacktrace
}
2020-11-12 23:24:31 +00:00
func call0 ( a , b int ) {
fmt . Printf ( "call0: first: %d second: %d\n" , a , b )
}
2018-05-04 17:31:45 +00:00
func call1 ( a , b int ) int {
fmt . Printf ( "first: %d second: %d\n" , a , b )
return a + b
}
2020-11-12 23:24:31 +00:00
func call2 ( a , b int ) ( int , int ) {
fmt . Printf ( "call2: first: %d second: %d\n" , a , b )
return a , b
}
func callexit ( ) {
fmt . Printf ( "about to exit\n" )
os . Exit ( 0 )
}
2018-05-04 17:31:45 +00:00
func callpanic ( ) {
fmt . Printf ( "about to panic\n" )
panic ( "callpanic panicked" )
}
2020-11-12 23:24:31 +00:00
func callbreak ( ) {
fmt . Printf ( "about to break" )
runtime . Breakpoint ( )
}
2018-07-28 19:12:07 +00:00
func stringsJoin ( v [ ] string , sep string ) string {
// This is needed because strings.Join is in an optimized package and
// because of a bug in the compiler arguments of optimized functions don't
// have a location.
return strings . Join ( v , sep )
}
2018-07-31 12:50:10 +00:00
type astruct struct {
X int
}
2018-08-18 08:53:21 +00:00
type a2struct struct {
Y int
}
2018-07-31 12:50:10 +00:00
func ( a astruct ) VRcvr ( x int ) string {
return fmt . Sprintf ( "%d + %d = %d" , x , a . X , x + a . X )
}
func ( pa * astruct ) PRcvr ( x int ) string {
return fmt . Sprintf ( "%d - %d = %d" , x , pa . X , x - pa . X )
}
type PRcvrable interface {
PRcvr ( int ) string
}
type VRcvrable interface {
VRcvr ( int ) string
}
2018-05-04 17:31:45 +00:00
var zero = 0
2018-07-31 16:32:30 +00:00
func makeclos ( pa * astruct ) func ( int ) string {
i := 0
return func ( x int ) string {
i ++
return fmt . Sprintf ( "%d + %d + %d = %d" , i , pa . X , x , i + pa . X + x )
}
}
2018-08-17 06:17:22 +00:00
var ga astruct
2018-08-18 08:53:21 +00:00
var globalPA2 * a2struct
func escapeArg ( pa2 * a2struct ) {
globalPA2 = pa2
}
2018-08-17 06:17:22 +00:00
2019-05-09 15:29:58 +00:00
func square ( x int ) int {
return x * x
}
func intcallpanic ( a int ) int {
if a == 0 {
panic ( "panic requested" )
}
return a
}
func onetwothree ( n int ) [ ] int {
return [ ] int { n + 1 , n + 2 , n + 3 }
}
2019-05-30 15:08:37 +00:00
func curriedAdd ( n int ) func ( int ) int {
return func ( m int ) int {
return n + m
}
}
func getAStruct ( n int ) astruct {
return astruct { X : n }
}
func getAStructPtr ( n int ) * astruct {
return & astruct { X : n }
}
func getVRcvrableFromAStruct ( n int ) VRcvrable {
return astruct { X : n }
}
func getPRcvrableFromAStructPtr ( n int ) PRcvrable {
return & astruct { X : n }
}
func getVRcvrableFromAStructPtr ( n int ) VRcvrable {
return & astruct { X : n }
}
2019-06-17 16:51:29 +00:00
func noreturncall ( n int ) {
return
}
2020-02-18 22:19:06 +00:00
type Base struct {
2019-09-26 14:37:23 +00:00
y int
}
type Derived struct {
x int
Base
}
func ( b * Base ) Method ( ) int {
return b . y
}
2020-02-18 22:19:06 +00:00
type X int
func ( _ X ) CallMe ( ) {
println ( "foo" )
}
type X2 int
func ( _ X2 ) CallMe ( i int ) int {
return i * i
}
2021-07-08 15:47:53 +00:00
func regabistacktest ( s1 , s2 , s3 , s4 , s5 string , n uint8 ) ( string , string , string , string , string , uint8 ) {
return s1 + s2 , s2 + s3 , s3 + s4 , s4 + s5 , s5 + s1 , 2 * n
}
func regabistacktest2 ( n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , n9 , n10 int ) ( int , int , int , int , int , int , int , int , int , int ) {
return n1 + n2 , n2 + n3 , n3 + n4 , n4 + n5 , n5 + n6 , n6 + n7 , n7 + n8 , n8 + n9 , n9 + n10 , n10 + n1
}
2022-05-03 17:46:24 +00:00
func regabistacktest3 ( sargs [ 10 ] string , n uint8 ) ( r [ 10 ] string , m uint8 ) {
for i := range sargs {
r [ i ] = sargs [ i ] + sargs [ ( i + 1 ) % len ( sargs ) ]
}
m = n * 3
return
}
func floatsum ( a , b float64 ) float64 {
return a + b
}
2021-09-24 22:27:44 +00:00
type Issue2698 struct {
a uint32
b uint8
c uint8
d uintptr
}
func ( i Issue2698 ) String ( ) string {
return fmt . Sprintf ( "%d %d %d %d" , i . a , i . b , i . c , i . d )
}
2023-05-15 21:46:33 +00:00
type Issue3364 struct {
a int
b uint32
}
func ( i Issue3364 ) String ( ) string {
return fmt . Sprintf ( "%d %d" , i . a , i . b )
}
2018-05-04 17:31:45 +00:00
func main ( ) {
one , two := 1 , 2
2018-07-28 19:12:07 +00:00
intslice := [ ] int { 1 , 2 , 3 }
stringslice := [ ] string { "one" , "two" , "three" }
comma := ","
2018-07-31 12:50:10 +00:00
a := astruct { X : 3 }
pa := & astruct { X : 6 }
2018-08-18 08:53:21 +00:00
a2 := a2struct { Y : 7 }
2019-06-17 16:51:29 +00:00
var pa2 * astruct
var str string = "old string value"
dap: use larger string type variable load limits in 'repl', 'variables' context (#2418)
* dap: use larger variable load limits in 'repl', 'variables' context
When evaluate requests are triggered in the context of 'repl'
(DEBUG CONSOLE in VSCode) or 'variables' (copy values from VARIABLES
section in VSCode), they are the result of human action and have
more rooms to display. So it is not too bad to apply longer limits.
Variable auto-loading for strings or arrays is nice but currently
it's unclear to me how this should be integrated in the DEBUG
CONSOLE or with the Copy Value feature. Until we have better ideas
and tools, let's go with these larger limits.
Unfortunately, the "Copy Value" from WATCH section triggers evaluate
requests with "watch" context and we don't want to load large data
automatically for "watch". So, users who want to query a large value
should first copy the expression to DEBUG CONSOLE and evaluate it.
Not ideal but not the end of the world either.
Updates golang/vscode-go#1318
* dap: apply large limit only to the string type result
* dap: move string reload logic to convertVariable* where other reload logic is
Currently we are thinking string reload for evaluation as a temporary
workaround until we figure out an intutitive way to present long strings.
So, I hope moving this logic near other reload logic may be better.
And, use the address based expression when reloading - when handling the
function return values, we may not have an expression to use.
* dap: make deep source check happy
* dap: move string reevaluation logic back to onEvaluateRequest
Reloading string variables is tricky if they are in registers.
We don't attempt to reload them but for clarity, move this up
to the onEvaluateRequest handler.
For function call, use a generous limit for string load
since the results are volatile.
* dap: check variable isn't affected by evaluate in other context
2021-05-25 17:23:41 +00:00
longstrs := [ ] string { "very long string 0123456789a0123456789b0123456789c0123456789d0123456789e0123456789f0123456789g012345678h90123456789i0123456789j0123456789" }
2022-05-03 17:46:24 +00:00
rast3 := [ 10 ] string { "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "height" , "nine" , "ten" }
2018-07-31 12:50:10 +00:00
var vable_a VRcvrable = a
var vable_pa VRcvrable = pa
var pable_pa PRcvrable = pa
2020-02-18 22:19:06 +00:00
var x X = 2
var x2 X2 = 2
2021-09-24 22:27:44 +00:00
issue2698 := Issue2698 {
a : 1 ,
b : 2 ,
c : 3 ,
d : 4 ,
}
2023-05-15 21:46:33 +00:00
issue3364 := Issue3364 {
a : 1 ,
b : 2 ,
}
2018-07-31 12:50:10 +00:00
2018-07-31 16:32:30 +00:00
fn2clos := makeclos ( pa )
fn2glob := call1
fn2valmeth := pa . VRcvr
fn2ptrmeth := pa . PRcvr
var fn2nil func ( )
2019-09-26 14:37:23 +00:00
d := & Derived { 3 , Base { 4 } }
2022-11-07 23:22:12 +00:00
var ref strings . Builder
fmt . Fprintf ( & ref , "blah" )
2020-12-10 17:03:11 +00:00
runtime . Breakpoint ( ) // breakpoint here
2018-05-04 17:31:45 +00:00
call1 ( one , two )
2018-07-31 16:32:30 +00:00
fn2clos ( 2 )
2019-09-25 17:23:02 +00:00
strings . LastIndexByte ( stringslice [ 1 ] , 'w' )
2019-09-26 14:37:23 +00:00
d . Method ( )
d . Base . Method ( )
2020-02-18 22:19:06 +00:00
x . CallMe ( )
2023-05-15 21:46:33 +00:00
fmt . Println ( one , two , zero , call , call0 , call2 , callexit , callpanic , callbreak , callstacktrace , stringsJoin , intslice , stringslice , comma , a . VRcvr , a . PRcvr , pa , vable_a , vable_pa , pable_pa , fn2clos , fn2glob , fn2valmeth , fn2ptrmeth , fn2nil , ga , escapeArg , a2 , square , intcallpanic , onetwothree , curriedAdd , getAStruct , getAStructPtr , getVRcvrableFromAStruct , getPRcvrableFromAStructPtr , getVRcvrableFromAStructPtr , pa2 , noreturncall , str , d , x , x2 . CallMe ( 5 ) , longstrs , regabistacktest , regabistacktest2 , issue2698 . String ( ) , issue3364 . String ( ) , regabistacktest3 , rast3 , floatsum , ref )
2018-05-04 17:31:45 +00:00
}