How to target platforms with launch.json - windows

The omnisharp ReadMe says this:
Operating System Specific Configurations
If there specific commands
that need to be changed per operating system, you can use the fields:
'windows', 'osx', or 'linux'. You can replace any of the fields
mentioned above for the specific operating system.
This is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
"args": [
"c:\\git\\core\\XunitTestLib\\Steps\\",
// "~/../../XunitTestLib/Steps"
],
"cwd": "${workspaceFolder}/TestConsole",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}
When debugging I want to builds on Windows to start with the "args" entry which is uncommented, but on mac os I want it to start with the line which is commented out.
I am assuming that I would duplicate the configuration, once for Windows and mac, each, but this statement is confusing:
You can replace any of the fields mentioned above for the specific operating system.
It appears to be saying that I can replace "args" with "osx" but that obviously does not work.
How do I create a configuration for a target platform?

Turns out that targeting multiple platforms is a lot easier than I expected and is explained here with regards to the tasks.json file (but works just the same for launch.json).
My launch.json file adjusted for osx and windows would look like this:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
"windows": {
"args": [
"c:\\git\\core\\XunitTestLib\\Steps\\"
]
},
"osx": {
"args": [
"~/../../XunitTestLib/Steps"
]
},
"cwd": "${workspaceFolder}/TestConsole",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}

Related

Unable to debug Golang on Vscode M1 Mac (arm64)

I have an M1 mac and cannot invoke functions via DLV in VSCode.
Unable to evaluate expression: backend does not support function calls
Delve Debugger
Version: 1.8.2
❯ go version ─╯
go version go1.18 darwin/arm64
What am I missing?
Launch.JSON file
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${file}",
"env": {
"PATH": "/usr/local/go/bin:${fileDirname}"
},
"args": []
}
]
}
From Delve (May 2022):
Support for calling functions on ARM64 has landed! https://github.com/go-delve/delve/pull/2996
Requires Go & Delve built from source with the latest changes.
Call functions from a debug session on ARM64 CPUs, including the Apple M1!
Note: Support function call injection on arm64 with Go 1.19 (CL 395754, as noted in issue 2277), so you will need to wait for Q4 2022.
The following json works for me-
{
"version": "0.2.0",
"configurations": [
{
"name": "DEV",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {
"ENV_SERVERADDRESS": "0.0.0.0:7171",
}
}
]
}
On an M1:
{
// 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": "Debug normal",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}",
"env": {},
"args": []
},
{
"name": "Debug arg=migrate",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}",
"env": {},
"args": [
"migrate"
]
}
]
}
Which Go version?
Did you install delve with that version?

Ctrl+D (EOF) in debug mode VSCode

Version: 1.62.0
Commit: b3318bc0524af3d74034b8bb8a64df0ccf35549a
Date: 2021-11-04T20:38:29+02:00
Electron: 13.5.1
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
ОС: Solus 4.3 Fortitude, Linux x64 5.14.16-204.current
There is a program written in D.
In the loop, a string is fed to the input, read and further execution of the algorithm takes place.
When running in normal mode, the program works without any problems.
When running in debug mode, I can't continue running the program because it hangs on the input process. I can't continue executing my code after pressing "Enter".
My launch.json:
"version": "0.2.0",
"configurations": [
{
"type": "gdb",
"request": "launch",
"name": "Launch Program",
"target": "./lesson_2/bin/lesson_2",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
}
]
I tried to connect an external terminal, but it didn't work out.
Did so:
"version": "0.2.0",
"configurations": [
{
"type": "gdb",
"request": "launch",
"name": "Launch Program",
"target": "./lesson_2/bin/lesson_2",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText",
"console": "externalTerminal",
"debugOptions": [
"RedirectOutput"
]
}
]
And that's it:
"version": "0.2.0",
"configurations": [
{
"type": "gdb",
"request": "launch",
"name": "Launch Program",
"target": "./lesson_2/bin/lesson_2",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText",
"externalConsole": true
}
]
I also tried adding this option, but nothing has changed:
"console": "integratedTerminal"
I use Native debug.
In general, I don't know what to do. I ask for help.

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"
]
}
]
}

