This is the fourth in a series of patches to enable LLDB debugging of WebAssembly code that runs in a WebAssembly engine. Previous patches added ObjectFile, SymbolVendor and DynamicLoader plugin classes for Wasm, see: D71575, D72751, D72650.
The idea is to use the GDB-remote protocol to connect to a Wasm engine that implements a GDB-remote stub that offers the ability to access the engine runtime internal state. This patch introduce a new Process plugin wasm, with:
- Class ProcessWasm that inherits from ProcessGDBRemote and that provides functions to access the Wasm engine state through a GDBRemote connection.
- Class ThreadWasm that inherits from ThreadGDBRemote and that provides functions to access the Wasm call stack and create the Wasm stack unwinder.
- Class UnwindWasm that manages stack unwinding for Wasm.
The code that represents a DWARF expression is now separated from the logic to evaluate that expression. The former is still in class DWARFExpression, while for the latter a new plugin type is introduced, DWARFEvaluator.
- Class DWARFEvaluator contains the generic code for evaluating DWARF expressions, and it is possible to introduce platform-specific plugin classes to evaluate platform-specific DWARF opcodes.
- Class DWARFEvaluatorFactory is the plugin base-class that is initialized, once per module, and cached in a Module instance. It creates DWARFEvaluator objects for a given DWARFExpression.
- Class WasmDWARFEvaluatorFactory represents the plugin to create DWARFEvaluators specific for WebAssembly.
- class WasmDWARFEvaluator contains the logic to evaluate DW_OP_WASM_location, which requires accesssing the Wasm engine through gdb-remote to query the state of the Wasm program (locals, globals, stack, memory and data sections), and to send requests through gdb-remote.
Note that the GDB-remote protocol needs to be extended with a few Wasm-specific custom query commands, implemented in ProcessWasm and used to access Wasm-specific constructs like the Wasm memory, Wasm locals and globals.
Wasm addresses are encoded with 64 bits with this format:
63 61 32 0 +-+-------------+-------------+ |T| module_id | offset | +-+-------------+-------------+
where T is 0:Code, 1:Data, 2:Memory.
This shouldn't be in here. Remove DW_OP_WASM_location as it is custom.