Repository navigation
preserve browser state across continuation prompts in the debugger - #17491
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
isBrowseActive() in RSession.cpp excluded R_GlobalEnv as a valid captured browser environment. For top-level debugging (debugSource() of a script with breakpoints, or browser() at top level), the inject's parent.frame() correctly captures R_GlobalEnv — so the !=R_GlobalEnv clause then rejected the legitimate state, isBrowseActive() returned FALSE, and onConsolePrompt's early-return path fired before any kContextDepthChanged event reached the client. The debug highlight and debugger toolbar therefore never appeared. Test the right invariant — that the env was captured (non-nil) — rather than excluding R_GlobalEnv specifically. R_GlobalEnv is a perfectly valid captured env when debugging at the top level of a sourced script. Adds a top-level breakpoint regression test that mirrors the reproducer from #17481. preserve browser state across continuation prompts in the debugger Continuation prompts ("+ ") share the hist == 1 path with fresh REPL prompts in RReadConsole, so they were calling setBrowserActive(false) mid-parse on every line of a multi-line expression entered at the Browse[N]> prompt. That cleared the captured browser environment, flipped the cached browser-active flag to false, and could prevent the client from receiving a kContextDepthChanged event when state didn't appear to change after the multi-line eval — leaving the call stack pane empty and the source-editor debug highlight stale. Detect continuation prompts via getOption("continue") and skip the setAtTopLevelPrompt / setBrowserActive updates in that case. The underlying REPL (browser or top-level) hasn't changed across a continuation, so the cached state should be preserved from the prior fresh prompt. Regression introduced by #17288. replace em-dashes with ascii dashes in debugger test handle nested debugger in test still update top-level prompt flag at continuation prompts The previous commit skipped both setAtTopLevelPrompt and setBrowserActive at continuation prompts on the theory that the underlying REPL state had not changed. But setAtTopLevelPrompt(false) is called right before each line of input is returned to R (RStdCallbacks.cpp:440), so when R issued the "+ " prompt for the next line of a multi-line expression, the flag remained false instead of bouncing back to true. NotebookQueue::process() bails out when isAtTopLevel() is false, so it deferred the next line of any multi-line chunk expression and never resumed -- leaving R hung at the "+ " prompt. This regressed the "multiline expressions in chunks execute without hanging" automation test. Restore the atTopLevelPrompt update at continuation prompts, but key it off browserContextActive() instead of the (always-false) `browsing` flag derived from the prompt regex -- the "+ " prompt itself doesn't reveal whether we're inside a browser. browserActive remains untouched at continuation prompts, preserving the original fix for multi-line input at Browse[N]>.
d5c6f20 to
761fc76
Compare
The waitUntil only checked element existence, so it could fire on a transient highlight before the post-step events from the .doTrace auto-step settled. Wait for the line number to match and add a brief flush before asserting.
Code ReviewThe fix logic is sound and well-reasoned. Three review passes (code quality, test coverage, comment accuracy) surfaced the following. Critical (1)Non-ASCII em-dash in The project's Important (4)1. The comment says "consumers like the RMarkdown notebook queue use this flag to advance to the next line of a multi-line chunk expression." 2. The project provides 3. The breakpoint is placed on gutter child 4. No test for bare Test 2 covers the Suggestions (3)5. If 6. "brief window" in Adding one sentence would help: "This window spans from when 7. No output assertion after exiting the top-level debugger Test 2 verifies the highlight appears but not that the script completes and produces Strengths
|
gtritchie
left a comment
There was a problem hiding this comment.
Overall LGTM, AI review flagged some nitpicky things (and a real issue with em-dashes that needs to be addressed before merging).
- replace utf-8 em-dashes with -- in RStdCallbacks.cpp - fix inaccurate NotebookQueue reference in atTopLevelPrompt comment - tighten isBrowseActive comment with C++-side capture details and precise window boundaries - replace fixed Sys.sleep waits in tests with waitUntil predicates that poll for the actual condition (function defined, line number, console output) rather than time - clarify that gutter children use 0-based indexing in BRAT, and that the breakpoint lands on the print() line - assert "[1] 23" appears after the debugger exits so a hung session would fail the test
Intent
Addresses #17481. Two related debugger regressions introduced by #17288, both surfacing as "the debug UI doesn't appear when the debugger is activated":
debugSource()) never showed the highlight or call stack at all.Browse[N]>prompt could clear the captured browser context, freezing the debug UI for the rest of the session.Summary
Top-level breakpoints (
isBrowseActive()excludedR_GlobalEnv)isBrowseActive()inRSession.cpprequired the captured browser env to be!= R_GlobalEnv. For top-level debugging the script is evaluated inglobalenv(), so the inject'sparent.frame()correctly capturesR_GlobalEnv— and the check then rejected the legitimate state.onConsolePrompttook itsif (*pContextDepth == 0 && !s_browserActive) return;early-return path before firingkContextDepthChanged, so the client never saw the debug context.The right invariant is "env was captured" (non-nil), not "env is non-globalenv".
R_GlobalEnvis a perfectly valid captured env when debugging at the top level of a sourced script.Multi-line input at the Browse prompt
Continuation prompts (
+) share thehist == 1path with fresh REPL prompts inRReadConsole, so they were callingsetBrowserActive(false)between every line of a multi-line expression at the Browse prompt. That cleared the captureds_browserEnvand stuck the cacheds_browserActive(SessionEnvironment side) atFALSE, which in turn could preventonConsolePromptfrom firing a freshkContextDepthChangedafter the multi-line eval finished (the change-detection conditions all read equal because nothing had legitimately changed during the continuation detour).A continuation prompt does not change which REPL we're in (browser or top-level), so the cached state from the prior fresh prompt should be preserved. We now detect continuation prompts via
getOption("continue")and skip thesetAtTopLevelPrompt/setBrowserActiveupdates in that case. This also tightens theatTopLevelPromptsemantics from #17352: continuation-while-in-browser now correctly reads as not at top level.Test plan
Manual:
x <- 1; y <- 22; print(x + y)), set a breakpoint on line 2, runSource(ordebugSource()). Confirm the debug highlight appears at line 2 and the debugger toolbar is enabled. Pre-fix this never worked.f <- function() { browser(); 1 + 1 }; f(). AtBrowse[1]>, paste a multi-linelocal({ … })block. Confirm the highlight and call stack remain visible across the paste, and thatncontinues to step correctly..rs.isBrowserActive()parity: at any Browse prompt (top-level or function-level),.rs.isBrowserActive()returnsTRUE. Pre-fix it returnedFALSEfor top-level and could readFALSEmid-multi-line.Automated coverage in
test-automation-debugger.R:.rs.isBrowserActive()isTRUEmid-eval and.ace_executing-linesurvives the paste.sourceActiveDocumentasserts.ace_executing-lineappears at the breakpoint line.