-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add documentation for WSL #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Windows 10's Windows Subsystem for Linux | ||
| With the release of Windows 10 Creators Update, you will now be able to use Visual Studio Code and the Microsoft C/C++ extension to debug your `Windows Subsystem for Linux (WSL)` [Bash on Ubuntu](https://msdn.microsoft.com/en-us/commandline/wsl/about) projects. | ||
|
|
||
| Code can be written on Windows itself using VSCode and debugged through `bash.exe` to the Bash on Windows layer. | ||
|
|
||
| **NOTE: Creator's Update is required due to bugfixes within the subsystem that we rely on to provide debugging. Debugging using a previous version of WSL is unsupported and likely will not work.** | ||
|
|
||
| ## Prerequisites | ||
| * [Windows 10 Creators Update with Windows Subsystem for Linux and Bash](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide) installed. | ||
| * Install g++/gcc and gdb within `WSL` to allow compiling and debugging. You can use the package manager to do this. For example, to install g++, you can run `sudo apt install g++` in the Bash window. | ||
| * [Visual Studio Code](https://code.visualstudio.com) + Microsoft C/C++ extension for VSCode. | ||
|
|
||
| ## How-To | ||
| To debug, commands will be routed from Windows through `bash.exe` to set up debugging. Because our extension runs as a 32-bit process, it will need to use the `C:\Windows\SysNative` folder to access the `bash.exe` executable that is normally in `C:\Windows\System32`. We will be using the `"pipeTransport"` ability within the extension to do debugging and `"sourceFileMap"` to map the source from the subsystem's paths back to Windows path. | ||
|
|
||
| **NOTE: Applications will need to be compiled in the `Windows Subsystem for Linux (WSL)` prior to debugging.** | ||
|
|
||
| ### Example `launch.json` for Launching | ||
|
|
||
| In the following example, I have a local drive, `Z:\` that has my source code within windows for an app called kitchensink. I have set up the `"program"` and `"cwd"` paths to point to the directory within `WSL`. I have set up the `"pipeTransport"` to use `bash.exe`. I have also set up a `"sourceFileMap"` to have everything that is returned by `gdb` that starts with `/mnt/z` to point to `Z:\\` in Windows. | ||
|
|
||
| ``` | ||
| { | ||
| "name": "C++ Launch", | ||
| "type": "cppdbg", | ||
| "request": "launch", | ||
| "program": "/mnt/z/Bash/kitchensink/a.out", | ||
| "args": ["-fThreading"], | ||
| "stopAtEntry": false, | ||
| "cwd": "/mnt/z/Bash/kitchensink", | ||
| "environment": [], | ||
| "externalConsole": true, | ||
| "windows": { | ||
| "MIMode": "gdb", | ||
| "setupCommands": [ | ||
| { | ||
| "description": "Enable pretty-printing for gdb", | ||
| "text": "-enable-pretty-printing", | ||
| "ignoreFailures": true | ||
| } | ||
| ] | ||
| }, | ||
| "pipeTransport": { | ||
| "pipeCwd": "", | ||
| "pipeProgram": "c:\\windows\\sysnative\\bash.exe", | ||
| "pipeArgs": ["-c"], | ||
| "debuggerPath": "/usr/bin/gdb" | ||
| }, | ||
| "sourceFileMap": { | ||
| "/mnt/z": "z:\\" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Example `launch.json` for Attaching to an Existing Process | ||
|
|
||
| This configuration similar to the launch process above. I have chosen to start the same application above from the Bash command line and now I want to attach to it for debugging. I have changed the `"processID"` to use the remote process picker by specifying the command `"${command:pickRemoteProcess}"` and set up the same `"sourceFileMap"`. When I press F5 to attach, I get a picker drop down showing the running processes within `WSL`. I can scroll or search for the process I want to attach to and start debugging. | ||
|
|
||
| ``` | ||
| { | ||
| "name": "C++ Attach", | ||
| "type": "cppdbg", | ||
| "request": "attach", | ||
| "program": "/mnt/z/Bash/kitchensink/a.out", | ||
| "processId": "${command:pickRemoteProcess}", | ||
| "windows": { | ||
| "MIMode": "gdb", | ||
| "setupCommands": [ | ||
| { | ||
| "description": "Enable pretty-printing for gdb", | ||
| "text": "-enable-pretty-printing", | ||
| "ignoreFailures": true | ||
| } | ||
| ] | ||
| }, | ||
| "pipeTransport": { | ||
| "pipeCwd": "", | ||
| "pipeProgram": "c:\\windows\\sysnative\\bash.exe", | ||
| "pipeArgs": ["-c"], | ||
| "debuggerPath": "/usr/bin/gdb" | ||
| }, | ||
| "sourceFileMap": { | ||
| "/mnt/z": "z:\\" | ||
| } | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm dumb, but I don't understand when I'd use the latter? This is like Debug / Attach to Process in 'full' VS, right?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a process already running in Bash on Windows and want to debug it, this is how you do it.