forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 50
Treat SourceProviderSourceType::BunTranspiledModule as Module in debugger/inspector/cache/completion switches #345
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
Open
robobun
wants to merge
1
commit into
main
Choose a base branch
from
farm/ee589aa8/buntranspiledmodule-switch-arms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟣 Pre-existing (not touched by this PR, noticed while reading the file): in
clearInspectorBreakpointState()thereplacedInternalFunctions().removeAllMatchinglambda checks== &m_debugger.vm()where the parallelreplacedThunks()block just above and both blocks inremoveSymbolicBreakpoint()use!=. The inversion means this-VM entries are never removed onDebugger.disable(the InternalFunction debugger hooks stay installed and theBox<ReplacedInternalFunction>entries leak), and in a multi-VM process other-VM entries get theirmatchCountdecremented by this agent's symbolic breakpoints. The actual line is ~2127; anchoring here because it's outside the diff.Extended reasoning...
What the bug is
In
InspectorDebuggerAgent::clearInspectorBreakpointState()(called frominternalDisable()/willDestroyFrontendAndBackend()), the cleanup lambda forreplacedInternalFunctions()has an inverted VM guard:Compare to the immediately preceding
replacedThunks()block in the same function, and to both blocks inremoveSymbolicBreakpoint(), which all use!=:replacedInternalFunctions()is a process-globalNeverDestroyed<Vector<Box<ReplacedInternalFunction>>>shared across all VMs/agents (guarded bys_replacedInternalFunctionsLock). The intent of the guard is: skip entries belonging to other VMs; only decrement/remove entries owned by this agent's VM. The==inverts that.Step-by-step proof
Single-VM (typical Bun process):
Debugger.addSymbolicBreakpointwith e.g.symbol: "fetch".addSymbolicBreakpoint()walks the heap, finds matchingInternalFunctions, anddidCreateInternalFunction()swaps their native function pointers tointernalFunction{Call,Construct}WithDebuggerHookand appends aBox<ReplacedInternalFunction>to the global vector.willDestroyFrontendAndBackend()→internalDisable()→clearInspectorBreakpointState().removeAllMatchinglambda runs on each entry. For every entry,&entry->internalFunction->vm() == &m_debugger.vm()is true (there is only one VM), so the lambda returnsfalseand the entry is kept.~ReplacedInternalFunction()never runs, so the InternalFunction's native function pointers are never restored — every subsequent call still routes throughinternalFunctionWithDebuggerHook, which takess_replacedInternalFunctionsLock, does a linearfind(), and callsvm.forEachDebugger(...)before dispatching. TheBoxentries also leak for the process lifetime.Multi-VM process:
clearInspectorBreakpointState().== &m_debugger.vm()is true →return false→ kept (leak, as above).== &m_debugger.vm()is false → falls through to them_symbolicBreakpointsloop. VM A's "foo" breakpoint matches, so VM B's entry has itsmatchCountdecremented, potentially hitting 0 and being removed — restoring VM B's InternalFunction to its original pointer while VM B's debugger is still active and expects the hook.Why nothing else prevents it
The only other place these entries are removed is
removeSymbolicBreakpoint(), which is only called when the frontend explicitly issuesDebugger.removeSymbolicBreakpoint. On disconnect /Debugger.disable, onlyclearInspectorBreakpointState()runs, andm_symbolicBreakpoints.clear()happens after the buggy block, so this is the sole opportunity to restore the hooks.Fix
Flip
==to!=to match the three parallel sites:Relation to this PR
None. This PR only touches
didParseSource()in this file to add aBunTranspiledModulecase; it does not touchclearInspectorBreakpointState(), symbolic breakpoints, or the InternalFunction hook machinery. Flagged as pre-existing since we happened to be in this file.