WatchPoint

Image link

How to debug a Linux build using Visual Studio and WSL

In this tutorial

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.

New call-to-action

Don’t miss my next C++ debugging tutorial: sign up to my WatchPoint mailing list below.
Get tutorials straight to your inbox

Become a GDB Power User. Get Greg’s debugging tips directly in your inbox every 2 weeks.

Want GDB pro tips directly in your inbox?

Share this tutorial