c - R包: breakpoint setup for C function with gdb in Debian (Testing)

标签 c r debugging gdb debian

我想从我的包中调试 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)ontinue 执行,而不是 signal 0。)

关于c - R包: breakpoint setup for C function with gdb in Debian (Testing),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30175243/

相关文章:

R:每两个月休息一次的切割功能

visual-studio - Visual Studio 2005(和其他): how to deploy debug dll (msvcp80p. dll 和 friend ,用于调试目的)

c - 如何识别大型C项目中的“死c文件”?

c - 如何确定字符串长度?

C 相当于 Fortran 名单

r - 弃用 R 3.0 中的多核 (mclapply)

c - 128 位整数在英特尔 C 编译器中支持 +、-、*、/和 %?

r - 调整条形图ggplot2中的轴限制

c++ - cmake生成VS项目不能断点

c - C 程序如何在不终止的情况下生成自身的核心转储?