sway icon indicating copy to clipboard operation
sway copied to clipboard

Initial DWARF debug symbols output code.

Open vaivaswatha opened this issue 1 year ago • 6 comments

This PR adds support to express line number mapping from assembly to source using DWARF object files. Since there are offset details that are specific to the Fuel ISA, I'm using the existing SourceMap that's already being built, rather than generating directly from the instructions.

An important point to note is that DWARF uses line-col to express positions rather than an absolute offset-from-start format. To avoid computing line-col from absolute positions (which requires re-reading the source files), I'm changing the source position format everywhere to line-col. This also simplifies our code at many places (for example, in forc-debug). The only exception is the addr2line tool, where the use of absolute positions is in a function that seemed quite complex to me to attempt changes. So I have, temporarily, added code to compute absolute positions from line-col information and then reuse the existing functions. This is inefficient, but I think that's okay since it's a standalone tool and the whole thing runs just once for every command invocation.

The DWARF information is written to a file specified by the -g flag and can be verified using llvm-dwarfdump --debug-line ./test.obj. If the argument to the -g flag is a filename that ends with .json, then the existing JSON format is written out, otherwise it's a DWARF object in an ELF container.

vaivaswatha avatar Jan 28 '24 08:01 vaivaswatha

Benchmark for 44960fb

Click to view benchmark
Test Base PR %
code_action 5.1±0.08ms 5.2±0.19ms +1.96%
code_lens 286.5±9.67ns 340.7±10.20ns +18.92%
compile 3.0±0.04s 2.9±0.03s -3.33%
completion 4.7±0.01ms 4.7±0.16ms 0.00%
did_change_with_caching 2.8±0.02s 2.8±0.04s 0.00%
document_symbol 960.2±19.98µs 968.7±12.88µs +0.89%
format 73.6±0.94ms 73.7±1.18ms +0.14%
goto_definition 368.8±7.16µs 355.1±4.98µs -3.71%
highlight 8.9±0.19ms 8.8±0.03ms -1.12%
hover 537.8±7.45µs 536.8±7.03µs -0.19%
idents_at_position 123.0±0.40µs 122.9±0.63µs -0.08%
inlay_hints 657.6±24.83µs 658.3±28.34µs +0.11%
on_enter 488.4±15.89ns 496.9±17.56ns +1.74%
parent_decl_at_position 3.6±0.03ms 3.6±0.04ms 0.00%
prepare_rename 371.6±6.56µs 351.7±4.15µs -5.36%
rename 9.2±0.16ms 9.1±0.03ms -1.09%
semantic_tokens 1029.6±18.23µs 1041.1±23.59µs +1.12%
token_at_position 359.1±3.53µs 349.1±2.43µs -2.78%
tokens_at_position 3.6±0.03ms 3.6±0.02ms 0.00%
tokens_for_file 410.4±11.53µs 410.9±4.15µs +0.12%
traverse 37.4±0.47ms 38.2±1.23ms +2.14%

github-actions[bot] avatar Feb 21 '24 07:02 github-actions[bot]

Benchmark for d65f3d3

Click to view benchmark
Test Base PR %
code_action 5.3±0.15ms 5.5±0.13ms +3.77%
code_lens 334.7±10.47ns 289.0±8.65ns -13.65%
compile 3.1±0.05s 3.1±0.07s 0.00%
completion 5.0±0.22ms 5.0±0.21ms 0.00%
did_change_with_caching 3.0±0.07s 2.9±0.07s -3.33%
document_symbol 1029.9±27.10µs 1011.7±56.89µs -1.77%
format 75.9±3.46ms 73.7±0.79ms -2.90%
goto_definition 362.0±5.73µs 361.5±5.77µs -0.14%
highlight 9.2±0.27ms 9.4±0.19ms +2.17%
hover 537.4±9.63µs 539.7±6.45µs +0.43%
idents_at_position 122.1±0.29µs 121.9±0.55µs -0.16%
inlay_hints 647.4±11.14µs 662.4±23.23µs +2.32%
on_enter 504.4±44.41ns 486.6±12.63ns -3.53%
parent_decl_at_position 3.6±0.05ms 3.8±0.03ms +5.56%
prepare_rename 355.1±4.32µs 361.8±16.89µs +1.89%
rename 9.4±0.26ms 10.2±0.19ms +8.51%
semantic_tokens 1027.6±10.58µs 1048.8±28.31µs +2.06%
token_at_position 350.2±4.05µs 360.2±2.36µs +2.86%
tokens_at_position 3.6±0.05ms 3.8±0.05ms +5.56%
tokens_for_file 495.0±5.16µs 408.9±3.02µs -17.39%
traverse 41.0±1.03ms 39.5±1.17ms -3.66%

