Skip to content

Commit 2aef748

Browse files
committed
Don't count all the frames just to skip the current inlined ones. (llvm#80918)
The algorithm to find the DW_OP_entry_value requires you to find the nearest non-inlined frame. It did that by counting the number of stack frames so that it could use that as a loop stopper. That is unnecessary and inefficient. Unnecessary because GetFrameAtIndex will return a null frame when you step past the oldest frame, so you already have the "got to the end" signal without counting all the stack frames. And counting all the stack frames can be expensive. (cherry picked from commit a04c636)
1 parent 22782c4 commit 2aef748

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lldb/include/lldb/Target/Thread.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,13 @@ class Thread : public std::enable_shared_from_this<Thread>,
391391
/// and having the thread call the SystemRuntime again.
392392
virtual bool ThreadHasQueueInformation() const { return false; }
393393

394+
/// GetStackFrameCount can be expensive. Stacks can get very deep, and they
395+
/// require memory reads for each frame. So only use GetStackFrameCount when
396+
/// you need to know the depth of the stack. When iterating over frames, its
397+
/// better to generate the frames one by one with GetFrameAtIndex, and when
398+
/// that returns NULL, you are at the end of the stack. That way your loop
399+
/// will only do the work it needs to, without forcing lldb to realize
400+
/// StackFrames you weren't going to look at.
394401
virtual uint32_t GetStackFrameCount() {
395402
return GetStackFrameList()->GetNumFrames();
396403
}

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,10 @@ static bool Evaluate_DW_OP_entry_value(std::vector<Value> &stack,
613613
StackFrameSP parent_frame = nullptr;
614614
addr_t return_pc = LLDB_INVALID_ADDRESS;
615615
uint32_t current_frame_idx = current_frame->GetFrameIndex();
616-
uint32_t num_frames = thread->GetStackFrameCount();
617-
for (uint32_t parent_frame_idx = current_frame_idx + 1;
618-
parent_frame_idx < num_frames; ++parent_frame_idx) {
616+
617+
for (uint32_t parent_frame_idx = current_frame_idx + 1;;parent_frame_idx++) {
619618
parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
620-
// Require a valid sequence of frames.
619+
// If this is null, we're at the end of the stack.
621620
if (!parent_frame)
622621
break;
623622

0 commit comments

Comments
 (0)