How to debug an R package (with C and C++ code) in Eclipse?
Asked Answered
S

2

16

In Visual Studio we can use "attach to process" in order to debug the DLLs.

Is there any way to debug C/C++ code of an R package in Eclipse/StatET (i.e. something like this example of debugging external code linked to Scilab)?

Southwards answered 24/3, 2014 at 17:1 Comment(0)
U
8

The following steps work for Eclipse-CDT C/C++ (LUNA).

  1. Compile R (3.2) with debug information. Steps for downloading source using SVN can be found in R install guide.

$./configure --enable-R-shlib --with-valgrind-instrumentation=2 --with-system-valgrind-headers --CFLAGS='-g -O0 -fPIC' FFLAGS='-g -O0 -fPIC' CXXFLAGS='-g -O0 -fPIC' FCFLAGS='-g -O0 -fPIC' 
$make
$sudo make install 

This will install R under /usr/local/lib/R.

Note: -g and -O are needed to add debug symbols and to make sure that comiple optimization do not prevent debugging.

  1. Setup proper directory structure for an R-package with C source code. Use a makefile rather than relying on Eclipse-StatET for building the project. Makes the setup more easily portable to Windows.

  2. R CMD install at the command line or using the Makefile will install the package to the user's local R library.

  3. Under Eclipse (Luna) create a "New Debug Configuration" under C/C++ Application.

  4. Under 'Main' tab:

a. select a C/C++ Application:

/usr/local/lib/R/bin/exec/R

b. Project may point to the R-package project.

c. Check "Connect process input & output to a terminal".

  1. Under "Arguments" tab use:

--slave --vanilla --no-save

  1. Under 'Environment' tab add:

a. LD_LIBRARY_PATH: /use/local/lib/R/lib

b. R_HOME /usr/local/lib/R Select "Append environment to native environment"

  1. Under "Debugger" tab

a. Pick GDB debugger gdb

b. If 'GDB command set' is not displayed as an option, click 'Select other...' at the very bottom. Choose 'Legacy Create Process Launcher'. Doing so will now display options for picking GDB command set: Pick Standard with protocol mi.

  1. Under "source" tab

a. Add absolute path to the R directory with R source (optional) ~/Downloads/R

b. Add absolute path to the package src directory and any other dependent libraries.

  1. Click Debug.
Unkennel answered 2/5, 2015 at 10:20 Comment(3)
I think there is no need to compile R with debugging mode. We are not going to debug R itselfSouthwards
Excellent point. It would make things easier. It was an initial step, I had tried when I could not get 'debug' symbols. I did not mess with PKG_CFLAGS and wanted to use R default flags. Previously, I was not able to override R CFLAGS.Unkennel
R packages are usually open source, whatever package you are using compile that with debug symbols, and check it with gdbGaddis
S
1

You should run R first. Then you should run the package and attached it to the R process (Debug configuration > C/C++ attach to application). Both R and eclipse must be run as root.

Shared library must be the address to ...dll or ...so, which is the R package library.

Note 1: You should setup eclipse to compile an R package.

http://blog.fellstat.com/?p=170

Southwards answered 2/5, 2015 at 8:53 Comment(1)
Thanks for the response. I was having trouble getting debugger to run. Previous steps were all fine.Unkennel

© 2022 - 2024 — McMap. All rights reserved.