diff --git a/tools/cmake/UploadMethodManager.cmake b/tools/cmake/UploadMethodManager.cmake index 339f515..4c3a69f 100644 --- a/tools/cmake/UploadMethodManager.cmake +++ b/tools/cmake/UploadMethodManager.cmake @@ -52,10 +52,10 @@ ) # add debug target - if(MBED_UPLOAD_SUPPORTS_DEBUG) + if(MBED_UPLOAD_SUPPORTS_DEBUG AND MBED_GDB_FOUND) add_custom_target(debug-${target} COMMENT "starting GDB to debug ${target}..." - COMMAND arm-none-eabi-gdb + COMMAND ${MBED_GDB} --command=${CMAKE_BINARY_DIR}/mbed-cmake.gdbinit $ USES_TERMINAL) diff --git a/tools/cmake/app.cmake b/tools/cmake/app.cmake index b1c5399..9d32a40 100644 --- a/tools/cmake/app.cmake +++ b/tools/cmake/app.cmake @@ -58,6 +58,21 @@ # Note: This is nice in general, but is also required because STM32Cube will only work on files with a .elf extension set(CMAKE_EXECUTABLE_SUFFIX .elf) +# Find the GDB server, assuming it will be in the same path as the compiler. +get_filename_component(CMAKE_COMPILER_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY) +find_program(MBED_GDB + NAMES arm-none-eabi-gdb gdb-multiarch + HINTS ${CMAKE_COMPILER_BIN_DIR} + DOC "Path to the GDB client program to use when debugging.") + +if(EXISTS "${MBED_GDB}") + message(STATUS "Mbed: Found GDB executable: ${MBED_GDB}") + set(MBED_GDB_FOUND TRUE) +else() + message(STATUS "Mbed: Could not find arm-none-eabi-gdb or gdb-mutiarch. Debugging will be unavailable. Set the MBED_GDB variable to specify its path.") + set(MBED_GDB_FOUND FALSE) +endif() + # Load upload method configuration defaults for this target. # Loading the settings here makes sure they are set at global scope, and also makes sure that # the user can override them by changing variable values after including app.cmake. diff --git a/tools/cmake/mbed_ide_debug_cfg_generator.cmake b/tools/cmake/mbed_ide_debug_cfg_generator.cmake index ec7eefa..831ad2a 100644 --- a/tools/cmake/mbed_ide_debug_cfg_generator.cmake +++ b/tools/cmake/mbed_ide_debug_cfg_generator.cmake @@ -58,22 +58,30 @@ "{ \"configurations\": [") + # Find objdump as the extension uses it. In a sane world it should be in the compiler bin dir. + find_program(MBED_OBJDUMP + NAMES arm-none-eabi-objdump objdump + HINTS ${CMAKE_COMPILER_BIN_DIR} + DOC "Path to the GNU objdump program. Needed for VS Code cortex-debug" + REQURED) + function(mbed_generate_ide_debug_configuration CMAKE_TARGET) # Create name (combine target name, Mbed target, and build config to generate a unique string) set(CONFIG_NAME "Connect to GDB ${CMAKE_TARGET} ${MBED_TARGET} ${CMAKE_BUILD_TYPE}") - # from here: https://stackoverflow.com/questions/38089178/is-it-possible-to-attach-to-a-remote-gdb-target-with-vscode + # property list here: https://github.com/Marus/cortex-debug/blob/master/debug_attributes.md set_property(GLOBAL APPEND_STRING PROPERTY VSCODE_LAUNCH_JSON_CONTENT " { - \"type\": \"gdb\", - \"request\": \"attach\", + \"type\": \"cortex-debug\", \"name\": \"${CONFIG_NAME}\", \"executable\": \"$\", - \"target\": \"localhost:${GDB_PORT}\", - \"remote\": true, \"cwd\": \"\${workspaceRoot}\", - \"gdbpath\": \"arm-none-eabi-gdb\" + \"gdbPath\": \"${MBED_GDB}\", + \"objdumpPath\": \"${MBED_OBJDUMP}\", + \"servertype\": \"external\", + \"gdbTarget\": \"localhost:${GDB_PORT}\", + \"request\": \"attach\" },") endfunction(mbed_generate_ide_debug_configuration) diff --git a/tools/cmake/toolchains/GCC_ARM.cmake b/tools/cmake/toolchains/GCC_ARM.cmake index 5d74715..d7eeda9 100644 --- a/tools/cmake/toolchains/GCC_ARM.cmake +++ b/tools/cmake/toolchains/GCC_ARM.cmake @@ -1,9 +1,10 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc") -set(CMAKE_C_COMPILER "arm-none-eabi-gcc") -set(CMAKE_CXX_COMPILER "arm-none-eabi-g++") +# specify the cross compiler. Use cache variables so that VS Code can detect the compiler from the cache. +set(CMAKE_C_COMPILER arm-none-eabi-gcc CACHE FILEPATH "C Compiler") +set(CMAKE_CXX_COMPILER arm-none-eabi-g++ CACHE FILEPATH "CXX Compiler") +set(CMAKE_ASM_COMPILER arm-none-eabi-gcc CACHE FILEPATH "ASM Compiler") set(GCC_ELF2BIN "arm-none-eabi-objcopy") set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})