Repository navigation
address review findings on debug frame resolution - #18863
Conversation
- report the browse frame's depth separately from context_depth, which now follows the frame the user selects from the call stack; the client read context_depth == 1 as "execution is halted here" for clickable objects and the code browser's executing-line arrow - keep the call-site fallback for the browsed frame when the function has source of its own, so an empty runtime srcref no longer sends it to a deparsed copy instead of the file - resolve the browsed frame to the outermost context sharing the browser environment, matching .rs.getFunctionContext, so eval(envir = <a frame>) and top-level code under source() name the same frame the client browses - repeat the last browser position when a step cannot be resolved, so the client stops waiting on its requery timer - drop src_context from .rs.callFrames, which no longer has a reader - assert the trace installed in the deep-stack e2e test, which asserted a counter that a failed trace would also leave at zero
gtritchie
left a comment
There was a problem hiding this comment.
No blocking issues. 2 follow-up (+0 pre-existing, not commented)
🔴 must be resolved before merge. 🟠 is real but not merge-blocking — either address it here or open an issue to do so later. 🟡 is optional.
- 🟠
src/cpp/session/modules/SessionEnvironment.R:1460— halted frame with source reports its caller's call site as its own position - 🟠
src/cpp/session/modules/environment/SessionEnvironment.cpp:1137— repeat-last-position fallback is empty for the first step after a frame change
| # source of its own. Handing a source-less function its caller's | ||
| # location is exactly #18754; there we leave the srcref unset and | ||
| # simulate a position from the deparsed body below. | ||
| callSrcref <- attr(call, "srcref", exact = TRUE) |
There was a problem hiding this comment.
🟠 When the halted frame has source, this fallback reports where the caller made the call, not a line in the halted function, so the highlight can land in another file.
Use the function's own srcref here (e.g. attr(origFun, "srcref")) rather than attr(call, "srcref"), and have the new test check line_number too.
Why
attr(call, "srcref") belongs to the call expression, which sits in the caller. If located_fn lives in file A and outer_fn in file B, the frame reports file B at outer_fn's call line. The new test in test-debugger.R puts both functions in one file and only checks file_name, so it passes either way.
Not merge-blocking: it only happens when the runtime srcref is <in-bc-interp> and no inner call is mapped, and the result is no worse than before #18846.
There was a problem hiding this comment.
Confirmed and fixed in 20d80c1. Reproduced it with the two functions in separate files: the browsed frame came back naming the caller's file at the caller's line.
Applied to the browsed frame only -- that line is shared with the lapply/do.call path, where the call site is the deliberate answer and is covered by test-debugger.R plus a debugger.test.ts case, so switching it wholesale would have regressed traceback navigation. Outer frames keep attr(call, "srcref"); the browsed frame now uses attr(origFun, "srcref").
Test rewritten as you suggested (two files, asserts line_number/end_line_number); with the fix reverted it fails on all three assertions, where the single-file version failed on none.
Also corrected the comment's rationale: the <in-bc-interp> claim was wrong. R_GetCurrentSrcref resolves that symbol through fixBCSrcref/R_getCurrentSrcref before we see it, so the branch is reached when the runtime srcref is absent, not when it is the symbol.
| SEXP srcref = inferDebugSrcrefs(depth, pLineDebugState); | ||
| if (srcref != R_NilValue) | ||
| enqueBrowserLineChangedEvent(srcref); | ||
| else if (!s_lastBrowserLineJson.isEmpty()) |
There was a problem hiding this comment.
🟠 If the first step after entering or changing frames can't be resolved, nothing is sent, so the client still waits 500 ms and re-queries.
Save the position the context-change event reports into s_lastBrowserLineJson rather than clearing it at line 1116.
Why
Line 1116 clears s_lastBrowserLineJson on every frame change, and only a resolved step in the same frame fills it again. So this repeat path does nothing until one step in the new frame has succeeded.
Not merge-blocking: the cost is one 500 ms delay and one extra requery_context call; the position shown stays correct.
There was a problem hiding this comment.
Confirmed and fixed in 20d80c1, slightly differently than suggested. Instead of assigning at the clear site, commonEnvironmentStateData() now records the browse frame's range whenever it builds the state, so s_lastBrowserLineJson means "the position the client currently holds" on every path that reports one -- the context-change event, set_context_depth and requery_context -- rather than only resolved same-frame steps. The clear in onConsolePrompt is gone.
Checked the repeat is inert on the client: function_line_number is always 1, so functionRelativePosition(-currentFunctionLineNumber_ + 1) is identity and the repeated range compares equal to currentBrowsePosition_; the handler skips the view update and just cancels the timer. Added a bounds check on frames.getValueAt(depth - 1), since this read isn't under the contextCallfun guard the existing one has and callFramesFromR returns empty frames on error.
- the srcref fallback for the frame the browser is halted in used the call that created it, which is a position in the caller and can name another file entirely; use the function's own definition instead. outer frames keep the call-site fallback, which is what makes them navigable from the traceback - strengthen the testthat case to put the two functions in separate files and assert the line, which the single-file version could not distinguish - record the position each context-change event leaves the client at, instead of clearing it; the repeat-last-position path was dead until one step in the new frame had resolved, so the first unresolved step after a frame change still cost a 500 ms stall and a requery_context round trip
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
Follow-up to #18846, which fixed #18754 but left a few loose ends found in review.
That PR changed what
context_depthmeans in the environment-state payload: itnow names the frame the browser is halted in rather than being forced to 1 while
stepping. Two client-side predicates still read it as "execution is halted here",
and two source-reference paths needed narrowing.
Changes
Report the browse frame's depth separately.
context_depthalso follows theframe the user selects from the call stack, so it cannot answer "is this the
executing frame". The payload now carries
browse_frame_depthalongside it, andEnvironmentObjects.enableClickableObjects()and theCodeBrowserNavigationEventexecuting flag compare against that instead of hardcoding 1. Without this, clicking
a data frame in the Environment pane stopped calling
View()and the code browserlost its executing-line arrow whenever the browsed frame was not innermost -- any
tryCatch,withCallingHandlersorsuppressWarningswrapper, or a Shinyreactive. This also fixes the same question being answered wrongly after selecting
an outer frame from the call stack, which predates fix source navigation when debugging nested package functions #18846.
Keep the call-site fallback for a browsed frame that has source of its own.
The new branch nulled the srcref unconditionally, including when the function
carried source references -- reachable when
R_GetCurrentSrcref()returns the<in-bc-interp>symbol for byte-compiled code. That sent the client to a deparsedcopy of the function with an unnavigable filename instead of to the file. Debugging internal R functions in RStudio does not go to source #18754
is about functions with no source of their own, so the null-out is now gated on
that.
Resolve the browsed frame to the outermost context sharing the browser
environment, matching what
.rs.getFunctionContextreports to the client. Morethan one context can share an environment --
eval(expr, envir = <a frame env>),or top-level code under
source()-- and the previous per-frame identity testmarked every one of them current, so the frame the client reads could fall into
the wrong branch and simulate a wrong line.
Repeat the last browser position when a step cannot be resolved. Suppressing
the event entirely left the client's requery timer armed; it stalled 500 ms and
then issued a
requery_contextRPC that resolved to nothing again.Drop
src_contextfrom.rs.callFrames, which no longer has a reader on theC++ side.
Assert the trace installed in the deep-stack e2e test. It asserted
FRAME_BUILDS: 0, which is also what atrace()that never installed leavesbehind, so the test would have kept passing if the regression returned.
Testing
Added a testthat case covering the restored fallback; it fails on two assertions
with the
hasSourceRefsgate reverted.rstudio-tests --scope r --filter 'debugger|environment|linter'-- 205 passnpm run test:desktop-dev -- tests/panes/debugger-- 33 passed, 5 skippednpm run test:desktop-dev -- tests/panes/environment-- 9 passed, 3 skippedNo
NEWS.mdentry: this corrects work from #18846, which has not shipped in arelease yet.