LLDB mainline
ThreadWasm.cpp
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#include "ThreadWasm.h"
10
11#include "ProcessWasm.h"
12#include "RegisterContextWasm.h"
13#include "UnwindWasm.h"
14#include "lldb/Target/Target.h"
15
16using namespace lldb;
17using namespace lldb_private;
18using namespace lldb_private::wasm;
19
21 if (!m_unwinder_up) {
22 assert(CalculateTarget()->GetArchitecture().GetMachine() ==
23 llvm::Triple::wasm32);
24 m_unwinder_up.reset(new wasm::UnwindWasm(*this));
25 }
26 return *m_unwinder_up;
27}
28
29llvm::Expected<std::vector<lldb::addr_t>> ThreadWasm::GetWasmCallStack() {
30 if (ProcessSP process_sp = GetProcess()) {
31 ProcessWasm *wasm_process = static_cast<ProcessWasm *>(process_sp.get());
32 return wasm_process->GetWasmCallStack(GetID());
33 }
34 return llvm::createStringError("no process");
35}
36
39 uint32_t concrete_frame_idx = 0;
40 ProcessSP process_sp(GetProcess());
41 ProcessWasm *wasm_process = static_cast<ProcessWasm *>(process_sp.get());
42
43 if (frame)
44 concrete_frame_idx = frame->GetConcreteFrameIndex();
45
46 if (concrete_frame_idx == 0)
47 return std::make_shared<RegisterContextWasm>(
48 *this, concrete_frame_idx, wasm_process->GetRegisterInfo());
49
51}
uint32_t GetConcreteFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
Definition StackFrame.h:455
lldb::TargetSP CalculateTarget() override
Definition Thread.cpp:1421
std::unique_ptr< lldb_private::Unwind > m_unwinder_up
It gets set in Thread::ShouldResume.
Definition Thread.h:1394
lldb::ProcessSP GetProcess() const
Definition Thread.h:158
friend class StackFrame
Definition Thread.h:1303
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame)
Definition Unwind.h:56
ProcessWasm provides the access to the Wasm program state retrieved from the Wasm engine.
Definition ProcessWasm.h:47
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.
Unwind & GetUnwinder() override
llvm::Expected< std::vector< lldb::addr_t > > GetWasmCallStack()
Retrieve the current call stack from the WebAssembly remote process.
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) override
UnwindWasm manages stack unwinding for a WebAssembly process.
Definition UnwindWasm.h:20
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47