[vscode-go] debugging.md: note that 'go build', not 'go run' must be used with dlv

626 views
Skip to first unread message

Gerrit Dou (Gerrit)

unread,
Dec 29, 2021, 4:10:52 AM12/29/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Dou has uploaded this change for review.

View Change

debugging.md: note that 'go build', not 'go run'  must be used with dlv

Updates https://github.com/go-delve/delve/issues/2844

Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
GitHub-Last-Rev: 06fe6868bb2110d6238953244a93d7e9e0543ef4
GitHub-Pull-Request: golang/vscode-go#1982
---
M docs/debugging.md
1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/docs/debugging.md b/docs/debugging.md
index 4019f80..9366604 100644
--- a/docs/debugging.md
+++ b/docs/debugging.md
@@ -84,8 +84,9 @@
* Supported modes
* `debug`: build and debug a main package
* `test`: build and debug a test
- * `exec`: debug a precompiled binary. The binary needs to be built with `-gcflags=all="-N -l"` flags to avoid stripping debugging information.
- * `auto`: automatically choose between `debug` and `test` depending on the open file.
+ * `exec`: debug a precompiled binary
+ * The binary must be built with `go build -gcflags=all="-N -l"` to disable inlining and optimizations that can interfere with debugging.
+ * `auto`: automatically choose between `debug` and `test` depending on the open file

⚠️ If a `port` attribute is added to any of the launch configurations, it will signal VS Code that instead of launching the debug server internally, it should connect to an external user-specified `dlv dap` server at `host:port` and launch the target there. See ["Remote Debugging"](#remote-debugging) for more details).

@@ -97,6 +98,7 @@

* Supported modes
* `local`: attaches to a local process
+ * The binary must be built with `go build -gcflags=all="-N -l"` to disable inlining and optimizations that can interfere with debugging.
* `remote`: attaches to an in-progress debug session run by an external server

You can debug an already running program using the `local` mode type configuration. The Go extension will start `dlv-dap` and configure it to attach to the specified process. Users can select the process to debug with one of the following options:
@@ -420,7 +422,7 @@
$ dlv-dap dap --listen=:12345
```

-Use the following `launch` configuration to tell `dlv-dap` to execute a binary precompiled with `-gcflags='all=-N -l'`:
+Use the following `launch` configuration to tell `dlv-dap` to execute a binary precompiled with `go build -gcflags='all=-N -l'`:

```json5
{
@@ -504,6 +506,11 @@
### Debug sessions started with the "debug test" CodeLens or the test UI does not use my `launch.json` configuration.

The "debug test" CodeLens and the [test UI](https://github.com/golang/vscode-go/blob/master/docs/features.md#test-and-benchmark) do not use the `launch.json` configuration ([Issue 855](https://github.com/golang/vscode-go/issues/855)). As a workaround, use the `go.delveConfig` setting and the `go.testFlags` setting. Please note that these all apply to all debug sessions unless overwritten by a specific `launch.json` configuration.
+
+### Why can't I use local attach with a process started with `go run`?
+
+Unlike `go build`, `go run` passes `-s -w` to the linker to strip the debug info. If you try attach to such a binary with a debugger, it will fail an error like `decoding dwarf section info at offset 0x0: too short`. Use `go build -gcflags='all=-N -l'` to build your binary instead. See Go Issue [24833](https://github.com/golang/go/issues/24833) for more information.
+
## Reporting Issues

When you are having issues in `dlv-dap` mode, first check if the problems are reproducible after updating `dlv-dap`. It's possible that the problems are already fixed. Follow the instruction for [updating dlv-dap](#updating-dlv-dap)) and [updating extension](https://code.visualstudio.com/docs/editor/extension-gallery#\_extension-autoupdate).

To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
Gerrit-Change-Number: 374674
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
Gerrit-MessageType: newchange

Gerrit Dou (Gerrit)

unread,
Dec 29, 2021, 4:17:23 AM12/29/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Dou uploaded patch set #2 to this change.

View Change

debugging.md: note that 'go build', not 'go run'  must be used with dlv

Updates go-delve/delve#2844


Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
GitHub-Last-Rev: 06fe6868bb2110d6238953244a93d7e9e0543ef4
GitHub-Pull-Request: golang/vscode-go#1982
---
M docs/debugging.md
1 file changed, 23 insertions(+), 3 deletions(-)

To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
Gerrit-Change-Number: 374674
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Dou (Gerrit)

unread,
Dec 29, 2021, 4:28:13 AM12/29/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Hyang-Ah Hana Kim.

Gerrit Dou uploaded patch set #3 to this change.

View Change

debugging.md: note that 'go build', not 'go run'  must be used with dlv

Updates go-delve/delve#2844

Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
GitHub-Last-Rev: 692327cdf92c67997d979ea9fee90f25c851997f

GitHub-Pull-Request: golang/vscode-go#1982
---
M docs/debugging.md
1 file changed, 23 insertions(+), 3 deletions(-)

To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
Gerrit-Change-Number: 374674
Gerrit-PatchSet: 3
Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Suzy Mueller <suz...@golang.org>
Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Dou (Gerrit)

unread,
Dec 29, 2021, 4:35:56 AM12/29/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Hyang-Ah Hana Kim.

Gerrit Dou uploaded patch set #4 to this change.

View Change

debugging.md: note that 'go build', not 'go run'  must be used with dlv

Updates go-delve/delve#2844

Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
GitHub-Last-Rev: a64cb34ca857bf96188c3e836121dc3323d2ba82

GitHub-Pull-Request: golang/vscode-go#1982
---
M docs/debugging.md
1 file changed, 23 insertions(+), 3 deletions(-)

To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
Gerrit-Change-Number: 374674
Gerrit-PatchSet: 4

Hyang-Ah Hana Kim (Gerrit)

unread,
Dec 29, 2021, 11:40:08 AM12/29/21
to Gerrit Dou, goph...@pubsubhelper.golang.org, Hyang-Ah Hana Kim, Suzy Mueller, Gopher Robot, golang-co...@googlegroups.com

Patch set 4:Code-Review +2

View Change

1 comment:

  • File docs/debugging.md:

    • Patch Set #4, Line 88: must be built with `go build -gcflags=all="-N -l"`

      Weird that people attempt to debug a binary running with go run :-(
      Strictly speaking, binaries built with bazel, blaze, or other build systems can be debugged by supplying the gcflags.

To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
Gerrit-Change-Number: 374674
Gerrit-PatchSet: 4
Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Suzy Mueller <suz...@golang.org>
Gerrit-Comment-Date: Wed, 29 Dec 2021 16:40:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Ian Lance Taylor (Gerrit)

unread,
Dec 29, 2021, 1:30:07 PM12/29/21
to Gerrit Dou, goph...@pubsubhelper.golang.org, Hyang-Ah Hana Kim, Suzy Mueller, Gopher Robot, golang-co...@googlegroups.com

Patch set 4:Trust +1

View Change

    To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: vscode-go
    Gerrit-Branch: master
    Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
    Gerrit-Change-Number: 374674
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Suzy Mueller <suz...@golang.org>
    Gerrit-Comment-Date: Wed, 29 Dec 2021 18:30:02 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Polina Sokolova (Gerrit)

    unread,
    Dec 29, 2021, 3:45:46 PM12/29/21
    to Gerrit Dou, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Hyang-Ah Hana Kim, Suzy Mueller, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Hyang-Ah Hana Kim.

    View Change

    1 comment:

    • File docs/debugging.md:

      • Weird that people attempt to debug a binary running with go run :-( […]

        Hmm, I see your point. We could add something like "or another compatible build system"? But then this already long note will get even longer.

    To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: vscode-go
    Gerrit-Branch: master
    Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
    Gerrit-Change-Number: 374674
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Polina Sokolova <pol...@google.com>
    Gerrit-CC: Suzy Mueller <suz...@golang.org>
    Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Comment-Date: Wed, 29 Dec 2021 20:45:34 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-MessageType: comment

    Hyang-Ah Hana Kim (Gerrit)

    unread,
    Dec 29, 2021, 3:52:41 PM12/29/21
    to Gerrit Dou, goph...@pubsubhelper.golang.org, Polina Sokolova, Ian Lance Taylor, Hyang-Ah Hana Kim, Suzy Mueller, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Polina Sokolova.

    View Change

    1 comment:

    • File docs/debugging.md:

      • Hmm, I see your point. […]

        Let's just go with your current version. It looks like people are so creative that it's impossible to enumerate all the possibilities and exceptions people would encounter. We explicitly cover here the case we verified working - so it's an improvement.

    To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: vscode-go
    Gerrit-Branch: master
    Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
    Gerrit-Change-Number: 374674
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Polina Sokolova <pol...@google.com>
    Gerrit-CC: Suzy Mueller <suz...@golang.org>
    Gerrit-Attention: Polina Sokolova <pol...@google.com>
    Gerrit-Comment-Date: Wed, 29 Dec 2021 20:52:36 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Hyang-Ah Hana Kim <hya...@gmail.com>
    Comment-In-Reply-To: Polina Sokolova <pol...@google.com>
    Gerrit-MessageType: comment

    Polina Sokolova (Gerrit)

    unread,
    Dec 29, 2021, 4:32:56 PM12/29/21
    to Gerrit Dou, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Ian Lance Taylor, Hyang-Ah Hana Kim, Suzy Mueller, Gopher Robot, golang-co...@googlegroups.com

    Polina Sokolova submitted this change.

    View Change


    Approvals: Hyang-Ah Hana Kim: Looks good to me, approved Ian Lance Taylor: Trusted
    debugging.md: note that 'go build', not 'go run'  must be used with dlv

    Updates go-delve/delve#2844

    Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
    GitHub-Last-Rev: a64cb34ca857bf96188c3e836121dc3323d2ba82
    GitHub-Pull-Request: golang/vscode-go#1982
    Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/374674
    Reviewed-by: Hyang-Ah Hana Kim <hya...@gmail.com>
    Trust: Ian Lance Taylor <ia...@golang.org>
    ---
    M docs/debugging.md
    1 file changed, 26 insertions(+), 3 deletions(-)

    diff --git a/docs/debugging.md b/docs/debugging.md
    index 051b019..b51ffea 100644

    --- a/docs/debugging.md
    +++ b/docs/debugging.md
    @@ -84,8 +84,9 @@
    * Supported modes
    * `debug`: build and debug a main package
    * `test`: build and debug a test
    - * `exec`: debug a precompiled binary. The binary needs to be built with `-gcflags=all="-N -l"` flags to avoid stripping debugging information.
    - * `auto`: automatically choose between `debug` and `test` depending on the open file.
    + * `exec`: debug a precompiled binary
    +        * The binary must be built with `go build -gcflags=all="-N -l"` to disable inlining and optimizations that can interfere with debugging.

    + * `auto`: automatically choose between `debug` and `test` depending on the open file

    ⚠️ If a `port` attribute is added to any of the launch configurations, it will signal VS Code that instead of launching the debug server internally, it should connect to an external user-specified `dlv dap` server at `host:port` and launch the target there. See ["Remote Debugging"](#remote-debugging) for more details).

    @@ -97,6 +98,7 @@

    * Supported modes
    * `local`: attaches to a local process
    +        * The binary must be built with `go build -gcflags=all="-N -l"` to disable inlining and optimizations that can interfere with debugging.

    * `remote`: attaches to an in-progress debug session run by an external server

    You can debug an already running program using the `local` mode type configuration. The Go extension will start `dlv-dap` and configure it to attach to the specified process. Users can select the process to debug with one of the following options:
    @@ -420,7 +422,7 @@
    $ dlv-dap dap --listen=:12345
    ```

    -Use the following `launch` configuration to tell `dlv-dap` to execute a binary precompiled with `-gcflags='all=-N -l'`:
    +Use the following `launch` configuration to tell `dlv-dap` to execute a binary precompiled with `go build -gcflags='all=-N -l'`:

    ```json5
    {
    @@ -504,6 +506,11 @@
    ### Debug sessions started with the "debug test" CodeLens or the test UI does not use my `launch.json` configuration.

    The "debug test" CodeLens and the [test UI](https://github.com/golang/vscode-go/blob/master/docs/features.md#test-and-benchmark) do not use the `launch.json` configuration ([Issue 855](https://github.com/golang/vscode-go/issues/855)). As a workaround, use the `go.delveConfig` setting and the `go.testFlags` setting. Please note that these all apply to all debug sessions unless overwritten by a specific `launch.json` configuration.
    +
    +### Why can't I use local attach with a process started with `go run`?
    +
    +Unlike `go build`, `go run` passes `-s -w` to the linker to strip the debug info. If you try attach to such a binary with a debugger, it will fail an error like `decoding dwarf section info at offset 0x0: too short`. Use `go build -gcflags='all=-N -l'` to build your binary instead. See Go Issue [24833](https://github.com/golang/go/issues/24833) for more information.
    +
    ## Reporting Issues

    When you are having issues in `dlv-dap` mode, first check if the problems are reproducible after updating `dlv-dap`. It's possible that the problems are already fixed. Follow the instruction for [updating dlv-dap](#updating-dlv-dap)) and [updating extension](https://code.visualstudio.com/docs/editor/extension-gallery#\_extension-autoupdate).

    To view, visit change 374674. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: vscode-go
    Gerrit-Branch: master
    Gerrit-Change-Id: I1886c63e5eb1acc7ac48072b68239770367acf87
    Gerrit-Change-Number: 374674
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Dou <letsus...@gmail.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Polina Sokolova <pol...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Suzy Mueller <suz...@golang.org>
    Gerrit-MessageType: merged
    Reply all
    Reply to author
    Forward
    0 new messages