You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I tested debugging C code in an R package with the "(lldb) Attach to R" configuration in VS Code locally. It works almost the same as in Positron, except that if you debug R code that wraps the C code at the same time, the debugging is done in R rather than the VS Code debugger.
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: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.
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:
Some links that might help to work out how to fix this:
The text was updated successfully, but these errors were encountered: