Running GDB on R Itself
You may have written some C code to interface to R and found it to be buggy. In order to run GDB on that C function, you must first run R itself through GDB.
Although you can invoke R through GDB from a shell command line, for our purposes here, I suggest using separate windows for R and GDB. Here is the procedure:
- Start R in one window, as usual.
-
In another window, determine the ID number of your R process. In UNIX family systems,
for instance, this is obtained by something like:
ps -a - In that second window, submit GDB's
attachcommand with the R process number. - Submit the
continuecommand to GDB.
You can set breakpoints in the R source code either before continuing or by interrupting GDB later with CTRL-C.
The R source code is dominated by S expression pointers (SEXPs), which are pointers to C
structs that contain an R variable's value, type, and so on. You can use the R internal
function Rf_PrintValue(s) to inspect SEXP values. For example, if the SEXP is
named s, then in GDB, type this:
call Rf_PrintValue(s)
This prints the value.