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().GetTriple().isWasm());
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
37lldb::addr_t ThreadWasm::GetConcreteFramePC(uint32_t concrete_frame_idx) {
38 lldb::addr_t cfa, pc;
39 bool behaves_like_zeroth_frame;
40 if (GetUnwinder().GetFrameInfoAtIndex(concrete_frame_idx, cfa, pc,
41 behaves_like_zeroth_frame))
42 return pc;
44}
45
48 uint32_t concrete_frame_idx = 0;
49 ProcessSP process_sp(GetProcess());
50 ProcessWasm *wasm_process = static_cast<ProcessWasm *>(process_sp.get());
51
52 if (frame)
53 concrete_frame_idx = frame->GetConcreteFrameIndex();
54
55 if (concrete_frame_idx == 0)
56 return std::make_shared<RegisterContextWasm>(
57 *this, concrete_frame_idx, wasm_process->GetRegisterInfo());
58
60}
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:96
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