Visual Studio Code Python Debugger Windows

I seem to be missing something simple, but I can't figure out why I am unable to debug python using Visual Studio Code on Windows. I've tried setting up the debugger as shown by Microsoft, and this youtube video. I've done a clean install of Visual Studio Code (including the python extension) and Python 3.6. I have no other python versions installed. I keep getting the following errors in the Python Debugger:
cd "c:\Users\xxx\Documents\Python Scripts" ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\python.exe" "C:\Users\xxx\.vscode\extensions\ms-python.python-2018.3.1\pythonFiles\PythonTools\visualstudio_py_launcher.py" "c:\Users\xxx\Documents\Python Scripts" 53746 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput "c:\Users\xxx\Documents\Python Scripts\.vscode\launch.json"
-bash: cd: c:\Users\xxx\Documents\Python Scripts: No such file or directory
env: ‘C:\\Users\\xxx\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe’: No such file or directory
It's complaining that it can't find the python.exe file, but it clearly can since VS code indicates that it's attached:
My launch.json file is the default, and I've tried all the configurations:
// 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": "${file}"
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"port": 3000,
"secret": "my_secret",
"host": "localhost"
},
{
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Terminal (external)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"debugOptions": [
"RedirectOutput",
"Django"
]
},
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "${workspaceFolder}/app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
]
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "module.name"
},
{
"name": "Python: Pyramid",
"type": "python",
"request": "launch",
"args": [
"${workspaceFolder}/development.ini"
],
"debugOptions": [
"RedirectOutput",
"Pyramid"
]
},
{
"name": "Python: Watson",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/console.py",
"args": [
"dev",
"runserver",
"--noreload=True"
]
},
{
"name": "Python: All debug Options",
"type": "python",
"request": "launch",
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"module": "module.name",
"env": {
"VAR1": "1",
"VAR2": "2"
},
"envFile": "${workspaceFolder}/.env",
"args": [
"arg1",
"arg2"
],
"debugOptions": [
"RedirectOutput"
]
}
]
}
Pylinting works fine, and I have not custom user settings in Visual Studio Code that are related to python. I've tried setting the complete file path to python.exe in settings.json but it makes no difference.
Any help is greatly appreciated. Thanks in advance
I had the same problem but finally got out of it after several adjustment to my settings.
make sure all other settings are in place as you've mentioned especially pythonPath in settings.json and also get "python" installed from the "extension" toolbar in VS code.
Simply change your debug configuration from "Python: Scripts" (or any other configuration you've selected previously) to "Python: Terminal(external)" and you are good to go!
I know, is a pain and I'm experiencing the same.
Apparently python.exe is executing correctly. You will keep seeing that banner because "This is necessary to bootstrap the debugger."
At least this is what Microsoft says.

Debugging with Visual Studio Code on OSX Not Working Without Manual Path

I'm trying to debug a dotnet core project on OSX and keep getting a reference error that it cant find the required library.
A fatal error was encountered. The library 'libhostpolicy.dylib' required to execute the application was not found in '/Users/Chris/Google Drive/Repos/project/src/project.api/bin/Debug/netcoreapp1.0'.
WARNING: The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use Microsoft.NETCore.App 1.0.0 or newer. This may be expected if the target process did not run .NET code.
The program '/Users/Chris/Google Drive/Repos/project/project.api/src/project.api/bin/Debug/netcoreapp1.0/project.api.dll' has exited with code 131 (0x00000083).
So I looked in the bin directory and noticed there's an additional directory under netcoreapp1.0 called osx.10.11-x64.
In my launch.json if I add that manually to the program path everything works - I was just wondering if that's normal and if the runtime could be picked up dynamically so I don't have to change the program path for different machines I work on (windows, nix, osx)
Here's a copy of launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/src/project.api/bin/Debug/netcoreapp1.0/osx.10.11-x64/project.api.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}

Resources