Skip to content

Stepping with duplicated lines can be wrong when keep.source = FALSE #14276

Closed

Description

@DavisVaughan

CC @kevinushey, this is what I mentioned yesterday about seeing cases where duplicate lines make the debugger bounce around

Let's fake the idea of stepping into a function from a package where you don't have source refs (pretty common)

eval(parse(text = "fn <- function() {
  x <- 1
  1 + 1
  x <- 1
  2 + 2
  3 + 3
  x <- 1
  1
}", keep.source = FALSE))

debugonce(fn)
fn()

Note that x <- 1 is duplicated here. This results in the following stepping behavior:

Screen.Recording.2024-02-15.at.11.58.41.AM.mov

If you remove the keep.source = FALSE part, then things do work as expected.

I know that when there aren't source refs, we essentially end up grepping for x <- 1 in the sources of the function itself. It seems like we try and keep track of the previous debug line and use it as a minimum "line preference" here:

linepref <- attr(var, "_rs_lastline")

In theory that should work well when it is used here:

# There is more than one instance of the call text in the function; try
# to pick the first match past the preferred line.
best <- which(pos > offsets[linepref])

I have a feeling that somehow this lastDebugLine is not being updated correctly for some reason in the no-srcref case:

pLineDebugState->lastDebugLine = stepLine;

Activity

  1. added
    new
    on Feb 15, 2024
  2. added and removed
    new
    on Feb 23, 2024
  3. added this to the Later milestone on Feb 29, 2024
  4. jthomasmock commented on Feb 29, 2024

    @jthomasmock
    Contributor

    Might be related to #13925

  5. ronblum commented on Mar 13, 2024

    @ronblum
    Contributor

    Verified that debugger doesn't jump around in

    • RStudio Desktop 2024.04.0-daily+573 on MacOS 14.4
    • RStudio Server 2024.04.0-daily+573 on Ubuntu 22.04 via Chrome on MacOS 14.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions