Unable to debug with embedded gdb server in Clion

The problem I have is with debugging using the arm-none-eabi-gdb debugger in the Embedded GDB Server configuration in the CLion configuration it does not work properly when I execute the debug from CLion.
To be more detailed, I am using following configuration (I am also using J-Link hardware as my debugger connected via SWD on a STM32F103RBT6 board).
My CMakeLists.txt file (last part is UPLOAD Target) is shown below:
add_custom_target(UPLOAD
arm-none-eabi-gdb
-iex "file \"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf.elf\""
-iex "target remote tcp:localhost:2331"
-iex "load \"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf.elf\""
-iex "set mem inaccessible-by-default off"
-iex "break main"
-iex "mon reset"
-iex "continue"
-iex "bt"
)
Note: the arm-none-eabi-gdb and JLinkGDBServerCL both are in the Windows PATH environment.
While using the command line I can easily debug with no issues (note I go to the build folder and run the arm-none-eabi-gdb from there) and in the image below one can see everything works fine [look at the (gdb) commands] while the Jlink GDB server GUI is running in the background with configuration like the image below.
And the manual (by typing) gdb communication works fine as below
To verify the GDB server parameters are working file I gett he same result when I use following CLI GDB Server in another command prompt window as by executing following command
"C:\Program Files (x86)\SEGGER\JLink\JLinkGDBServerCL.exe" -port 2331 -s -device STM32F103RB -endian little -speed 1000 -vd -select USB -if swd -noir -singlerun -strict
But from Clion side I encounter two problems with the CLion's Embedded GDB Server Debug configuration.
Firstly, in the image below it never executes the GDB server at all
I get following error result shown in the image
Please note that I generate CMakeLists.txt file before every try and then rebuild the project every time before debugging.
I would like to know if there is something wrong with my setting or whether there is bug with CLion Embedded GDB Server or not!? Any help is really appreciated
请先登录再写评论。
Apparently both gdbserver and jlink work but they can not connect to each other, even though the ports look correctly.
Try to increase startup delay in gdb server advanced options and also try to use 127.0.0.1 instead of localhost in connection parameters.
One more possible reason - too paranoic network firewall settings.
Hello!
Please provide a screenshot of File | Settings | Build, Execution, Deployment | Toolchains (please capture the screenshot after the compiler detection is completed).
New CmakeLists.txt file with little tweaks:
set(CMAKE_VERBOSE_MAKEFILE ON)
cmake_minimum_required(VERSION 3.15)
#Forces cross compiling
set(CMAKE_SYSTEM_NAME Generic)
# Should be set after the line above
set(CMAKE_SYSTEM_VERSION 1)
set(PROJECT_NAME CLION-f103-armclang)
# specify cross compilers and tools
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
SET(CMAKE_C_COMPILER_ID ARMClang)
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER armclang)
SET(CMAKE_CXX_COMPILER_ID ARMClang)
SET(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER armclang)
set(CMAKE_ASM_COMPILER_ID ARMCC)
SET(CMAKE_ASM_COMPILER_WORKS 1)
set(CMAKE_ASM_COMPILER armasm)
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
set(OBJDUMP arm-none-eabi-objdump)
set(SIZE arm-none-eabi-size)
##################### CHIP Configuration ###################################
set(TARGET arm-arm-none-eabi)
set(CMAKE_SYSTEM_PROCESSOR Cortex-M3)
set(CHIP STM32F103xB)
set(CPU_FAMILY STM32F10X_MD)
############################################################################
# driver type USE_HAL_DRIVER or USE_FULL_LL_DRIVER
set(DRIVER_TYPE USE_HAL_DRIVER)
# library type
set(USE_MICROLIB ON)
# setting the C/C++ standards
# much better than CMAKE_CXX_STANDARD/CMAKE_C_STANDARD
set(CXX_STD_FLAG c++11)
set(C_STD_FLAG c99)
##### Compile time definitions
if(DEFINED USE_MICROLIB)
add_definitions(-D__MICROLIB)
endif()
add_definitions(-D_RTE)
add_definitions(-D${CHIP})
add_definitions(-D${DRIVER_TYPE})
add_definitions(-DDEBUG)
add_definitions(-D${CPU_FAMILY})
SET(CMAKE_ASM_FLAGS_INIT "--cpu ${CMAKE_SYSTEM_PROCESSOR} \
--pd \"_RTE_ SETA 1\" \
--pd \"STM32F10X_MD SETA 1\" \
--pd \"__MICROLIB SETA 1\" \
-g \
")
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/startup/STM32F103RBTx_FLASH.sct)
set(COMPILER_OPT_FLAGS "-Og -g3")
set(COMMON_FLAGS "${FPU_FLAGS} -mthumb -ffunction-sections -fno-rtti -flto \
-funsigned-char -fshort-enums -fshort-wchar -gdwarf-3 \
-fno-common -fmessage-length=0 -xc -c -MD --verbose \
")
set(WARNING_FLAGS "-Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes \
-Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path \
-Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command \
-Wno-documentation -Wno-license-management -Wno-parentheses-equality ")
set(STDLIBCXX_OPTIONAL_CLANG)
set(TCPU_FLAGS "--target=${TARGET} -mcpu=${CMAKE_SYSTEM_PROCESSOR}")
set(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} \
${STDLIBCXX_OPTIONAL_CLANG} \
--std=${CXX_STD_FLAG} \
")
SET(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} --std=${C_STD_FLAG}")
# Don't move the line below otherwise a wrong compiler and tools will be picked
PROJECT(${PROJECT_NAME} C CXX ASM)
set(CMAKE_CXX_STANDARD 11)
file(GLOB_RECURSE SOURCES "startup/*.*" "Drivers/*.*" "Core/*.*")
include_directories(Core/Inc Drivers/STM32F1xx_HAL_Driver/Inc
Drivers/STM32F1xx_HAL_Driver/Inc/Legacy
Drivers/CMSIS/Device/ST/STM32F1xx/Include
Drivers/CMSIS/Include)
add_executable(${PROJECT_NAME} ${SOURCES} ${LINKER_SCRIPT})
set(CMAKE_EXE_LINKER_FLAGS_INIT "--cpu=${CMAKE_SYSTEM_PROCESSOR} \
--info sizes --info totals --info unused --info veneers --info summarysizes \
--strict --scatter=${LINKER_SCRIPT} \
--summary_stderr --load_addr_map_info \
--symbols --callgraph --xref --map " CACHE INTERNAL "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT} \
--list=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map \
--library_type=microlib \
--lto" CACHE INTERNAL "" FORCE)
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}> ${BIN_FILE}
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")
add_custom_target(UPLOAD
arm-none-eabi-gdb
-ex "cd ${CMAKE_BINARY_DIR}"
-ex "file ${PROJECT_NAME}.elf"
-ex "target remote tcp:localhost:2331"
-ex "load ${PROJECT_NAME}.elf"
-ex "set mem inaccessible-by-default off"
-ex "break main"
-ex "mon reset halt"
-ex "continue"
-ex "bt"
)
Below I have enclosed different possible debug configuration - none of them work with the above CMakeLists.txt file, I have written every each of the configuration problems (Please NOTE that I am not using or going to use OpenOCD plug-in at all) I just use Embedded GDB server configuration.
Firstly in the main file I have put following break-points
For every each of the debug configuration testing I am erasing the cmake-build-debug folder and then running Cmake- Resert Cache and Reload Project and then rebuilding the project.
SETUP 1
Debug Result Setup 1


Setup 2
Debug Result Setup 2



SETUP 3
Debug Result Setup 3
Ilia Motornyi & Anna Falevskaya Kindly let me know what is wrong with the configurations both GDBServer and the arm-none-eabi-gdb..exe commands.
Ssskypesw, please try my advises again. If you still are not able to fix the problem, please copy content of 'Console' tab in the debugger window here.
Ilia Motornyi
---DONE--- Please check the generated files below - The CMakeLists.txt file above has the fix for the extra .elf extension.
---DONE--- I have taken out the add_custom_target(UPLOAD ...) section from CMakeLists.txt file and I have deleted the CMake template file.
In addition I have used the .elf file as the target (image below)
---DONE--- Please check following configuration that I am going to use
---DONE--- Please see above
The Console result is as below
Thanks illia, it seems adding 500ms delay has solved my problem