I debug Golang application with breakpoints in VS Code.
Debugger complains that can't find file, which exists.
Does anyone of you know how to enable breakpoints for Go application in VS Code?
Debugger logs:
Debuggee is not running. Setting breakpoints without halting.
All cleared
Creating on: /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go:63
Creating on: /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go:84
All cleared
All set:[]
SetBreakPointsResponse
2021-10-21T12:52:17+02:00 debug layer=rpc <- RPCServer.CreateBreakpoint(rpc2.CreateBreakpointIn{"Breakpoint":{"id":0,"name":"","addr":0,"addrs":null,"file":"/home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go","line":63,"Cond":"","HitCond":"","continue":false,"traceReturn":false,"goroutine":false,"stacktrace":0,"LoadArgs":{"FollowPointers":true,"MaxVariableRecurse":1,"MaxStringLen":64,"MaxArrayValues":64,"MaxStructFields":-1},"LoadLocals":{"FollowPointers":true,"MaxVariableRecurse":1,"MaxStringLen":64,"MaxArrayValues":64,"MaxStructFields":-1},"WatchExpr":"","WatchType":0,"hitCount":null,"totalHitCount":0,"disabled":false}})
2021-10-21T12:52:17+02:00 debug layer=rpc -> *rpc2.CreateBreakpointOut{"Breakpoint":{"id":0,"name":"","addr":0,"addrs":null,"file":"","line":0,"Cond":"","HitCond":"","continue":false,"traceReturn":false,"goroutine":false,"stacktrace":0,"LoadArgs":null,"LoadLocals":null,"WatchExpr":"","WatchType":0,"hitCount":null,"totalHitCount":0,"disabled":false}} error: "could not find file /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go"
2021-10-21T12:52:17+02:00 debug layer=rpc <- RPCServer.CreateBreakpoint(rpc2.CreateBreakpointIn{"Breakpoint":{"id":0,"name":"","addr":0,"addrs":null,"file":"/home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go","line":84,"Cond":"","HitCond":"","continue":false,"traceReturn":false,"goroutine":false,"stacktrace":0,"LoadArgs":{"FollowPointers":true,"MaxVariableRecurse":1,"MaxStringLen":64,"MaxArrayValues":64,"MaxStructFields":-1},"LoadLocals":{"FollowPointers":true,"MaxVariableRecurse":1,"MaxStringLen":64,"MaxArrayValues":64,"MaxStructFields":-1},"WatchExpr":"","WatchType":0,"hitCount":null,"totalHitCount":0,"disabled":false}})
2021-10-21T12:52:17+02:00 debug layer=rpc -> *rpc2.CreateBreakpointOut{"Breakpoint":{"id":0,"name":"","addr":0,"addrs":null,"file":"","line":0,"Cond":"","HitCond":"","continue":false,"traceReturn":false,"goroutine":false,"stacktrace":0,"LoadArgs":null,"LoadLocals":null,"WatchExpr":"","WatchType":0,"hitCount":null,"totalHitCount":0,"disabled":false}} error: "could not find file /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go"
2
Error on CreateBreakpoint: could not find file /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go
File exists:
gbajson#misio:~$ ls -l /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go
-rw-r--r-- 1 gbajson gbajson 2961 Oct 21 12:22 /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go
I already checked that it's not a problem with file permissions.
I also followed up the procedure for the lagacy version of dlv:
https://github.com/golang/vscode-go/blob/master/docs/debugging-legacy.md#selecting-legacy-debug-adapter
Debugger configuration
workspace.code-workspace
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Debug Go",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"debugAdapter": "legacy",
"env": {},
"args": [],
"showLog": true,
"logOutput": "rpc",
"trace": "log"
},
settings.json
{
"go.delveConfig": {
"debugAdapter": "legacy",
},
I found the problem. VS Code doesn't handle symbolic links well.
When I set up a project in VS Code in real path debugger started to work properly.
gbajson#misio:~$ realpath /home/gbajson/Sync/clickr/clickr-node-api/clickr-node-api.go
/storage/amoje/Sync/clickr/clickr-node-api/clickr-node-api.go
This problem is also described in: https://github.com/golang/vscode-go/issues/1677
Wanted to share my solution here.
After reading a few github issues vs-code-go, seems like the issue was a result of remotePath or substitutePath. After a few attempts, setting remotePath to "" finally did the trick.
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "",
"port": 40000,
"host": "<host>",
}
]
}
This is a follow-on from the answer by gbajson.
Symbolic links were the problem for me. Using this configuration in launch.json resolved the issue, while allowing me to keep my symlinks:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/server/main.go",
"envFile": "${workspaceFolder}/.env",
"substitutePath": [
{
"from": "/home/me/go-workspaces",
"to": "/data/projects/workspaces"
}
]
}
]
}
Specifically, it is the "substitutePath" part.
My workspace directory was actually symlinked from "/home/me/go-workspaces" to the real directory "/data/projects/workspaces".
See: https://github.com/golang/vscode-go/blob/master/docs/debugging.md#debugging-symlink-directories
You can use "sudo ps aux | fgrep {your process name}" to check your process.If it start more than 1 process, maybe you should change your process start mode without daemon process.
Related
I am not able to get debugging working on VSCode for a testing framework using WebdriverIO . Only this message is displayed: - Waiting for the debugger to disconnect.
However, I am able to get debugging up and running for a TS code one time. If I am starting my machine once, and then again, it is giving same issue as - Waiting for the debugger to disconnect.
Below is the launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"outputCapture": "std",
"name": "Launch Program",
"program": "${workspaceRoot}/node_modules/#wdio/cli/bin/wdio.js",
"args": ["${workspaceRoot}/build/main/config/wdio.conf.js"],
"preLaunchTask": null,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"resolveSourceMapLocations": [ //code to avoid 'Could not read sourcemaps' issues
"${workspaceFolder}/**",
"!**/node_modules/**"
]
}]
}
Console-log stack-trace:
C:\Program Files\nodejs\node.exe .\node_modules#wdio\cli\bin\wdio.js
C:\Automation\angular_ui-auto-framework/build/main/config/wdio.conf.js
Debugger attached. Execution of 1 workers started at
2022-12-21T15:25:32.199Z [2022-12-21 20:55:32:902] - DONE - File
'c:\Automation\angular_ui-auto-framework\src\osr_ui-automation\Results\testReport.json'
is deleted successfully Waiting for the debugger to disconnect...
I have faced similar problems with latest version of the vscode. I had to downgrade to nodejs 16lts and downgrade vscode to 1.57 and using below launch.json working fine so far.
{
"name": "Start Spec",
"type": "node",
"request": "launch",
"args": ["wdio.conf.js", "--spec", "${file}"],
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"program": "${workspaceRoot}/node_modules/#wdio/cli/bin/wdio.js",
"console": "integratedTerminal"
}
I'm new to VS Code. I got debugging with lldb working--for one day it worked great.
Then it began to malfunction, displaying the arrow several source statements away from the actual execution. I've tried several config changes using online guidance to no avail. I thought that maybe the debug database was messed up so I wanted to try to get it to regenerate, so moved the outDebug file aside. That did not cause it to be rebuilt.
I'm running this launch.json configuration:
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/rmv_ms",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"miDebuggerPath": "/usr/bin/lldb",
"preLaunchTask": "clang build active file"
},
and this in tasks.json:
"tasks": [
{
"label": "clang build active file",
"type": "shell",
"command": "/usr/bin/clang",
"args": [
"-std=c17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": { "kind":"build", "isDefault":true },
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},`enter code here`
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$gcc"
}
]
The latest behavior is that when I try to start debug session it displays a menu asking me what to attach to (whatever that means) but I don't even see my program listed.
I am a reccent deno user. Been using node for a long time, switched to deno and am very happy with it. It's really good
However, I have an issue.
Whenever I try to debug a deno file, the vscode debugger starts running for like half a second and then stops, and nothing happens.
It doesnt freeze or anything, it just starts for a moment and stops.
I am using this as launch configuration
{
"version": "0.2.0",
"configurations": [
{
"name": "Deno1",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"outputCapture": "std",
"runtimeArgs": ["run", "--inspect-brk", "-A", "${fileName}"],
"port": 9229,
}
]
}
I took it from this post
I should add that I was able to debug this file already, but one day it just started showing this issue i just described without (to my knowledge) any change on my part.
I am trying to debug this file
How can I fix this issue?
To make it work you need to add a "program" field to launch.json and move the path of the file there, which is briefly mentioned in this answer from the post you linked to. But also you need to change "port" to "attachSimplePort":
{
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Program",
"type": "node",
"program": "${workspaceFolder}/tests/grammar.test.ts",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--inspect-brk",
"--allow-all"
],
"attachSimplePort": 9229,
"outputCapture": "std",
}
]
}
To debug another part of the application just change the path in program, for example to an entrypoint file like main.ts. With --inspect-brk the debugger will first break at the first line of the program and then you can for example continue to a breakpoint with F5 or the continue button in the debugger panel.
(Deno v1.14)
I've set up a launch.json file such that a C++ program uses an external console (so that it can receive user inputs), but when launching, VSCode simply opens a terminal window without running the program in it. If "externalConsole": true, is set to false, the program runs and can be debugged fine, just can't take inputs.
Note: No task.json file is used, CMake is used to create the executable binary.
Launch file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/bin/program_bin",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/bin",
"environment": [],
"MIMode": "lldb",
"externalConsole": true,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
]
}
]
}
Is it possible that VSCode doesn't have 'permission' to run an external terminal? Using on MacOS.
I have the same issue. This may not be the working answer, but hopefully it will get us farther down the correct path.
I did some digging and found the following:
VS Code Documentation mentioned that it opens an external console via lldb-mi.
A search for lldb-mi led to this post on the Apple Developer forums.
...which leads to an open source Github Repo with a build of lldb-mi
I need to read through the documentation for that build first, and then I'll give it a shot. I'll post results if it solves the issue.
I've tried to use standard (recomended ways of debugging from vscode documentation) and ran into the same issues with external terminal.
I'm also using mac and switching to CodeLLDB plugin to use LLDB for debugging helped
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
just follow documentation: https://github.com/vadimcn/vscode-lldb/blob/v1.8.1/MANUAL.md
But as a hint here is my working setup:
(I couldn't though make it work on windows, but I'm running windows via Parallel II, so maybe natively this plugin will work too)
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/g++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
{
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
// "stdio": ["input.txt", null, null], // https://github.com/vadimcn/vscode-lldb/blob/v1.8.1/MANUAL.md#stdio-redirection
"cwd": "${fileDirname}",
"preLaunchTask": "C/C++: clang build active file" // this have to be the same as "label" in tasks.json
}
],
"version": "2.0.0"
}
just make sure you have all tools available, check by running in cli:
/usr/bin/clang --version
# and
lldb --version
good luck
I'm trying to debug a revel app with visual studio but I can't get it to work.
I've seen this question how to debug revel framework(golang) application in visual studio code(vscode) but no answers yet...
I've tried with this config:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "~/code/go/bin/revel",
"env": {},
"args": [],
"showLog": true
}
]
}
But I'm getting this error:
Failed to continue: "The program attribute must point to valid directory, .go file or executable."
I think it must be the rebel binary the one to be run here, but I don't know how to pass the app path, should it go in "args"?
Yes it's possible.
Suppose that the GOPATH is C:\Work\golang
Revel project name is myapp, thus the location of the project (workspace) will be C:\Work\golang\src\myapp.
Make some changes to the controllers etc...
Run the application with revel run myapp, then press CTRL+C to exit. This step is necessary to generate corresponding go files. The generated file, i.e. the main package will be available under ${workspaceRoot}/app/tmp/main.go
Configure launch.json as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"env": {},
"showLog": true,
"program": "${workspaceRoot}/app/tmp/",
"args": ["-importPath", "myapp", "-srcPath", "c:\\work\\golang\\src", "-runMode", "dev"]
}
]
}
The important parts are program and args parameters, while the other parameters are unmodified.
Set breakpoint and start the delve debugger...
EDIT:
Setting args parameter to ["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"] also work, and I think this should work in other platforms (Mac, Linux) too.
The error message is related to delve issue. See https://github.com/Microsoft/vscode-go/issues/986