adcomp
adcomp copied to clipboard
gdbsource() eats GDB errors
Description:
When using gdbsource(..., interactive = TRUE), GDB errors are getting eaten somewhere.
Reproducible Steps:
Run the following script:
library(TMB)
writeLines(con = "/tmp/gdb_woes.cpp", "
#include <TMB.hpp>
template<class Type>
Type objective_function<Type>::operator() () {
PARAMETER(p);
Type x = 1;
abort();
return p + x;
}
")
TMB::compile("/tmp/gdb_woes.cpp", flags = "-g0 -O0")
dyn.load(TMB::dynlib("/tmp/gdb_woes"))
writeLines(con = '/tmp/gdb_woes_testcase.R', '
dyn.load(TMB::dynlib("/tmp/gdb_woes"))
TMB::MakeADFun(data = list(), parameters = list(p=1), DLL = "gdb_woes")
')
gdbsource('/tmp/gdb_woes_testcase.R', interactive = TRUE)
Current Output:
Program received signal SIGABRT, Aborted.
0x00007ffff79567bb in raise () from /lib/x86_64-linux-gnu/libc.so.6
#0 0x00007ffff79567bb in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff7941535 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff2c41718 in objective_function<double>::operator()() () from /tmp/gdb_woes.so
. . . snip . . .
(gdb) up
#1 0x00007ffff7941535 in abort () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) up
#2 0x00007ffff2c41718 in objective_function<double>::operator()() () from /tmp/gdb_woes.so
(gdb) print p
(gdb) print x
(gdb) argh
(gdb) help print
Print value of expression EXP.
Variables accessible are those of the lexical environment of the selected
. . . snip . . .
Expected Output:
Running outside of gdbsource():-
$ R -d gdb
(gdb) run --vanilla < /tmp/gdb_woes_testcase.R
Program received signal SIGABRT, Aborted.
0x00007ffff79567bb in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) up
#1 0x00007ffff7941535 in abort () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) up
#2 0x00007ffff2c41718 in objective_function<double>::operator()() () from /tmp/gdb_woes.so
(gdb) print p
No symbol table is loaded. Use the "file" command.
(gdb) print x
No symbol table is loaded. Use the "file" command.
(gdb) argh
Undefined command: "argh". Try "help".
(gdb) file /tmp/gdb_woes.so
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /tmp/gdb_woes.so...(no debugging symbols found)...done.
Aha, that's because I turned debugging off when using TMB::compile(). Fixing flags so I get debug symbols I can see output when my print commands are valid:
(gdb) print p
$1 = 1
(gdb) pritn x
(gdb) print x
$2 = 1
TMB Version:
> packageVersion("TMB")
[1] ‘1.7.18’
R Version:
> R.version.string
[1] "R version 3.6.3 (2020-02-29)"
... and ...
> R.version.string
[1] "R version 4.0.3 (2020-10-10)"
Operating System:
Debian 5.10.5-1
Replacing the system call in gdbsource with system2 seems to solve this, at least on Linux:
system2('R', c(
"-d", "gdb",
paste("--debugger-args=\"-x", gdbscript, "\"")))