Implement Debugger.getPossibleBreakpoints (#2067)#2067
Open
huntie wants to merge 2 commits into
Open
Conversation
|
@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109301771. |
…#2066) Summary: NOTE: This is the minimum fix for fixing React Native compatibility with [vscode-js-debug](https://github.com/microsoft/vscode-js-debug). D109301771 continues by implementing this method fully. **Motivation**: CDP spec / VS Code debugger compatibility. `Debugger.getPossibleBreakpoints` is a gap in our Chrome DevTools Protocol coverage. To date, this hasn't been load bearing for our Chrome DevTools frontend fork in React Native DevTools. **However**, in other clients such as VS Code, not implementing this method breaks debugging against Hermes targets, since these clients expect at minimum a spec compliant CDP response (currently `-32601 method not found`). **This diff** Handle `Debugger.getPossibleBreakpoints` in Hermes as a spec-compliant stub endpoint, unconditionally returning an empty result (`{ locations: [] }`). - This is valid / equivalent to today's behaviour — setting a breakpoint applies to the whole line (no inner granularity). - A stub is how Expo and Radon IDE handle this issue today, e.g. `VscodeDebuggerGetPossibleBreakpointsHandler` in Expo CLI. https://github.com/expo/expo/blob/cc3f274fa0bb56aa0aa85ef68d78f1348e40d7f8/packages/%40expo/cli/src/start/server/metro/debugging/messageHandlers/VscodeDebuggerGetPossibleBreakpoints.ts#L17-L22 **This change alone is enough to stop VS Code erroring.** Computing breakpoint locations is a bit more involved (and notably might be blocked by the newer Babel transform profile rollout in RN), and is implemented separately in the next diff. **Changes** - Add `Debugger.getPossibleBreakpoints` to the CDP message-type roots (`cdp/tools/message_types.txt`) and regenerate `MessageTypes.{h,cpp}` (the pinned upstream protocol already defines the request/response and `BreakLocation` types). - Dispatch the method in `CDPAgent` to a new `DebuggerDomainAgent::getPossibleBreakpoints` that unconditionally returns `{ locations: [] }`. Differential Revision: D109439195
Summary:
**Motivation**: CDP spec / VS Code debugging compatibility.
Implements the `Debugger.getPossibleBreakpoints` CDP method so debug clients such as the React Native DevTools Sources panel and VS Code can discover and indicate valid breakpoint positions within a source range.
We walk the existing Hermes bytecode debug info, so no new compiler work is required.
**Changes**
- `DebugInfo::getAllLocationsForRange` enumerates every source location within a 1-based, half-open line/column range, mirroring the region scan in `getAddressForLocation` but collecting all matches instead of a single best one.
- `vm::Debugger::getPossibleBreakpoints` resolves the script's `RuntimeModule`/`DebugInfo`, classifies each location's real opcode as a debugger statement, call, or return via `getRealOpCode`/`isCallType`, then reduces the per-instruction debug info to one location per source statement (plus every call, return, and `debugger` location) and de-duplicates by source position. This statement-level granularity matches V8's `getPossibleBreakpoints` and Hermes' own stepper, which stops at the first instruction of each distinct statement; without it the one-entry-per-instruction debug info surfaces a candidate at nearly every token.
- Exposes the capability on the public `debugger::Debugger` API via a new `BreakLocation`/`BreakLocationType` value type.
- Wires it into the CDP layer: adds the method to the message-type roots and regenerates `MessageTypes` (the pinned upstream protocol already defines `getPossibleBreakpoints` and `BreakLocation`), dispatches it in `CDPAgent`, and handles it in `DebuggerDomainAgent` with the CDP/Hermes 0-based to 1-based conversion and a 1000-location cap matching V8's `kMaxNumBreakpoints`.
**Behaviour**
- Unknown `scriptId` returns CDP error `-32000` "No script with id"; a `start`/`end` on different scripts or with `start` after `end` returns "Invalid range"; an empty range returns `{ locations: [] }`.
- `restrictToFunction` is accepted but ignored for now, and lazily-compiled functions are not yet enumerated.
Differential Revision: D109301771
3f353da to
49178d5
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Motivation: CDP spec / VS Code debugging compatibility.
Implements the
Debugger.getPossibleBreakpointsCDP method so debug clients such as the React Native DevTools Sources panel and VS Code can discover and indicate valid breakpoint positions within a source range.We walk the existing Hermes bytecode debug info, so no new compiler work is required.
Changes
DebugInfo::getAllLocationsForRangeenumerates every source location within a 1-based, half-open line/column range, mirroring the region scan ingetAddressForLocationbut collecting all matches instead of a single best one.vm::Debugger::getPossibleBreakpointsresolves the script'sRuntimeModule/DebugInfo, classifies each location's real opcode as a debugger statement, call, or return viagetRealOpCode/isCallType, then reduces the per-instruction debug info to one location per source statement (plus every call, return, anddebuggerlocation) and de-duplicates by source position. This statement-level granularity matches V8'sgetPossibleBreakpointsand Hermes' own stepper, which stops at the first instruction of each distinct statement; without it the one-entry-per-instruction debug info surfaces a candidate at nearly every token.debugger::DebuggerAPI via a newBreakLocation/BreakLocationTypevalue type.MessageTypes(the pinned upstream protocol already definesgetPossibleBreakpointsandBreakLocation), dispatches it inCDPAgent, and handles it inDebuggerDomainAgentwith the CDP/Hermes 0-based to 1-based conversion and a 1000-location cap matching V8'skMaxNumBreakpoints.Behaviour
scriptIdreturns CDP error-32000"No script with id"; astart/endon different scripts or withstartafterendreturns "Invalid range"; an empty range returns{ locations: [] }.restrictToFunctionis accepted but ignored for now, and lazily-compiled functions are not yet enumerated.Differential Revision: D109301771