Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[lldb] Create ThreadPlanStepOut ctor that never skips frames #136163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025

Conversation

felipepiovezan
Copy link
Contributor

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of "go this parent frame"; ThreadPlanStepOut needs to respect that, not skipping over any frames it finds uninteresting. This commit creates a constructor that respects such instruction.

@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2025

@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)

Changes

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of "go this parent frame"; ThreadPlanStepOut needs to respect that, not skipping over any frames it finds uninteresting. This commit creates a constructor that respects such instruction.


Full diff: https://github.com/llvm/llvm-project/pull/136163.diff

3 Files Affected:

  • (modified) lldb/include/lldb/Target/ThreadPlanStepOut.h (+9)
  • (modified) lldb/source/Target/Thread.cpp (+1-1)
  • (modified) lldb/source/Target/ThreadPlanStepOut.cpp (+22)
diff --git a/lldb/include/lldb/Target/ThreadPlanStepOut.h b/lldb/include/lldb/Target/ThreadPlanStepOut.h
index f37d09467dda3..bc106380bca5c 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepOut.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepOut.h
@@ -17,12 +17,21 @@ namespace lldb_private {
 
 class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
 public:
+  /// Creates a thread plan to step out from frame_idx, skipping parent frames
+  /// that artificial and hidden frames. Also skips frames without debug info
+  /// based on step_out_avoids_code_without_debug_info.
   ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
                     Vote report_run_vote, uint32_t frame_idx,
                     LazyBool step_out_avoids_code_without_debug_info,
                     bool continue_to_next_branch = false,
                     bool gather_return_value = true);
 
+  /// Creates a thread plan to step out from frame_idx to frame_idx + 1.
+  ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
+                    Vote report_run_vote, uint32_t frame_idx,
+                    bool continue_to_next_branch = false,
+                    bool gather_return_value = true);
+
   ~ThreadPlanStepOut() override;
 
   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index ddd4315b6cc9e..1d941a3614275 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -1360,7 +1360,7 @@ ThreadPlanSP Thread::QueueThreadPlanForStepOutNoShouldStop(
       false; // No need to calculate the return value here.
   ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
       *this, stop_other_threads, report_stop_vote, report_run_vote, frame_idx,
-      eLazyBoolNo, continue_to_next_branch, calculate_return_value));
+      continue_to_next_branch, calculate_return_value));
 
   ThreadPlanStepOut *new_plan =
       static_cast<ThreadPlanStepOut *>(thread_plan_sp.get());
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp b/lldb/source/Target/ThreadPlanStepOut.cpp
index 546405c267601..c7da0e2be89b4 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -83,6 +83,28 @@ ThreadPlanStepOut::ThreadPlanStepOut(
                      frame_idx, continue_to_next_branch);
 }
 
+ThreadPlanStepOut::ThreadPlanStepOut(Thread &thread, bool stop_others,
+                                     Vote report_stop_vote,
+                                     Vote report_run_vote, uint32_t frame_idx,
+                                     bool continue_to_next_branch,
+                                     bool gather_return_value)
+    : ThreadPlan(ThreadPlan::eKindStepOut, "Step out", thread, report_stop_vote,
+                 report_run_vote),
+      ThreadPlanShouldStopHere(this), m_return_bp_id(LLDB_INVALID_BREAK_ID),
+      m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
+      m_immediate_step_from_function(nullptr),
+      m_calculate_return_value(gather_return_value) {
+  SetFlagsToDefault();
+  m_step_from_insn = thread.GetRegisterContext()->GetPC(0);
+
+  StackFrameSP return_frame_sp = thread.GetStackFrameAtIndex(frame_idx + 1);
+  StackFrameSP immediate_return_from_sp =
+      thread.GetStackFrameAtIndex(frame_idx);
+
+  SetupReturnAddress(return_frame_sp, immediate_return_from_sp, frame_idx,
+                     continue_to_next_branch);
+}
+
 void ThreadPlanStepOut::SetupReturnAddress(
     StackFrameSP return_frame_sp, StackFrameSP immediate_return_from_sp,
     uint32_t frame_idx, bool continue_to_next_branch) {

@@ -17,12 +17,21 @@ namespace lldb_private {

class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
public:
/// Creates a thread plan to step out from frame_idx, skipping parent frames
/// that artificial and hidden frames. Also skips frames without debug info
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: that ARE*

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe "if they are artificial or hidden frames".

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right to me. There needs to be a version of step out that just does what it is told to do, and doesn't try to second-guess the agent that queued it.

@felipepiovezan felipepiovezan force-pushed the users/felipepiovezan/step_out_4 branch from bde0158 to fc70c64 Compare April 17, 2025 20:48
@felipepiovezan felipepiovezan changed the base branch from users/felipepiovezan/step_out_3 to main April 17, 2025 20:48
The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
@felipepiovezan felipepiovezan force-pushed the users/felipepiovezan/step_out_4 branch from fc70c64 to b1665da Compare April 17, 2025 20:49
@felipepiovezan
Copy link
Contributor Author

Addressed review comments, rebased on top of main

@felipepiovezan felipepiovezan merged commit 12becff into main Apr 17, 2025
10 checks passed
@felipepiovezan felipepiovezan deleted the users/felipepiovezan/step_out_4 branch April 17, 2025 21:13
felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Apr 17, 2025
…6163)

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Apr 17, 2025
…6163)

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…6163)

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…6163)

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants