Skip to content

Commit

Permalink
Merge pull request #8301 from jimingham/dont-count-frames
Browse files Browse the repository at this point in the history
Don't count all the frames just to skip the current inlined ones. (#8
  • Loading branch information
jimingham authored Feb 29, 2024
2 parents e675dcf + 2aef748 commit 5083d68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lldb/include/lldb/Target/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ class Thread : public std::enable_shared_from_this<Thread>,
/// and having the thread call the SystemRuntime again.
virtual bool ThreadHasQueueInformation() const { return false; }

/// GetStackFrameCount can be expensive. Stacks can get very deep, and they
/// require memory reads for each frame. So only use GetStackFrameCount when
/// you need to know the depth of the stack. When iterating over frames, its
/// better to generate the frames one by one with GetFrameAtIndex, and when
/// that returns NULL, you are at the end of the stack. That way your loop
/// will only do the work it needs to, without forcing lldb to realize
/// StackFrames you weren't going to look at.
virtual uint32_t GetStackFrameCount() {
return GetStackFrameList()->GetNumFrames();
}
Expand Down
7 changes: 3 additions & 4 deletions lldb/source/Expression/DWARFExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,10 @@ static bool Evaluate_DW_OP_entry_value(std::vector<Value> &stack,
StackFrameSP parent_frame = nullptr;
addr_t return_pc = LLDB_INVALID_ADDRESS;
uint32_t current_frame_idx = current_frame->GetFrameIndex();
uint32_t num_frames = thread->GetStackFrameCount();
for (uint32_t parent_frame_idx = current_frame_idx + 1;
parent_frame_idx < num_frames; ++parent_frame_idx) {

for (uint32_t parent_frame_idx = current_frame_idx + 1;;parent_frame_idx++) {
parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
// Require a valid sequence of frames.
// If this is null, we're at the end of the stack.
if (!parent_frame)
break;

Expand Down

0 comments on commit 5083d68

Please sign in to comment.