Skip to content

Commit 3236978

Browse files
committed
Move some functions to private where appropriate, and add a few
comments explaining how this is to be used.
1 parent daa9968 commit 3236978

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

lldb/include/lldb/Target/StackFrameList.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,21 @@ class StackFrameList {
9999
friend class Thread;
100100
friend class ScriptedThread;
101101

102+
/// Use this API to build a stack frame list (used for scripted threads, for
103+
/// instance.) This API is not meant for StackFrameLists that have unwinders
104+
/// and partake in lazy stack filling (using GetFramesUpTo). Rather if you
105+
/// are building StackFrameLists with this API, you should build the entire
106+
/// list before making it available for use.
102107
bool SetFrameAtIndex(uint32_t idx, lldb::StackFrameSP &frame_sp);
103108

104-
/// Realizes frames up to (and including) end_idx (which can be greater than
105-
/// the actual number of frames.)
109+
/// Ensures that frames up to (and including) `end_idx` are realized in the
110+
/// StackFrameList. `end_idx` can be larger than the actual number of frames,
111+
/// in which case all the frames will be fetched.
106112
/// Returns true if the function was interrupted, false otherwise.
107-
/// Must be called with a shared_locked mutex locked.
113+
/// Must be called with a shared mutex locked in `guard`.
108114
bool GetFramesUpTo(uint32_t end_idx, InterruptionControl allow_interrupt,
109115
std::shared_lock<std::shared_mutex> &guard);
110116

111-
/// These two Fetch frames APIs must be called with the stack mutex shared
112-
/// lock acquired. They are the only places where we acquire the writer
113-
/// end of the stack list mutex to add frames, but they will always exit with
114-
/// the shared side reacquired.
115-
/// Returns true if fetching frames was interrupted, false otherwise
116-
bool FetchFramesUpTo(uint32_t end_idx, InterruptionControl allow_interrupt,
117-
std::shared_lock<std::shared_mutex> &guard);
118-
119-
void FetchOnlyConcreteFramesUpTo(uint32_t end_idx,
120-
std::shared_lock<std::shared_mutex> &guard);
121-
122-
// This gets called without the StackFrameList lock held, callers should
123-
// hold the lock.
124-
void SynthesizeTailCallFrames(StackFrame &next_frame);
125-
126117
bool GetAllFramesFetched() { return m_concrete_frames_fetched == UINT32_MAX; }
127118

128119
void SetAllFramesFetched() { m_concrete_frames_fetched = UINT32_MAX; }
@@ -197,6 +188,23 @@ class StackFrameList {
197188
GetFrameAtIndexNoLock(uint32_t idx,
198189
std::shared_lock<std::shared_mutex> &guard);
199190

191+
/// These two Fetch frames APIs are called in GetFramesUpTo, they are the ones
192+
/// that actually add frames. They must be called with the stack list shared
193+
/// lock acquired. They will acquire the writer end of the stack list mutex
194+
/// to add frames, but they will always exit with the shared side reacquired.
195+
/// Returns true if fetching frames was interrupted, false otherwise.
196+
bool FetchFramesUpTo(uint32_t end_idx, InterruptionControl allow_interrupt,
197+
std::shared_lock<std::shared_mutex> &guard);
198+
199+
/// This is the same as FetchFramesUpTo, but only fetches concrete frames.
200+
/// It is not currently interruptible - so it returns nothing.
201+
void FetchOnlyConcreteFramesUpTo(uint32_t end_idx,
202+
std::shared_lock<std::shared_mutex> &guard);
203+
204+
// This is a utility function, called by FetchFramesUpTo. It must be called
205+
// with the writer end of the stack list mutex held.
206+
void SynthesizeTailCallFrames(StackFrame &next_frame);
207+
200208
StackFrameList(const StackFrameList &) = delete;
201209
const StackFrameList &operator=(const StackFrameList &) = delete;
202210
};

lldb/source/Target/StackFrameList.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,6 @@ bool StackFrameList::FetchFramesUpTo(uint32_t end_idx,
415415
guard.lock();
416416
});
417417

418-
if (m_frames.size() > end_idx || GetAllFramesFetched()) {
419-
return false;
420-
}
421-
422418
#if defined(DEBUG_STACK_FRAMES)
423419
StreamFile s(stdout, false);
424420
#endif
@@ -721,6 +717,7 @@ StackFrameSP StackFrameList::GetFrameWithStackID(const StackID &stack_id) {
721717
}
722718

723719
bool StackFrameList::SetFrameAtIndex(uint32_t idx, StackFrameSP &frame_sp) {
720+
std::unique_lock<std::shared_mutex> guard(m_list_mutex);
724721
if (idx >= m_frames.size())
725722
m_frames.resize(idx + 1);
726723
// Make sure allocation succeeded by checking bounds again

0 commit comments

Comments
 (0)