blob: 4f0ecba613bfa932b61acea03d19ea25325effcd [file] [log] [blame]
Jason Molenda02706c32013-11-08 04:59:54 +00001//===-- HistoryUnwind.cpp ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/lldb-private.h"
11
Jason Molenda02706c32013-11-08 04:59:54 +000012#include "Plugins/Process/Utility/HistoryUnwind.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000013#include "Plugins/Process/Utility/RegisterContextHistory.h"
Jason Molenda02706c32013-11-08 04:59:54 +000014
Jason Molenda02706c32013-11-08 04:59:54 +000015#include "lldb/Target/Process.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000016#include "lldb/Target/StackFrame.h"
Jason Molenda02706c32013-11-08 04:59:54 +000017#include "lldb/Target/Target.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000018#include "lldb/Target/Thread.h"
Jason Molenda02706c32013-11-08 04:59:54 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Kate Stoneb9c1b512016-09-06 20:57:50 +000023// Constructor
Jason Molendaa8ff5432014-03-06 06:31:18 +000024
Kate Stoneb9c1b512016-09-06 20:57:50 +000025HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs,
26 bool stop_id_is_valid)
27 : Unwind(thread), m_pcs(pcs), m_stop_id_is_valid(stop_id_is_valid) {}
Jason Molenda02706c32013-11-08 04:59:54 +000028
Jason Molendaa8ff5432014-03-06 06:31:18 +000029// Destructor
30
Kate Stoneb9c1b512016-09-06 20:57:50 +000031HistoryUnwind::~HistoryUnwind() {}
Jason Molenda02706c32013-11-08 04:59:54 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033void HistoryUnwind::DoClear() {
34 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
35 m_pcs.clear();
36 m_stop_id_is_valid = false;
Jason Molenda02706c32013-11-08 04:59:54 +000037}
38
39lldb::RegisterContextSP
Kate Stoneb9c1b512016-09-06 20:57:50 +000040HistoryUnwind::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.reset(new RegisterContextHistory(
47 *frame->GetThread().get(), frame->GetConcreteFrameIndex(),
48 frame->GetThread()->GetProcess()->GetAddressByteSize(), pc));
Jason Molenda02706c32013-11-08 04:59:54 +000049 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 }
51 return rctx;
Jason Molenda02706c32013-11-08 04:59:54 +000052}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054bool HistoryUnwind::DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
55 lldb::addr_t &pc) {
56 // FIXME do not throw away the lock after we acquire it..
57 std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex);
58 guard.unlock();
59 if (frame_idx < m_pcs.size()) {
60 cfa = frame_idx;
61 pc = m_pcs[frame_idx];
62 return true;
63 }
64 return false;
Jason Molenda02706c32013-11-08 04:59:54 +000065}
66
Kate Stoneb9c1b512016-09-06 20:57:50 +000067uint32_t HistoryUnwind::DoGetFrameCount() { return m_pcs.size(); }