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() { return static_cast<WasmAddressType>(type); }
39
40 operator lldb::addr_t() { return *(uint64_t *)this; }
41};
42
43static_assert(sizeof(wasm_addr_t) == 8, "");
44
45/// ProcessWasm provides the access to the Wasm program state
46/// retrieved from the Wasm engine.
48public:
49 ProcessWasm(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
50 ~ProcessWasm() override = default;
51
53 lldb::ListenerSP listener_sp,
54 const FileSpec *crash_file_path,
55 bool can_connect);
56
57 static void Initialize();
58 static void DebuggerInitialize(Debugger &debugger);
59 static void Terminate();
60
61 static llvm::StringRef GetPluginNameStatic();
62 static llvm::StringRef GetPluginDescriptionStatic();
63
64 llvm::StringRef GetPluginName() override;
65
66 size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
67 Status &error) override;
68
69 bool CanDebug(lldb::TargetSP target_sp,
70 bool plugin_specified_by_name) override;
71
72 /// Retrieve the current call stack from the WebAssembly remote process.
73 llvm::Expected<std::vector<lldb::addr_t>> GetWasmCallStack(lldb::tid_t tid);
74
75 /// Query the value of a WebAssembly variable from the WebAssembly
76 /// remote process.
77 llvm::Expected<lldb::DataBufferSP>
78 GetWasmVariable(WasmVirtualRegisterKinds kind, int frame_index, int index);
79
80protected:
81 std::shared_ptr<process_gdb_remote::ThreadGDBRemote>
82 CreateThread(lldb::tid_t tid) override;
83
84private:
85 friend class UnwindWasm;
86 friend class ThreadWasm;
87
91
93 const ProcessWasm &operator=(const ProcessWasm &) = delete;
94};
95
96} // namespace wasm
97} // namespace lldb_private
98
99#endif
static llvm::raw_ostream & error(Stream &strm)
A file utility class.
Definition FileSpec.h:57
friend class Debugger
Definition Process.h:359
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:88
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