I created a singularity image for arm development. I installed a singularity in my WSL.
I am going to code and debug at wsl,then move it to arm platform by using Cross compiler in my singularity.
How to use vscode to build my program (arm version)? Or how to use singularity integratly with vscode?
I tried to build my program with singularity shell,and it succeed.I have learnt something about vscode's task and launch,and build my program with wsl,but I dont know how to use them to bootup a singularity and then build my program.
To use Visual Studio Code (VSCode) to build your program for the ARM platform using a Singularity image, you will need to configure the tasks and launch settings in VSCode.
First, you will need to create a tasks.json file in the .vscode folder in your project directory. This file will define the command to run the build process using Singularity. The command would look something like this:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "singularity exec /path/to/your/image.sif arm-linux-gnueabihf-gcc -o main main.c",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
You will also need to configure the launch settings in launch.json. This file is used to configure how your program is executed. You can use the preLaunchTask field to specify the build task you created above, so that it runs before your program is launched:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "build"
}
]
}
Once you have configured the tasks and launch settings, you should be able to use the Tasks: Run Build Task command in VSCode to build your program using the Singularity image and the Cross compiler, and use the Debug: Start Debugging command to run and debug your program.
You can also use the vscode-singularity extension, which is a Singularity extension for VSCode. It allows you to manage Singularity images, containers and shells directly from VSCode.
Related
In a Python project, how do you tell the built-in VSCode debugger to step into the code of functions from other libraries on execution?
I know it is possible for functions implemented in standard libraries by adding a
"debugOptions": ["DebugStdLib"]
to your configuration in launch.json as specified here, however it does not seem to be possible to force the debugger to step into the code of non-standard modules, such as the ones you have written yourself and imported into the current file.
In order to improve the accepted answer by John Smith, it is worth mentioning that now the option has been renamed again. The new option is
"justMyCode": false
and as per the documentation
When omitted or set to True (the default), restricts debugging to
user-written code only. Set to False to also enable debugging of
standard library functions.
This is done by customising your debugger.
If you haven't already, you need to initialise the debugger customisation. You can do this by opening the debugger section in the side bar and selecting create a launch.json file.
Once this is done, a launch.json file will be created in a .vscode folder in your workspace.
Edit this file. It will look something like this:
{
...,
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
Add "justMyCode": false to the "Python: Current File" configuration, like this:
{
...,
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
}
]
}
True as of Visual Studio Code version 1.59.0.
Reference:
https://code.visualstudio.com/docs/python/debugging
A debugger configuration with
"debugOptions": ["DebugStdLib"]
added in launch.json in fact will step into user-defined and pip-installed modules, contrary to what's written in the main question.
Most of the time, I debug unit tests rather than the running application.
If that is also the case on your side and you use:
Visual Studio Code
pytest
The Python Test Explorer for Visual Studio Code (A test runner extension (adds a debug menu and provided debug buttons above tests directly in the IDE)) https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
Then use the following launch.json as mentionned in the plugin page:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug test",
"type": "python",
"request": "attach",
"console": "externalTerminal",
"justMyCode": false,
"stopOnEntry": true,
"envFile": "${workspaceFolder}/.env.test",
"purpose": ["debug-test"]
}
]
}
For those using the standard VSCode Debugger, a little more clarification on how to configure this in VS Code might be needed
Create Your Debugger Configuration As Follows
Open up your .vscode/launch.json
Add a configuration {} to the configurations list:
"configurations": []
This one will be recognized by the built-in VSCode Debugger:
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false
}
Key points:
purpose should be set to ["debug-test"]
"justMyCode": should be set to false.
References: Official VSCode Docs
The configurations in launch.json file as follows work for me.
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "test",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"purpose": ["debug-in-terminal"]
}
]
Would like to set up VS Code to work with Cygwin/Cygwin64.
Already have these set up:
Installed Cygwin64 on windows
Installed gcc (Compiler) and gdb (Debugger) packages from Cygwin installer
GCC and GDB are NOT in windows path.
Installed Visual Studio Code
Posting this because it took me a couple of days from multiple different sources to set this up.
This is specifically for Windows with Cygwin/Cygwin64 installed.
DISCLAIMER: I've only tested this for building single files.
Instructions here are for setting up on VS Code
Install the extension C/C++ on VS Code
Name: C/C++
Id: ms-vscode.cpptools
Description: C/C++ IntelliSense, debugging, and code browsing.
Version: 0.23.1
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
If you have a workspace already, skip this step.
Create a folder and add this folder into VS Code. Then save workspace.
Set up launch.json
Go to "Debug > Open Configurations", this should open the launch.json file. Below is my configuration. If you're testing this and unsure of what you're doing, I suggest you save your original content somewhere before replacing things.
Note: "preLaunchTask": "gcc.exe build active file" runs the task labelled "gcc.exe build active file".
{
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "%PATH%;z:\\cygwin64\\bin"
}
],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": { "engineLogging": true }, //optional
"preLaunchTask": "gcc.exe build active file"
}
]
}
Set up task.json
Go to "Terminal > Configure Tasks..." and select "gcc.exe build active file"
The various "-W" flags in "args" are meant to make the compiler more strict. You can remove them if you'd like.
{
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:\\cygwin64\\bin\\gcc.exe",
"args": [
"-g",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-Werror", // Optional
"-Wall", // Optional
"-Wextra", // Optional
"-ansi", // Optional
"-pedantic", // Optional
"${file}"
],
"options": {
"cwd": "C:\\cygwin64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
],
"version": "2.0.0"
}
Build and Debug Active File
Go to the C file you want to build, press Ctrl+Shift+P for "Command Palette > C/C++ Build and Debug Active File > gcc.exe build active file" or if you only want to build then go to "Terminal > Run Build Task".
Cygwin64 is inefficient because it is using a medium memory model. This makes it use 64 bit absolute addresses instead of 32 bit relative addresses for static data.
I will recommend to use the Clang plugin for Visual Studio instead, unless you have a specific reason to use Cygwin64. See https://devblogs.microsoft.com/cppblog/clang-llvm-support-in-visual-studio/
You also get rid of the cygwin DLL when using the Clang plugin.
I have cloned libsass and sassc and compiled it manually using makefile to generate its executable. Everything works just fine But I need to debug the libsass library to do some changes. I am using VSCode in Mac.
For a simple helloworld program, when I configure launch.json to execute its executable, the breakpoint works just fine. But for sassc it is not working.
This is the launch.json file am using in VSCode. Should I make any changes in this or should I understand something else?
{
// 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": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/sassc/bin/sassc", //sassc.exe path
"args": ["${workspaceFolder}/ex/sample.scss","${workspaceFolder}/ex/sample.css"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
Edit:
I am using Mac and as per https://social.msdn.microsoft.com/Forums/en-US/ef99e9f5-2a48-423b-b6c0-fa5617d7c63d/how-do-i-get-c-to-work-on-visual-studio-for-mac?forum=visualstudiogeneral, C/C++ project is not yet supported in Mac Visual Studio and I am not gonna use VM. So either I had to use XCode or VSCode as per my knowledge and since VSCode is lightweight and I have worked with it before, I opted for VSCode. If you have any other suggestions, let me know.
I cannot figure out how to setup debugging in VS Code so I can serve the app with node in WSL. I am using:
Debugger for Chrome
React app created with create-react-app
Starting server in bash (WSL) via npm start
This works in that is launches a new browser window and the app is served, but I cannot set any break points. They all report Unverified breakpoint.
This is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "React",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}/src"
}
]
}
The problem seems related to webpack, but I can't figure out what I need to do differently.
I have also struggled with this problem and found a solution:
My Setup
Visual Studio Code 1.43.2
Debugger for Chrome 4.12.6
Visual Studio Code Remote - WSL 0.42.4
React Application (create-react-app)
NPM 6.13.7 running in WSL (npm start)
LOCAL => WSL
Use the following configuration in your launch.json if you have started your vscode instance locally (not using WSL) and want to connect to a NPM instance running in WSL.
{
"name": "chrome-localhost-local-to-wsl",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMapPathOverrides": {
"/mnt/c/*": "C:/*"
}
},
WSL => WSL
Use the following configuration in your launch.json if you have started your vscode instance via WSL (using the Visual Studio Code Remote - WSL extension) and want to connect to a NPM instance running in WSL.
{
"name": "chrome-localhost-wsl-to-wsl",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMapPathOverrides": {
"/mnt/c/*": "/__vscode-remote-uri__/mnt/c/*",
},
}
You might have to adjust the drive in both configurations. I am running everything from C:/dev so /mnt/c/* is perfectly fine for me. If you have your code located for example at D:/dev/demo/src you will have to use /mnt/d/*.
What helped me a lot to debug what is going on was the .script command of the Debugger for Chrome extension.
Update: It seems that something has changed recently in the integration of WSL, Chrome and VSCode so the sourceMapPathOverrides are not required anymore. We successfully use the following configuration now for our WSL Setup:
{
"name": "chrome-localhost-wsl-to-wsl",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
}
You just need to add a sourceMapPathOverrides to your launch.json. It ends up looking something like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": { "/mnt/c/*": "C:/*" }
}
]
}
I'm about 99% sure this cannot be done: run react app under linux (wsl) and try to debug in VS Code under Windows. The problem is that the source map created when you run the app in linux is using linux file names, but VS Code needs windows paths. The clue was in looking at the sources in dev tools. When run under linux, there were linux file paths.
Initial workaround is to just run app under windows and I'm happily debugging now. Longer term is to try out what Sung Kim suggested and try to just do my editing in WSL also.
I was hoping to try VSCode on the AngularJS tutorial, say step 1, and get debugging and building working.
I was able to get it running, but it's a bit of a hack and VSCode doesn't like it.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app\\js\\app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": "run.bat",
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
I get an "Error Connection failed" even though it is actually running in a separate command prompt window.
Is there a way to for VSCode to debug a simple application like this that only uses package.json start like this:
"start": "http-server -a 0.0.0.0 -p 8000"
Thanks,
Derek
Visual Studio Code supports only Node and Mono debugging, it does not support debugging client JavaScript in the browser.
If you want debug Javascript in the browser, use the browser tools. If you want try out node.js debugging support in VSCode. Start with a sample node.js or express app, then follow the direction in Visual Studio Code website on setting up debugging.
If you would like to see Visual Studio Code supporting debugging, you can vote it up in user voice.