Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdbsource() eats GDB errors #341

Open
lentinj opened this issue Mar 1, 2021 · 1 comment
Open

gdbsource() eats GDB errors #341

lentinj opened this issue Mar 1, 2021 · 1 comment

Comments

@lentinj
Copy link
Contributor

lentinj commented Mar 1, 2021

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

@lentinj
Copy link
Contributor Author

lentinj commented Mar 3, 2021

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, "\"")))

@lentinj lentinj changed the title gdbsource() eats GDB errots gdbsource() eats GDB errors Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant