LLDB  mainline
StackFrameList.h
Go to the documentation of this file.
1 //===-- StackFrameList.h ----------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_TARGET_STACKFRAMELIST_H
10 #define LLDB_TARGET_STACKFRAMELIST_H
11 
12 #include <memory>
13 #include <mutex>
14 #include <vector>
15 
16 #include "lldb/Target/StackFrame.h"
17 
18 namespace lldb_private {
19 
20 class ScriptedThread;
21 
23 public:
24  // Constructors and Destructors
25  StackFrameList(Thread &thread, const lldb::StackFrameListSP &prev_frames_sp,
26  bool show_inline_frames);
27 
29 
30  /// Get the number of visible frames. Frames may be created if \p can_create
31  /// is true. Synthetic (inline) frames expanded from the concrete frame #0
32  /// (aka invisible frames) are not included in this count.
33  uint32_t GetNumFrames(bool can_create = true);
34 
35  /// Get the frame at index \p idx. Invisible frames cannot be indexed.
36  lldb::StackFrameSP GetFrameAtIndex(uint32_t idx);
37 
38  /// Get the first concrete frame with index greater than or equal to \p idx.
39  /// Unlike \ref GetFrameAtIndex, this cannot return a synthetic frame.
40  lldb::StackFrameSP GetFrameWithConcreteFrameIndex(uint32_t unwind_idx);
41 
42  /// Retrieve the stack frame with the given ID \p stack_id.
43  lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id);
44 
45  /// Mark a stack frame as the currently selected frame and return its index.
47 
48  /// Get the currently selected frame index.
50 
51  /// Mark a stack frame as the currently selected frame using the frame index
52  /// \p idx. Like \ref GetFrameAtIndex, invisible frames cannot be selected.
54 
55  /// If the current inline depth (i.e the number of invisible frames) is valid,
56  /// subtract it from \p idx. Otherwise simply return \p idx.
59  return idx - m_current_inlined_depth;
60  else
61  return idx;
62  }
63 
64  /// Calculate and set the current inline depth. This may be used to update
65  /// the StackFrameList's set of inline frames when execution stops, e.g when
66  /// a breakpoint is hit.
68 
69  /// If the currently selected frame comes from the currently selected thread,
70  /// point the default file and line of the thread's target to the location
71  /// specified by the frame.
73 
74  /// Clear the cache of frames.
75  void Clear();
76 
77  void Dump(Stream *s);
78 
79  /// If \p stack_frame_ptr is contained in this StackFrameList, return its
80  /// wrapping shared pointer.
81  lldb::StackFrameSP
83 
84  size_t GetStatus(Stream &strm, uint32_t first_frame, uint32_t num_frames,
85  bool show_frame_info, uint32_t num_frames_with_source,
86  bool show_unique = false,
87  const char *frame_marker = nullptr);
88 
89 protected:
90  friend class Thread;
91  friend class ScriptedThread;
92 
93  bool SetFrameAtIndex(uint32_t idx, lldb::StackFrameSP &frame_sp);
94 
95  void GetFramesUpTo(uint32_t end_idx);
96 
97  void GetOnlyConcreteFramesUpTo(uint32_t end_idx, Unwind &unwinder);
98 
99  void SynthesizeTailCallFrames(StackFrame &next_frame);
100 
102 
104 
106 
108 
110 
111  void SetCurrentInlinedDepth(uint32_t new_depth);
112 
113  typedef std::vector<lldb::StackFrameSP> collection;
114  typedef collection::iterator iterator;
115  typedef collection::const_iterator const_iterator;
116 
117  /// The thread this frame list describes.
119 
120  /// The old stack frame list.
121  // TODO: The old stack frame list is used to fill in missing frame info
122  // heuristically when it's otherwise unavailable (say, because the unwinder
123  // fails). We should have stronger checks to make sure that this is a valid
124  // source of information.
125  lldb::StackFrameListSP m_prev_frames_sp;
126 
127  /// A mutex for this frame list.
128  // TODO: This mutex may not always be held when required. In particular, uses
129  // of the StackFrameList APIs in lldb_private::Thread look suspect. Consider
130  // passing around a lock_guard reference to enforce proper locking.
131  mutable std::recursive_mutex m_mutex;
132 
133  /// A cache of frames. This may need to be updated when the program counter
134  /// changes.
136 
137  /// The currently selected frame.
139 
140  /// The number of concrete frames fetched while filling the frame list. This
141  /// is only used when synthetic frames are enabled.
143 
144  /// The number of synthetic function activations (invisible frames) expanded
145  /// from the concrete frame #0 activation.
146  // TODO: Use an optional instead of UINT32_MAX to denote invalid values.
148 
149  /// The program counter value at the currently selected synthetic activation.
150  /// This is only valid if m_current_inlined_depth is valid.
151  // TODO: Use an optional instead of UINT32_MAX to denote invalid values.
153 
154  /// Whether or not to show synthetic (inline) frames. Immutable.
156 
157 private:
158  StackFrameList(const StackFrameList &) = delete;
159  const StackFrameList &operator=(const StackFrameList &) = delete;
160 };
161 
162 } // namespace lldb_private
163 
164 #endif // LLDB_TARGET_STACKFRAMELIST_H
lldb_private::StackFrameList::SetSelectedFrame
uint32_t SetSelectedFrame(lldb_private::StackFrame *frame)
Mark a stack frame as the currently selected frame and return its index.
Definition: StackFrameList.cpp:780
lldb_private::StackFrameList::Clear
void Clear()
Clear the cache of frames.
Definition: StackFrameList.cpp:824
lldb_private::StackFrameList::GetNumFrames
uint32_t GetNumFrames(bool can_create=true)
Get the number of visible frames.
Definition: StackFrameList.cpp:619
lldb_private::StackFrameList::m_current_inlined_pc
lldb::addr_t m_current_inlined_pc
The program counter value at the currently selected synthetic activation.
Definition: StackFrameList.h:152
lldb_private::StackFrameList::SetCurrentInlinedDepth
void SetCurrentInlinedDepth(uint32_t new_depth)
Definition: StackFrameList.cpp:216
lldb_private::StackFrameList::DecrementCurrentInlinedDepth
bool DecrementCurrentInlinedDepth()
Definition: StackFrameList.cpp:203
lldb_private::StackFrameList::m_thread
Thread & m_thread
The thread this frame list describes.
Definition: StackFrameList.h:118
StackFrame.h
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::StackFrameList::GetAllFramesFetched
bool GetAllFramesFetched()
Definition: StackFrameList.h:101
lldb_private::StackFrameList::GetStackFrameSPForStackFramePtr
lldb::StackFrameSP GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr)
If stack_frame_ptr is contained in this StackFrameList, return its wrapping shared pointer.
Definition: StackFrameList.cpp:831
lldb_private::StackFrameList::SetAllFramesFetched
void SetAllFramesFetched()
Definition: StackFrameList.h:103
lldb_private::StackFrameList
Definition: StackFrameList.h:22
lldb_private::StackFrameList::GetStatus
size_t GetStatus(Stream &strm, uint32_t first_frame, uint32_t num_frames, bool show_frame_info, uint32_t num_frames_with_source, bool show_unique=false, const char *frame_marker=nullptr)
Definition: StackFrameList.cpp:846
lldb_private::StackFrameList::StackFrameList
StackFrameList(Thread &thread, const lldb::StackFrameListSP &prev_frames_sp, bool show_inline_frames)
Definition: StackFrameList.cpp:36
lldb_private::Thread
Definition: Thread.h:61
lldb_private::StackFrameList::GetFramesUpTo
void GetFramesUpTo(uint32_t end_idx)
Definition: StackFrameList.cpp:437
lldb_private::StackFrameList::GetVisibleStackFrameIndex
uint32_t GetVisibleStackFrameIndex(uint32_t idx)
If the current inline depth (i.e the number of invisible frames) is valid, subtract it from idx.
Definition: StackFrameList.h:57
lldb_private::StackFrameList::GetSelectedFrameIndex
uint32_t GetSelectedFrameIndex() const
Get the currently selected frame index.
Definition: StackFrameList.cpp:775
lldb_private::StackFrameList::m_current_inlined_depth
uint32_t m_current_inlined_depth
The number of synthetic function activations (invisible frames) expanded from the concrete frame #0 a...
Definition: StackFrameList.h:147
lldb_private::StackFrameList::operator=
const StackFrameList & operator=(const StackFrameList &)=delete
lldb_private::StackFrameList::m_mutex
std::recursive_mutex m_mutex
A mutex for this frame list.
Definition: StackFrameList.h:131
lldb_private::StackFrameList::SetFrameAtIndex
bool SetFrameAtIndex(uint32_t idx, lldb::StackFrameSP &frame_sp)
Definition: StackFrameList.cpp:764
lldb_private::StackFrameList::SynthesizeTailCallFrames
void SynthesizeTailCallFrames(StackFrame &next_frame)
Given that next_frame will be appended to the frame list, synthesize tail call frames between the cur...
Definition: StackFrameList.cpp:366
lldb_private::StackFrameList::GetFrameAtIndex
lldb::StackFrameSP GetFrameAtIndex(uint32_t idx)
Get the frame at index idx. Invisible frames cannot be indexed.
Definition: StackFrameList.cpp:648
lldb_private::StackFrameList::GetFrameWithStackID
lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id)
Retrieve the stack frame with the given ID stack_id.
Definition: StackFrameList.cpp:737
lldb_private::StackFrameList::ResetCurrentInlinedDepth
void ResetCurrentInlinedDepth()
Definition: StackFrameList.cpp:81
lldb_private::StackFrameList::m_prev_frames_sp
lldb::StackFrameListSP m_prev_frames_sp
The old stack frame list.
Definition: StackFrameList.h:125
uint32_t
lldb_private::StackFrameList::collection
std::vector< lldb::StackFrameSP > collection
Definition: StackFrameList.h:113
lldb_private::StackFrameList::GetOnlyConcreteFramesUpTo
void GetOnlyConcreteFramesUpTo(uint32_t end_idx, Unwind &unwinder)
Definition: StackFrameList.cpp:224
lldb_private::StackFrameList::~StackFrameList
~StackFrameList()
Definition: StackFrameList.cpp:50
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb_private::StackFrameList::const_iterator
collection::const_iterator const_iterator
Definition: StackFrameList.h:115
lldb_private::StackFrameList::m_show_inlined_frames
const bool m_show_inlined_frames
Whether or not to show synthetic (inline) frames. Immutable.
Definition: StackFrameList.h:155
lldb_private::StackFrameList::GetFrameWithConcreteFrameIndex
lldb::StackFrameSP GetFrameWithConcreteFrameIndex(uint32_t unwind_idx)
Get the first concrete frame with index greater than or equal to idx.
Definition: StackFrameList.cpp:715
lldb_private::StackFrameList::iterator
collection::iterator iterator
Definition: StackFrameList.h:114
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ScriptedThread
Definition: ScriptedThread.h:27
lldb_private::StackFrameList::m_frames
collection m_frames
A cache of frames.
Definition: StackFrameList.h:135
lldb_private::StackFrameList::GetCurrentInlinedDepth
uint32_t GetCurrentInlinedDepth()
Definition: StackFrameList.cpp:63
lldb_private::StackID
Definition: StackID.h:17
lldb_private::StackFrameList::Dump
void Dump(Stream *s)
Definition: StackFrameList.cpp:628
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::StackFrameList::SetDefaultFileAndLineToSelectedFrame
void SetDefaultFileAndLineToSelectedFrame()
If the currently selected frame comes from the currently selected thread, point the default file and ...
Definition: StackFrameList.cpp:809
lldb_private::Unwind
Definition: Unwind.h:18
lldb_private::StackFrameList::CalculateCurrentInlinedDepth
void CalculateCurrentInlinedDepth()
Calculate and set the current inline depth.
Definition: StackFrameList.cpp:56
lldb_private::StackFrameList::SetSelectedFrameByIndex
bool SetSelectedFrameByIndex(uint32_t idx)
Mark a stack frame as the currently selected frame using the frame index idx.
Definition: StackFrameList.cpp:799
lldb_private::StackFrameList::m_concrete_frames_fetched
uint32_t m_concrete_frames_fetched
The number of concrete frames fetched while filling the frame list.
Definition: StackFrameList.h:142
lldb_private::StackFrameList::m_selected_frame_idx
uint32_t m_selected_frame_idx
The currently selected frame.
Definition: StackFrameList.h:138