First, (re)build linuxcnc:
% ./configure --with-realtime=uspace; makeIf 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-environmentThen 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]) yThen 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 btsince rtapi_app has one main thread plus one thread for each realtime thread.