Debugging with Eclipse Print


This application note describes how to use Eclipse for building and debugging applications for Emcraft Cortex‑M BSPs.

You will need a Linux version of Eclipse IDE installed on you Linux development host.
Go to and select the latest version of Eclipse IDE for C/C++ Developers. At the moment of writing, the current version is the "Oxygen" release. Download and install Eclipse to your host.

Adding a Project to Eclipse

Here is how to create a single file project in Eclipse.

  • Start Eclipse and select a workspace directory. The workspace directory is an arbitrary directory, different from the directory where your source file is located.
  • Create an empty project, open File -> New -> C Project, choose С/C++ -> C Project and click Next:
  • Enter the name of the project, for example, c-example and click Next.
  • On the next screen you will be prompted to choose build configurations. Leave all defaults and click Next to proceed.
  • On the next screen, enter arm-v7-linux-uclibceabi- as a Cross compiler prefix and
    /usr/local/arm-v7-linux-uclibceabi/bin as a Cross compiler path:
  • Click Finish.
  • Add your source file to the project, open File -> Import, select File System:
  • Click Next, and, using Browse, navigate to the directory with your source file.Select the directory in the left window,
    this will add its content to the project:
  • Click Finish.

Creating Build Configuration and Building the Project

Now, we need to instruct Eclipse on how to build the project for the Cortex‑M3/M4 target.

  • Right-click on the just created project and select Properties. Navigate to C/C++ Build->Environment.
  • Click Add and add the INSTALL_ROOT variable as the root of your Emcraft BSP directory:
  • Edit the PATH variable and prepend the existing PATH with
    ${INSTALL_ROOT}/tools/bin:${INSTALL_ROOT}/tools/arm-v7-linux-uclibceabi/bin (note the colon at the end):
  • Click Apply.
  • Navigate to Settings.
  • In the Tool Settings tab on the right, select Include paths:
  • Click on the + button and enter the include the path ${INSTALL_ROOT}/A2F/root/usr/include, click Ok when done:
  • Navigate to Miscellaneous and add -static to Other flags:
  • In the same window, navigate to Cross GCC Linker -> Library search path:
  • Click on the + button and enter the library search path ${INSTALL_ROOT}/A2F/root/usr/lib:
  • Navigate to Miscellaneous and add -static to Linker flags, click Apply and Close when done:
  • To build the project, press Ctrl-B.

Debugging the Project on the Target

On the host filesystem, the executable binaries are located in the Debug subfolder of the Eclipse workspace directory you selected on start of Eclipse:

% ls -la /home/sermir/workspace/c-example/Debug
total 284
drwxrwxr-x  2 sermir sermir 4096     Aug 21 13:02 .
drwxrwxr-x  4 sermir sermir 4096     Aug 21 13:00 ..
-rwxrwxr-x  1 sermir sermir 151720   Aug 21 13:02 c-example
-rw-rw-r--  1 sermir sermir 20       Aug 21 13:02 clone.d
-rw-rw-r--  1 sermir sermir 10603    Aug 21 13:02 clone.o
-rw-rw-r--  1 sermir sermir 1041     Aug 21 13:09 makefile
-rw-rw-r--  1 sermir sermir 231      Aug 21 13:02
-rw-rw-r--  1 sermir sermir 390      Aug 21 13:09
-rw-rw-r--  1 sermir sermir 731      Aug 21 13:09

In the directory above, c-example is the binary for Cortex-M3 target.

For remote debugging, you need to deploy the  c-example binary to the target. This can be done in several ways:

  • Using scp or sftp to copy the binary to the target;
  • Using NFS share configured on the host and mounting this share from the target.

We will demonstrate the second method. Suppose we have the Eclipse workspace directory (for example, /home/sermir/workspace/) exported as NFS share. Let's modify the Linux project to auto-mount this directory via NFS. Add the following lines to etc/rc and rebuild the project:

% cd projects/rootfs
% vi etc/rc
sleep 2
mount -o nolock /mnt/

After loading the project to the target, you should have your Eclipse workspace directory mounted as /mnt:

/ # df
Filesystem 1K-blocks Used Available Use% Mounted on
420590592 356163584 43038720 89% /mnt
/ #
/ # ls -la /mnt/c-example/Debug/
drwxrwxr-x   2 1002 1002 4096    Aug 21 2017 .
drwxrwxr-x   4 1002 1002 4096    Aug 21 2017 ..
-rwxrwxr-x   1 1002 1002 151720  Aug 21 2017 c-example
-rw-rw-r--   1 1002 1002 20      Aug 21 2017 clone.d
-rw-rw-r--   1 1002 1002 106032  Aug 21 2017 clone.o
-rw-rw-r--   1 1002 1002 1041    Aug 21 2017 makefile
-rw-rw-r--   1 1002 1002 231     Aug 21 2017
-rw-rw-r--   1 1002 1002 390     Aug 21 2017
-rw-rw-r--   1 1002 1002 731     Aug 21 2017
/ #

Now, we need to add Debug Configuration to the Eclipse project:

  • Open Run -> Debug Configurations:
  • Create a new configuration in C/C++ Remote Application by clicking + in the upper left part of the dialogue:
  • In the Main tab, change the Using GDB Autimatic Remote Debugging Launcher: click to Select other... and choose Manual Remote Debugging Launcher:
  • Now, switch to the Debugger tab and change gdb to arm-v7-linux-uclibceabi-gdb:
  • Select the Connection tab and enter an IP address of you target, and gdbserver connection port:
  • Click Apply (don't click on Debug yet!).

Now, we are ready to debug on the target. In the target console window, start gdbserver with you application using the port number your specified above:

/ # gdbserver :1234 /mnt/c-example/Debug/c-example
Process /mnt/c-example/Debug/c-example created; pid = 80
Listening on port 1234

Back to the Eclipse, click Debug. You will be asked to switch to the Debug Perspective window, accept it:

Click to enlarge

When started under remote debugger, the program automatically stops at the main() function.

Now you can execute you program with steps, put breakpoints, and examine variables:

Click to enlarge