How to create and debug CMake project on a remote target

“CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.”

This document will show How to Create a new CMake Project or Import an existing CMake Project, Build, Run and Debug the CMake Project.

Create CMake Project:

To create CMake Project, Open TimeStorm and click on new → C Project. In the C Project wizard, we can see the CMake project category. Expand the category which shows Empty Project and Hello World Cmake Project. To illustrate, the sample Hello World C Cmake project is selected as shown below. After selecting, click Next for setting up the Project General Settings.

All the fields in the General Setting wizard are optional. Enter the Author properties of the project and click Next to select the project configuration.

The configuration wizard shows Debug and Release options. Click on the Next button to select the SDK.

Current TimeStorm supports only Yocto SDK for CMake. FactorySDK and other SK (including usingNative toolchain) are disabled. Select Yocto SDK as shown below.

Click on the Finish button to create the project. We can see the created CMake project in the project explorer.

Import CMake Project:

To import the existing CMake project into TimeStorm. Right click on the project explorer → Import → General → Existing CMake Projects into workspace and click Next button as shown below.

Import new CMake Project wizard will open with Project Name, Existing Code Location with browse button, Languages (C, C++), and Toolchain for Indexer settings with CMake TimeStorm Cross-Compile, GNU Autotools Toolchain as shown below.

In the Import new CMake Project, click on the browse button and point to the existing CMake Project’s Location and click on OK button. The Project Name will autofill based on the pointed CMake Project and click on the Next button as shown below.

Select SDK wizard will open with SDK Type and Toolchain from SDK. Current TimeStorm supports only Yocto SDK for CMake. and the remaining FactorySDK and other SDK are disabled. Select Yocto SDK as shown below and click Next.

Click on the Finish button to import the project. We can see the imported CMake project in the project explorer as shown below.

Build CMake Project:

To build the CMake project, right click on the project and click on the Build Project and it starts to build and we can see the build logs in the console as shown below.

We can also switch the toolchain by right clicking on the project → TimeStorm SDK Switch. For more details, see How to Switch TimeStorm SDKs

Run CMake application on a Remote Target:

To run CMake applications on a remote target, right click on the project → Run As → Remote C/C++ Application. It will open a Run configuration wizard with Main, Arguments, Environment, Source, Target, Download Files, Common tabs as shown below.

Main Tab

In the Main tab, you can change the C/C++application by searching the project. You can change the project too if you want to use this configuration for a different project.

Arguments tab

In the Arguments tab, you can specify the arguments to be passed to the application program. The remote working directory is set as ‘.’, which means that the directory specified in the target definition is used as the working directory.

The command to be executed is filled in. Uncheck ‘Use default command’ to change this value. Keep in mind the directory structure on your target when constructing this command. For example, if you have copied your application file to a directory named /apps but you want to execute it from a working directory named /home/test, you must include the path to your application in your command.

For example: ../../apps/my_app

Environment tab

In the ‘Environment’ tab, you can set environment variables for the target

The panel shown below contains the following buttons:

New — Click the ‘New’ button to create a new entry, and the ‘New Environment Variable’ dialog will appear, as shown below. Click the ‘Variables’ button to select the variables that you want to use. Then, click ‘OK’ twice.

Select — Click the ‘Select‘ button to import environment variables from the host file system.

Edit — To change an entry, select it from the list, and click the ‘Edit’ button.

Remove — To delete an entry, select it from the list, and click the ‘Remove’ button.

Source tab

The Source tab shows the location of the source files for the project.

  • Source Lookup Path — This field shows the project being run, as well as any projects that it references.
  • Add — You can add arbitrary source file locations by using the Add button. These locations are searched after the generic locations, from the top to the bottom item in order.
  • Edit, Remove, Up, Down — The other buttons to the right of the list allow you to edit, remove, or reorder the list items, and to restore the default information.
  • Search for duplicate source files on the path — Selecting this checkbox causes TimeStorm to notify the user if it is unable to determine which source file corresponds to an executing binary file. For example, if you have two source files with the same filename in different directories of the search path, TimeStorm is unable to determine which file is related to the binary file with that name. If this checkbox is selected, TimeStorm displays a message and asks the user to select which file to use. This checkbox is not selected by default.

Target tab

The Target tab, allows you to select the hardware target used when you run the application.

In the Target tab, use the drop-down list to select a hardware target that you have already created. If you have not yet created a hardware target or want to change the settings for an existing target, click ‘Manage targets’ to open the Hardware Targets management utility.

Download Files tab

In the ‘Download Files’ tab, you can select the files that TimeStorm transfers to your target. The application that has to be downloaded is already listed. You can use this panel to download additional files to your target, along with your application.

The application specified in the File field is listed as [Target Program]. This is the application that will be run. You can change where it is downloaded by selecting it and clicking Edit.

If the program links in shared libraries, then these libraries will be downloaded to the target as well and the Files field is listed as [Target Program and Libraries]. These libraries will be downloaded to the same location as the target program. To download the program and libraries to separate locations, remove the default entry and re-add each as a separate entry.

File paths are interpreted as relative to the target directory to which you download files. If you transfer files by using FTP, the actual destination directories depend on the configuration of your FTP software. In some cases, directories specified in this panel are appended to the user’s home directory on the target.