github-actions[bot] avatar Feb 22 '24 09:02 github-actions[bot]

Although this PR still draft (because it isn't fit for merging yet), it would be helpful if various stakeholders would have a look at it.

Primarily, this PR adds support to express line number mapping from assembly to source using DWARF object files. Since there are offset details that are specific to the Fuel ISA, I'm using the existing SourceMap that's already being built, rather than generating directly from the instructions.

An important point to note is that DWARF uses line-col to express positions rather than an absolute offset-from-start format. To avoid computing line-col from absolute positions (which requires re-reading the source files), I'm changing the source position format everywhere to line-col. This also simplifies our code at many places (for example, in forc-debug). The only exception is the addr2line tool, where the use of absolute positions is in a function that seemed quite complex to me to attempt changes. So I have, temporarily, added code to compute absolute positions from line-col information and then reuse the existing functions. This is inefficient, but I think that's ok since it's a standalone tool and the whole thing runs just once for every command invocation (IIUC).

The DWARF information is written to test.debug (and hence the draft PR) and can be verified using llvm-dwarfdump --debug-line ./test.debug. We'll have to introduce a new flag or use the existing -g flag (to write DWARF objects instead of JSONs).

Review requests:

@kayagokalp, @sdankel.

  1. This change from using absolute position to using line-col everywhere: https://github.com/FuelLabs/sway/pull/5521/files#diff-0229fd4ea2ee9ab8bd33615a6bf59125aae11b0b492f359a14dae4eb1b163faaR106.
  2. In general, the idea of using DWARF to carry debug information (line number information for the moment).

@Dentosal Changes in addr2line.

vaivaswatha avatar Mar 04 '24 05:03 vaivaswatha

The addr2line changes seem fine in sense that the code likely works. However, as the todo comment notes, it's quite inefficient.

Dentosal avatar Mar 04 '24 06:03 Dentosal

I'm on board with using DWARF format since it'll allow us to do a lot more with the debugger in the future. Using line-col everywhere seems good from the debugger and LSP perspective.

sdankel avatar Mar 04 '24 19:03 sdankel

Benchmark for b6d30dc

Click to view benchmark
Test Base PR %
code_action 5.3±0.01ms 5.2±0.04ms -1.89%
code_lens 290.3±5.87ns 288.8±16.75ns -0.52%
compile 4.2±0.08s 4.3±0.10s +2.38%
completion 4.9±0.07ms 4.8±0.13ms -2.04%
did_change_with_caching 3.8±0.10s 4.1±0.15s +7.89%
document_symbol 1034.1±15.81µs 1116.1±60.51µs +7.93%
format 73.4±1.27ms 74.8±1.83ms +1.91%
goto_definition 376.7±2.68µs 372.8±6.09µs -1.04%
highlight 9.3±0.04ms 8.8±0.16ms -5.38%
hover 555.6±5.96µs 543.0±29.81µs -2.27%
idents_at_position 121.9±0.64µs 122.3±1.24µs +0.33%
inlay_hints 657.7±18.37µs 688.6±35.26µs +4.70%
on_enter 491.5±10.84ns 490.3±17.59ns -0.24%
parent_decl_at_position 3.7±0.15ms 3.6±0.07ms -2.70%
prepare_rename 387.3±2.75µs 373.9±6.99µs -3.46%
rename 9.4±0.11ms 9.1±0.05ms -3.19%
semantic_tokens 1050.9±44.30µs 1048.7±19.88µs -0.21%
token_at_position 355.6±2.94µs 365.0±3.44µs +2.64%
tokens_at_position 3.7±0.06ms 3.6±0.06ms -2.70%
tokens_for_file 414.2±2.73µs 411.8±3.79µs -0.58%
traverse 38.3±1.27ms 38.8±0.78ms +1.31%

github-actions[bot] avatar Mar 05 '24 16:03 github-actions[bot]

Benchmark for 1d9621f

Click to view benchmark
Test Base PR %
code_action 5.5±0.14ms 5.4±0.13ms -1.82%
code_lens 288.6±14.70ns 291.9±11.73ns +1.14%
compile 6.1±0.18s 5.8±0.07s -4.92%
completion 5.3±0.38ms 5.6±0.47ms +5.66%
did_change_with_caching 5.4±0.11s 5.3±0.09s -1.85%
document_symbol 1008.6±29.97µs 1082.2±48.95µs +7.30%
format 71.2±2.59ms 73.8±0.87ms +3.65%
goto_definition 366.9±5.36µs 368.4±6.64µs +0.41%
highlight 9.2±0.23ms 9.1±0.09ms -1.09%
hover 580.5±8.52µs 589.6±7.25µs +1.57%
idents_at_position 122.0±0.37µs 122.6±0.73µs +0.49%
inlay_hints 673.9±18.57µs 669.6±17.18µs -0.64%
on_enter 496.2±15.18ns 491.5±38.35ns -0.95%
parent_decl_at_position 3.7±0.05ms 3.9±0.26ms +5.41%
prepare_rename 367.4±23.57µs 370.6±15.74µs +0.87%
rename 9.8±0.29ms 9.6±0.19ms -2.04%
semantic_tokens 1066.4±12.19µs 1053.7±40.48µs -1.19%
token_at_position 356.5±2.47µs 365.9±5.32µs +2.64%
tokens_at_position 3.7±0.04ms 3.8±0.27ms +2.70%
tokens_for_file 416.0±18.47µs 422.2±5.04µs +1.49%
traverse 44.1±2.63ms 44.0±2.03ms -0.23%

github-actions[bot] avatar Mar 07 '24 08:03 github-actions[bot]

Benchmark for 07cb98e

Click to view benchmark
Test Base PR %
code_action 5.3±0.01ms 5.4±0.09ms +1.89%
code_lens 289.6±10.75ns 296.0±5.84ns +2.21%
compile 6.2±0.07s 6.2±0.07s 0.00%
completion 4.8±0.05ms 5.0±0.07ms +4.17%
did_change_with_caching 5.7±0.04s 5.6±0.08s -1.75%
document_symbol 956.1±19.23µs 1034.0±26.00µs +8.15%
format 69.7±1.70ms 72.5±0.94ms +4.02%
goto_definition 360.6±3.46µs 366.9±6.33µs +1.75%
highlight 8.8±0.15ms 9.1±0.35ms +3.41%
hover 624.7±17.88µs 600.8±8.32µs -3.83%
idents_at_position 123.2±0.76µs 123.6±0.66µs +0.32%
inlay_hints 657.3±14.86µs 685.7±46.75µs +4.32%
on_enter 487.2±19.15ns 490.9±19.63ns +0.76%
parent_decl_at_position 3.6±0.03ms 3.8±0.09ms +5.56%
prepare_rename 364.1±6.31µs 365.7±6.17µs +0.44%
rename 9.3±0.26ms 9.6±0.40ms +3.23%
semantic_tokens 1047.0±17.22µs 1048.9±31.14µs +0.18%
token_at_position 357.4±1.39µs 358.7±2.54µs +0.36%
tokens_at_position 3.6±0.03ms 3.7±0.03ms +2.78%
tokens_for_file 413.0±2.45µs 414.3±13.60µs +0.31%
traverse 44.7±1.46ms 45.0±2.00ms +0.67%

github-actions[bot] avatar Mar 12 '24 16:03 github-actions[bot]

Benchmark for 625fff5

Click to view benchmark
Test Base PR %
code_action 5.3±0.17ms 5.5±0.19ms +3.77%
code_lens 289.0±12.50ns 288.7±6.98ns -0.10%
compile 6.2±0.07s 6.3±0.09s +1.61%
completion 4.8±0.13ms 4.9±0.02ms +2.08%
did_change_with_caching 5.7±0.05s 5.8±0.13s +1.75%
document_symbol 988.1±31.07µs 965.3±21.39µs -2.31%
format 70.1±0.76ms 73.1±1.22ms +4.28%
goto_definition 360.7±8.05µs 361.7±7.49µs +0.28%
highlight 8.7±0.23ms 9.1±0.17ms +4.60%
hover 636.8±23.73µs 600.9±21.32µs -5.64%
idents_at_position 122.4±1.67µs 122.6±0.86µs +0.16%
inlay_hints 663.1±8.07µs 673.6±30.97µs +1.58%
on_enter 484.0±17.68ns 482.0±18.31ns -0.41%
parent_decl_at_position 3.6±0.05ms 3.7±0.03ms +2.78%
prepare_rename 362.7±9.40µs 362.0±5.95µs -0.19%
rename 9.2±0.03ms 9.5±0.25ms +3.26%
semantic_tokens 1050.4±32.23µs 1055.6±18.52µs +0.50%
token_at_position 356.2±1.92µs 359.0±2.37µs +0.79%
tokens_at_position 3.6±0.04ms 3.7±0.03ms +2.78%
tokens_for_file 412.5±2.45µs 432.6±1.73µs +4.87%
traverse 47.1±2.34ms 48.1±2.58ms +2.12%

github-actions[bot] avatar Mar 13 '24 23:03 github-actions[bot]

Benchmark for 043bfa4

Click to view benchmark
Test Base PR %
code_action 5.3±0.11ms 5.5±0.13ms +3.77%
code_lens 302.3±27.67ns 291.7±7.82ns -3.51%
compile 6.2±0.09s 6.2±0.12s 0.00%
completion 4.8±0.02ms 4.9±0.11ms +2.08%
did_change_with_caching 5.7±0.06s 5.7±0.04s 0.00%
document_symbol 990.3±23.89µs 1040.4±30.64µs +5.06%
format 69.9±1.66ms 73.4±0.95ms +5.01%
goto_definition 358.7±2.38µs 372.5±6.91µs +3.85%
highlight 8.7±0.18ms 9.1±0.16ms +4.60%
hover 615.4±14.26µs 607.6±21.29µs -1.27%
idents_at_position 122.2±1.42µs 124.1±1.68µs +1.55%
inlay_hints 659.2±28.86µs 681.2±30.31µs +3.34%
on_enter 484.5±12.72ns 488.9±13.96ns +0.91%
parent_decl_at_position 3.6±0.02ms 3.7±0.06ms +2.78%
prepare_rename 361.6±6.13µs 371.0±5.37µs +2.60%
rename 9.2±0.04ms 9.5±0.05ms +3.26%
semantic_tokens 1063.3±14.09µs 1076.5±16.15µs +1.24%
token_at_position 351.5±2.57µs 370.9±13.86µs +5.52%
tokens_at_position 3.6±0.05ms 3.7±0.04ms +2.78%
tokens_for_file 412.2±5.08µs 425.0±2.34µs +3.11%
traverse 45.5±1.66ms 45.5±2.01ms 0.00%

github-actions[bot] avatar Mar 14 '24 01:03 github-actions[bot]