brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 319c5e2 Raw
72 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 "UnwindWasm.h"10#include "Plugins/Process/gdb-remote/ThreadGDBRemote.h"11#include "ProcessWasm.h"12#include "RegisterContextWasm.h"13#include "ThreadWasm.h"14#include "lldb/Utility/LLDBLog.h"15#include "lldb/Utility/Log.h"16 17using namespace lldb;18using namespace lldb_private;19using namespace process_gdb_remote;20using namespace wasm;21 22lldb::RegisterContextSP23UnwindWasm::DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) {24  if (m_frames.size() <= frame->GetFrameIndex())25    return lldb::RegisterContextSP();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 37uint32_t UnwindWasm::DoGetFrameCount() {38  if (m_unwind_complete)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,59                                       lldb::addr_t &pc,60                                       bool &behaves_like_zeroth_frame) {61  if (m_frames.size() == 0)62    DoGetFrameCount();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}72