[OSy] CLion project setup, running, debugging

osyv at post.cz osyv at post.cz
Mon Nov 7 11:35:24 CET 2016


Hello,

for those who would like to have more integrated environment for developing and debugging assignments, there is an option of using CLion.

Project setup:
CLion uses CMake for its management of project dependencies. However, there is a way how to circumvent this and reuse original makefiles.
When importing the directory with root makefile to the project (Menu -> File -> Import Project), add "kernel" to User Include Directories.
After import, delete line with setting flags, e.g.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

and replace the line in CMakeLists.txt file:

add_executable(<project_directory_underscores_only> ${SOURCE_FILES})

with:

add_library(<project_directory_underscores_only>_cmake EXCLUDE_FROM_ALL ${SOURCE_FILES})
add_custom_target(<project_directory_underscores_only> COMMAND make -C ${<project_directory_underscores_only>_SOURCE_DIR}
        CLION_EXE_DIR=${PROJECT_BINARY_DIR})

where <project_directory_underscores_only> is the name of the project directory, but for instance for "kalisto-0.9.9" replaced as "kalisto_0_9_9".
For info, add_library with EXCLUDE_FROM_ALL enables code navigation and refactoring to some extent; if you manage to get rid of system libraries,
it should give less hassle, I wasn't successful at this though - also it complains about redefinition at certain functions, like free in mm/malloc.c.

 Afterwards, confirm CMake reload. To build, click binaries button at the top left or Ctrl+F9.

Running setup:
Menu -> Run -> Edit Configurations -> (+) (Add new configuration) -> Application. Choose testing script in Executable. Name configuration
appropriately in Name. To run, click green arrow or Shift+F10.

Debugging setup:
A bit more tricky.  First, create a small script next to msim.conf, containing (see doc [1]):

msim -g <port-number> &

or anywhere else, but make sure you add -c <path-to-msim.conf>. Port number for instance 3000. Add rights to execute.

Now, back in CLion, proceed as in running setup above, but choose GDB Remote Debugging instead of Application. Choose path for mips gdb,
target remote address - localhost:<port-number>, symbol file.  Name the configuration appropriately. Then, in Before launch listbox, 
add (+) "Run External Tool", add (+) -> Create Tool -> Tool Settings: here choose script mentioned above as Program, and add its path 
as Working Directory. Finally, to start debugging, you should select this configuration in combobox at the top right of CLion. After that,
 click the bug button, or Shift+F9. Variables can be seen down in Debugger -> Variables tab.

Regards

Jan Vinárek

[1] http://d3s.mff.cuni.cz/~holub/sw/msim/reference.html#cmd_gdb



More information about the NSWI004 mailing list