How to debug in Windows Subsystem Linux (WSL) using GDB debugger
-
Must be on Windows 10 and it is up to date.
-
Must be on the latest Insider Preview build 1703 or higher (Creators Update) Link
-
Must have WSL (Windows Subsystem Linux) installed. I used this great how to from How-To Geek to install Bash on Ubuntu on Windows. Link
-
Must have Visual Studio 2017 installed. You can use the the free edition (Visual Studio Community 2017). Download here
- Install metapackage build-essential, gdb server, and openssh server
- Open WSL
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y gdbserver
sudo apt=get install -y openssh-server
- Open sshd_config using vi, emacs, or nano. I prefer nano as it is much easier to use for beginners.
nano /etc/ssh/sshd_config
- set PasswordAuhentication to yes
- Generate SSH keys
sudo ssh-keygen -A
- Start openssh server
sudo service ssh start
- Create a console application in Visual Studio
- Target x64
- Add SSh connections
- Host Name: localhost
- Port: 22
- User Name: "Enter your bash user name"
- Password: "Enter password associated with your bash user name"
- Ensure debugging mode is set to gdb
- Go to Project -> ConsoleApplication1 Properties -> Configuration Properties -> Debugging
- Set Debugging Mode to gdb