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

Adds a DAP server with support for debugging sway unit tests #5477

Merged
merged 78 commits into from
Feb 20, 2024

Conversation

sdankel
Copy link
Member

@sdankel sdankel commented Jan 16, 2024

Description

Related FuelLabs/sway-vscode-plugin#166

Adds a DAP server as a new forc plugin, forc-debug. This enables a UI debugging experience in IDEs such as VSCode.

For now, only debugging forc tests is supported. Users can:

  • set breakpoints inside of forc tests
  • step through the test, one VM instruction at a time, or continue to the next breakpoint
  • debug through multiple tests sequentially
  • see the VM register values in the IDE while debugging
  • see the current VM opcode, its inputs, and/or immediate value when when the VM is stopped

Screenshots

Feb-01-2024.21-37-48.mp4
Feb-01-2024.21-44-37.mp4

Feb-01-2024 21-46-40

Local testing

  1. Install forc-debug
  2. Copy this sample launch.json in the VSCode workspace with sway code to debug:
{
    "version": "0.2.0",
    "configurations": [
        {
        "type": "sway",
        "request": "launch",
        "name": "Debug Sway",
        "program": "${file}"
    }]
}
  1. Follow the steps for testing the VSCode extension

Limitations

  • Breakpoints only work inside of the project/workspace being debugged
  • Stack trace support is limited
  • Not every line has source maps. Once debugging, "verified" breakpoints will show red and "unverified" (no source maps) will be greyed out.
  • Watch/repl expressions are not yet supported
  • Step into/out of is not supported
  • If you click "step over" many times in rapid succession, the server takes a while to catch up.

Closes #5394

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@sdankel sdankel changed the title Sophie/sourcemaps Adds a DAP debug server and executable Jan 16, 2024
@sdankel sdankel changed the title Adds a DAP debug server and executable Adds a DAP debug server Jan 16, 2024
sdankel and others added 11 commits January 16, 2024 00:18
This PR implements `-o` flags so that we can disable optimizations. This
will be useful as we are working towards debugger support and
optimizations pollute source map generated.

Provide option to the e2e test binary to specify build profile. For
tests that have their ABI tested, or rely on their compiled
hashes (for deployment), since that changes with build profile, the
tests are marked as unsupported for debug profile.
(better to test with and have expected results for release than the
debug profile).

Add testing release profile in CI since the default is now debug. Two
tests in `should_fail` that are expected to fail due to
overflows are disabled because there's a bug in our IR gen. This is
tracked by #5449

---------

Co-authored-by: Vaivaswatha Nagaraj <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: Sophie Dankel <[email protected]>
IGI-111 pushed a commit that referenced this pull request Feb 9, 2024
## Description

An issue was reported by @sdankel on #5477 caused by #5557.

A segmentation fault would occur when the for loop handling was
performed inside the match. This would occur even when that part of the
code was not called. Looks like a weird rust issue.

## Checklist

- [ ] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

Co-authored-by: Igor Rončević <[email protected]>
@sdankel sdankel requested a review from tritao February 13, 2024 00:01
Copy link

Benchmark for 89b3e02

Click to view benchmark
Test Base PR %
code_action 5.2±0.11ms 5.2±0.19ms 0.00%
code_lens 295.3±7.85ns 306.8±9.43ns +3.89%
compile 3.1±0.04s 3.1±0.03s 0.00%
completion 4.8±0.05ms 4.9±0.27ms +2.08%
did_change_with_caching 3.0±0.03s 3.0±0.05s 0.00%
document_symbol 1003.9±39.44µs 956.7±19.92µs -4.70%
format 89.7±1.04ms 90.0±0.74ms +0.33%
goto_definition 364.1±9.39µs 360.8±7.27µs -0.91%
highlight 9.0±0.14ms 8.9±0.20ms -1.11%
hover 544.3±5.81µs 537.7±7.16µs -1.21%
idents_at_position 122.3±0.66µs 122.2±1.67µs -0.08%
inlay_hints 659.9±22.44µs 650.6±19.39µs -1.41%
on_enter 482.1±18.08ns 498.6±18.23ns +3.42%
parent_decl_at_position 3.6±0.09ms 3.6±0.04ms 0.00%
prepare_rename 358.1±10.54µs 361.0±5.61µs +0.81%
rename 9.6±0.17ms 9.4±0.28ms -2.08%
semantic_tokens 1062.1±24.90µs 1031.2±20.57µs -2.91%
token_at_position 358.3±4.78µs 354.5±4.37µs -1.06%
tokens_at_position 3.6±0.04ms 3.6±0.06ms 0.00%
tokens_for_file 417.4±2.53µs 418.3±4.35µs +0.22%
traverse 39.3±0.88ms 38.7±0.84ms -1.53%

