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
15
16namespace lldb_private {
17namespace wasm {
18
19/// ProcessWasm provides the access to the Wasm program state
20/// retrieved from the Wasm engine.
22public:
23 ProcessWasm(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
24 ~ProcessWasm() override = default;
25
27 lldb::ListenerSP listener_sp,
28 const FileSpec *crash_file_path,
29 bool can_connect);
30
31 static void Initialize();
32 static void DebuggerInitialize(Debugger &debugger);
33 static void Terminate();
34
35 static llvm::StringRef GetPluginNameStatic() { return "wasm"; }
36 static llvm::StringRef GetPluginDescriptionStatic();
37
38 llvm::StringRef GetPluginName() override;
39
40 bool ShouldUseMemoryCache(const ProcessAddress &process_addr) override;
41
42 size_t DoReadMemory(const ProcessAddress &vm_addr, void *buf, size_t size,
43 Status &error) override;
44
45 bool CanDebug(lldb::TargetSP target_sp,
46 bool plugin_specified_by_name) override;
47
48 CFAComparison CompareCFAs(const StackID &lhs, const StackID &rhs) override;
49
50 /// Retrieve the current call stack from the WebAssembly remote process.
51 llvm::Expected<std::vector<lldb::addr_t>> GetWasmCallStack(lldb::tid_t tid);
52
53 /// Query the value of a frame-scoped WebAssembly variable, which is a local
54 /// or a value on the operand stack.
55 llvm::Expected<lldb::DataBufferSP>
56 GetWasmVariable(WasmVirtualRegisterKinds kind, uint32_t frame_index,
57 uint32_t index);
58
59 /// Query the value of the global at \a index in the global index space of the
60 /// module instance \a module_id names. An index only names a global together
61 /// with an instance. Only a stub that advertises "qWasmInstance+" can be told
62 /// which instance to read, so see CanNameInstance first.
63 llvm::Expected<lldb::DataBufferSP> GetWasmGlobalForModule(uint32_t module_id,
64 uint32_t index);
65
66 /// Query the value of a WebAssembly global through the frame at \a
67 /// frame_index, which reaches only the globals of the module instance that
68 /// frame is executing. This is the only scope a stub that cannot be told
69 /// which instance to read offers.
70 llvm::Expected<lldb::DataBufferSP> GetWasmGlobalForFrame(uint32_t frame_index,
71 uint32_t index);
72
73 /// Whether the instance holding a global can be named to the stub, which
74 /// needs both a valid id to name it by and a stub that accepts one. Where it
75 /// cannot, a frame executing that instance has to stand in for it.
76 bool CanNameInstance(uint32_t module_id);
77
78protected:
79 std::shared_ptr<process_gdb_remote::ThreadGDBRemote>
80 CreateThread(lldb::tid_t tid) override;
81
82private:
83 friend class UnwindWasm;
84 friend class ThreadWasm;
85
86 /// Ask the WebAssembly stub for a single value, which comes back as the
87 /// hex-encoded bytes of the whole value.
88 llvm::Expected<lldb::DataBufferSP> SendWasmValueQuery(llvm::StringRef packet);
89
90 /// Read a WebAssembly global of the module instance \a module_id names,
91 /// through whichever scope that stub can be asked for it in.
92 size_t ReadGlobal(uint32_t module_id, uint32_t index, void *buf, size_t size,
93 Status &error);
94
95 /// The frame to read a global of \a module_id through, for a stub that cannot
96 /// be told which instance to read. Fails when no frame is executing that
97 /// module, which leaves its globals out of reach.
98 llvm::Expected<uint32_t> GetFallbackFrameIndex(uint32_t module_id);
99
101
103 const ProcessWasm &operator=(const ProcessWasm &) = delete;
104};
105
106} // namespace wasm
107} // namespace lldb_private
108
109#endif
static llvm::raw_ostream & error(Stream &strm)
A file utility class.
Definition FileSpec.h:56
An address in a process, qualified by an address space.
friend class Debugger
Definition Process.h:372
An error handling class.
Definition Status.h:118
lldb::DynamicRegisterInfoSP & GetRegisterInfo()
llvm::Expected< uint32_t > GetFallbackFrameIndex(uint32_t module_id)
The frame to read a global of module_id through, for a stub that cannot be told which instance to rea...
size_t ReadGlobal(uint32_t module_id, uint32_t index, void *buf, size_t size, Status &error)
Read a WebAssembly global of the module instance module_id names, through whichever scope that stub c...
llvm::Expected< lldb::DataBufferSP > GetWasmGlobalForModule(uint32_t module_id, uint32_t index)
Query the value of the global at index in the global index space of the module instance module_id nam...
llvm::Expected< lldb::DataBufferSP > GetWasmVariable(WasmVirtualRegisterKinds kind, uint32_t frame_index, uint32_t index)
Query the value of a frame-scoped WebAssembly variable, which is a local or a value on the operand st...
const ProcessWasm & operator=(const ProcessWasm &)=delete
bool ShouldUseMemoryCache(const ProcessAddress &process_addr) override
Whether ReadMemory should serve reads of process_addr out of the memory cache.
llvm::StringRef GetPluginName() override
std::shared_ptr< process_gdb_remote::ThreadGDBRemote > CreateThread(lldb::tid_t tid) override
llvm::Expected< lldb::DataBufferSP > GetWasmGlobalForFrame(uint32_t frame_index, uint32_t index)
Query the value of a WebAssembly global through the frame at frame_index, which reaches only the glob...
CFAComparison CompareCFAs(const StackID &lhs, const StackID &rhs) override
Compares the call frame addresses of two frames.
bool CanNameInstance(uint32_t module_id)
Whether the instance holding a global can be named to the stub, which needs both a valid id to name i...
ProcessWasm(const ProcessWasm &)
static llvm::StringRef GetPluginNameStatic()
Definition ProcessWasm.h:35
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)
llvm::Expected< std::vector< lldb::addr_t > > GetWasmCallStack(lldb::tid_t tid)
Retrieve the current call stack from the WebAssembly remote process.
llvm::Expected< lldb::DataBufferSP > SendWasmValueQuery(llvm::StringRef packet)
Ask the WebAssembly stub for a single value, which comes back as the hex-encoded bytes of the whole v...
~ProcessWasm() override=default
size_t DoReadMemory(const ProcessAddress &vm_addr, void *buf, size_t size, Status &error) override
Actually do the reading of memory from a process.
ProcessWasm(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
static llvm::StringRef GetPluginDescriptionStatic()
A class that represents a running process on the host machine.
CFAComparison
How the call frame addresses of two frames order them.
Definition StackID.h:19
std::shared_ptr< lldb_private::DynamicRegisterInfo > DynamicRegisterInfoSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Listener > ListenerSP
std::shared_ptr< lldb_private::Target > TargetSP
uint64_t tid_t
Definition lldb-types.h:85