gdb prints output (stdout) to RGui console instead of gdb console on Windows when debugging C++ code

307 Views Asked by At

I am debugging a C++ shared library (DLL) of an R library that uses the Rcpp framework.

I am on Windows and use gdb for debugging (the version installed via the Rtools).

I start debugging via the recommended command:

gdb Rgui.exe --silent

My problem: It seems that RGui captures all output created by Rcpp and R "print" functions in gdb to stdout and shows it in the RGui R console instead of the gdb console (terminal):

(gdb) call dbg_print(df)

enter image description here

How can I "redirect" the output to the gdb console?

PS 1: I could not find a setting for this in the RGui preferences

PS 2: Here is the code of the dbg_print function:

void dbg_print(DataFrame df) {
  Rcpp::print(df);
}

// Calls R's print function:
// inline void print(SEXP s) {
//    Rf_PrintValue(s);           // defined in Rinternals.h
// }

See also the source code for Rf_PrintValue in core R:

Edit 1: Rgui.exe does not offer an obvious switch for output redirection:

enter image description here

Edit 2: I am quite sure that R prints to stdout

All printing in R is done via the functions Rprintf and REprintf [...]

Rprintf writes to standard output. It is redirected by the sink() function, and is suitable for ordinary output.

REprintf writes to standard error and is useful for error messages and warnings. It is not redirected by sink().

Edit 3: @duckmayr has pointed me to an R callback function (in C) called R_WriteConsole that could be used to register my own printing routine to redirect R output to the gdb console (stdout). I am looking for more example code like this...

0

There are 0 best solutions below