Code Focused

C++ Debugging in Visual Studio: Let's Start with the Basics

Debugging is a crucial part of the development process. In this new series of tried and true C++ tips, we look at the basics of debugging and step through some more advanced debuggings tips for C++ developers.

We all know that debugging is an important part of software development process. Some might argue that it's best not to touch the debugger at all (and just write clean C++ code). The reality is that sooner or later you will encounter a situation where the debugger will save your code and/or career!

With the Visual Studio IDE you get one of the best-integrated debuggers for C++. For me, it's crucial to know how to use that tool efficiently. That's the aim here, and so I'd like to share a few tips and encourage you to search for even more advanced ways to use the debugger.

In the series, we'll cover:

  • The basics of the Visual Studio IDE.
  • How to change the version of the code at runtime (that way, you can test two or more solutions without recompiling).
  • How to improve the logger so that you can quickly move to the message source.
  • Conditional breakpoints
  • How to control to which function the debugger can step into

And that's just for starters. We'll also look at how to get more information about objects while debugging, how to investigate lots of objects, mouse events, and debugging visualizers.

This time out, let's start fresh and look at the basics of the VS IDE. Things you should do to get familiar with the IDE:

  • Learn the keyboard shortcuts! You should at least know the essential tasks like running the debugger, stepping in/out/over, continuing execution.
  • Manage breakpoints: Do you know how to set breakpoints, or how to enable or disable breakpoints? Did you know you can even export breakpoints?
  • Visual Studio 2015 offers a number of features for debugging. so why not use the latest version? Even if you still compile using VS 2013, you can open projects in VS2015, change the Platform Toolset to the version you need, and that way you're using the better debugger. Moreover, If you want to track performance or memory problems, it has a dedicated set of profiling tools.
  • Start a debugging session (via the F5 key) and just wait until debugger stops on your breakpoints.
  • Run the debugger to the cursor or pause the debugger to see what code is being executed at the moment. VS offers a way to break on various exceptions. There is a separate window (also improved in VS 2015) that you can control which exceptions will be handled.
  • When you hit a breakpoint you can observe the state of your application in various VS windows. Most notable are:
    • Call Stack windows shows where you are in the code, what chain of methods was called up to the breakpoint.
    • Autos and Locals window show current variables used in the app. What's more, Autos Window will also report the return value of the executed function.
    • Threads Window shows the currently active Threads. You can also use Parallel Stacks Window.aspx to get an even better visualization of the state of threads.
    • Output Window is one of the most useful windows: you can see your log messages here. All messages from OutputDebugString go there.
  • From a breakpoint, you'll usually move line by line to see the code execution. You can step into a function or step over. There is also a method to set the next statement -- that way you can skip some part of the code or repeat the steps.

Figure 1 shows shows a basic debugger session.

Basic Visual Studio Debugger
[Click on image for larger view.] Figure 1: Basic Visual Studio Debugger

This short article was just a quick run through some of the basic tools in the VS debugger, so you probably skipped through most of it because you know all of it already.

Stay tuned and next time we'll tackle one technique I am especially keen on: how to improve logging to the output window so that you can quickly jump to the source code.

About the Author

Bartlomiej Filipek is a software developer in Poland who specializes in C++, Windows and graphics programming. He worked for a number of companies developing multimedia, document editors, games, graphics drivers and flight planning systems, and has taught game development at local university. Follow Bart's blog at and on Twitter @fenbf.

comments powered by Disqus


  • Death of the Dev Machine?

    Here's a takeaway from this week's Ignite 2020 event: An advanced Azure cloud portends the death of the traditional, high-powered dev machine packed with computing, memory and storage components.

  • COVID-19 Is Ignite 2020's Elephant in the Room: 'Frankly, It Sucks'

    As in all things of our new reality, there was no escaping the drastic changes in routine caused by the COVID-19 pandemic during Microsoft's big Ignite 2020 developer/IT pro conference, this week shifted to an online-only event after drawing tens of thousands of in-person attendees in years past.

  • Visual Studio 2019 v16.8 Preview Update Adds Codespaces

    To coincide with the Microsoft Ignite 2020 IT pro/developer event, the Visual Studio dev team shipped a new update, Visual Studio 2019 v16.8 Preview 3.1, with the main attraction being support for cloud-hosted Codespaces, now in a limited beta.

  • Speed Lines Graphic

    New for Blazor: Azure Static Web Apps Support

    With Blazor taking the .NET web development world by storm, one of the first announcements during Microsoft's Ignite 2020 developer/IT event was its new support in Azure Static Web Apps.

  • Entity Framework Core 5 RC1 Is Feature Complete, Ready for Production

    The first release candidate for Entity Framework 5 -- Microsoft's object-database mapper for .NET -- has shipped with a go live license, ready for production.

Upcoming Events