Skip to content

Commit 5083d68

Browse files
authored
Merge pull request #8301 from jimingham/dont-count-frames
Don't count all the frames just to skip the current inlined ones. (#8
2 parents e675dcf + 2aef748 commit 5083d68

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)