How to watch the values of variables continuously in Go debugging?

To watch the values of variables continuously in Go debugging, you can use conditional breakpoints along with the continue command for continuous execution. Here's a step-by-step approach:

  1. Set a breakpoint at the point where you want to start watching the variable values. You can set a breakpoint using the break command, specifying the file and line number:
break main.go:10
  1. Start the debugger by running the program in debug mode:
go run -gcflags="all=-N -l" -tags debug main.go

The -gcflags="all=-N -l" flag disables optimizations, and the -tags debug flag ensures the inclusion of debug symbols.

  1. Once the debugger starts, it will stop at the breakpoint. Now, you can use the print command to view the current values of variables:
print myVariable
  1. To continuously watch the variable value, you can use the continue command, which resumes execution until the next breakpoint:
continue
  1. When the next breakpoint is hit, the debugger will halt, and you can again use the print command to view the updated value of the variable.

  2. Repeat the continue command to keep watching the variable values at each breakpoint.

By combining breakpoints and the continue command, you can continuously monitor the values of variables during the debugging process in Go.