Skip to content

Implement Debugger.getPossibleBreakpoints (#2067)#2067

Open
huntie wants to merge 2 commits into
facebook:static_hfrom
huntie:export-D109301771
Open

Implement Debugger.getPossibleBreakpoints (#2067)#2067
huntie wants to merge 2 commits into
facebook:static_hfrom
huntie:export-D109301771

Conversation

@huntie

@huntie huntie commented Jun 23, 2026

Copy link
Copy Markdown
Member

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

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 23, 2026
@meta-codesync

meta-codesync Bot commented Jun 23, 2026

Copy link
Copy Markdown

@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109301771.

huntie added 2 commits June 23, 2026 09:10
…#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
@meta-codesync meta-codesync Bot changed the title Implement Debugger.getPossibleBreakpoints Implement Debugger.getPossibleBreakpoints (#2067) Jun 23, 2026
@huntie huntie force-pushed the export-D109301771 branch from 3f353da to 49178d5 Compare June 23, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant