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#include "lldb/Target/Unwind.h"
16
17using namespace lldb;
18using namespace lldb_private;
19using namespace lldb_private::wasm;
20
22 if (!m_unwinder_up) {
23 assert(CalculateTarget()->GetArchitecture().GetMachine() ==
24 llvm::Triple::wasm32);
25 m_unwinder_up.reset(new wasm::UnwindWasm(*this));
26 }
27 return *m_unwinder_up;
28}
29
30llvm::Expected<std::vector<lldb::addr_t>> ThreadWasm::GetWasmCallStack() {
31 if (ProcessSP process_sp = GetProcess()) {
32 ProcessWasm *wasm_process = static_cast<ProcessWasm *>(process_sp.get());
33 return wasm_process->GetWasmCallStack(GetID());
34 }
35 return llvm::createStringError("no process");
36}
37
38lldb::addr_t ThreadWasm::GetConcreteFramePC(uint32_t concrete_frame_idx) {
39 lldb::addr_t cfa, pc;
40 bool behaves_like_zeroth_frame;
41 if (GetUnwinder().GetFrameInfoAtIndex(concrete_frame_idx, cfa, pc,
42 behaves_like_zeroth_frame))
43 return pc;
45}
46
49 uint32_t concrete_frame_idx = 0;
50 ProcessSP process_sp(GetProcess());
51 ProcessWasm *wasm_process = static_cast<ProcessWasm *>(process_sp.get());
52
53 if (frame)
54 concrete_frame_idx = frame->GetConcreteFrameIndex();
55
56 if (concrete_frame_idx == 0)
57 return std::make_shared<RegisterContextWasm>(
58 *this, concrete_frame_idx, wasm_process->GetRegisterInfo());
59
61}
virtual uint32_t GetConcreteFrameIndex()
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
Definition StackFrame.h:486
lldb::TargetSP CalculateTarget() override
Definition Thread.cpp:1449
std::unique_ptr< lldb_private::Unwind > m_unwinder_up
It gets set in Thread::ShouldResume.
Definition Thread.h:1477
lldb::ProcessSP GetProcess() const
Definition Thread.h:162
friend class StackFrame
Definition Thread.h:1371
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:21
lldb::DynamicRegisterInfoSP & GetRegisterInfo()
Definition ProcessWasm.h:68
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::addr_t GetConcreteFramePC(uint32_t concrete_frame_idx)
Return the program counter the Wasm unwinder recorded for the given concrete frame index,...
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) override
UnwindWasm manages stack unwinding for a WebAssembly process.
Definition UnwindWasm.h:20
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47