Luca Braglia
Luca Braglia

Reputation: 3243

R packages: breakpoint setup for C function with gdb in Debian (Testing)

I'd like to debug a C function from a package of mine.

I would like to check execution with gdb, although i find difficulties to set breakpoints.

Following 4.4.1 Finding entry points in dynamically loaded code from Writing R Extensions:

1) Call the debugger on the R executable, for example by R -d gdb.

l@np350v5c:~$ R -d gdb
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/lib/R/bin/exec/R...(no debugging symbols found)...done.
(gdb)

2) Start R.

(gdb) run
Starting program: /usr/lib/R/bin/exec/R --no-save --no-restore -q
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff338d700 (LWP 6171)]
[New Thread 0x7ffff2b8c700 (LWP 6172)]
[New Thread 0x7ffff038b700 (LWP 6173)]
[New Thread 0x7fffedb8a700 (LWP 6174)]
[New Thread 0x7fffeb389700 (LWP 6175)]
[New Thread 0x7fffe8b88700 (LWP 6176)]
[New Thread 0x7fffe6387700 (LWP 6177)]
[Thread 0x7ffff338d700 (LWP 6171) exited]
[Thread 0x7fffeb389700 (LWP 6175) exited]
[Thread 0x7ffff038b700 (LWP 6173) exited]
[Thread 0x7fffe6387700 (LWP 6177) exited]
[Thread 0x7ffff2b8c700 (LWP 6172) exited]
[Thread 0x7fffe8b88700 (LWP 6176) exited]
[Thread 0x7fffedb8a700 (LWP 6174) exited]

3) At the R prompt, use dyn.load or library to load your shared object.

> library(ifctools)

4) Send an interrupt signal. This will put you back to the debugger prompt.

> # <-- Ctrl + C here
Program received signal SIGINT, Interrupt.
0x00007ffff71202b3 in select () at ../sysdeps/unix/syscall-template.S:81
81                 ../sysdeps/unix/syscall-template.S: File o directory non esistente.

5) Set the breakpoints in your code. The c function i need to look at is called reg_guess_fc.

(gdb) b reg_guess_fc
Breakpoint 1 at 0x7fffe0e8de50: file reg_guess_fc.c, line 13.

6) Continue execution of R by typing signal 0RET.

(gdb) signal 0 [ENTER]
Continuing with no signal.
[ENTER AGAIN]
> #Now i believe i'm supposed to call code breakpointed, so
> example(guess_fc)

gss_fc> ## using fictious data
gss_fc> Surnames <- c("Rossi", "Bianchi")

gss_fc> Names <- c("Mario", "Giovanna")

gss_fc> Birthdates <- as.Date(c("1960-01-01", "1970-01-01"))

gss_fc> Female <- c(FALSE, TRUE)

gss_fc> Comune_of_birth <- c("F205", # milan
gss_fc                       "H501") # rome

gss_fc> guess_fc(Surnames, Names, Birthdates, Female, Comune_of_birth)
[1] TRUE TRUE

In other words the C function reg_guess_fc, called by R function guess_fc is not stopped at line 1 as i hoped setting the breakpoint as above. What am I missing?

If it can help, the package is here.

Upvotes: 4

Views: 241

Answers (1)

Martin Morgan
Martin Morgan

Reputation: 46856

guess_fc() calls

rval <- .Call("reg_wrong_fc", surname, name, year, month, 
    day, female, codice_catastale, PACKAGE = "ifctools")

so maybe you are simply not calling the C code you thought you were? (I'd have entered c to (c)ontinue execution, rather than signal 0.)

Upvotes: 3

Related Questions