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

question: how to put breakpoint to a Go method with gdb or delve #31013

Closed
vigneshkm opened this issue Mar 23, 2019 · 12 comments
Closed

question: how to put breakpoint to a Go method with gdb or delve #31013

vigneshkm opened this issue Mar 23, 2019 · 12 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@vigneshkm
Copy link

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

$ go version
go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Didnt check as this is a query related to debuggers with go rather than go itself

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/vignesh/go-book/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build931353307=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I want to debug a go code. I want to put breakpoint on a method (belonging to a named type) in a imported package. I went through a lot of online materials where they only put breakpoints on a line number in file (eg:breakpoint a.go:15).

I have done a lot of debugging in 'C' where I put breakpoints on functions. Is this kind of debugging possible in go??

I have the following code in my main package.

clientContext := sdk.Context(fabsdk.WithUser("Admin"), fabsdk.WithOrg("ordererorg")).

I want to put breakpoints to

  1. function WithUser() which belongs to package fabsdk in file github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/context.go.
  2. method Context() belonging to type FabricSDK in file github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/fabsdk.go in package fabsdk.

Is it possible to put breakpoints to method WithUser() and context() or Is breakpoints only allowed at a line number in a file?? I could use either gdb or delve or any other debugger as well.

What did you expect to see?

need to put breakpoints on a method or function

What did you see instead?

(gdb) br sdk.Context
Function "sdk.Context" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n

(gdb) br github.com/hyperledger/fabric-sdk-go/pkg/fabsdk.Context
Function "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk.Context" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (github.com/hyperledger/fabric-sdk-go/pkg/fabsdk.Context) pending.

@vigneshkm vigneshkm changed the title How to put breakpoint to a go method with gdb or delve How to put breakpoint to a Go method with gdb or delve Mar 23, 2019
@cherrymui
Copy link
Member

cherrymui commented Mar 24, 2019

(for gdb)

function WithUser() which belongs to package fabsdk in file github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/context.go.

Try b github.com/hyperledger/fabric-sdk-go/pkg/fabsdk.WithUser?

method Context() belonging to type FabricSDK in file github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/fabsdk.go in package fabsdk.

Try b 'github.com/hyperledger/fabric-sdk-go/pkg/fabsdk.(*FabricSDK).Context'?

In general, the symbol name of a method is pkg_path.T.M for value method or pkg_path.(*T).M for pointer method.

@vigneshkm
Copy link
Author

@cherrymui , I tried your solution with delve and it works. Thank you very much for your response and the explanation of path of a symbol :)

@josharian
Copy link
Contributor

I'd actually like to re-open this as a feature request. Writing out the full symbol name is onerous. I often resort to running nm/objdump, grepping for the function name I want, and then using the address instead.

It'd be nice if delve did some/all of these things:

  • Given b WithUser and only a single function containing the substring WithUser, set a breakpoint on it and print what it resolved to.
  • Given b WithUser, print a list of all symbols containing the substring WithUser, so that the user can easily copy/paste one.
  • Add a command like resolve WithUser that prints a list of all symbols with the substring WithUser.

cc @aarzilli @heschik @thanm

@josharian josharian reopened this Mar 29, 2019
@josharian
Copy link
Contributor

Bonus: support the same features in gdb/lldb!

Also cc @dr2chase @aclements (I'm not sure exactly who the debugger team is nowadays)

@aarzilli
Copy link
Contributor

Just b Context is probably ambiguous but delve should be able to resolve something like b FabricSDK.Context or b fabsdk.Context correctly. Supporting something like this in lldb would require writing a language layer for it (which existed for a while until it was removed because nobody maintained it).

@josharian
Copy link
Contributor

Even if b Context is ambiguous, delve could print all the possible disambiguations (up to some limit), no? That’d be more useful than simply rejecting it.

I didn’t realize the lldb script had been removed. Bummer.

@aarzilli
Copy link
Contributor

Even if b Context is ambiguous, delve could print all the possible disambiguations (up to some limit), no?

yes, and it does.

@aclements
Copy link
Member

You can also place a breakpoint using a line number, like "br fabsdk/context.go:NNN". I believe in gdb it will do some amount of disambiguation of the file name, so you don't have to type the full path to use this syntax.

@heschi
Copy link
Contributor

heschi commented Mar 29, 2019

And just for the record, I don't think there's anything in the compiler/linker we can do to affect any of this. Maybe we could do something in runtime-gdb.py? But to me this seems like a Delve feature request, if anything.

@cherrymui
Copy link
Member

I agree with @heschik that this is more on the debugger side than the compiler side.

Ideally maybe gdb/lldb should probably just hint symbols with partial matches. C++ function names are also quite long, in many cases.

@andybons andybons changed the title How to put breakpoint to a Go method with gdb or delve question: how to put breakpoint to a Go method with gdb or delve May 14, 2019
@andybons
Copy link
Member

@josharian would you mind updating the title of this issue with what you'd like to accomplish? Should your feature requests be separate issues perhaps?

@andybons andybons added this to the Unreleased milestone May 14, 2019
@andybons andybons added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 14, 2019
@josharian
Copy link
Contributor

Re-reading this thread, I think I'll just close it.

@golang golang locked and limited conversation to collaborators May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

9 participants