blob: 8615f714673992ec17f7ae60f268e6cea4baa322 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- StackFrameList.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// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
14#include "lldb/Target/StackFrameList.h"
15#include "lldb/Target/StackFrame.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20//----------------------------------------------------------------------
21// StackFrameList constructor
22//----------------------------------------------------------------------
23StackFrameList::StackFrameList() :
24 m_mutex (Mutex::eMutexTypeRecursive),
25 m_frames (),
26 m_current_frame_idx (0)
27{
28}
29
30//----------------------------------------------------------------------
31// Destructor
32//----------------------------------------------------------------------
33StackFrameList::~StackFrameList()
34{
35}
36
37
38uint32_t
39StackFrameList::GetNumFrames() const
40{
41 Mutex::Locker locker (m_mutex);
42 return m_frames.size();
43}
44
45// After we have determined the number of frames, we can set the count here
46// and have the frame info be generated on demand.
47void
48StackFrameList::SetNumFrames(uint32_t count)
49{
50 Mutex::Locker locker (m_mutex);
51 return m_frames.resize(count);
52}
53
54StackFrameSP
55StackFrameList::GetFrameAtIndex (uint32_t idx) const
56{
57 StackFrameSP frame_sp;
58 {
59 Mutex::Locker locker (m_mutex);
60 if (idx < m_frames.size())
61 frame_sp = m_frames[idx];
62 }
63 return frame_sp;
64}
65
66bool
67StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp)
68{
69 Mutex::Locker locker (m_mutex);
70 if (idx >= m_frames.size())
71 m_frames.resize(idx + 1);
72 // Make sure allocation succeeded by checking bounds again
73 if (idx < m_frames.size())
74 {
75 m_frames[idx] = frame_sp;
76 return true;
77 }
78 return false; // resize failed, out of memory?
79}
80
81uint32_t
82StackFrameList::GetCurrentFrameIndex () const
83{
84 Mutex::Locker locker (m_mutex);
85 return m_current_frame_idx;
86}
87
88
89uint32_t
90StackFrameList::SetCurrentFrame (lldb_private::StackFrame *frame)
91{
92 Mutex::Locker locker (m_mutex);
93 const_iterator pos,
94 begin = m_frames.begin(),
95 end = m_frames.end();
96 for (pos = begin; pos != end; ++pos)
97 {
98 if (pos->get() == frame)
99 {
100 m_current_frame_idx = std::distance (begin, pos);
101 return m_current_frame_idx;
102 }
103 }
104 m_current_frame_idx = 0;
105 return m_current_frame_idx;
106}
107
108// Mark a stack frame as the current frame using the frame index
109void
110StackFrameList::SetCurrentFrameByIndex (uint32_t idx)
111{
112 Mutex::Locker locker (m_mutex);
113 m_current_frame_idx = idx;
114}
115
116// The thread has been run, reset the number stack frames to zero so we can
117// determine how many frames we have lazily.
118void
119StackFrameList::Clear ()
120{
121 Mutex::Locker locker (m_mutex);
122 m_frames.clear();
123}
124
125void
126StackFrameList::InvalidateFrames (uint32_t start_idx)
127{
128 Mutex::Locker locker (m_mutex);
129 size_t num_frames = m_frames.size();
130 while (start_idx < num_frames)
131 {
132 m_frames[start_idx].reset();
133 ++start_idx;
134 }
135}