Cannot debug targets if using CMakePresets along with toolchainFile
Brief Issue Summary
Steps to reproduce:
- Write a simple CMake project.
- Write a minimum toolchain:
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
- Write CMakePresets, define a configure preset using
toolchainFile. - Configure project in vscode, and then debug one target.
- Error occurs:

It seems that CMakeTools determines which debugger backend to use by finding compiler type only in CMAKE_C(XX)_COMPILER cache entry, ignoring CMAKE_TOOLCHAIN_FILE.
CMake Tools Diagnostics
{
"os": "win32",
"vscodeVersion": "1.77.3",
"cmtVersion": "1.13.45",
"configurations": [
{
"folder": "c:\\xxx\\modern-cpp-learn",
"cmakeVersion": "3.26.3",
"configured": true,
"generator": "Ninja",
"usesPresets": true,
"compilers": {}
}
],
"cpptoolsIntegration": {
"isReady": false,
"hasCodeModel": false,
"activeBuildType": "",
"buildTypesSeen": [],
"requests": [],
"responses": [],
"partialMatches": [],
"targetCount": 0,
"executablesCount": 0,
"librariesCount": 0,
"targets": []
},
"settings": [
{
"communicationMode": "automatic",
"useCMakePresets": "auto",
"configureOnOpen": false
}
]
}
Debug Log
No response
Additional Information
No response
Thanks for the report! To confirm, in your generated CMakeCache.txt file, is there only an entry for CMAKE_TOOLCHAIN_FILE and not for CMAKE_C_COMPILER or CMAKE_CXX_COMPILER. That's surprising given that the configure step succeeded.
I think yes and my cmake version is 3.26.3 on Windows 10 x64.
C:\xxx\modern-cpp-learn\build>cmake --toolchain ..\cmake\toolchains\clang.cmake -G Ninja ..
-- The C compiler identification is Clang 15.0.7 with GNU-like command-line
-- The CXX compiler identification is Clang 15.0.7 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/xxx/LLVM-15.0.7-win64-compiled/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/xxx/LLVM-15.0.7-win64-compiled/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (4.2s)
-- Generating done (0.0s)
-- Build files have been written to: C:/xxx/modern-cpp-learn/build
C:\xxx\modern-cpp-learn\build>type CMakeCache.txt | findstr CMAKE_CXX_COMPILER
CMAKE_CXX_COMPILER_AR:FILEPATH=C:/xxx/LLVM-15.0.7-win64-compiled/bin/llvm-ar.exe
CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS:FILEPATH=C:/xxx/LLVM-15.0.7-win64-compiled/bin/clang-scan-deps.exe
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=C:/xxx/LLVM-15.0.7-win64-compiled/bin/llvm-ranlib.exe
//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR
CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS
CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB
CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1
C:\xxx\modern-cpp-learn\build>type CMakeCache.txt | findstr CMAKE_CXX_COMPILER:
C:\xxx\modern-cpp-learn\build>type ..\cmake\toolchains\clang.cmake
set(CMAKE_C_COMPILER clang.exe)
set(CMAKE_CXX_COMPILER clang++.exe)
set(CMAKE_LINKER lld-link.exe)
As a workaround, try adding a cmake.debugConfig setting like this:
"cmake.debugConfig": {
"MIMode": "lldb",
"miDebuggerPath": "path/to/lldb-mi.exe"
}
Or you can consider adding the CACHE option to your set commands in the toolchain.
As a workaround, try adding a
cmake.debugConfigsetting like this:"cmake.debugConfig": { "MIMode": "lldb", "miDebuggerPath": "path/to/lldb-mi.exe" }Or you can consider adding the
CACHEoption to yoursetcommands in the toolchain.
That's what I did, thx for your advice😆
This issue is now marked as 'stale' due to there being no activity on it for the past 30 days and being labelled 'more info needed'. Unless the 'stale' label is removed or the issue is commented on, this will be closed in 7 days. If you would like to make this issue exempt from getting stale, please remove the 'more info needed' and 'stale' labels or add the 'stale-exempt' label
This issue is now closed due to there being no activity on it for the past 7 days since being marked as 'stale'.