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

dlv problem #993

Closed
excavador opened this issue Nov 7, 2017 · 16 comments
Closed

dlv problem #993

excavador opened this issue Nov 7, 2017 · 16 comments
Labels

Comments

@excavador
Copy link

Hello,

I am trying to debug my golang program by dlv on OSX.
bazel 0.7.0, rules_go latest.

If I build program by bazel, I receive error

➜ dlv attach 74960
could not attach to pid 74960: decoding dwarf section info at offset 0x0: too short

I found same issue for dlv:
https://github.com/derekparker/delve/issues/79
But static linking does not work on OSX (according to rules_go documentation).

If I build program by

go build

dlv able to attach to my program

How to build golang binaries in bazel on OSX for working with dlv?
Thank you

@jayconrod
Copy link
Contributor

At the moment, I can't reproduce this because dlv is getting killed on my mac (bad Xcode upgrade?).

We're both at a conference this week, so we may be slow to address this.

@excavador
Copy link
Author

@jayconrod if your received problem about lldb-server, just run

xcode-select --install

It will solve problem

@jayconrod
Copy link
Contributor

Reproduced. The dlv thing was a linker issue. Downloading a new Go SDK fixed it.

Could you try building with -c dbg? I think we're stripping debug symbols in the default configuration.

@excavador
Copy link
Author

excavador commented Nov 7, 2017

➜ bazel build -c dbg //exe/bazel/runner
INFO: Found 1 target...
ERROR: /Users/oleg/pp/src/XXX/exe/bazel/runner/BUILD.bazel:14:1: GoCompile exe/bazel/runner/~debug~runner~/XXX/exe/bazel/runner.a failed (Exit 1).
2017/11/07 19:15:52 missing strict dependencies:
	exe/bazel/runner/main.go: import of gopkg.in/urfave/cli.v2, which is not a direct dependency
	exe/bazel/runner/main.go: import of gopkg.in/yaml.v2, which is not a direct dependency
Target //exe/bazel/runner:runner failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.348s, Critical Path: 0.85s

My build file is following (generated by gazelle)

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "go_default_library",
    srcs = ["main.go"],
    importpath = "XXX/exe/bazel/runner",
    visibility = ["//visibility:private"],
    deps = [
        "//vendor/gopkg.in/urfave/cli.v2:go_default_library",
        "//vendor/gopkg.in/yaml.v2:go_default_library",
    ],
)

go_binary(
    name = "runner",
    importpath = "XXX/exe/bazel/runner",
    library = ":go_default_library",
    visibility = ["//visibility:public"],
)

Probably, it can be fixed easy in build file but is also means we have some problem with gazelle.

@jayconrod
Copy link
Contributor

Not sure if that's a problem with the rules or with Gazelle. Could you post the go_library rule for one of those "missing" imports? I'm wondering if the importpath attribute is wrong.

@excavador
Copy link
Author

@jayconrod these rules generated by gazelle by following settings

gazelle(
		name = "gazelle",
		prefix = "XXX",
		external = "vendored",
)
➜ cat vendor/gopkg.in/urfave/cli.v2/BUILD.bazel
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
    name = "go_default_library",
    srcs = [
        "app.go",
        "args.go",
        "category.go",
        "cli.go",
        "command.go",
        "context.go",
        "errors.go",
        "flag.go",
        "flag_generated.go",
        "funcs.go",
        "help.go",
    ],
    importpath = "gopkg.in/urfave/cli.v2",
    visibility = ["//visibility:public"],
)
➜ cat vendor/gopkg.in/yaml.v2/BUILD.bazel
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
    name = "go_default_library",
    srcs = [
        "apic.go",
        "decode.go",
        "emitterc.go",
        "encode.go",
        "parserc.go",
        "readerc.go",
        "resolve.go",
        "scannerc.go",
        "sorter.go",
        "writerc.go",
        "yaml.go",
        "yamlh.go",
        "yamlprivateh.go",
    ],
    importpath = "gopkg.in/yaml.v2",
    visibility = ["//visibility:public"],
)

@jayconrod
Copy link
Contributor

Reproduced. This is a problem with the rules, not Gazelle. It only fails with -c dbg. Not sure what's causing that yet.

ianthehat added a commit to ianthehat/rules_go that referenced this issue Nov 8, 2017
Use the deps, not the direct dependancies of the deps
Fixes reported in person issue with pure="on"

Get the toolchain_flags from the rule not the aspect
Fixes bazelbuild#993
ianthehat added a commit to ianthehat/rules_go that referenced this issue Nov 8, 2017
Use the deps, not the direct dependancies of the deps
Fixes reported in person issue with pure="on"

Get the toolchain_flags from the rule not the aspect
Fixes bazelbuild#993
ianthehat added a commit that referenced this issue Nov 9, 2017
Use the deps, not the direct dependancies of the deps
Fixes reported in person issue with pure="on"

Get the toolchain_flags from the rule not the aspect
Fixes #993
@excavador
Copy link
Author

Still have problem.

➜ dlv attach 48440
could not attach to pid 48440: decoding dwarf section info at offset 0x0: too short

build with "-c dbg" works, but delve can not attach

Can you please reopen bug?

@excavador
Copy link
Author

@ianthehat @jayconrod can you please re-open bug?
Original problem still actual

@ianthehat
Copy link
Contributor

I can't reproduce the problem, I can correctly debug a binary built using -c dbg on osx using dlv exec and list all the symbols now.

@excavador
Copy link
Author

excavador commented Nov 9, 2017

@ianthehat interesting. After clean --expunge problem was solved.

Sorry for stupid question, but what the difference between plain build and build with "-c dbg"?
Just strip debug symbol?

Would be ok if I add "build -c dbg" to tools/bazel.rc or some unobvious consequences exist?

@excavador
Copy link
Author

@ianthehat @jayconrod by the way, documentation about "-c" option missed:
https://docs.bazel.build/versions/master/command-line-reference.html#build

What does this option mean?

@ianthehat
Copy link
Contributor

-c is the short form of --compilation_mode

in debug mode we disable stripping and also inlining (you can control just stripping with --strip instead)
I would not recommend putting it in tools/bazel.rc. It would work, but that file is intended to be checked in, and you probably don't want to force everyone to build slow large binaries.

Note that you can also use --run_under

bazel-run -c dbg --run_under='dlv exec' //my:binary

where bazel-run is the bazel run wrapper script you can get using

curl --output bazel-run https://raw.githubusercontent.com/bazelbuild/bazel/master/scripts/bazel-run.sh && chmod +x bazel-run

and that's nice and easy to alias to bazel-dlv or something

@excavador
Copy link
Author

excavador commented Nov 9, 2017

I would not recommend putting it in tools/bazel.rc. It would work, but that file is intended to be checked in, and you probably don't want to force everyone to build slow large binaries.
Otherwise I would not able to analyze core-dumps from production installation

@ianthehat
Copy link
Contributor

I would strongly recommend that for building production binaries you are using --bazelrc and --nomaster_bazelrc and controlling every argument explicitly on your release builder bots, not relying on the default bazel rc files.

If you are willing to bear the cost of debug binaries for the benefits of debuggable servers, then that is fine, and you should add -c dbg to your release building scripts.

@excavador
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants