Description
Expected steps:
-
Build R as usual
-
Use
which_r
to switch to the built version of R (R-devel
by the standard instructions). -
Ensure CodeLLDB Extension installed
-
Create a new file
launch.json
in the.vscode
folder with the following code:{ "version": "0.2.0", "configurations": [ { "name": "(lldb) Attach to R", "type": "lldb", "request": "attach", "pid": "${command:pickMyProcess}", "stopOnEntry": false } ] }
-
Start R and run
Sys.getpid()
to get the process ID of the running R process. -
In the RUN AND DEBUG sidebar, select
(lldb) Attach to R
from the dropdown at the top, then click the green play button next to it. Paste the pid in the search bar at the top and select the corresponding process. Wait for it to get attached. -
Set a breakpoint in a C file, e.g.
$TOP_SRCDIR/src/nmath/rgamma.c
, by clicking to the left of a line number in the body of the function. -
Run some code that calls the C function, e.g.
rgamma(5, 1)
The debugger should start at the breakpoint set in the C code
You can also use e.g. debug(rgamma)
to start the debugger from the R code that wraps the C code.
Issue with first attempt in Codespaces/Gitpod. Get error message:
Could not attach: The current value of ptrace_scope is 1, which can cause ptrace to fail to attach to a running process.
To fix this, run:sudo sysctl -w kernel.yama.ptrace_scope=0
For more information, see: https://www.kernel.org/doc/Documentation/security/Yama.txt.
Some links that might help to work out how to fix this: