[Lldb-commits] [lldb] 76bc772 - [lldb][gui] make 'step out' step out of the selected frame

Luboš Luňák via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 4 23:30:51 PDT 2022


Author: Luboš Luňák
Date: 2022-04-05T08:29:13+02:00
New Revision: 76bc7729208976e6ff6bc28b08e460d97cab5bb3

URL: https://github.com/llvm/llvm-project/commit/76bc7729208976e6ff6bc28b08e460d97cab5bb3
DIFF: https://github.com/llvm/llvm-project/commit/76bc7729208976e6ff6bc28b08e460d97cab5bb3.diff

LOG: [lldb][gui] make 'step out' step out of the selected frame

Differential Revision: https://reviews.llvm.org/D123001

Added: 
    

Modified: 
    lldb/include/lldb/Target/Thread.h
    lldb/source/Core/IOHandlerCursesGUI.cpp
    lldb/source/Target/Thread.cpp
    lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py
    lldb/test/API/commands/gui/basicdebug/func.c
    lldb/test/API/commands/gui/basicdebug/main.c

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h
index 2fd7d8859f525..f5f024434c8ee 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -539,9 +539,12 @@ class Thread : public std::enable_shared_from_this<Thread>,
   /// This function is designed to be used by commands where the
   /// process is publicly stopped.
   ///
+  /// \param[in] frame_idx
+  ///     The frame index to step out of.
+  ///
   /// \return
   ///     An error that describes anything that went wrong
-  virtual Status StepOut();
+  virtual Status StepOut(uint32_t frame_idx = 0);
 
   /// Retrieves the per-thread data area.
   /// Most OSs maintain a per-thread pointer (e.g. the FS register on
@@ -836,7 +839,7 @@ class Thread : public std::enable_shared_from_this<Thread>,
   ///    See standard meanings for the stop & run votes in ThreadPlan.h.
   ///
   /// \param[in] frame_idx
-  ///     The fame index.
+  ///     The frame index.
   ///
   /// \param[out] status
   ///     A status with an error if queuing failed.

diff  --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp
index 7fc23292983fa..caf88c7fdf376 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -6402,8 +6402,11 @@ class ApplicationDelegate : public WindowDelegate, public MenuDelegate {
       if (exe_ctx.HasThreadScope()) {
         Process *process = exe_ctx.GetProcessPtr();
         if (process && process->IsAlive() &&
-            StateIsStoppedState(process->GetState(), true))
-          exe_ctx.GetThreadRef().StepOut();
+            StateIsStoppedState(process->GetState(), true)) {
+          Thread *thread = exe_ctx.GetThreadPtr();
+          uint32_t frame_idx = thread->GetSelectedFrameIndex();
+          exe_ctx.GetThreadRef().StepOut(frame_idx);
+        }
       }
     }
       return MenuActionResult::Handled;
@@ -7361,7 +7364,9 @@ class SourceFileWindowDelegate : public WindowDelegate {
             m_debugger.GetCommandInterpreter().GetExecutionContext();
         if (exe_ctx.HasThreadScope() &&
             StateIsStoppedState(exe_ctx.GetProcessRef().GetState(), true)) {
-          exe_ctx.GetThreadRef().StepOut();
+          Thread *thread = exe_ctx.GetThreadPtr();
+          uint32_t frame_idx = thread->GetSelectedFrameIndex();
+          exe_ctx.GetThreadRef().StepOut(frame_idx);
         }
       }
       return eKeyHandled;

diff  --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index 332e03bedbf17..3803748be2971 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -1953,7 +1953,7 @@ Status Thread::StepOver(bool source_step,
   return error;
 }
 
-Status Thread::StepOut() {
+Status Thread::StepOut(uint32_t frame_idx) {
   Status error;
   Process *process = GetProcess().get();
   if (StateIsStoppedState(process->GetState(), true)) {
@@ -1963,7 +1963,7 @@ Status Thread::StepOut() {
 
     ThreadPlanSP new_plan_sp(QueueThreadPlanForStepOut(
         abort_other_plans, nullptr, first_instruction, stop_other_threads,
-        eVoteYes, eVoteNoOpinion, 0, error));
+        eVoteYes, eVoteNoOpinion, frame_idx, error));
 
     new_plan_sp->SetIsControllingPlan(true);
     new_plan_sp->SetOkayToDiscard(false);

diff  --git a/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py b/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py
index 98c8ff5db08b7..ee5a74c1f1798 100644
--- a/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py
+++ b/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py
@@ -32,7 +32,7 @@ def test_gui(self):
         self.child.send("s") # step
         self.child.expect("return 1; // In function[^\r\n]+<<< Thread 1: step in")
         self.child.send("u") # up
-        self.child.expect_exact("func(); // Break here")
+        self.child.expect_exact("func();    // Break here")
         self.child.send("d") # down
         self.child.expect_exact("return 1; // In function")
         self.child.send("f") # finish
@@ -40,7 +40,19 @@ def test_gui(self):
         self.child.send("s") # move onto the second one
         self.child.expect("<<< Thread 1: step in")
         self.child.send("n") # step over
-        self.child.expect("<<< Thread 1: step over")
+        self.child.expect("// Dummy command 1[^\r\n]+<<< Thread 1: step over")
+        self.child.send("n")
+
+        # Test that 'up' + 'step out' steps out of the selected function.
+        self.child.send("s") # move into func_up()
+        self.child.expect("// In func_up")
+        self.child.send("s") # move into func_down()
+        self.child.expect("// In func_down")
+        self.child.send("u") # up
+        self.child.expect("// In func_up")
+        self.child.send("f") # finish
+        self.child.expect("// Dummy command 2[^\r\n]+<<< Thread 1: step out")
+        self.child.send("n")
 
         # Press escape to quit the gui
         self.child.send(escape_key)

diff  --git a/lldb/test/API/commands/gui/basicdebug/func.c b/lldb/test/API/commands/gui/basicdebug/func.c
index f404a177af4f7..2fe5cb093dedb 100644
--- a/lldb/test/API/commands/gui/basicdebug/func.c
+++ b/lldb/test/API/commands/gui/basicdebug/func.c
@@ -1,3 +1,12 @@
 int func() {
   return 1; // In function
 }
+
+void func_down() {
+  int dummy = 1; // In func_down
+  (void)dummy;
+}
+
+void func_up() {
+  func_down(); // In func_up
+}

diff  --git a/lldb/test/API/commands/gui/basicdebug/main.c b/lldb/test/API/commands/gui/basicdebug/main.c
index f776fb99898de..51fbb5ea30651 100644
--- a/lldb/test/API/commands/gui/basicdebug/main.c
+++ b/lldb/test/API/commands/gui/basicdebug/main.c
@@ -1,7 +1,14 @@
 extern int func();
+extern void func_up();
 
 int main(int argc, char **argv) {
-  func(); // Break here
-  func(); // Second
+  int dummy;
+  func();    // Break here
+  func();    // Second
+  dummy = 1; // Dummy command 1
+
+  func_up(); // First func1 call
+  dummy = 2; // Dummy command 2
+
   return 0;
 }


        


More information about the lldb-commits mailing list