This panel contains the following buttons:

  • Add File – Use the ‘Add File’ button to specify additional files to transfer, along with the application. These files are transferred every time you transfer the application file.
  • Edit – To change where the application (or any other file in this list) is installed, select it and click ‘Edit’ to change its destination directory.
  • Remove – To eliminate a file from the items to download, select it in the list and click the ‘Remove’ button.
  • Download Now – The ‘Download Now’ button copies files immediately, without running the application.
  • Restore Default – The ‘Restore Default’ button resets the panel to its initial state (download only the application and its libraries).

NOTE: Downloaded files overwrite any identically named files on the target without giving a warning. TimeStorm will not create destination directories on the target, so be sure to create them before launching the configuration.

Common tab

The ‘Common’ tab, sets options for sharing this run configuration among multiple projects.

The options with the Common tab include:

  • Local File — By default, run configurations are saved with the workspace state files, so they can only be used with projects in the current workspace. (This setting corresponds to the ‘Local file’ radio button on this panel.) However, you can make the configuration available for use in other workspaces by choosing the ‘Shared file’ radio button.
  • Shared File — When you select this option, the run configuration is saved as a .launch file that can be imported into another TimeStorm workspace. Optionally, you can specify a different location for the file so that it is more easily accessible to multiple projects.
  • Display in Favorites Menu — You can select whether to include this run configuration on the main ‘Run’ and ‘Debug’ menus. For example, if you select the ‘Run’ checkbox, the run configuration always appears in the ‘Run History’ submenu.
  • You can choose to include the run configuration in either menu, both menus, or neither menu

  • Launch in Background — Selecting the ‘Launch in background’ checkbox causes this run configuration to run as a background thread. Running as a background thread is the default value. Clear this checkbox if you want to run in the foreground, along with other TimeStorm processing.
  • After setting the values in all the tabs, click the Run button at the bottom of the run configuration dialog. This will connect your host to your target, download the application to the target and execute the application on the target. The commands executed on the target and the program output progress are displayed in the console view as shown below.

    Debug CMake application on a Remote Target:

    Debug Configuration:

    To debug an CMake application, build the project using the debug build configuration that has the toolchain settings to include complete debug information in the binary. After the project is built, you have to create a debug configuration to debug the application. A debug configuration is similar to a run configuration created in the previous section, but with additional settings for the launching and using the debugger. To create a debug configuration, right click on the project and click on Debug As > Remote C/C++ application in the project context menu. This will open a Debug configurations dialog as shown below.

    The debug configuration dialog is similar to the run configuration dialog as shown below with an additional debugger tab that includes the settings for the debugger. Most of the values in all the tabs are filled in by default. In most cases, you have to select the target you have to debug on the debug tab and click the debug button to start debugging. By default the debugger will stop at the main function and you can continue debugging from there.

    To change the debugger settings, click on the Debugger tab as shown below.

    This tab contains the following options:

    Stop on startup at — Select this checkbox if you want execution to pause when your application starts.

    (This option is selected by default.)

    Specify the function name at which the execution should pause.

    Debugger Options — This section of the panel includes two tabs: 1.) Main and 2.) Shared Libraries. The ‘Main’ tab is shown above.

    • Main — This tab includes the following fields:
    • GDB Debugger — This field is filled in with the gdb from the SDK used with the Active Build Configuration to build the project. Set ‘Debug’ as the Active Build Configuration to be sure that the correct gdb is filled in.
    • GDB command file — This field allows you to specify a .gdb-command file using the Browse button. The debugger will execute the commands specified in this file.

    Shared Libraries — The Shared Libraries tab shown below, includes the following options:

    • Directories — This field specifies any additional directories for the debugger to search to find shared libraries (with debugging symbols). By default the debugger will automatically search the paths specified in the project's build settings (see option below). Use the ‘Add’ button if you want to add other paths. Use the ‘Up’ and ‘Down’ buttons to move through the list of directories. Use the ‘Remove’ button to delete a path.
    • Load shared library symbols automatically — Select this checkbox if you want these library symbols to be displayed as loaded in the ‘Shared Libraries’ view and if you want the debugger to hit any breakpoints in the shared library project. (This option is selected by default.)

    GDB Server Settings - The GDB Server settings tab has GDB Server path, Port Number, GDB Server options. As per the requirement, we can modify the Server Settings.

    After modifying the debugger settings, click on the Debug button to start debugging. TimeStorm will connect to the target, download the application, start the gdbserver and prompt you to switch to Debug perspective. Debug perspective is a layout of various views like stack, variables and breakpoints management that help you in debugging. Select the ‘Remember my decision’ checkbox and click on the yes button. The debug perspective will open as shown in figure 33 and the debugger waits at the breakpoint you have set in the code or the ‘stop at function’ you entered in the debugger tab.

    You can use the buttons circled in the figure above to step in, step out, pause and terminate the debug session. For more details, please refer to C/C++ Development User Guide in TimeStorm help.

    Adding a breakpoint

    You can add a breakpoint at a line in your source code, by opening the file in the editor and double clicking in the vertical grey bar in the source editor next to the line where you would like to add the breakpoint. This is shown below.

    Stepping commands: The TimeStorm Platform helps developers debug by providing buttons in the toolbar and key binding shortcuts to control program execution.