Skip to content

Commit a04c636

Browse files
authored
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.
1 parent fc0e9c8 commit a04c636

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
@@ -390,6 +390,13 @@ class Thread : public std::enable_shared_from_this<Thread>,
390390
/// and having the thread call the SystemRuntime again.
391391
virtual bool ThreadHasQueueInformation() const { return false; }
392392

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

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,10 @@ static bool Evaluate_DW_OP_entry_value(std::vector<Value> &stack,
608608
StackFrameSP parent_frame = nullptr;
609609
addr_t return_pc = LLDB_INVALID_ADDRESS;
610610
uint32_t current_frame_idx = current_frame->GetFrameIndex();
611-
uint32_t num_frames = thread->GetStackFrameCount();
612-
for (uint32_t parent_frame_idx = current_frame_idx + 1;
613-
parent_frame_idx < num_frames; ++parent_frame_idx) {
611+
612+
for (uint32_t parent_frame_idx = current_frame_idx + 1;;parent_frame_idx++) {
614613
parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
615-
// Require a valid sequence of frames.
614+
// If this is null, we're at the end of the stack.
616615
if (!parent_frame)
617616
break;
618617

0 commit comments

Comments
 (0)