vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Cannot debug targets if using CMakePresets along with toolchainFile

Open nakido-official opened this issue 3 years ago • 6 comments

Brief Issue Summary

Steps to reproduce:

  1. Write a simple CMake project.
  2. Write a minimum toolchain:
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
  1. Write CMakePresets, define a configure preset using toolchainFile.
  2. Configure project in vscode, and then debug one target.
  3. 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

nakido-official avatar Apr 14 '23 03:04 nakido-official

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.

benmcmorran avatar Apr 18 '23 16:04 benmcmorran

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)

nakido-official avatar Apr 19 '23 07:04 nakido-official

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.

bobbrow avatar Apr 19 '23 17:04 bobbrow

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.

That's what I did, thx for your advice😆

nakido-official avatar Apr 20 '23 12:04 nakido-official

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

github-actions[bot] avatar Oct 18 '23 15:10 github-actions[bot]

This issue is now closed due to there being no activity on it for the past 7 days since being marked as 'stale'.

github-actions[bot] avatar Oct 26 '23 07:10 github-actions[bot]