summaryrefslogtreecommitdiffstats
path: root/lldb/source/Target/StackFrameList.cpp
blob: 8615f714673992ec17f7ae60f268e6cea4baa322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//===-- StackFrameList.cpp --------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Target/StackFrameList.h"
#include "lldb/Target/StackFrame.h"

using namespace lldb;
using namespace lldb_private;

//----------------------------------------------------------------------
// StackFrameList constructor
//----------------------------------------------------------------------
StackFrameList::StackFrameList() :
    m_mutex (Mutex::eMutexTypeRecursive),
    m_frames (),
    m_current_frame_idx (0)
{
}

//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
StackFrameList::~StackFrameList()
{
}


uint32_t
StackFrameList::GetNumFrames() const
{
    Mutex::Locker locker (m_mutex);
    return m_frames.size();
}

// After we have determined the number of frames, we can set the count here
// and have the frame info be generated on demand.
void
StackFrameList::SetNumFrames(uint32_t count)
{
    Mutex::Locker locker (m_mutex);
    return m_frames.resize(count);
}

StackFrameSP
StackFrameList::GetFrameAtIndex (uint32_t idx) const
{
    StackFrameSP frame_sp;
    {
        Mutex::Locker locker (m_mutex);
        if (idx < m_frames.size())
            frame_sp = m_frames[idx];
    }
    return frame_sp;
}

bool
StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp)
{
    Mutex::Locker locker (m_mutex);
    if (idx >= m_frames.size())
        m_frames.resize(idx + 1);
    // Make sure allocation succeeded by checking bounds again
    if (idx < m_frames.size())
    {
        m_frames[idx] = frame_sp;
        return true;
    }
    return false;   // resize failed, out of memory?
}

uint32_t
StackFrameList::GetCurrentFrameIndex () const
{
    Mutex::Locker locker (m_mutex);
    return m_current_frame_idx;
}


uint32_t
StackFrameList::SetCurrentFrame (lldb_private::StackFrame *frame)
{
    Mutex::Locker locker (m_mutex);
    const_iterator pos,
                   begin = m_frames.begin(),
                   end = m_frames.end();
    for (pos = begin; pos != end; ++pos)
    {
        if (pos->get() == frame)
        {
            m_current_frame_idx = std::distance (begin, pos);
            return m_current_frame_idx;
        }
    }
    m_current_frame_idx = 0;
    return m_current_frame_idx;
}

// Mark a stack frame as the current frame using the frame index
void
StackFrameList::SetCurrentFrameByIndex (uint32_t idx)
{
    Mutex::Locker locker (m_mutex);
    m_current_frame_idx = idx;
}

// The thread has been run, reset the number stack frames to zero so we can
// determine how many frames we have lazily.
void
StackFrameList::Clear ()
{
    Mutex::Locker locker (m_mutex);
    m_frames.clear();
}

void
StackFrameList::InvalidateFrames (uint32_t start_idx)
{
    Mutex::Locker locker (m_mutex);
    size_t num_frames = m_frames.size();
    while (start_idx < num_frames)
    {
        m_frames[start_idx].reset();
        ++start_idx;
    }
}
OpenPOWER on IntegriCloud