Wednesday, February 4, 2026

CMake Debugger

hi everyone today I'm going to show you
an exciting new feature in visual studio
for your cmic development my name is
Tina bakunja and I'm a product manager
here on the C plus plus team at
Microsoft focusing on cmake and
cross-platform development we have a new
cmake debugger integrated into Visual
Studio that allows you to debug your
cmic scripts and your cmake list.txt
files let's take a look at how it works
in Visual Studio
alright so now I'm in visual studio and
I have a cmake project open there's a
few different ways I can access the cmic
debugger from this point the first is I
can navigate to the project drop down
and select configure my project with
Scenic debugger this will spin up the
cmake debugger for this project
the next is I can also right-click any
of my cmake list.txt files in the
solution Explorer and the same option
will populate to open the cmake debugger
also if cmic cash generation fails for
any reason there will be a notification
that populates in the solution Explorer
to debug your project with the cmake
debugger
alright so now let's take a look at the
scenic debugger in action what I'll do
is open the cmakelist.txt file that I
want to debug I'm going to open the C
link list of txt file under the test sub
folder in this case
this file includes all of my testing
logic
I can start by setting a breakpoint for
my debugger on a line number and then
running the cmic debugger from the
project drop down
okay I can see that the IDE has entered
the debugging state in the locals window
I can see the state of the target I
defined under the added executable
command called test instant savior
I can expand to see more information
about this target like that it is using
ninja to generate and then I can scroll
down to verify that the source of this
target is set up properly
now let's watch the first test called
test one and step through the debugger
line by line I can step through this
code like any other debugger in Visual
Studio
I can now view the properties for this
first test that was set called pass
regular expression this can be super
useful as you get into larger cmic
projects as you can view all the state
of these types of variables at a given
point in time
as you can see in the locals window I
can also expand and view the state of
all of my cmake cache variables as I
step through code
I can set watches on variables by
right-clicking and selecting ad watch
these variables will now be watched in
the watch window
you can also navigate over to exception
settings and see the different C make
specific exceptions that you can set
your code to break on for example I'll
set a breakpoint on any warning that is
thrown and you'll see as I click through
my debugger and step through my code
that it will break on the first warning
message
this can be toggled to any other kinds
of Errors you see as well
all right so what do you think the cmake
debugger can allow a lot of insights
into your cmake projects at configure
time and works like any other debugger
would in Visual Studio as you could see
download the latest version of Visual
Studio play around with the cmic
debugger and please let us know your
thoughts we hope this helps you with
your cmake workflows and makes them a
lot more efficient also be sure to check
out the pure virtual C plus conference
on June 6th for more C plus plus content

No comments:

Post a Comment