September 9th, 2024

Supercharge C++ Debugging with AI-Generated breakpoint expressions

Harshada Hole
Product Manager

Have you ever spent hours debugging your C++ code, struggling to set up the right conditional breakpoint or tracepoint? Or wished for a smarter way to obtain detailed runtime information without manually crafting complex expressions? You’re in luck! With Visual Studio 2022, the latest GitHub Copilot feature now offers AI-generated expressions for both conditional breakpoints and tracepoints, available from C# 17.10 and now extended to C++. With these AI-generated conditional breakpoints and tracepoints, you can now automate the creation of intelligent expressions tailored to your specific debugging needs, significantly speeding up the process and enhancing your ability to diagnose and resolve issues.

Image of a conditional expression being set on the breakpoint

What are conditional breakpoints and tracepoints?

Conditional breakpoints and tracepoints are powerful debugging tools that enhance your ability to control and monitor code execution. A conditional breakpoint pauses execution only when a specified condition is true, making it ideal for targeting specific scenarios. For example, you can halt code only when a variable exceeds a certain value or a function is called with particular parameters, while a Tracepoints enable logging of messages to the output window or a file without interrupting code execution and replaces traditional ‘printf’ statements, offering detailed runtime insights without the need for code recompilation.

These tools are invaluable for identifying bugs, testing various scenarios, and tracking variables and expression values without manually stepping through each line of code. However, crafting the correct expressions for conditional breakpoints or tracepoints can be challenging and time-consuming, especially when remembering the correct syntax in complex codebases.

Fortunately, with GitHub Copilot you have the flexibility to choose from predefined conditions that suit your needs or to define custom conditions for precise and efficient debugging.

How can AI-generated expressions help you debug faster?

Visual Studio 2022 integrates with GitHub Copilot, AI-powered code completion tool that suggests lines of code or entire functions, effectively acting as a pair programmer that enhances coding efficiency. When you position the cursor in the textbox for a conditional breakpoint or tracepoint, GitHub Copilot promptly provides three AI-generated expression suggestions based on your codebase. You can choose the most suitable condition or create your own custom conditions as needed.

With AI-generated expressions, you can save time and effort by letting GitHub Copilot do the hard work for you. You can also discover new ways of writing expressions that you might not have thought of before. AI-generated expressions can help you debug your code faster and more effectively and learn from the suggestions along the way.

How to use AI-generated expressions in Visual Studio 2022?

To use AI-generated expressions for conditional breakpoints and tracepoints in Visual Studio 2022, you need to have a GitHub account and sign in with GitHub in Visual Studio. You also need to make sure Tools > Options > Debugging > enable AI suggestions for breakpoint expressions” is enabled.

Once you have enabled GitHub Copilot, you can start using AI-generated expressions for conditional breakpoints and tracepoints in your C++ code.

Gif of a conditional expression break point being set and then edited via settings

You can also use keyboard shortcuts to navigate and select the suggestions. Use Ctrl+Space to invoke the suggestion list, use the up and down arrow keys to move through the list, and use Enter to select a suggestion.

Try it and let us know what you think

We hope you enjoy using AI-generated expressions for conditional breakpoints and tracepoints in Visual Studio 2022. This feature aims to make debugging your C++ code faster and easier. We’d love your feedback and suggestions for improvement. Please leave a comment below or use the Send Feedback button in Visual Studio.

Learn more about other Copilot assisted features in Visual Studio by checking out additional resources Debug with GitHub Copilot – Visual Studio (Windows) | Microsoft Learn

Stay connected with the Visual Studio team by following us on Twitter @VS_Debugger, Twitter @VisualStudio, Twitter @VisualC YouTube, and LinkedIn.

Author

Harshada Hole
Product Manager

Harshada Hole is a Product Manager on the Visual Studio Debugging and Profiling Team, dedicated to enhancing the diagnostics experience by making it more productive and efficient for developers.