doubipeng1336 2019-03-23 07:35
浏览 192
已采纳

如何使用gdb或delve将断点置于go方法中

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 Isbreakpoints only allowed at a line number in a file?? I could use either gdb or delve or any other debugger as well.

  • 写回答

1条回答 默认 最新

  • dqyy38265 2019-03-24 10:03
    关注

    If you have the version of github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/context.go that was used to build your Go binary — for example, in your src or vendor directory — then just open that file, find the WithUser function, and put a breakpoint on its first line.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?