StackFrameList.h revision 263363
1//===-- StackFrameList.h ----------------------------------------*- 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#ifndef liblldb_StackFrameList_h_
11#define liblldb_StackFrameList_h_
12
13// C Includes
14// C++ Includes
15#include <vector>
16
17// Other libraries and framework includes
18// Project includes
19#include "lldb/Host/Mutex.h"
20#include "lldb/Target/StackFrame.h"
21
22namespace lldb_private {
23
24class StackFrameList
25{
26public:
27    //------------------------------------------------------------------
28    // Constructors and Destructors
29    //------------------------------------------------------------------
30    StackFrameList (Thread &thread,
31                    const lldb::StackFrameListSP &prev_frames_sp,
32                    bool show_inline_frames);
33
34    ~StackFrameList();
35
36    uint32_t
37    GetNumFrames (bool can_create = true);
38
39    lldb::StackFrameSP
40    GetFrameAtIndex (uint32_t idx);
41
42    lldb::StackFrameSP
43    GetFrameWithConcreteFrameIndex (uint32_t unwind_idx);
44
45    lldb::StackFrameSP
46    GetFrameWithStackID (const StackID &stack_id);
47
48    // Mark a stack frame as the current frame
49    uint32_t
50    SetSelectedFrame (lldb_private::StackFrame *frame);
51
52    uint32_t
53    GetSelectedFrameIndex () const;
54
55    // Mark a stack frame as the current frame using the frame index
56    bool
57    SetSelectedFrameByIndex (uint32_t idx);
58
59    uint32_t
60    GetVisibleStackFrameIndex(uint32_t idx)
61    {
62        if (m_current_inlined_depth < UINT32_MAX)
63            return idx - m_current_inlined_depth;
64        else
65            return idx;
66    }
67
68    void
69    CalculateCurrentInlinedDepth ();
70
71    void
72    SetDefaultFileAndLineToSelectedFrame();
73
74    void
75    Clear ();
76
77    void
78    InvalidateFrames (uint32_t start_idx);
79
80    void
81    Dump (Stream *s);
82
83    lldb::StackFrameSP
84    GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr);
85
86    size_t
87    GetStatus (Stream &strm,
88               uint32_t first_frame,
89               uint32_t num_frames,
90               bool show_frame_info,
91               uint32_t num_frames_with_source,
92               const char *frame_marker = NULL);
93
94protected:
95
96    friend class Thread;
97
98    bool
99    SetFrameAtIndex (uint32_t idx, lldb::StackFrameSP &frame_sp);
100
101    static void
102    Merge (std::unique_ptr<StackFrameList>& curr_ap,
103           lldb::StackFrameListSP& prev_sp);
104
105    void
106    GetFramesUpTo (uint32_t end_idx);
107
108    bool
109    GetAllFramesFetched()
110    {
111        return m_concrete_frames_fetched == UINT32_MAX;
112    }
113
114    void
115    SetAllFramesFetched ()
116    {
117        m_concrete_frames_fetched = UINT32_MAX;
118    }
119
120    bool
121    DecrementCurrentInlinedDepth ();
122
123    void
124    ResetCurrentInlinedDepth();
125
126    uint32_t
127    GetCurrentInlinedDepth ();
128
129    void
130    SetCurrentInlinedDepth (uint32_t new_depth);
131
132    //------------------------------------------------------------------
133    // Classes that inherit from StackFrameList can see and modify these
134    //------------------------------------------------------------------
135    typedef std::vector<lldb::StackFrameSP> collection;
136    typedef collection::iterator iterator;
137    typedef collection::const_iterator const_iterator;
138
139    Thread &m_thread;
140    lldb::StackFrameListSP m_prev_frames_sp;
141    mutable Mutex m_mutex;
142    collection m_frames;
143    uint32_t m_selected_frame_idx;
144    uint32_t m_concrete_frames_fetched;
145    uint32_t m_current_inlined_depth;
146    lldb::addr_t m_current_inlined_pc;
147    bool m_show_inlined_frames;
148
149private:
150    //------------------------------------------------------------------
151    // For StackFrameList only
152    //------------------------------------------------------------------
153    DISALLOW_COPY_AND_ASSIGN (StackFrameList);
154};
155
156} // namespace lldb_private
157
158#endif  // liblldb_StackFrameList_h_
159