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 /// Retrieve the current call stack from the WebAssembly remote process.
49 llvm::Expected<std::vector<lldb::addr_t>> GetWasmCallStack(lldb::tid_t tid);
50
51 /// Query the value of a frame-scoped WebAssembly variable, which is a local
52 /// or a value on the operand stack.
53 llvm::Expected<lldb::DataBufferSP>
54 GetWasmVariable(WasmVirtualRegisterKinds kind, uint32_t frame_index,
55 uint32_t index);
56
57 /// Query the value of the global at \a index in the global index space of the
58 /// module instance \a module_id names. An index only names a global together
59 /// with an instance. Only a stub that advertises "qWasmInstance+" can be told
60 /// which instance to read, so see CanNameInstance first.
61 llvm::Expected<lldb::DataBufferSP> GetWasmGlobalForModule(uint32_t module_id,
62 uint32_t index);
63
64 /// Query the value of a WebAssembly global through the frame at \a
65 /// frame_index, which reaches only the globals of the module instance that
66 /// frame is executing. This is the only scope a stub that cannot be told
67 /// which instance to read offers.
68 llvm::Expected<lldb::DataBufferSP> GetWasmGlobalForFrame(uint32_t frame_index,
69 uint32_t index);
70
71 /// Whether the instance holding a global can be named to the stub, which
72 /// needs both a valid id to name it by and a stub that accepts one. Where it
73 /// cannot, a frame executing that instance has to stand in for it.
74 bool CanNameInstance(uint32_t module_id);
75
76protected:
77 std::shared_ptr<process_gdb_remote::ThreadGDBRemote>
78 CreateThread(lldb::tid_t tid) override;
79
80private:
81 friend class UnwindWasm;
82 friend class ThreadWasm;
83
84 /// Ask the WebAssembly stub for a single value, which comes back as the
85 /// hex-encoded bytes of the whole value.
86 llvm::Expected<lldb::DataBufferSP> SendWasmValueQuery(llvm::StringRef packet);
87
88 /// Read a WebAssembly global of the module instance \a module_id names,
89 /// through whichever scope that stub can be asked for it in.
90 size_t ReadGlobal(uint32_t module_id, uint32_t index, void *buf, size_t size,
91 Status &error);
92
93 /// The frame to read a global of \a module_id through, for a stub that cannot
94 /// be told which instance to read. Fails when no frame is executing that
95 /// module, which leaves its globals out of reach.
96 llvm::Expected<uint32_t> GetFallbackFrameIndex(uint32_t module_id);
97
99
101 const ProcessWasm &operator=(const ProcessWasm &) = delete;
102};
103
104} // namespace wasm
105} // namespace lldb_private
106
107#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:371
An error handling class.
Definition Status.h:118
lldb::DynamicRegisterInfoSP & GetRegisterInfo()
Definition ProcessWasm.h:98
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...
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.
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