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