brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 1204faf Raw
82 lines · cpp
1//===-- HistoryUnwind.cpp -------------------------------------------------===//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 "lldb/lldb-private.h"10 11#include "Plugins/Process/Utility/HistoryUnwind.h"12#include "Plugins/Process/Utility/RegisterContextHistory.h"13 14#include "lldb/Target/Process.h"15#include "lldb/Target/StackFrame.h"16#include "lldb/Target/Target.h"17#include "lldb/Target/Thread.h"18 19#include <memory>20 21using namespace lldb;22using namespace lldb_private;23 24// Constructor25 26HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs,27                             HistoryPCType pc_type)28    : Unwind(thread), m_pcs(pcs), m_pc_type(pc_type) {}29 30// Destructor31 32HistoryUnwind::~HistoryUnwind() = default;33 34void HistoryUnwind::DoClear() {35  std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);36  m_pcs.clear();37}38 39lldb::RegisterContextSP40HistoryUnwind::DoCreateRegisterContextForFrame(StackFrame *frame) {41  RegisterContextSP rctx;42  if (frame) {43    addr_t pc = frame->GetFrameCodeAddress().GetLoadAddress(44        &frame->GetThread()->GetProcess()->GetTarget());45    if (pc != LLDB_INVALID_ADDRESS) {46      rctx = std::make_shared<RegisterContextHistory>(47          *frame->GetThread().get(), frame->GetConcreteFrameIndex(),48          frame->GetThread()->GetProcess()->GetAddressByteSize(), pc);49    }50  }51  return rctx;52}53 54static bool BehavesLikeZerothFrame(HistoryPCType pc_type, uint32_t frame_idx) {55  switch (pc_type) {56  case HistoryPCType::Returns:57    return (frame_idx == 0);58  case HistoryPCType::ReturnsNoZerothFrame:59    return false;60  case HistoryPCType::Calls:61    return true;62  }63  llvm_unreachable("Fully covered switch above");64}65 66bool HistoryUnwind::DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,67                                          lldb::addr_t &pc,68                                          bool &behaves_like_zeroth_frame) {69  // FIXME do not throw away the lock after we acquire it..70  std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex);71  guard.unlock();72  if (frame_idx < m_pcs.size()) {73    cfa = frame_idx;74    pc = m_pcs[frame_idx];75    behaves_like_zeroth_frame = BehavesLikeZerothFrame(m_pc_type, frame_idx);76    return true;77  }78  return false;79}80 81uint32_t HistoryUnwind::DoGetFrameCount() { return m_pcs.size(); }82