Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R doesn't recognize command line option. (WARNING: unknown option '-d')

Tags:

windows

r

gdb

I am trying to use gdb to debug compiled code in an R package in the same way as specified in the video: https://vimeo.com/11937905 and Writing R Extensions section 4.4.

These sources say to use the command R -d gdb when starting R. However, whenever I try to do this I get a message saying WARNING: unknown option '-d' and R is started under normal conditions. Why isn't R recognizing the -d flag? I am using Windows 10.

like image 793
Matthew Lueder Avatar asked Jun 14 '16 15:06

Matthew Lueder


1 Answers

As @MatthewLueder has found out himself finally debugging on Windows does not work as on Linux.

A how-to is described in the R for Windows FAQ

The main reason for the missing -d argument in R seems to be that Windows cannot send a signal to a process to interrupt the execution and pass the control to the (gdb) debugger:

  • Without interrupting R you cannot set a breakpoint.
  • Without starting R into the R console you cannot load libraries to be debugged (without making your hands dirty).

Therefore R on Windows offers a work-around using RGui instead of R:

gdb /path/to/R-3.x.x/bin/x64/Rgui.exe
(gdb) run

After starting the RGui you are in an R shell and can load your packages that contain the DLLs to be debugged.

To set breakpoints for debugging you can interrupt R to break into the debugger via a menu item that is only visible if RGui was started with gdb:

enter image description here

Now you can set breakpoints in your code via b a_function_name, enter c to continue R, call the function in R and voilà: gdb shows the breakpoint hit and you can debug (stepping through the code and printing variable values).

PS: I am currently developing an R package to improve the debugging of C++ code in R packages since it is quite difficult to view the current values of R variables or Rcpp data types in gdb: https://github.com/aryoda/R_CppDebugHelper

like image 90
R Yoda Avatar answered Oct 17 '22 17:10

R Yoda