LLDB mainline
UnwindWasm.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 "UnwindWasm.h"
11#include "ProcessWasm.h"
12#include "RegisterContextWasm.h"
13#include "ThreadWasm.h"
15#include "lldb/Utility/Log.h"
16
17using namespace lldb;
18using namespace lldb_private;
19using namespace process_gdb_remote;
20using namespace wasm;
21
24 if (m_frames.size() <= frame->GetFrameIndex())
26
27 ThreadSP thread = frame->GetThread();
28 ThreadGDBRemote *gdb_thread = static_cast<ThreadGDBRemote *>(thread.get());
29 ProcessWasm *wasm_process =
30 static_cast<ProcessWasm *>(thread->GetProcess().get());
31
32 return std::make_shared<RegisterContextWasm>(*gdb_thread,
33 frame->GetConcreteFrameIndex(),
34 wasm_process->GetRegisterInfo());
35}
36
39 return m_frames.size();
40
41 m_unwind_complete = true;
42 m_frames.clear();
43
44 ThreadWasm &wasm_thread = static_cast<ThreadWasm &>(GetThread());
45 llvm::Expected<std::vector<lldb::addr_t>> call_stack_pcs =
46 wasm_thread.GetWasmCallStack();
47 if (!call_stack_pcs) {
48 LLDB_LOG_ERROR(GetLog(LLDBLog::Unwind), call_stack_pcs.takeError(),
49 "Failed to get Wasm callstack: {0}");
50 m_frames.clear();
51 return 0;
52 }
53
54 m_frames = *call_stack_pcs;
55 return m_frames.size();
56}
57
58bool UnwindWasm::DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
60 bool &behaves_like_zeroth_frame) {
61 if (m_frames.size() == 0)
63
64 if (frame_idx >= m_frames.size())
65 return false;
66
67 behaves_like_zeroth_frame = (frame_idx == 0);
68 cfa = 0;
69 pc = m_frames[frame_idx];
70 return true;
71}
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
This base class provides an interface to stack frames.
Definition StackFrame.h:44
lldb::ThreadSP GetThread() const
Definition StackFrame.h:128
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
uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
Thread & GetThread()
Definition Unwind.h:61
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
ProcessWasm provides the access to the Wasm program state retrieved from the Wasm engine.
Definition ThreadWasm.h:19
llvm::Expected< std::vector< lldb::addr_t > > GetWasmCallStack()
Retrieve the current call stack from the WebAssembly remote process.
std::vector< lldb::addr_t > m_frames
Definition UnwindWasm.h:41
lldb::RegisterContextSP DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &pc, bool &behaves_like_zeroth_frame) override
uint32_t DoGetFrameCount() override
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::Thread > ThreadSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP