Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to get debugging working with LLDB #196

Open
hturner opened this issue Sep 25, 2024 · 2 comments
Open

Try to get debugging working with LLDB #196

hturner opened this issue Sep 25, 2024 · 2 comments

Comments

@hturner
Copy link
Member

hturner commented Sep 25, 2024

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:

@hturner
Copy link
Member Author

hturner commented Sep 25, 2024

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.

Debugging R code:
image

Debugging C code:
image

@iaine
Copy link
Collaborator

iaine commented Sep 25, 2024

It does appear that Docker still blocks ptrace by default unless a custom filter is given to Docker to allow it: https://securitylabs.datadoghq.com/articles/container-security-fundamentals-part-6/

May be we might add --cap-add=SYS_PTRACE --security-opt seccomp=unconfined to one of the container builds to see if it is enabled for debugging?
https://stackoverflow.com/questions/19215177/how-to-solve-ptrace-operation-not-permitted-when-trying-to-attach-gdb-to-a-pro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants