blob: 14afcbee0b49c41e5dadd572face39ce67e6983c [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
12#include "Plugins/Process/Utility/RegisterContextHistory.h"
13#include "Plugins/Process/Utility/HistoryUnwind.h"
14
15#include "lldb/Target/StackFrame.h"
16#include "lldb/Target/Thread.h"
17#include "lldb/Target/Process.h"
18#include "lldb/Target/Target.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
Jason Molendaa8ff5432014-03-06 06:31:18 +000023// Constructor
24
Jason Molenda02706c32013-11-08 04:59:54 +000025HistoryUnwind::HistoryUnwind (Thread &thread,
26 std::vector<lldb::addr_t> pcs,
Jason Molenda02706c32013-11-08 04:59:54 +000027 bool stop_id_is_valid) :
28 Unwind (thread),
29 m_pcs (pcs),
Jason Molenda02706c32013-11-08 04:59:54 +000030 m_stop_id_is_valid (stop_id_is_valid)
31{
32}
33
Jason Molendaa8ff5432014-03-06 06:31:18 +000034// Destructor
35
Jason Molenda02706c32013-11-08 04:59:54 +000036HistoryUnwind::~HistoryUnwind ()
37{
38}
39
40void
41HistoryUnwind::DoClear ()
42{
43 Mutex::Locker locker(m_unwind_mutex);
44 m_pcs.clear();
45 m_stop_id_is_valid = false;
46}
47
48lldb::RegisterContextSP
49HistoryUnwind::DoCreateRegisterContextForFrame (StackFrame *frame)
50{
51 RegisterContextSP rctx;
52 if (frame)
53 {
54 addr_t pc = frame->GetFrameCodeAddress().GetLoadAddress (&frame->GetThread()->GetProcess()->GetTarget());
55 if (pc != LLDB_INVALID_ADDRESS)
56 {
57 rctx.reset (new RegisterContextHistory (*frame->GetThread().get(), frame->GetConcreteFrameIndex(),
58 frame->GetThread()->GetProcess()->GetAddressByteSize(), pc));
59 }
60 }
61 return rctx;
62}
63
64bool
65HistoryUnwind::DoGetFrameInfoAtIndex (uint32_t frame_idx, lldb::addr_t& cfa, lldb::addr_t& pc)
66{
Jason Molendad81c4832014-06-23 21:30:15 +000067 Mutex::Locker (m_unwind_mutex); // FIXME do not throw away the lock after we acquire it..
Jason Molenda02706c32013-11-08 04:59:54 +000068 if (frame_idx < m_pcs.size())
69 {
70 cfa = frame_idx;
71 pc = m_pcs[frame_idx];
72 return true;
73 }
74 return false;
75}
76
77uint32_t
78HistoryUnwind::DoGetFrameCount ()
79{
80 return m_pcs.size();
81}