Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect global variables in GoLand when debugging a golang program?

When I debug a go program in GoLand, I can't see the value of global variable. Can anyone tell me why and how to fix it?

Here is an example:

I set a breakpoint in the last line of main function. But as shown in the picture, we can only get the value of 'a', but not 'a' and 'xx'.

package main

import "fmt"

var xx int = 1

func main() {
    var a int = 1
    fmt.Println(a)
    xx = 3
    fmt.Println("end")
}

enter image description here

like image 251
hc ch Avatar asked Mar 08 '23 08:03

hc ch


1 Answers

We can use Evaluate function to get the value of global variables, but can only get one value each time

evaluate

like image 118
hc ch Avatar answered May 18 '23 11:05

hc ch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!