gdbWatchPoint

How to debug a Linux build using Visual Studio and WSL

Written by Dr Greg Law | Last updated 10th Jun 2020

If you use Microsoft Visual Studio for your coding, then Visual Studio can debug on Linux using Windows Subsystem for Linux (WSL) and GDB. 

The WSL lets you run a GNU/Linux environment, including most command-line tools, utilities, and applications, directly on Windows, unmodified, without the overhead of a virtual machine.

In this GDB tutorial, I’ve asked Microsoft Developer Advocate Sy Brand to show you how.

Setup for GDB debugging

To install WSL, go to https://AKA.MS/WSL on your web browser. Just follow the instructions to get a full installation of your favorite Linux distribution.

When you are back in your code, go to My Configurations, click on Manage Configuration, and add a new configuration so you can target WSL right from Visual Studio. Scroll down the list to find the WSL-GCC-Debug, and that allows a new target.

You are set. 

Yes, it is easy to get started.

Effective breakpoints

Now you can set breakpoints like you usually cannot do in Visual Studio. You can change the settings to add conditions to the breakpoint. Or you can add actions such as show a message in the output window whenever the breakpoint is hit.

Debugging in context

You can see your locals in your window and when you are at a breakpoint, and you know where you are in your code. So, you stay in your debugging flow all the time.

You can even right-click on a variable and add a watchpoint. 

Super helpful! 

Visual Studio offers you a genuinely comfortable debugging experience.

Enjoy the Visual Studio debugging experience.

To make sure you do not miss our next GDB tutorial: sign up for our gdbWatchPoint newsletter now.

Get tutorials straight to your inbox
Become a GDB Power User. Get Greg's debugging tips directly in your inbox every 2 weeks.
  • Concurrency Defects Resolution
    New techniques to help quickly find and resolve defects in multithreaded and multiprocess applications
    Download the technical paper
Get tutorials straight to your inbox
Become a GDB Power User. Get Greg's debugging tips directly in your inbox every 2 weeks.