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

fix: multi /pkg/<module> in dlv debugging #119378

Open
wuhuua opened this issue Feb 20, 2024 · 2 comments
Open

fix: multi /pkg/<module> in dlv debugging #119378

wuhuua opened this issue Feb 20, 2024 · 2 comments
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community X-blathers-triaged blathers was able to find an owner

Comments

@wuhuua
Copy link

wuhuua commented Feb 20, 2024

This issue is copied from my PR: cockroachdb/rules_go#18

When I try to debug cockroach with VSCode, I found some bugs when I try to set breakpoints.
VSCode tells me that some files cannot be found in dlv sources, even if I use this to substitute the path to package path:

  {
    "from": "${workspaceFolder}",
    "to": "github.com/cockroachdb/cockroach"
  }, 

One of the cases is /pkg/gossip/gossip.go
When using dlv as follows:

dlv exec ../_bazel/bin/pkg/cmd/cockroach/cockroach_/cockroach -- start --insecure --store=node1 --listen-addr=localhost:26257 --http-addr=localhost:8080 --join=localhost:26257,localhost:26258,localhost:26259

and then use sources command to list all sources. You can find its path like this:

github.com/cockroachdb/cockroach/pkg/gossip/pkg/gossip/gossip.go
The relpath pkg/gossip has been appended twice.

This problem is associated with one issue in cockroach:
#64379
You modified complilepkg.go as follows:

// We want the source files to show up (e.g. in stack traces) with the package
// path. We use -trimpath to replace the root path with the correct prefix
// of the package path.
root := abs(".")
relSrcPath, err := filepath.Rel(root, srcs.goSrcs[0].filename)
if err != nil {
  return err
}
rootPkgPath := filepath.Clean(strings.TrimSuffix(packagePath, filepath.Dir(relSrcPath)))
gcFlags = append(gcFlags, fmt.Sprintf("-trimpath=%s=>%s", root, rootPkgPath))

But when you debug bazel, you can get the command passed bazel looks like this:

bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/go_sdk/builder_reset/builder compilepkg 
-sdk external/go_sdk -installsuffix linux_amd64 -tags bazel,gss,bazel,gss 
-src bazel-out/k8-dbg/bin/foo/foo_go_proto_/example.com/foo/foo.pb.go 
-src foo/foo.go -embedroot bazel-out/k8-dbg/bin -embedroot '' 
-embedlookupdir foo/foo_go_proto_/example.com/foo -embedlookupdir foo 
(serveral arcs)
-importpath heyhey -p example.com/foo -package_list bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/go_sdk/packages.txt -o bazel-out/k8-dbg/bin/foo/foo.a -x bazel-out/k8-dbg/bin/foo/foo.x -gcflags '-N -l' -asmflags '')

The first src is the protobuf file and therefore srcs.goSrcs[0].filename is bazel-out/k8-dbg/bin/foo/foo_go_proto_/example.com/foo/foo.pb.go, but we are expecting the source file which is not generated.

so I modify this part as follows:

srcFullPath := srcs.goSrcs[0].filename
for _, goSrc := range srcs.goSrcs {
  if !strings.HasSuffix(goSrc.filename, ".pb.go") {
    srcFullPath = goSrc.filename
    break
  }
}
relSrcPath, err := filepath.Rel(root, srcFullPath)

Once srcs has source code which is not generated, we use its path.
Then problem is fixed, and we get its path in dlv as follows:
github.com/cockroachdb/cockroach/pkg/gossip/gossip.go

Jira issue: CRDB-36174

@wuhuua wuhuua added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Feb 20, 2024
Copy link

blathers-crl bot commented Feb 20, 2024

Hello, I am Blathers. I am here to help you get the issue triaged.

It looks like you have not filled out the issue in the format of any of our templates. To best assist you, we advise you to use one of these templates.

I have CC'd a few people who may be able to assist you:

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Feb 20, 2024
@RaduBerinde
Copy link
Member

CC @rickystewart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community X-blathers-triaged blathers was able to find an owner
Projects
None yet
Development

No branches or pull requests

2 participants