r/cpp • u/RandomCameraNerd • Feb 13 '26
Your Optimized Code Can Be Debugged - Here's How With MSVC C++ Dynamic Debugging - Eric Brumer
https://youtu.be/YnbO140OXuI?si=4TH-5q78yyB0z-MEJust watched this video, really cool stuff. I donβt have any background in compiler development, how hard will it be for other compilers (and build systems?) to adopt something like this?
97
Upvotes
34
u/ericbrumer MSVC Dev Lead Feb 13 '26
Howdy, speaker here. If folks have additional questions feel free to ask. Keep in mind, if you're using the latest Visual Studio 2022, or any Visual Studio 2026 build, you're able to turn on C++ Dynamic Debugging by choosing the right option in your build configuration, or throwing `/dynamicdeopt` to cl.exe, lib.exe, and link.exe in your builds.
A few common questions we've got about C++ Dynamic Debugging, some of which are already here in other comments:
* Does it work for asynchronous breakpoints like exceptions, data breakpoints, or just pressing the pause button? Not out of the gate, no. However, if you already are aware which functions matter, then you can deoptimize those functions (see 9:30 in the video), and the next time those functions are entered they will be deoptimized.
* What about having a reduced set of optimizations to make debugging easier? We thought about that, but when we prototyped our approach we saw the power of full optimizations (including inlining!) pairing with full debuggability covered far more cases and offered much more power in the codebases we were looking at. We use dynamic debugging in the compiler codebase, for instance, and it REALLY helps having code run very quickly. Another way to phrase this is in the view of game development: I want my game to run at 60 fps, but be able to debug it fully. Our approach makes that a reality.
* [for the more compiler-savvy folks] What about globals that are optimized away? Or functions that are fully inlined? Or <other fun optimizer thing>? Yes -- you can debug those. If you run into problems, or find a case where it's not kicking in as you expect, please open a bug (https://developercommunity.visualstudio.com/cpp/report) and feel free to ping me.
At the end of the day, if you debug optimized code and want a more seamless way to debug any part of your code: you should give C++ Dynamic Debugging a shot. If you are used to debugging unoptimized code and wish your code ran faster without sacrificing debuggability: you should give C++ Dynamic Debugging a shot.
At a minimum: check out the demo I did of OpenCV which starts at 3:42.
More info at https://aka.ms/dynamicdebugging and https://aka.ms/vcdd
8
u/5477 Feb 14 '26
This looks to be the holy grail of debugging C++, and seems to 99% resolve the need for running "debug" binaries!
2
u/RaspberryCrafty3012 Feb 14 '26
Sounds interesting and necessary for windows.
On Linux and Apple I don't need to link against debug libs for a debug build, so only my own code is "slow".Β
2
u/SoerenNissen Feb 13 '26
That's pretty cool
2
u/SyntheticDuckFlavour Feb 14 '26
My strategy is to try writing performant code in debug builds. Has two benefits: you can debug it without much issues, and the release rebuild is almost inevitably going to be faster as a bonus.
1
u/bitzap_sr Feb 14 '26
OOC, doesn't Visual Studio support setting breakpoints in inlined functions and support printing inlined function locals? I mean in regular optimized binaries? I got that impression from the video. Doesn't codeview/pdb support describing inlined code, like DWARF does?
0
u/Agron7000 Feb 13 '26
I wonder what passive debugging looks like.
0
u/einpoklum Feb 18 '26
They haven't "enabled full debuggability" through changes to an OS-specific, closed-source IDE.
-3
u/arihoenig Feb 14 '26
I mean, like what? People didn't think they could debug code after it was optimized?
0
u/[deleted] Feb 13 '26
[deleted] β view deleted comment