Trying to remote debug with Clion

Hello,

I use eclipse as my main IDE, would really like if Clion would be viable one day. Currently I cant setup remote debugging properly. The target is a cut-down "buildroot" Linux, project is CMake the  Toolchain is the default with `-DCMAKE_TOOLCHAIN_FILE` defining paths to cross-compilers and sysroot.

gdb/gdbserver is 10.1, I am using Linux and connecting to the target over ssh. The "Remote GDB Server" launch works as far as transferring and starting gdbserver. However there are still things missing.

Need to specify absulute path to gdbserver

cant seem to use the normal PATH Variable. Not sure how you start the ssh session (This point is minor)

gdbserver --no-startup-with-shell :1234 /tmp/CLion/debug/test
env: can't execute 'gdbserver': No such file or directory


Insufficient ways to define the GDB Server commandline.


I need to add '--no-startup-with-shell --once', I cant do this without removing the default cmdline. Means I have to re-add ':1234 /tmp/CLion/debug/test', neither are available as Macro.

GDB is not setup to read symbols

(that was my fault)

Not possible to add parameters to GDB

I would like to add a special gdbinit file for setting up paths and python scripts, and ignore the default one. This is stored within the toolchain, so some Toolchainpath Macro would be the next thing to request.

1 comment
Comment actions Permalink

For some more references i will add my cmake_toolchain and gdbinit file.

Ideally one could extract information from the toolchain-file. `PACKAGE_PREFIX_DIR` (ex. /opt/toolchain/usr) is basically the root of the toolchain, but that is a nonstandard variable. `CMAKE_PROGRAM_PATH` (ex. /opt/toolchain/usr/bin) would be a good variable to offer as Macro, same as `CMAKE_SYSROOT` (ex /opt/toolchain/usr/x86_64-linux-gnu/sysroot).

From this, one could create several paths to either load a gdbinit file (ex. `CMAKE_PROGRAM_PATH`/../share/gdbinit) or set some gdb options directly (ex. '-iex "set sysroot /opt/toolchain/usr/x86_64-linux-gnu/sysroot"').


# CMake toolchain file

# Allow relocation of the toolchain, PACKAGE_PREFIX_DIR
# should point to the root installation (CT prefix path during build)
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_TOOLCHAIN_REMOVE_MPATH ${CMAKE_CURRENT_LIST_DIR})

set(CMAKE_SYSTEM_NAME Linux_Crosstool)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_SYSTEM_VERSION 4.19.145)

set(CMAKE_INSTALL_SO_NO_EXE 0)

# Generic paths and search settings
set(CMAKE_PROGRAM_PATH "${PACKAGE_PREFIX_DIR}/bin")
set(CMAKE_SYSROOT "${PACKAGE_PREFIX_DIR}/x86_64-linux-gnu/sysroot")
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(ENV{PKG_CONFIG_PATH} "")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} "${CMAKE_SYSROOT}")

# Compiler binaries
set(CMAKE_C_COMPILER "${PACKAGE_PREFIX_DIR}/bin/x86_64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "${PACKAGE_PREFIX_DIR}/bin/x86_64-linux-gnu-g++")
#gdbinit
python sys.path.append(0, '/opt/toolchain/usr/share/gcc-10/python');
add-auto-load-safe-path /opt/toolchain/usr/share/gdb/auto-load
add-auto-load-safe-path /opt/toolchain/usr/x86_64-linux-gnu/sysroot/lib
set sysroot /opt/toolchain/usr/x86_64-linux-gnu/sysroot

set debug-file-directory /opt/toolchain/usr/lib/debug
0

Please sign in to leave a comment.