15.1.4 Debugging R/C Code...........................................
Chapter 13 discussed a number of tools and methods for debugging R code.
However, the R/C interface presents an extra challenge. The problem in
using a debugging tool such as GDB here is that you must first apply it to R
itself.
The following is a walk-through of the R/C debugging steps using GDB
on our previoussd.ccode as the example.
$R-dgdb
GNU gdb 6.8-debian
...
(gdb) run
Starting program: /usr/lib/R/bin/exec/R
...
> dyn.load("sd.so")
> # hit ctrl-c here
Program received signal SIGINT, Interrupt.
0xb7ffa430 in __kernel_vsyscall ()
(gdb) b subdiag
Breakpoint 1 at 0xb77683f3: file sd.c, line 3.
(gdb) continue
Continuing.
Breakpoint 1, subdiag (m=0x92b9480, n=0x9482328, k=0x9482348, result=0x9817148)
at sd.c:3
3 int nval =*n, kval =*k;
(gdb)
So, what happened in this debugging session?
- We launched the debugger, GDB, with R loaded into it, from a com-
mand line in a terminal window:
R-dgdb - We told GDB to run R:
(gdb) run - We loaded our compiled C code into R as usual:
dyn.load("sd.so")
- We hit theCTRL-C interrupt key pair to pause R and put us back at the
GDB prompt. - We set a breakpoint at the entry tosubdiag():
(gdb) b subdiag
326 Chapter 15