diff --git a/tools/cmake/UploadMethodManager.cmake b/tools/cmake/UploadMethodManager.cmake index ad477f23487..be3ff13bee9 100644 --- a/tools/cmake/UploadMethodManager.cmake +++ b/tools/cmake/UploadMethodManager.cmake @@ -37,9 +37,9 @@ function(mbed_adjust_upload_debug_commands target) # GDB load command doesn't support binary format. Ignore OUTPUT_EXT # and fix to Intel Hex format. # - # NOTE: The .hex file name needs to be quoted (\\\") to pass along + # NOTE: The .hex file name needs to be quoted (\") to pass along # to gdb correctly. - list(TRANSFORM MBED_UPLOAD_LAUNCH_COMMANDS APPEND " \\\"${HEX_FILE}\\\"" AT ${LOAD_INDEX}) + list(TRANSFORM MBED_UPLOAD_LAUNCH_COMMANDS APPEND " \"${HEX_FILE}\"" AT ${LOAD_INDEX}) # Update MBED_UPLOAD_LAUNCH_COMMANDS in cache set(MBED_UPLOAD_LAUNCH_COMMANDS ${MBED_UPLOAD_LAUNCH_COMMANDS} CACHE INTERNAL "" FORCE) diff --git a/tools/cmake/mbed_ide_debug_cfg_generator.cmake b/tools/cmake/mbed_ide_debug_cfg_generator.cmake index 720be3acfad..01741071db6 100644 --- a/tools/cmake/mbed_ide_debug_cfg_generator.cmake +++ b/tools/cmake/mbed_ide_debug_cfg_generator.cmake @@ -137,9 +137,13 @@ elseif(MBED_GENERATE_VS_CODE_DEBUG_CFGS) # Create name (combine target name, Mbed target, and build config to generate a unique string) set(CONFIG_NAME "Debug ${CMAKE_TARGET} ${MBED_TARGET} ${CMAKE_BUILD_TYPE}") + # Escape quotes in the launch commands + string(REPLACE "\"" "\\\"" UPLOAD_LAUNCH_COMMANDS_FOR_JSON "${MBED_UPLOAD_LAUNCH_COMMANDS}") + string(REPLACE "\"" "\\\"" UPLOAD_RESTART_COMMANDS_FOR_JSON "${MBED_UPLOAD_RESTART_COMMANDS}") + # Convert CMake lists to json - list(JOIN MBED_UPLOAD_LAUNCH_COMMANDS "\", \"" UPLOAD_LAUNCH_COMMANDS_FOR_JSON) - list(JOIN MBED_UPLOAD_RESTART_COMMANDS "\", \"" UPLOAD_RESTART_COMMANDS_FOR_JSON) + list(JOIN UPLOAD_LAUNCH_COMMANDS_FOR_JSON "\", \"" UPLOAD_LAUNCH_COMMANDS_FOR_JSON) + list(JOIN UPLOAD_RESTART_COMMANDS_FOR_JSON "\", \"" UPLOAD_RESTART_COMMANDS_FOR_JSON) # property list here: https://github.com/Marus/cortex-debug/blob/master/debug_attributes.md set_property(GLOBAL APPEND_STRING PROPERTY VSCODE_LAUNCH_JSON_CONTENT " diff --git a/tools/cmake/upload_methods/UploadMethodLINKSERVER.cmake b/tools/cmake/upload_methods/UploadMethodLINKSERVER.cmake index 21b258de6e6..ef1758e9beb 100644 --- a/tools/cmake/upload_methods/UploadMethodLINKSERVER.cmake +++ b/tools/cmake/upload_methods/UploadMethodLINKSERVER.cmake @@ -66,10 +66,9 @@ set(UPLOAD_LAUNCH_COMMANDS "break main" "monitor reset" - # Workaround for LinkServer supplying incomplete memory information to GDB - # (in particular, seems to be missing the peripheral memory space and external RAM). - # Without this command, GDB will block the user from accessing values in any of these - # memory spaces. + # Tell GDB to allow reads to any region of memory, ignoring the memory map sent by the GDB server. + # This is needed because often the GDB server's memory map doesn't include peripheral memory, so + # the user can't inspect peripheral registers. "set mem inaccessible-by-default off" ) set(UPLOAD_RESTART_COMMANDS diff --git a/tools/cmake/upload_methods/UploadMethodOPENOCD.cmake b/tools/cmake/upload_methods/UploadMethodOPENOCD.cmake index 37e5b2c9952..7dee8d8cfa0 100644 --- a/tools/cmake/upload_methods/UploadMethodOPENOCD.cmake +++ b/tools/cmake/upload_methods/UploadMethodOPENOCD.cmake @@ -78,6 +78,11 @@ set(UPLOAD_LAUNCH_COMMANDS # Increase remote timeout to 30 sec in case programming takes a long time "set remotetimeout 30" + # Tell GDB to allow reads to any region of memory, ignoring the memory map sent by the GDB server. + # This is needed because often the GDB server's memory map doesn't include peripheral memory, so + # the user can't inspect peripheral registers. + "set mem inaccessible-by-default off" + "load" "tbreak main" "monitor reset halt" diff --git a/tools/cmake/upload_methods/UploadMethodPYOCD.cmake b/tools/cmake/upload_methods/UploadMethodPYOCD.cmake index b6ca4ec8945..f0e93716c06 100644 --- a/tools/cmake/upload_methods/UploadMethodPYOCD.cmake +++ b/tools/cmake/upload_methods/UploadMethodPYOCD.cmake @@ -60,6 +60,11 @@ set(UPLOAD_LAUNCH_COMMANDS "load" "tbreak main" +# Tell GDB to allow reads to any region of memory, ignoring the memory map sent by the GDB server. +# This is needed because often the GDB server's memory map doesn't include peripheral memory, so +# the user can't inspect peripheral registers. +"set mem inaccessible-by-default off" + # It appears the device under debug must be halted after UPLOAD_LAUNCH_COMMANDS, # or debugger will become abnormal. "monitor reset halt" diff --git a/tools/cmake/upload_methods/UploadMethodSTLINK.cmake b/tools/cmake/upload_methods/UploadMethodSTLINK.cmake index 872af59ae66..aac834d099d 100644 --- a/tools/cmake/upload_methods/UploadMethodSTLINK.cmake +++ b/tools/cmake/upload_methods/UploadMethodSTLINK.cmake @@ -49,6 +49,12 @@ set(UPLOAD_LAUNCH_COMMANDS "monitor halt" "monitor reset" "load" + + # Tell GDB to allow reads to any region of memory, ignoring the memory map sent by the GDB server. + # This is needed because often the GDB server's memory map doesn't include peripheral memory, so + # the user can't inspect peripheral registers. + "set mem inaccessible-by-default off" + "tbreak main" "monitor reset" ) diff --git a/tools/cmake/upload_methods/UploadMethodSTM32CUBE.cmake b/tools/cmake/upload_methods/UploadMethodSTM32CUBE.cmake index fac411279dd..3496aea0683 100644 --- a/tools/cmake/upload_methods/UploadMethodSTM32CUBE.cmake +++ b/tools/cmake/upload_methods/UploadMethodSTM32CUBE.cmake @@ -57,6 +57,12 @@ set(UPLOAD_GDBSERVER_DEBUG_COMMAND set(UPLOAD_LAUNCH_COMMANDS "monitor reset" "load" + + # Tell GDB to allow reads to any region of memory, ignoring the memory map sent by the GDB server. + # This is needed because often the GDB server's memory map doesn't include peripheral memory, so + # the user can't inspect peripheral registers. + "set mem inaccessible-by-default off" + "tbreak main" "monitor reset" )