Add Instruction-Level Execution Tracing#109
Open
bbyalcinkaya wants to merge 11 commits intomasterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds tracing semantics that write instruction-level execution logs to a specified output file. Each log entry is a JSON record containing the current instruction, its byte offset in the binary (if available), the value stack, and the local variables at the time of execution.
Changes
Semantics:
soroban-semantics.llvm-tracingthat does not affect the defaultsoroban-semantics.llvmtarget.In the tracing target:
<trace>configuration cell that holds the tracing-related data.tracing.md— the core tracing module. It intercepts instructions during execution, logs the VM state at each traced instruction.fs.md— defines file operation functions used by the tracing module to append log records to the output file.json-utils.md— defines JSON serialization functions for WebAssembly values, types, operators, instructions, and runtime structures (value stack, locals).CLI
--trace-fileoption tokomet runandkomet test. When provided, it enables the tracing backend and directs trace output to the specified file. Currently only supported on the LLVM backend.Usage
Example:
Example trace output (Click)
Another example with binary wasm:
Trace:
Since this is a binary input, most lines have a
posfield indicating the byte offset in the binary. The first three entries are part of the global initialization. The two entries with"pos": nullare instructions inserted by the semantics during execution rather than decoded from the binary. The remaining lines show the execution of the function body.Trace Format
Each line in the trace file is a JSON record with the following fields:
Limitations
Consecutive identical instructions may not be logged correctly for text format programs. This is a known limitation of the
<lastTraced>deduplication mechanism. When two identical instructions appear back-to-back and the first does not leave or rewrite to an intermediate value in<instrs>, the second will not be logged. This does not affect binary format programs, where each instruction is wrapped with its position and traced unconditionally. See the comments intracing.mdfor more details.