Debugging vcpkg portfiles.cmake with the VS Code CMake Tools Extensions #32643
Replies: 2 comments 5 replies
-
@Neumann-A
|
Beta Was this translation helpful? Give feedback.
-
@Neumann-A Here is my setup:
Whenever I do that, the configure stops at the beginning, presumably waiting for a debugger to be attached, but when I launch the configuration, I get an error I tried launching two cmake processes with the same pipe and the second one fails with
, after what trying to connect to the pipe produces the Is it expected that |
Beta Was this translation helpful? Give feedback.
-
Ever wonder how to correctly debug CMake? With CMake 3.27 the
--debugger
command was introduced and it can be used to debug vcpkg portfiles in VS Code.Starting with vcpkg release 2023.10.19 vcpkg supports CMake debugging for portfiles and CMake projects.
The command line options for debugging are:
--x-cmake-debug <pipename>[;port1;port2;....]
for debugging the script execution of vcpkg, e.g. portfiles etc. doc--x-cmake-configure-debug <pipename>[;port1;port2;....]
for debugging a CMake configure call of a port within vcpkg. docIn both cases the command allows to specifiy which port the debugging should be activated for since cmake will otherwise stall the execution until a debugger is attached. This could get tedious if you want to debug a port with a lot of other dependencies since the debugger would need to be attached sequentially to all of them. So you definitly want to specify the port in most cases.
So how do you attach a debugger? You need a debugger which supports the debug adapter protocol and knows how to deal with the information CMake provides. One of those debuggers is integrated in the CMake Tools VS Code extension. Since version 1.16 the extension allows to attach to an external CMake debugger pipe which allows debugging of arbitrary CMake executions such as within vcpkg.
To now start debugging you would have e.g. the following code in your
.vscode/launch.json
:and start vcpkg with the same pipename in the debugging commands as in your
launch.json
. You could also define a task in your.vscode/tasks.json
to execute the required commands from within VS Code directly such as (vcpkg is the root of your workspace otherwise adapt paths accordingly):(--binarysource=clear is used to avoid pulling in previously build binaries. Also don't forget to set breakpoints in the code you want to debug and make sure the execution actually hits that point since otherwise you might see the debugger directly close. Also works on !Windows just change the pipename to a domain socket as required by CMake and change the triplet in the example)
Other ways of debugging without attaching a debugger:
--trace-expand
via--cmake-args
. E.g.--cmake-args=--trace-expand
for script tracing or--cmake-args=-DVCPKG_CMAKE_CONFIGURE_OPTIONS=--trace-expand
for cmake configure within a port.--trace-expand
to theOPTIONS
parameter in thevcpkg_cmake_configure
call.--debug
to see which commands vcpkg itselfs executes.Beta Was this translation helpful? Give feedback.
All reactions