R 包:在 Debian 中使用 gdb 为 C 函数设置断点(测试)

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

我想从我的包中调试一个 C 函数。

我想用 gdb 检查执行情况,尽管我发现很难设置断点。

遵循 4.4.1 在动态加载的代码中查找入口点 来自 Writing R Extensions:

1) 在 R 可执行文件上调用调试器,例如通过 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) 启动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) 在 R 提示符下,使用 dyn.load 或库加载您的共享对象。

> library(ifctools)

4)发送中断信号。这将使您回到调试器提示符。

> # <-- 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) 在代码中设置断点。 我需要查看的 c 函数是 称为 reg_guess_fc.

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

6) 通过输入信号 0RET 继续执行 R。

(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

换句话说,C 函数 reg_guess_fc,由 R 函数 guess_fc 调用 没有在第 1 行停止,因为我希望像上面那样设置断点。我错过了什么?

如果有帮助,包是here

guess_fc() calls

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

所以也许您只是没有调用您认为的 C 代码? (我会输入 c 以 (c) 继续执行,而不是 signal 0。)