kayagokalp
kayagokalp previously approved these changes Feb 15, 2024
Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge work! Very excited for this 🚀 I left some nits and comments here and there but we can merge it as it is and discuss next steps in separate issues/PRs :)

forc-pkg/src/manifest.rs Outdated Show resolved Hide resolved
Copy link

Benchmark for 15ffa7f

Click to view benchmark
Test Base PR %
code_action 5.1±0.14ms 5.1±0.09ms 0.00%
code_lens 286.7±7.31ns 293.4±8.73ns +2.34%
compile 2.9±0.03s 3.1±0.13s +6.90%
completion 4.7±0.04ms 4.8±0.01ms +2.13%
did_change_with_caching 2.8±0.02s 2.8±0.02s 0.00%
document_symbol 1030.8±47.76µs 981.1±30.83µs -4.82%
format 71.4±0.81ms 72.2±1.00ms +1.12%
goto_definition 353.7±5.95µs 361.6±7.92µs +2.23%
highlight 8.8±0.20ms 8.7±0.02ms -1.14%
hover 524.0±9.16µs 535.8±6.76µs +2.25%
idents_at_position 122.9±0.26µs 121.3±0.71µs -1.30%
inlay_hints 637.4±8.39µs 658.8±21.46µs +3.36%
on_enter 491.1±11.14ns 478.1±9.51ns -2.65%
parent_decl_at_position 3.6±0.04ms 3.6±0.04ms 0.00%
prepare_rename 348.5±6.25µs 361.9±7.46µs +3.85%
rename 9.1±0.15ms 9.1±0.13ms 0.00%
semantic_tokens 1020.7±10.38µs 1015.5±15.85µs -0.51%
token_at_position 350.5±3.57µs 357.9±2.28µs +2.11%
tokens_at_position 3.6±0.02ms 3.6±0.06ms 0.00%
tokens_for_file 408.4±4.67µs 409.6±2.29µs +0.29%
traverse 37.5±0.89ms 37.2±0.78ms -0.80%

Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Sophie :)

@sdankel sdankel enabled auto-merge (squash) February 20, 2024 03:00
Copy link

Benchmark for 25eb563

Click to view benchmark
Test Base PR %
code_action 5.2±0.01ms 5.4±0.14ms +3.85%
code_lens 286.0±4.84ns 286.4±7.47ns +0.14%
compile 2.9±0.02s 3.0±0.03s +3.45%
completion 4.7±0.11ms 5.0±0.24ms +6.38%
did_change_with_caching 2.8±0.02s 2.9±0.03s +3.57%
document_symbol 1032.5±48.70µs 970.8±8.26µs -5.98%
format 75.0±1.19ms 75.7±0.57ms +0.93%
goto_definition 359.7±6.09µs 364.5±5.94µs +1.33%
highlight 8.8±0.20ms 9.0±0.23ms +2.27%
hover 532.0±7.17µs 543.7±10.61µs +2.20%
idents_at_position 121.3±0.41µs 122.4±0.44µs +0.91%
inlay_hints 645.5±27.78µs 658.3±21.86µs +1.98%
on_enter 500.3±7.18ns 492.3±8.43ns -1.60%
parent_decl_at_position 3.7±0.05ms 3.6±0.08ms -2.70%
prepare_rename 370.0±7.78µs 361.1±7.48µs -2.41%
rename 9.1±0.02ms 9.4±0.13ms +3.30%
semantic_tokens 1014.9±10.38µs 1056.2±11.85µs +4.07%
token_at_position 365.7±2.45µs 355.9±4.61µs -2.68%
tokens_at_position 3.7±0.03ms 3.6±0.05ms -2.70%
tokens_for_file 492.3±5.01µs 411.6±3.47µs -16.39%
traverse 37.3±1.13ms 37.0±0.91ms -0.80%

@sdankel sdankel merged commit 4cf3398 into master Feb 20, 2024
30 of 31 checks passed
@sdankel sdankel deleted the sophie/sourcemaps branch February 20, 2024 03:24
@tritao
Copy link
Contributor

tritao commented Feb 20, 2024

Great to see this one merged, awesome work ❤️

sdankel added a commit that referenced this pull request Feb 21, 2024
Follow up to #5477

#5477 (comment)

---------

Co-authored-by: Vaivaswatha Nagaraj <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: IGI-111 <[email protected]>
Co-authored-by: João Matos <[email protected]>
Co-authored-by: Joshua Batty <[email protected]>
Co-authored-by: Igor Rončević <[email protected]>
Co-authored-by: Sudhakar Verma <[email protected]>
Co-authored-by: Marcos Henrich <[email protected]>
Co-authored-by: jjcnn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request forc-debug Everything related to forc-debug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a DAP server for IDEs to interact with
10 participants