Skip to content

Fix stepping away from the bottom-most frame of a virtual inlined call stack. #114337

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 3 commits into from
Oct 31, 2024

Conversation

jimingham
Copy link
Collaborator

The computation of 'Thread::IsVirtualStep" was wrong - it called being at the bottom of a virtual call stack a "virtual step" but that is actually when you've gotten to concrete code and need to step for real.

I also added a test for this.

@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2024

@llvm/pr-subscribers-lldb

Author: None (jimingham)

Changes

The computation of 'Thread::IsVirtualStep" was wrong - it called being at the bottom of a virtual call stack a "virtual step" but that is actually when you've gotten to concrete code and need to step for real.

I also added a test for this.


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

3 Files Affected:

  • (modified) lldb/source/Target/ThreadPlanStepInRange.cpp (+2-1)
  • (modified) lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py (+10-1)
  • (modified) lldb/test/API/functionalities/inline-stepping/calling.cpp (+1-1)
diff --git a/lldb/source/Target/ThreadPlanStepInRange.cpp b/lldb/source/Target/ThreadPlanStepInRange.cpp
index 325a70619908b6..224a17d896ccf0 100644
--- a/lldb/source/Target/ThreadPlanStepInRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepInRange.cpp
@@ -489,7 +489,8 @@ bool ThreadPlanStepInRange::DoWillResume(lldb::StateType resume_state,
 bool ThreadPlanStepInRange::IsVirtualStep() {
   if (m_virtual_step == eLazyBoolCalculate) {
     Thread &thread = GetThread();
-    if (thread.GetCurrentInlinedDepth() == UINT32_MAX)
+    uint32_t cur_inline_depth = thread.GetCurrentInlinedDepth();
+    if (cur_inline_depth == UINT32_MAX || cur_inline_depth == 0)
       m_virtual_step = eLazyBoolNo;
     else
       m_virtual_step = eLazyBoolYes;
diff --git a/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py b/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py
index f52e0f0fd5bcfe..fe61b8e48f6d6d 100644
--- a/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py
+++ b/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py
@@ -364,7 +364,7 @@ def step_in_template(self):
         step_sequence = [["// In max_value specialized", "into"]]
         self.run_step_sequence(step_sequence)
 
-    def run_to_call_site_and_step(self, source_regex, func_name, start_pos):
+    def run_to_call_site_and_step(self, source_regex, func_name, start_pos, one_more_step_loc = None):
         main_spec = lldb.SBFileSpec("calling.cpp")
         # Set the breakpoint by file and line, not sourced regex because
         # we want to make sure we can set breakpoints on call sites:
@@ -408,6 +408,11 @@ def run_to_call_site_and_step(self, source_regex, func_name, start_pos):
                 # stepping for this function...
                 break
 
+        if one_more_step_loc:
+            thread.StepInto()
+            frame_0 = thread.frame[0]
+            self.assertEqual(frame_0.line_entry.line, line_number(self.main_source, one_more_step_loc),
+                                                                  "Was able to step one more time")
         process.Kill()
         target.Clear()
 
@@ -420,3 +425,7 @@ def virtual_inline_stepping(self):
         self.run_to_call_site_and_step(
             "In caller_trivial_inline_2", "caller_trivial_inline_2", 3
         )
+        self.run_to_call_site_and_step(
+            "In caller_trivial_inline_3", "caller_trivial_inline_3", 4, "After caller_trivial_inline_3"
+        )
+        
diff --git a/lldb/test/API/functionalities/inline-stepping/calling.cpp b/lldb/test/API/functionalities/inline-stepping/calling.cpp
index d7ee56b3c07909..7ed88a872c4eba 100644
--- a/lldb/test/API/functionalities/inline-stepping/calling.cpp
+++ b/lldb/test/API/functionalities/inline-stepping/calling.cpp
@@ -95,7 +95,7 @@ void caller_trivial_inline_1() {
 
 void caller_trivial_inline_2() {
   caller_trivial_inline_3(); // In caller_trivial_inline_2.
-  inline_value += 1;
+  inline_value += 1; // After caller_trivial_inline_3
 }
 
 void caller_trivial_inline_3() {

Copy link

github-actions bot commented Oct 31, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Oct 31, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@jimingham
Copy link
Collaborator Author

This is a fairly uncontroversial patch, and fixes a breakage in the dexter tests (part of the "cross-project-tests"). So I'm going to push this now even though folks haven't had a chance to review it yet.

@jimingham jimingham merged commit 3243e3d into llvm:main Oct 31, 2024
5 of 6 checks passed
@jimingham jimingham deleted the is-virtual-step branch October 31, 2024 01:26
smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
…l stack. (llvm#114337)

The computation of 'Thread::IsVirtualStep" was wrong - it called being
at the bottom of a virtual call stack a "virtual step" but that is
actually when you've gotten to concrete code and need to step for real.

I also added a test for this.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…l stack. (llvm#114337)

The computation of 'Thread::IsVirtualStep" was wrong - it called being
at the bottom of a virtual call stack a "virtual step" but that is
actually when you've gotten to concrete code and need to step for real.

I also added a test for this.
jimingham added a commit to swiftlang/llvm-project that referenced this pull request Nov 7, 2024
…l stack. (llvm#114337)

The computation of 'Thread::IsVirtualStep" was wrong - it called being
at the bottom of a virtual call stack a "virtual step" but that is
actually when you've gotten to concrete code and need to step for real.

I also added a test for this.

(cherry picked from commit 3243e3d)
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.

2 participants