Skip to content

Commit 2d2c3ba

Browse files
authored
Merge pull request #11712 from jimingham/fixup-stack-writer-mutex-cherrypick
Fix what seems to be a mismerge of a couple patches relating to StackFrameLists…
2 parents f5781a0 + f5ffacb commit 2d2c3ba

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

lldb/source/Target/InstrumentationRuntimeStopInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ InstrumentationRuntimeStopInfo::GetSuggestedStackFrameIndex(
4848
ThreadSP thread_sp = GetThread();
4949
if (!thread_sp)
5050
return std::nullopt;
51+
52+
StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
53+
if (!frame_sp)
54+
return {};
55+
if (!frame_sp->IsInlined() && inlined_stack)
56+
return {};
5157

5258
// Defensive upper-bound of when we stop walking up the frames in
5359
// case we somehow ended up looking at an infinite recursion.

lldb/source/Target/StackFrameList.cpp

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,6 @@ void StackFrameList::ResetCurrentInlinedDepth() {
8585
if (!m_show_inlined_frames)
8686
return;
8787

88-
GetFramesUpTo(0, DoNotAllowInterruption);
89-
if (m_frames.empty())
90-
return;
91-
if (!m_frames[0]->IsInlined()) {
92-
m_current_inlined_depth = UINT32_MAX;
93-
m_current_inlined_pc = LLDB_INVALID_ADDRESS;
94-
Log *log = GetLog(LLDBLog::Step);
95-
if (log && log->GetVerbose())
96-
LLDB_LOGF(
97-
log,
98-
"ResetCurrentInlinedDepth: Invalidating current inlined depth.\n");
99-
return;
100-
}
101-
102-
m_current_inlined_pc = LLDB_INVALID_ADDRESS;
103-
m_current_inlined_depth = UINT32_MAX;
104-
10588
StopInfoSP stop_info_sp = m_thread.GetStopInfo();
10689
if (!stop_info_sp)
10790
return;
@@ -111,6 +94,7 @@ void StackFrameList::ResetCurrentInlinedDepth() {
11194
// We're only adjusting the inlined stack here.
11295
Log *log = GetLog(LLDBLog::Step);
11396
if (inline_depth) {
97+
std::lock_guard<std::mutex> guard(m_inlined_depth_mutex);
11498
m_current_inlined_depth = *inline_depth;
11599
m_current_inlined_pc = m_thread.GetRegisterContext()->GetPC();
116100

@@ -120,6 +104,9 @@ void StackFrameList::ResetCurrentInlinedDepth() {
120104
"depth: %d 0x%" PRIx64 ".\n",
121105
m_current_inlined_depth, m_current_inlined_pc);
122106
} else {
107+
std::lock_guard<std::mutex> guard(m_inlined_depth_mutex);
108+
m_current_inlined_pc = LLDB_INVALID_ADDRESS;
109+
m_current_inlined_depth = UINT32_MAX;
123110
if (log && log->GetVerbose())
124111
LLDB_LOGF(
125112
log,
@@ -689,6 +676,13 @@ StackFrameList::GetFrameWithConcreteFrameIndex(uint32_t unwind_idx) {
689676
return frame_sp;
690677
}
691678

679+
static bool CompareStackID(const StackFrameSP &stack_sp,
680+
const StackID &stack_id) {
681+
ProcessSP process_sp = stack_sp->CalculateProcess();
682+
assert(process_sp && "StackFrames must have a process");
683+
return StackID::IsYounger(stack_sp->GetStackID(), stack_id, *(process_sp.get()));
684+
}
685+
692686
StackFrameSP StackFrameList::GetFrameWithStackID(const StackID &stack_id) {
693687
StackFrameSP frame_sp;
694688

@@ -698,17 +692,11 @@ StackFrameSP StackFrameList::GetFrameWithStackID(const StackID &stack_id) {
698692
// First see if the frame is already realized. This is the scope for
699693
// the shared mutex:
700694
std::shared_lock<std::shared_mutex> guard(m_list_mutex);
701-
// Do a search in case the stack frame is already in our cache.
702-
collection::const_iterator begin = m_frames.begin();
703-
collection::const_iterator end = m_frames.end();
704-
if (begin != end) {
705-
collection::const_iterator pos =
706-
std::find_if(begin, end, [&](StackFrameSP frame_sp) {
707-
return frame_sp->GetStackID() == stack_id;
708-
});
709-
if (pos != end)
710-
return *pos;
711-
}
695+
// Do a binary search in case the stack frame is already in our cache
696+
collection::const_iterator pos =
697+
llvm::lower_bound(m_frames, stack_id, CompareStackID);
698+
if (pos != m_frames.end() && (*pos)->GetStackID() == stack_id)
699+
return *pos;
712700
}
713701
// If we needed to add more frames, we would get to here.
714702
do {
@@ -762,7 +750,7 @@ void StackFrameList::SelectMostRelevantFrame() {
762750
}
763751
LLDB_LOG(log, "Frame #0 not recognized");
764752

765-
// If this thread has a non-trivial StopInof, then let it suggest
753+
// If this thread has a non-trivial StopInfo, then let it suggest
766754
// a most relevant frame:
767755
StopInfoSP stop_info_sp = m_thread.GetStopInfo();
768756
uint32_t stack_idx = 0;

lldb/source/Target/StopInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ class StopInfoBreakpoint : public StopInfo {
296296
ThreadSP thread_sp(m_thread_wp.lock());
297297
if (!thread_sp)
298298
return {};
299+
300+
StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
301+
if (!frame_sp)
302+
return {};
303+
if (!frame_sp->IsInlined() && inlined_stack)
304+
return {};
305+
299306
BreakpointSiteSP bp_site_sp = GetBreakpointSiteSP();
300307
if (!bp_site_sp)
301308
return {};

0 commit comments

Comments
 (0)