|
| 1 | +--- |
| 2 | +sidebar_position: 2 |
| 3 | +--- |
| 4 | + |
| 5 | +# Key concepts |
| 6 | + |
| 7 | +## Programs are associated with a contract's compiled bytecode |
| 8 | + |
| 9 | +This bytecode might either be the call bytecode, executed when a contract |
| 10 | +account with this bytecode receives a message on-chain, or the create bytecode, |
| 11 | +executed as part of deploying the contract associated with the bytecode. |
| 12 | + |
| 13 | +Reflecting this relationship, **ethdebug/format/program** records contain |
| 14 | +a reference to the concrete contract (i.e., not an `abstract contract` or |
| 15 | +`interface`), the environment the bytecode will be executed (call or |
| 16 | +create), and the compilation that yielded the contract and bytecode. |
| 17 | + |
| 18 | +## Programs contain instruction listings for debuggers to reference |
| 19 | + |
| 20 | +Programs contain a list of **ethdebug/format/program/instruction** objects, |
| 21 | +where each instruction corresponds to one machine instruction in the |
| 22 | +associated bytecode. |
| 23 | + |
| 24 | +These instructions are ordered sequentially, matching the order and |
| 25 | +corresponding one-to-one with the encoded binary machine instructions in |
| 26 | +the bytecode. Instructions specify the byte offset at which they appear in the |
| 27 | +bytecode; this offset is equivalent to program counter on non-EOF EVMs. |
| 28 | + |
| 29 | +By indexing these instructions by their offset, **ethdebug/format** |
| 30 | +programs allow debuggers to lookup high-level information at any point |
| 31 | +during machine execution. |
| 32 | + |
| 33 | +## Instructions describe high-level context details |
| 34 | + |
| 35 | +Each instruction object in a program contains crucial information about the |
| 36 | +high-level language state at that point in the bytecode execution. |
| 37 | +Instructions represent these details using the |
| 38 | +**ethdebug/format/program/context** schema, and these details may include: |
| 39 | + |
| 40 | +- Source code ranges associated with the instruction (i.e., "source mappings") |
| 41 | +- Variables known to be in scope following the instruction and where to |
| 42 | + find those variable's values in the machine state |
| 43 | +- Control flow information such as an instruction being associated with the |
| 44 | + process of calling from one function to another |
| 45 | + |
| 46 | +This information serves as a compile-time guarantee about the high-level |
| 47 | +state of the world that exists following each instruction. |
| 48 | + |
| 49 | +## Contexts inform high-level language semantics during machine tracing |
| 50 | + |
| 51 | +The context information provided for each instruction serves as a bridge |
| 52 | +between low-level EVM execution and high-level language constructs. Debuggers |
| 53 | +can use these strong compile-time guarantees to piece together a useful and |
| 54 | +consistent model of the high-level language code behind the running machine |
| 55 | +binary. |
| 56 | + |
| 57 | +By following the state of machine execution, a debugger can use context |
| 58 | +information to stay apprised of the changing compile-time facts over the |
| 59 | +course of the trace. Each successively-encountered context serves as the |
| 60 | +source of an observed state transition in the debugger's high-level state |
| 61 | +model. This allows the debugger to maintain an ever-changing and coherent |
| 62 | +view of the high-level language runtime. |
| 63 | + |
| 64 | +In essence, the information provided by objects in this schema serves as a |
| 65 | +means of reducing over state transitions, yielding a dynamic and accurate |
| 66 | +representation of the program's high-level state. This enables debugging |
| 67 | +tools to: |
| 68 | + |
| 69 | +1. Map the current execution point back to the original source code |
| 70 | +2. Reconstruct the state of variables at any given point |
| 71 | +3. Provide meaningful stack traces that reference function names and source |
| 72 | + locations |
| 73 | +4. Offer insights into control flow, such as entering or exiting functions, |
| 74 | + or iterating through loops |
| 75 | +5. Present data structures (like arrays or mappings) in a way that reflects |
| 76 | + their high-level representation, rather than their low-level storage |
| 77 | + |
| 78 | +By leveraging these contexts, debugging tools can offer a more intuitive and |
| 79 | +developer-friendly experience when working with EVM bytecode, effectively |
| 80 | +translating between the machine-level execution and the high-level code that |
| 81 | +developers write and understand. This continuous mapping between low-level |
| 82 | +execution and high-level semantics allows developers to debug their smart |
| 83 | +contracts more effectively, working with familiar concepts and structures |
| 84 | +even as they delve into the intricacies of EVM operation. |
0 commit comments