Unable to set watch variable in Golang debug

Asked 2 years ago, Updated 2 years ago, 93 views

I want to use lldb to watch the variable c in the code below, but an error has occurred and it doesn't work.What should I do?

go build-gcflags"-N-l"forprint.go and then enter lldb and watch
An invalid thread error occurs.

OS:OS X 10.11.1
lldb —lldb-340.4.70
Go: 1.5.1

print.go


package main
import "fmt"

funcmain(){
    c: = 1
    for c<=100 {
        fmt.Println(c)
        I want to watch c++//c
    }
}

go debugging

2022-09-30 20:58

1 Answers

The environment is different from mine, so I'm not sure if it will be an answer.

invalid thread appears because the program is not running yet (the execution context does not exist), so you must first set breakpoint to the main function and so on to run the program.

The following is the process of setting the watchpoint in this environment.

$go version
goversion go1.4.2 gccgo (Ubuntu 5.1.1-4ubuntu12) 5.1.1 20150504 linux/386

$ go build-gcflags"-N-l "lldb-test.go

$ lldb --version
lldb version 3.7.0 (revision)

$ lldb. / lldb-test

(lldb) breakpoint set-n main.main
(lldb) run
Process 7837 launched: './lldb-test' (i386)
Process 7837 stopped
* thread#1:tid=7837,0x080496b5lldb-test`main.main+26 at lldb-test.go:6, name='lldb-test', stop reason=breakpoint1.1
    frame#0:0x080496b5 lldb-test`main.main+26 at lldb-test.go:6
   3 import "fmt"
   4
   5 func main(){
->6c:=1
   7 for c<=100 {
   8 fmt.Println(c)
   I want to watch 9c++//c

(lldb) fr variable
(int)c=134519177

(lldb) watchpoint set variable c
Watchpoint created: Watchpoint1:addr=0xb5fcffec size=4state=enabled type=w
    declare@'/home/nemo/lldb-test.go:6'
    watchpoint spec = 'c'
    new value —134519177
(lldb) watchpoint list
Number of supported hardware watchpoints—4
Current watchpoints:
Watchpoint1:addr=0xb5fcffec size=4 state=enabled type=w
    declare@'/home/nemo/lldb-test.go:6'
    watchpoint spec = 'c'
    new value —134519177

(lldb) cont
Process 7837 resumming
Watchpoint 1 hit:
old value: 134519177<--1st
new value:1
Process 7837 stopped
* thread#1:tid=7837,0x080496bc lldb-test`main.main+33 at lldb-test.go:7, name='lldb-test', stop reason=watchpoint1
    frame#0:0x080496bclldb-test`main.main+33 at lldb-test.go:7
   4
   5 func main(){
   6c: = 1
->7 for c<=100 {
   8 fmt.Println(c)
   I want to watch 9c++//c
   10       }

(lldb) cont
Process 7837 resumming
Watchpoint 1 hit:
old value:1<--2nd
new value:2
Process 7837 stopped
* thread#3:tid=7893,0x08049742 lldb-test`main.main+167 at lldb-test.go:7, name='lldb-test', stop reason=watchpoint1
    frame#0:0x08049742 lldb-test`main.main+167 at lldb-test.go:7
   4
   5 func main(){
   6c: = 1
->7 for c<=100 {
   8 fmt.Println(c)
   I want to watch 9c++//c
   10       }

Addition (December 23, 2015)

The lldb version was 3.8 so I tried it.

##This time amd64 CPU
$ uname-srm
Linux 4.2.0-22-generic x86_64

## Equivalent to Golang 1.6 Beta 1
$ goversion
goversion develop +97f854c Sat Dec 19 10:00:04 2015 +0000 linux/amd64

$ lldb --version
lldb version 3.8.0 (revision)

Debugging in this environment using the same procedure as above, the results were the same and there was no problem.


2022-09-30 20:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.