Add `Vm` trace functionality and add trace to `boa_wasm`
This is the branch that was used for the web-debugger concept.
This branch is technically ready to be merged, but thought I'd post it as a draft for now to get feedback as it has some API changes along with quite a few changes to the Vm trace overall.
It changes the following:
- Search and handle the compiled bytecode trace prior to instruction execution and trace.
- Creates a
BoaJsobject and anevaluate_with_debug_hooksfunction inboa_wasm - Creates a
VmTrace(not the biggest fan of the name here if anyone has other ideas) for handling tracing and allowing users to define handle trace themselves via "registering" a function (defaults to println).
For reference, the standard trace output would now print like the below.
----------------------Compiled Output: '<main>'-----------------------
Location Count Handler Opcode Operands
000000 0000 none GetName 0000: 'greet'
000005 0001 none PushUndefined
000006 0002 none Swap
000007 0003 none PushLiteral 0
000012 0004 none Call 1
000017 0005 none SetReturnValue
000018 0006 none Return
Literals:
0000: <string> "World"
Bindings:
0000: greet
Functions:
0000: name: 'greet' (length: 1)
Handlers:
<empty>
-----------------------Compiled Output: 'greet'-----------------------
Location Count Handler Opcode Operands
000000 0000 none PutLexicalValue 0000: 'targetName'
000005 0001 none RestParameterPop
000006 0002 none PushLiteral 0
000011 0003 none GetName 0000: 'targetName'
000016 0004 none Add
000017 0005 none PushLiteral 1
000022 0006 none Add
000023 0007 none SetReturnValue
000024 0008 none Return
000025 0009 none Return
Literals:
0000: <string> "Hello, "
0001: <string> "!"
Bindings:
0000: targetName
Functions:
<empty>
Handlers:
<empty>
------------------------------------ Call Frame -- <main> ------------------------------------
Time Opcode Operands Stack
14╬╝s GetName 0000: 'greet' [ [function] ]
0╬╝s PushUndefined [ undefined, [function] ]
0╬╝s Swap [ [function], undefined ]
1╬╝s PushLiteral 0 [ "World", [function], undefined ]
------------------------------------ Call Frame -- greet -------------------------------------
0╬╝s PutLexicalValue 0000: 'targetName' [ ]
1╬╝s RestParameterPop [ ]
0╬╝s PushLiteral 0 [ "Hello, " ]
1╬╝s GetName 0000: 'targetName' [ "World", "Hello, " ]
5╬╝s Add [ "Hello, World" ]
0╬╝s PushLiteral 1 [ "!", "Hello, World" ]
1╬╝s Add [ "Hello, World!" ]
0╬╝s SetReturnValue [ ]
0╬╝s Return [ ]
-------------------------- Call Frame -- <Exiting greet via Return> --------------------------
140╬╝s Call 1 [ "Hello, World!" ]
0╬╝s SetReturnValue [ ]
0╬╝s Return [ ]
------------------------- Call Frame -- <Exiting <main> via Return> --------------------------
"Hello, World!"
Let me know what you think 😄
Test262 conformance changes
| Test result | main count | PR count | difference |
|---|---|---|---|
| Total | 50,731 | 50,731 | 0 |
| Passed | 42,973 | 42,973 | 0 |
| Ignored | 1,395 | 1,395 | 0 |
| Failed | 6,363 | 6,363 | 0 |
| Panics | 18 | 18 | 0 |
| Conformance | 84.71% | 84.71% | 0.00% |
Seeing this, I think it would be worth to create a Tracer trait instead of passing closures to handle tracing. Would also make it easier to send the output to files, loggers or other interesting usages.
Would also make it easier to send the output to files, loggers or other interesting usages.
Kind of what I was going for.
I was initially thinking of how to plug the trace output into a tui out of curiosity which led me to the wasm. I don't think it should be too crazy to switch it over to being trait based. 😄
Codecov Report
Attention: Patch coverage is 10.10638% with 169 lines in your changes are missing coverage. Please review.
Project coverage is 47.21%. Comparing base (
6ddc2b4) to head (606f48e). Report is 141 commits behind head on main.
:exclamation: Current head 606f48e differs from pull request most recent head 94045e1. Consider uploading reports for the commit 94045e1 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## main #3227 +/- ##
==========================================
- Coverage 47.24% 47.21% -0.03%
==========================================
Files 476 476
Lines 46892 46084 -808
==========================================
- Hits 22154 21760 -394
+ Misses 24738 24324 -414
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Switched the custom closures bits over to a trait.
It may be possible to go even further with the trait than currently implemented and selectively emit Vm state rather than pre-formatted messages. But I'm not exactly sure how much access we should provided, so I kept the current output as is for now.
@HalidOdat and @jedel1043 will review this to see if we want to expose the instructions or if this is good enough.
Made some changes to have VmTrace have a Vec<Box<dyn Tracer>> and moved should_trace to Tracer. Let me know what you think!
Looks good to me! Just needs a rebase :)