]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Process/Utility/HistoryUnwind.cpp
Import LLDB as of upstream SVN r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / source / Plugins / Process / Utility / HistoryUnwind.cpp
1 //===-- 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
20 using namespace lldb;
21 using namespace lldb_private;
22
23 // Constructor 
24
25 HistoryUnwind::HistoryUnwind (Thread &thread,
26                               std::vector<lldb::addr_t> pcs,
27                               bool stop_id_is_valid) :
28         Unwind (thread),
29         m_pcs (pcs),
30         m_stop_id_is_valid (stop_id_is_valid)
31 {
32 }
33
34 // Destructor
35
36 HistoryUnwind::~HistoryUnwind ()
37 {
38 }
39
40 void
41 HistoryUnwind::DoClear ()
42 {
43     Mutex::Locker locker(m_unwind_mutex);
44     m_pcs.clear();
45     m_stop_id_is_valid = false;
46 }
47
48 lldb::RegisterContextSP
49 HistoryUnwind::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
64 bool
65 HistoryUnwind::DoGetFrameInfoAtIndex (uint32_t frame_idx, lldb::addr_t& cfa, lldb::addr_t& pc)
66 {
67     Mutex::Locker (m_unwind_mutex);   // FIXME do not throw away the lock after we acquire it..
68     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
77 uint32_t
78 HistoryUnwind::DoGetFrameCount ()
79 {
80     return m_pcs.size();
81 }