Skip to content
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

feature(cli): add vscode compatibility handler to inspector proxy #21560

Merged

Conversation

byCedric
Copy link
Member

@byCedric byCedric commented Mar 6, 2023

Why

Builds upon #21449

This adds a handler that makes sure the vscode-js-debug extension can be used with the custom inspector proxy. These changes should NOT interfere with the other debuggers.

How

Test Plan

Checklist

@byCedric byCedric requested a review from EvanBacon as a code owner March 6, 2023 14:47
@byCedric byCedric marked this pull request as draft March 6, 2023 14:48
@byCedric byCedric marked this pull request as ready for review March 6, 2023 14:55
@byCedric byCedric force-pushed the @bycedric/cli/experimental-inspector-proxy-vscode-compat branch from 530b4c7 to ef9b38b Compare March 6, 2023 15:06
@byCedric byCedric force-pushed the @bycedric/cli/experimental-inspector-proxy-vscode-compat branch from a11aa42 to 4edd57b Compare March 7, 2023 15:36
Base automatically changed from @bycedric/cli/experimental-inspector-proxy to main March 8, 2023 17:16
@byCedric byCedric force-pushed the @bycedric/cli/experimental-inspector-proxy-vscode-compat branch from 4edd57b to 52711b3 Compare March 8, 2023 17:32
@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Mar 8, 2023
@byCedric byCedric force-pushed the @bycedric/cli/experimental-inspector-proxy-vscode-compat branch from eea9ee2 to 44d6104 Compare March 8, 2023 17:41
@byCedric byCedric force-pushed the @bycedric/cli/experimental-inspector-proxy-vscode-compat branch from 9e310c6 to 4c8918d Compare March 9, 2023 12:24
@expo expo deleted a comment from expo-bot Mar 9, 2023
@expo expo deleted a comment from expo-bot Mar 9, 2023
@expo expo deleted a comment from expo-bot Mar 9, 2023
@expo expo deleted a comment from expo-bot Mar 9, 2023
@expo expo deleted a comment from expo-bot Mar 9, 2023
…ages (#21566)

# Why

We don't need to show `callFrames` which are not traceable.

before | after
--- | ---
<img alt="image"
src="https://user-images.githubusercontent.com/1203991/223199631-fa5b5f25-733b-468d-b158-8e70b88c2b3d.png">
| <img alt="image"
src="https://user-images.githubusercontent.com/1203991/223199486-22496281-3de7-4693-a47b-63ec168762c8.png">


> ℹ️ **FunFact**
> The Chrome DevTools already filters these out from the `callFrames`

# How

- Filter `callFrames` in the `Debugger.paused` event

# Test Plan

- See added test

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).
…setBreakpointByUrl` (#21631)

# Why

Vscode is eagerly trying to create breakpoints, even before the
sourcemap is properly loaded. It uses the
[`Debugger.setBreakpointyUrl`](https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#method-setBreakpointByUrl),
with a `urlRegex`, which confuses Hermes.

> Vscode also incorrectly adds `file://` to the regex, already
containing a URL with protocol (e.g. `file://http://localhost/App.js`).
This is used to detect these specific breakpoint requests coming from
vscode.

My understanding is that Hermes is notifying the debugger of the loaded
bundle (including the sourcemap reference). After this notification, the
debuggers load the full sourcemap to understand the code that's being
executed. It looks like Hermes is using the `lineNumber` and
`columnNumber` from the actual bundle, resulting in `App.js:15` being
translated to `index.bundle:15`.

# How

This intercepts these invalid `urlRegex` from vscode, and asks Hermes to
create an unbounded breakpoint by avoiding `urlRegex`. After the
sourcemap is loaded in vscode, the unbounded breakpoint is reattempted
through `Debugger.setBreakpoint` using a `scriptId` that vscode resolves
using the proper `localRoot`/`remoteRoot` settings.

before | after
--- | ---

![vscode-breakpoint-worng-location](https://user-images.githubusercontent.com/1203991/224014318-251d65b4-7d57-4b4a-b5e3-ef40afb82e44.gif)
|
![vscode-breakpoint-correct-location](https://user-images.githubusercontent.com/1203991/224014649-8e219cb4-fea3-4871-984f-e632cdf0bce6.gif)


# Test Plan

- Clone https://github.com/byCedric/vscode-js-debug-issue-1583
- Set a breakpoint in `App.js` before connecting to Hermes
- The location of the breakpoint should not change

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).
…1639)

# Why

Remove `objectId` from symbol types to disable vscode to improperly
fetch object properties on symbols, causing Hermes to hard-crash.

vscode before | vsocde after
--- | ---

![vscode-symbol-hard-crash](https://user-images.githubusercontent.com/1203991/224037441-aba1da1f-e48b-43e7-b1ec-2e4d09ac8e2e.gif)
|
![vscode-symbol-no-crash](https://user-images.githubusercontent.com/1203991/224037191-fbbd88ed-e936-4008-8ce5-cb501e56eac5.gif)

chrome before | chrome after
--- | ---

![chrome-symbol-before](https://user-images.githubusercontent.com/1203991/224038387-0b360c7a-7a1e-4abf-b809-919f4b05f730.gif)
|
![chrome-symbol-after](https://user-images.githubusercontent.com/1203991/224038408-a843bb32-2541-441b-b7ad-e51ea6544fa1.gif)


# How

By removing the `objectId`, the vscode debugger doesn't have any
reference to request the `Runtime.getProperties` on the symbol itself.
This avoids being able to crash Hermes by running
`Runtime.getProperties` on `symbol` types.

# Test Plan

- Clone https://github.com/byCedric/vscode-js-debug-issue-1583
- Add `const testSymbol = Symbol('test');` near a breakpoint
- Try to expand the `testSymbol` in the variables explorer

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).
@byCedric
Copy link
Member Author

@Kudo @EvanBacon I'm merging this to main, with the exception of the callFrame filtering. See: #21560 (comment)

@byCedric byCedric merged commit b210db9 into main Mar 10, 2023
@byCedric byCedric deleted the @bycedric/cli/experimental-inspector-proxy-vscode-compat branch March 10, 2023 16:09
byCedric added a commit that referenced this pull request Apr 11, 2023
# Why

Builds upon #21449

This adds a handler that makes sure the `vscode-js-debug` extension can
be used with the custom inspector proxy. These changes should NOT
interfere with the other debuggers.

# How

- Added vscode compatibility handler
- Add missing `description` to function nodes, as required by
vscode-js-debug
    _(before microsoft/vscode-js-debug#1583
- Respond to `Debugger.getPossibleBreakpoints`, Hermes doesn't respond
to this message
- ~~Filter out "useless" `callFrames` when debugging~~ 
  **Moved back to PR, we need to limit filtering**
  → #21663
- Avoid Hermes binding breakpoints to wrong locations, before sourcemap
is loaded
  → #21631
- Avoid Hermes crashing by disabling `Runtime.getProperties` on `symbol`
types
  → #21639

# Test Plan

- See tests
- ~~Test project with vscode, see [this
repository](https://github.com/byCedric/vscode-js-debug-issue-1583) for
a test project.~~
- See #21641 to test `apps/bare-expo`

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@Kudo Kudo added the published Changes from the PR have been published to npm label Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: suggestions ExpoBot has some suggestions published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants