[Home]DebuggingRtapi

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Showing revision 5
When LinuxCNC 2.7+ is built "--with-realtime=uspace", it is possible to use gdb, including for debugging hardware drivers. However, realtime guarantees are lost when using a debugger on rtapi_app. With older versions, the same instructions apply for "--enable-simulator", except that hardware drivers are not built so they are not debuggable.

First, (re)build linuxcnc:

 % ./configure --with-realtime=uspace; make
If you are going to debug hardware components, you need a PREEMPT-RT kernel and you need to
 % sudo make setuid

Make sure you have your environment set:

 % . ../scripts/emc-environment
Then start hal and load any component:
 % halrun
 halcmd: loadrt and2

Then, in a fresh terminal, start the debugger (use 'sudo' to run the debugger as root if you did 'sudo make setuid' above):

 % sudo gdb --pid `pidof rtapi_app`
Set breakpoints if you wish:
 (gdb) break and2.comp:_
 No source file named and2.comp.
 Make breakpoint pending on future shared library load? (y or [n]) y
Then let rtapi_app continue:
 (gdb) continue

In the original terminal, finish setting up your hal components:

 halcmd: loadrt threads name1=thread period1=1000000
 halcmd: addf and2.0 thread 
 halcmd: start
 halcmd: 
At this point, gdb will stop at the breakpoint you set earlier:
 Breakpoint 2 at 0xb7f766e7: file and2.comp, line 8.
 Pending breakpoint "and2.comp:_" resolved
 HAL: creating thread thread, 1000000 nsec
 HAL: thread created
 THREADS: created 1000 uS thread
 task 0x80515c0 period = 1000000 ratio=1 

 Breakpoint 2, _ (inst=0xb7d070b4, period=1000000) at and2.comp:8
 8	and2.comp: No such file or directory.
 	in and2.comp
 Current language:  auto; currently c
 (gdb) print *inst
 $1 = {_next = 0x0, in0 = 0xb7d26ee0 "", in1 = 0xb7d26e98 "", 
   out = 0xb7d26e50 ""}
 (gdb) print *inst->in0
 $2 = 0 '\0'
To make gdb find the source files, it seems necessary to use the 'directory' command:
 (gdb) directory ~/emc2.head/src/hal/components/
 Source directories searched: /home/jepler/emc2.head/src/hal/components:$cdir:$cwd
 (gdb) frame 0
 #0  _ (inst=0xb7d070b4, period=1000000) at and2.comp:8
 8	FUNCTION(_) { out = in0 && in1; }
The commands you find yourself executing every time you start gdb can be put in a ".gdbinit" file; see gdb documentation for more information.

gdb will also break in the case of a signal, and you can press ctrl-c to stop it at any time. In case you interrupt it manually, it may be useful to see the stack of each thread:

 (gdb) thread apply all bt
since rtapi_app has one main thread plus one thread for each realtime thread.

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions | View current revision
Edited April 27, 2015 11:09 am by JeffEpler (diff)
Search:
Published under a Creative Commons License