Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break points don't seem to work in GDB #40910

Closed
nathan-fiscaletti opened this issue Aug 19, 2020 · 2 comments
Closed

break points don't seem to work in GDB #40910

nathan-fiscaletti opened this issue Aug 19, 2020 · 2 comments

Comments

@nathan-fiscaletti
Copy link
Contributor

nathan-fiscaletti commented Aug 19, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.4 linux/amd64

Does this issue reproduce with the latest release?

Unsure

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/go/go_packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build152069207=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Create the following simple Go program and compile it:

    package main
    
    import(
        "flag"
        "fmt"
        "os"
    )
    
    func main() {
        var printBreaks bool = false
        flag.BoolVar(&printBreaks, "print-breaks", false, "print artificial break point addresses")
        flag.Parse()
    
        // Print the address for the EnterSandman function and then quit
        if printBreaks {
            fmt.Printf("\n%s\n", "ARTIFICIAL BREAKPOINTS:")
            fmt.Printf("%s\n", "==============================")
            fmt.Printf("%s%x\n", "main.EnterSandman() : 0x", EnterSandman)
            os.Exit(0)
        }
    
        fmt.Printf("%s\n", "Before 1991")
    
        EnterSandman()
    
        fmt.Printf("%s\n", "After 1991")
    }
    
    func EnterSandman() {
        fmt.Printf("%s\n", "Say your prayers, little one")
    }
    $ go build -o example example.go
  2. Run it with the -print-breaks parameter to determine the address of the EnterSandman function.

    $ ./example -print-breaks
    
    ARTIFICIAL BREAKPOINTS:
    ==============================
    main.EnterSandman() : 0x49fe30
  3. Open it using GDB and set the break point.

    $ gdb example
    (gdb) break *0x49fe30
    Breakpoint 1 at 0x49fe30: file /home/root/example.go, line 29.
  4. The file / line shown by GDB match those of the function in the source file.

  5. Run the program in GDB.

What did you expect to see?

The program properly break at the desired function.

What did you see instead?

(gdb) break *0x49fe30
Breakpoint 1 at 0x49fe30: file /home/root/example.go, line 29.
(gdb) run
Starting program: /client-c-library/vcb/test/vvp/example
[New LWP 122353]
[New LWP 122354]
[New LWP 122355]
Before 1991
Say your prayers, little one
After 1991
[LWP 122354 exited]
[LWP 122353 exited]
[LWP 122349 exited]
[Inferior 1 (process 122349) exited normally]
(gdb)
@nathan-fiscaletti
Copy link
Contributor Author

However, if i instead do:

(gdb) break main.EnterSandman

It does work. Why does this work but breaking on the address does not?

@ianlancetaylor
Copy link
Contributor

This is happening because EnterSandman is inlined into main.

Closing because this is not a bug. In general we do not use the issue tracker for questions. You will get a better and faster answer if you use a forum. See https://golang.org/wiki/Questions. Thanks.

@golang golang locked and limited conversation to collaborators Aug 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants