LLDB mainline
ProcessWasm.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_WASM_PROCESSWASM_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_WASM_PROCESSWASM_H
11
14
15namespace lldb_private {
16namespace wasm {
17
18/// Each WebAssembly module has separated address spaces for Code and Memory.
19/// A WebAssembly module also has a Data section which, when the module is
20/// loaded, gets mapped into a region in the module Memory.
21enum WasmAddressType : uint8_t { Memory = 0x00, Object = 0x01, Invalid = 0xff };
22
23/// For the purpose of debugging, we can represent all these separated 32-bit
24/// address spaces with a single virtual 64-bit address space. The
25/// wasm_addr_t provides this encoding using bitfields.
27 uint64_t offset : 32;
28 uint64_t module_id : 30;
29 uint64_t type : 2;
30
32 : offset(addr & 0x00000000ffffffff),
33 module_id((addr & 0x00ffffff00000000) >> 32), type(addr >> 62) {}
34
37
38 WasmAddressType GetType() const { return static_cast<WasmAddressType>(type); }
39 uint32_t GetModuleID() const { return module_id; }
40 uint32_t GetOffset() const { return offset; }
41
42 operator lldb::addr_t() { return *(uint64_t *)this; }
43};
44
45static_assert(sizeof(wasm_addr_t) == 8, "");
46
47/// ProcessWasm provides the access to the Wasm program state
48/// retrieved from the Wasm engine.
50public:
51 ProcessWasm(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
52 ~ProcessWasm() override = default;
53
55 lldb::ListenerSP listener_sp,
56 const FileSpec *crash_file_path,
57 bool can_connect);
58
59 static void Initialize();
60 static void DebuggerInitialize(Debugger &debugger);
61 static void Terminate();
62
63 static llvm::StringRef GetPluginNameStatic();
64 static llvm::StringRef GetPluginDescriptionStatic();
65
66 llvm::StringRef GetPluginName() override;
67
68 size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
69 Status &error) override;
70
71 bool CanDebug(lldb::TargetSP target_sp,
72 bool plugin_specified_by_name) override;
73
74 /// Retrieve the current call stack from the WebAssembly remote process.
75 llvm::Expected<std::vector<lldb::addr_t>> GetWasmCallStack(lldb::tid_t tid);
76
77 /// Query the value of a WebAssembly variable from the WebAssembly
78 /// remote process.
79 llvm::Expected<lldb::DataBufferSP>
80 GetWasmVariable(WasmVirtualRegisterKinds kind, int frame_index, int index);
81
82protected:
83 std::shared_ptr<process_gdb_remote::ThreadGDBRemote>
84 CreateThread(lldb::tid_t tid) override;
85
86private:
87 friend class UnwindWasm;
88 friend class ThreadWasm;
89
93
95 const ProcessWasm &operator=(const ProcessWasm &) = delete;
96};
97
98} // namespace wasm
99} // namespace lldb_private
100
101#endif
static llvm::raw_ostream & error(Stream &strm)
A file utility class.
Definition FileSpec.h:57
friend class Debugger
Definition Process.h:356
An error handling class.
Definition Status.h:118
const ProcessWasm & operator=(const ProcessWasm &)=delete
llvm::StringRef GetPluginName() override
std::shared_ptr< process_gdb_remote::ThreadGDBRemote > CreateThread(lldb::tid_t tid) override
ProcessWasm(const ProcessWasm &)
static llvm::StringRef GetPluginNameStatic()
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
static void DebuggerInitialize(Debugger &debugger)
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec *crash_file_path, bool can_connect)
process_gdb_remote::GDBRemoteDynamicRegisterInfoSP & GetRegisterInfo()
Definition ProcessWasm.h:90
llvm::Expected< std::vector< lldb::addr_t > > GetWasmCallStack(lldb::tid_t tid)
Retrieve the current call stack from the WebAssembly remote process.
~ProcessWasm() override=default
ProcessWasm(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
llvm::Expected< lldb::DataBufferSP > GetWasmVariable(WasmVirtualRegisterKinds kind, int frame_index, int index)
Query the value of a WebAssembly variable from the WebAssembly remote process.
static llvm::StringRef GetPluginDescriptionStatic()
size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error) override
Read of memory from a process.
std::shared_ptr< GDBRemoteDynamicRegisterInfo > GDBRemoteDynamicRegisterInfoSP
WasmAddressType
Each WebAssembly module has separated address spaces for Code and Memory.
Definition ProcessWasm.h:21
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Listener > ListenerSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
uint64_t tid_t
Definition lldb-types.h:84
wasm_addr_t(WasmAddressType type, uint32_t module_id, uint32_t offset)
Definition ProcessWasm.h:35
wasm_addr_t(lldb::addr_t addr)
Definition ProcessWasm.h:31
WasmAddressType GetType() const
Definition ProcessWasm.h:38