LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Eclipse and LinuxCNC 

Michael Abel, Date 2012.05.06

This is a short how-to to do graphical debugging of rtapi_app within eclipse. 

With this trick it should be possible to have real-time programs running inside the debugger. It should also be possible to hit breakpoints while the app is running, but this feature does still not work properly (see unsolved issues below). Of course, debugging real-time programs isn't really real-time. Accordingly expect missed deadlines, timing problems and other strange behaviour.

Configuring the Eclipse Project

I'm was unable to export the project files. That's why here is an explanation on how to set up the Project for remote debugging:
(I hope most things are correct :)

Get and install Eclipse
For example "Eclipse IDE for C/C++ Developers (includes Incubating components)" from


(Filename: eclipse-cpp-indigo-SR2-incubation-linux-gtk.tar.gz)

On my debian squeeze system I have installed the debian packet "sun-java6-jre". Since there are sometimes problems with eclipse and the gcj-jre.

$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)

Create Project

-> "New" -> "Project ..." -> C/C++ -> "Makefile Project with existing code"

... Add name and existing code location (path to emc2-dev/)
    Toolchain: Linux GCC
... Press finish

-> "Project" -> "Properties" -> "C/C++ Build"
... Builder Settings:
... Set Build command to "make V=1 OPT=-O0"
... Set Build Directory to ${workspace_loc:/emc2-dev/src}
... Behavior:
... check "Stop on first build error"
... set "use parallel jobs"
... remove "all" from "Build(Incremental build)"
... Press OK

-> "Project -> Build all"

... Building and cleaning should work now...

-> "Run" -> "Debug Configurations"

... Choose "C/C++ Remote Attach to Application" And create a new Configuration

... Searching for the binary didn't work for me, so I had to browse and search for rtapi_app

... select <path>/emc2-dev/bin/rtapi_app

... In the next Tab: Set debugger command from "gdb" to "sudo gdb"

-> Enhance your sudoers file :
<user> ALL=NOPASSWD: /usr/bin/gdb

Deactivate Optimisation

Next deactivate optimization in the Makefiles. I.e. delete all "-Os" in the Makefiles. This is necessary since the debugger would jump through the code in a very strange way when optimization is enabled.

Here is a diff, that worked for me:

micha@triton:~/Projects/emc2-dev/src$ git diff -U0 Makefile Makefile.inc.in
diff --git a/src/Makefile b/src/Makefile
index 2916ee7..5fb4527 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -174 +174 @@ endif
-OPT := -Os
+OPT :=
@@ -844 +844 @@ ifneq "$(filter sim linux,$(BUILD_SYS))" ""
@@ -888 +888 @@ $(sort $(RTOBJS)) : objects/rt%.o : %.c
-       $(Q)ld -r -static -S -Os $(LDFLAGS) -o $@ $^ $(EXTRALINK) $(MATHLIB)
+       $(Q)ld -r -static -S $(LDFLAGS) -o $@ $^ $(EXTRALINK) $(MATHLIB)
diff --git a/src/Makefile.inc.in b/src/Makefile.inc.in
index 0625a1f..971fbc2 100644
--- a/src/Makefile.inc.in
+++ b/src/Makefile.inc.in
@@ -78 +78 @@ KERNELDIR = @KERNELDIR@
@@ -84 +84 @@ MATHLIB = @MATHLIB@
-ULFLAGS = -Wall -g -I. -I@RTDIR@/include -DULAPI -D_GNU_SOURCE -Os -DLOCALE_DIR=\"$(localedir)\" -DPACKAGE=\"$(package)\"
+ULFLAGS = -Wall -g -I. -I@RTDIR@/include -DULAPI -D_GNU_SOURCE -DLOCALE_DIR=\"$(localedir)\" -DPACKAGE=\"$(package)\"

Recompile (in the source directory)
make clean
sh autogen.sh
./configure  --with-realtime=linux

Start Debugging

... put some breakpoints into the code 

... Start call linuxcnc as root from commandline

-> Start the "Attach to process" debugging profile 

... select the running rtapi_app in the next "Select Process" Dialog

... hit a breakpoints and be happy

See also attached picture

Optional: gdbserver

It's also possible to use real remote debugging with gdbserver.
In this case you need a "C/C++ Remote Application" debugging configuration with the gdb command set to sudo gdb

Start rtapi_app with this command:

# gdbserver host:2345 <path>/emc2-dev/bin/rtapi_app

... then start remote debugging in eclipse

After that start linuxcnc

Unsolved Issues

* I was unable to set breakpoints in hal components (e.g. ddt). This is probably because they are loaded dynamically. (?)
* You will probably need to set breakpoints in advance i.e. before starting rtapi_app. Disabled breakpoints can possibly not enabled again. This is also the case at my other real time programs, the reason is still unknown.

Add .comp as C source file type [CDT/User/FAQ - Eclipse]

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited March 2, 2013 5:40 pm by Yishin Li (diff)
Published under a Creative Commons License