ManuelHentschel / VSCode-R-Debugger

R Debugger Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=RDebugger.r-debugger
MIT License
170 stars 11 forks source link

vscDebugger doesn't hit breaking points #165

Open Ruzejjur opened 2 years ago

Ruzejjur commented 2 years ago

Hello,

I have installed R 4.0.5. o my system with vscDebugger extension and package v0.4.7. following the guide in the documentation.
The debugger seems to work and there is no error in Debug console or in output. The issue is that when in debug mode, I can see the variables but when I run the code it does not hit breaking points. Breaking points are active and there is no error then I run through them. I've haven't modified any configurations in launch.json file and tried all of them. I can see the variables in Run and debug section only when I attach to existing R process. I've tried to install vscDebugger extension and package v0.4.6 and when I run the debugging it drops with no error in the output.

This is my first post and I don't know what information I should attach. So if you need anything else please specify and I will add it.

Thank you

katrinabrock commented 3 months ago

I'm having an issue where breakpoints inside a loaded package are being ignored. I'm using "debugMode": "file" with "loadPackages": [ "." ]. The file calls functions from the package. Breakpoints in the file always work, but breakpoints in the package sometimes work and sometimes don't. I haven't yet been able to determine what is the pattern is.

I've also tried explicitly running vscDebugger::.vsc.load_all('.') in the file, which doesn't help.

Is there any way from the debugger within the file, I can inspect the package functions that should have breakpoints and see whether the breakpoints have been inserted? Or any other way to debug this?

katrinabrock commented 3 months ago

Found one reproducible situation: initialize method of R6 object.

MRE here: https://github.com/katrinabrock/minimal-r-package

To reproduce, add breakpoints as indicated in the comments here: https://github.com/katrinabrock/minimal-r-package/blob/main/R/objects.R

Then, run the debugger configured here: https://github.com/katrinabrock/minimal-r-package/blob/main/.vscode/launch.json

katrinabrock commented 2 months ago

@ManuelHentschel

I probably should have just opened this as a new issue called something like Breakpoints in listed R6 methods not respected. This is another breakpoint issue unrelated to testthat. Pinging to make sure you saw it. :-)

ManuelHentschel commented 2 months ago

The problem with these R6 methods is that the lists they are in are not considered by functions like findLineNum and trace, which are used to manage breakpoints. Implementing this might be feasible, but would probably require writing custom versions of each of these functions.

If the R6 methods are defined in a top-level script that is sourced by .vsc.debugSource, the breakpoints work, though, because a different mechanism is used to set breakoint there.

Are there IDEs where breakpoints in R6 methods from packages work properly? I tried getting them to work in RStudio but not very successfully.

katrinabrock commented 2 months ago

Indeed this kind of breakpoint doesn't work in RStudio either. Interestingly, when you try to create the breakpoint, it first makes it provisional with "Breakpoints will be activated when the package is built or reloaded." Then, when you load_all() , the problematic breakpoint just disappears with no error or warning. debugSource("~/minimal-r-package/R/objects.R") leaves the breakpoint as provisional in the UI and produces Error in fBody[[i]] : no such index at level 5. I wonder if this is something trace and findLineNum will support in the future.

katrinabrock commented 2 months ago

Seems like this is indeed an issue with R6: https://github.com/r-lib/R6/issues/236

katrinabrock commented 2 months ago

Sorry for two posts within an hour, but I found one way to get an output from findLineNum for this kind of method. In my example:

> findLineNum('R/objects.R', 12, envir=as.environment(Person$public_methods))
/home/TOP/kbrock/minimal-r-package/R/objects.R#12:
 initialize step  2 in <environment: 0x55b784b10730>

I wonder if there is a way to find all the R6 objects and patch their environments in here:

https://github.com/ManuelHentschel/vscDebugger/blob/master/R/breakpointsManagement.R#L64