0

I am trying to debug this project

I am using visual studio code, and have the Go extension setup. I am able to set a breakpoint in the main function and debug it, but I never see the visual command prompt. I used Delve, ran the exe that the project produces, and attached. This allowed me to debug it, but I would prefer to debug it in vscode.

I tried using this vscode debug configuration:

    {
        "name": "Launch file",
        "type": "go",
        "request": "attach",
        "mode": "exec",
        "program": "${workspaceFolder}/lazygit.exe"
    },

and it is successful. But again, I cannot see the actual command window and actually use the project.

Is there any way to attach to an already open process in vscode, like in delve, or for vscode to launch the exe in a command window?

Matthew Mallimo
  • 361
  • 2
  • 8

3 Answers3

1

You are using the .exe file for debugging the code. Use the raw code to denug the application. Also there is a debug console where you can see the output when debugging using breakpoints or in case of any error. The configurations for launch.json should be:

{
    "name": "Launch",
    "type": "go",
    "request": "launch",
    "mode": "debug",
    "remotePath": "",
    "port": 2345,
    "host": "127.0.0.1",
    "program": "${workspaceFolder}",
    "env": {},
    "args": [],
    "showLog": true
}

Debug console will show the output of debugging and stdout:

enter image description here

Himanshu
  • 12,071
  • 7
  • 46
  • 61
  • I have tried this already. The application I am trying to debug uses a gui in the console. When I look at the debug console using this configuration that gui does not appear. That is why I was trying to attach to the exe. Any other suggestions? – Matthew Mallimo Aug 07 '18 at 18:05
  • @MatthewMallimo you can only debug the source code which is raw code. There is no way you can debug working gui application. Try to run the main file of project this will run the project with gui and then create breakpoints on the code. – Himanshu Aug 07 '18 at 18:07
0

Make sure you disable the compiler optimization in your go build command. It should be something like:

go build -gcflags="all=-N -l"
Machavity
  • 30,841
  • 27
  • 92
  • 100
0

I had a similar problem trying to debug an application that generated some kind of UI in the terminal. I managed to get the effect that after starting the debugger from VSCode, the program compiled and ran in a separate console, allowing me to test UI rendering and IO operations. My lanuch.json looks like this:

"version": "0.2.0",
    "configurations": [
        {
            // Other not related properties...
    
            "request": "launch",
            "mode": "debug",
            "console": "externalTerminal" // The important one
        }
    ]
Krzysztofz01
  • 432
  • 5
  • 13