1 //===-- StackFrameList.h ----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_TARGET_STACKFRAMELIST_H
10 #define LLDB_TARGET_STACKFRAMELIST_H
16 #include "lldb/Target/StackFrame.h"
18 namespace lldb_private {
20 class StackFrameList {
22 // Constructors and Destructors
23 StackFrameList(Thread &thread, const lldb::StackFrameListSP &prev_frames_sp,
24 bool show_inline_frames);
28 /// Get the number of visible frames. Frames may be created if \p can_create
29 /// is true. Synthetic (inline) frames expanded from the concrete frame #0
30 /// (aka invisible frames) are not included in this count.
31 uint32_t GetNumFrames(bool can_create = true);
33 /// Get the frame at index \p idx. Invisible frames cannot be indexed.
34 lldb::StackFrameSP GetFrameAtIndex(uint32_t idx);
36 /// Get the first concrete frame with index greater than or equal to \p idx.
37 /// Unlike \ref GetFrameAtIndex, this cannot return a synthetic frame.
38 lldb::StackFrameSP GetFrameWithConcreteFrameIndex(uint32_t unwind_idx);
40 /// Retrieve the stack frame with the given ID \p stack_id.
41 lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id);
43 /// Mark a stack frame as the currently selected frame and return its index.
44 uint32_t SetSelectedFrame(lldb_private::StackFrame *frame);
46 /// Get the currently selected frame index.
47 uint32_t GetSelectedFrameIndex() const;
49 /// Mark a stack frame as the currently selected frame using the frame index
50 /// \p idx. Like \ref GetFrameAtIndex, invisible frames cannot be selected.
51 bool SetSelectedFrameByIndex(uint32_t idx);
53 /// If the current inline depth (i.e the number of invisible frames) is valid,
54 /// subtract it from \p idx. Otherwise simply return \p idx.
55 uint32_t GetVisibleStackFrameIndex(uint32_t idx) {
56 if (m_current_inlined_depth < UINT32_MAX)
57 return idx - m_current_inlined_depth;
62 /// Calculate and set the current inline depth. This may be used to update
63 /// the StackFrameList's set of inline frames when execution stops, e.g when
64 /// a breakpoint is hit.
65 void CalculateCurrentInlinedDepth();
67 /// If the currently selected frame comes from the currently selected thread,
68 /// point the default file and line of the thread's target to the location
69 /// specified by the frame.
70 void SetDefaultFileAndLineToSelectedFrame();
72 /// Clear the cache of frames.
77 /// If \p stack_frame_ptr is contained in this StackFrameList, return its
78 /// wrapping shared pointer.
80 GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr);
82 size_t GetStatus(Stream &strm, uint32_t first_frame, uint32_t num_frames,
83 bool show_frame_info, uint32_t num_frames_with_source,
84 bool show_unique = false,
85 const char *frame_marker = nullptr);
90 bool SetFrameAtIndex(uint32_t idx, lldb::StackFrameSP &frame_sp);
92 void GetFramesUpTo(uint32_t end_idx);
94 void GetOnlyConcreteFramesUpTo(uint32_t end_idx, Unwind &unwinder);
96 void SynthesizeTailCallFrames(StackFrame &next_frame);
98 bool GetAllFramesFetched() { return m_concrete_frames_fetched == UINT32_MAX; }
100 void SetAllFramesFetched() { m_concrete_frames_fetched = UINT32_MAX; }
102 bool DecrementCurrentInlinedDepth();
104 void ResetCurrentInlinedDepth();
106 uint32_t GetCurrentInlinedDepth();
108 void SetCurrentInlinedDepth(uint32_t new_depth);
110 typedef std::vector<lldb::StackFrameSP> collection;
111 typedef collection::iterator iterator;
112 typedef collection::const_iterator const_iterator;
114 /// The thread this frame list describes.
117 /// The old stack frame list.
118 // TODO: The old stack frame list is used to fill in missing frame info
119 // heuristically when it's otherwise unavailable (say, because the unwinder
120 // fails). We should have stronger checks to make sure that this is a valid
121 // source of information.
122 lldb::StackFrameListSP m_prev_frames_sp;
124 /// A mutex for this frame list.
125 // TODO: This mutex may not always be held when required. In particular, uses
126 // of the StackFrameList APIs in lldb_private::Thread look suspect. Consider
127 // passing around a lock_guard reference to enforce proper locking.
128 mutable std::recursive_mutex m_mutex;
130 /// A cache of frames. This may need to be updated when the program counter
134 /// The currently selected frame.
135 uint32_t m_selected_frame_idx;
137 /// The number of concrete frames fetched while filling the frame list. This
138 /// is only used when synthetic frames are enabled.
139 uint32_t m_concrete_frames_fetched;
141 /// The number of synthetic function activations (invisible frames) expanded
142 /// from the concrete frame #0 activation.
143 // TODO: Use an optional instead of UINT32_MAX to denote invalid values.
144 uint32_t m_current_inlined_depth;
146 /// The program counter value at the currently selected synthetic activation.
147 /// This is only valid if m_current_inlined_depth is valid.
148 // TODO: Use an optional instead of UINT32_MAX to denote invalid values.
149 lldb::addr_t m_current_inlined_pc;
151 /// Whether or not to show synthetic (inline) frames. Immutable.
152 const bool m_show_inlined_frames;
155 StackFrameList(const StackFrameList &) = delete;
156 const StackFrameList &operator=(const StackFrameList &) = delete;
159 } // namespace lldb_private
161 #endif // LLDB_TARGET_STACKFRAMELIST_H