Cannot set arguments for go app during debugging - go

I'm trying to debug my goland app and have some problems with launch.json file. My app should be run with argument: my_go_app -c path_to_config.
My launch.json looks like:
{
// 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": "Launch my go app",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"args": ["-c /home/roman/projects/myapp/some.json"]
}
]
}
But when I debug app I have received the following error:
flag provided but not defined: -c /home/roman/projects/myapp/some.json
Usage of /tmp/__debug_bin542579318:
-c string
Specify the configuration file. (default "config.json")
Without debugging my app runs with success. Please explain what is wrong...

I have found where is problem. The json should be like this:
{
// 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": "Launch my go app",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"args": ["-c", "/home/roman/projects/myapp/some.json"]
}
]
}

Related

vscode can't find delve even though environment variables are set in launch.json

My launch.json:
{
// 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": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/checkers/x/checkers/keeper",
"args": [
],
"env": {"GOPATH":"/home/alain/go", "PATH":"/home/alain/go/bin", "GO15VENDOREXPERIMENT": 1}
}
]
}
The dlv binary is in /home/alain/go/bin and works perfectly. Even outside of that directory it works.
However, when trying to launch debuggin in vscode, I am still getting the error:
Failed to continue "Cannot find delve debugger. Install from https://github.com/go-delve/delve & ensure it is in your Go tools path, "GOPATH/bin" or "PATH"
For reference: I did install delve from https://github.com/go-delve/delve

VSCode Debugger: Debugger could not find file .go file

I'm trying to debug my program in VSCode. My Launch.json file looks as follows:
{
// 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": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/DS_PA1/srunner/",
"cwd" : "${workspaceFolder}/DS_PA1/srunner/"
}
]
}
My folder hierarchy is:
The debugger is set in the function main():
On launching, it starts the server and without stopping at the breakpoint it just printed the statement "Started KeyValueServer..."
Any pointers as to how I can make it stop at func main() so that I can debug manually?

VSCode Launch File Debug Configuration for Different Files

I am using VSCode to debug my Python files. I have two scripts, let's say a.py and b.py. These two files work with differents args. I would like to configure launch.json in such a way that, if I run a.py, it should input its corresponding args and same for other files. However, there is no if statement in launch file. And if I write two configurations, it just runs them sequentially. What should my launch.json look like? Here is my first attempt.
{
// 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": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${WorkspaceFolder}/src/data_processing/main.py",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"args": [
"/home/gokberk/Desktop/filtered_data",
"--gdc",
"gdc-client",
"--no-download",
"--manifest",
"/home/gokberk/Desktop/filtered_data/gdc_manifest.2021-05-26.txt",
"--source-slides-folder",
"/home/gokberk/Desktop/filtered_data"
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${WorkspaceFolder}/src/training.py",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"args": [
"--input-data-folder",
"/home/gokberk/Desktop/filtered_data",
"--alpha",
"0.2",
"--beta",
"0.2",
"--max-bag-size",
"50",
"--underlying-model-type",
"resnet18",
"--pretrained",
"--no-download",
"--source-slides-folder",
"/home/gokberk/Desktop/filtered_data"
]
}
]
}

Debugging Laravel application with Visual Studio Code opens up file listing

I'm trying to setup debugging environment for my Laravel application following this guide Debugging Laravel application on VSCode
However, all I get when I launch the debugger is a list of files displayed in Chrome, for some reason it is not launching index.php. How do I fix this?
Here's my launch.json
{
// 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",
"compounds": [
{
"name": "Launch & Debug",
"configurations": [
"Listen for Xdebug",
"Launch Chrome against localhost"
]
}],
"configurations": [
{
"type": "php",
"request": "launch",
"name": "Listen for Xdebug",
"cwd": "${workspaceRoot}/public",
"port": 9000
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5500/public",
"webRoot": "${workspaceFolder}/public",
"breakOnLoad": true
}
]
}

How do you configure visual studio code to run compiled Go code when using Run/Run&Debug (F5/CTRL+F5) VS code options?

I have installed the following task to compile my Go project following this blog post: https://robertbasic.com/blog/build-and-run-golang-projects-in-vs-code/
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Go",
"type": "shell",
"command": "go build",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Now I can compile the project using Terminal>Run build task
For running and debugging, I have created:
launch.json:
{
// 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": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"cwd": "${workspaceRoot}",
"args": [],
"env": {}
}
]
}
But it does not work, I get the following message:
package .: no Go files in /usr/home/username/projects/my_app/.vscode
Process exiting with code: 1 signal: false
Visual Studio Code under FreeBSD12.1 (probably not relevant).
What do I have to do to get the program running when using F5/CTRL+F5?
Any tip including recommended help section or blog entry is welcomed.
Assuming my main package is at the root folder of the workspace, I always define the same .vscode/launch.json:
{
// 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": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {},
"args": []
}
]
}
From there, I can press F5 from anywhere/any file, and the debug session simply starts.

Resources