52 lines · cpp
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-exception6//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 20Unwind &ThreadWasm::GetUnwinder() {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 37lldb::RegisterContextSP38ThreadWasm::CreateRegisterContextForFrame(StackFrame *frame) {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 50 return GetUnwinder().CreateRegisterContextForFrame(frame);51}52