[Lldb-commits] [lldb] r360375 - Improve step over performance by not stopping at branches that are function calls and stepping into and them out of each one

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Thu May 9 13:39:34 PDT 2019


Author: gclayton
Date: Thu May  9 13:39:34 2019
New Revision: 360375

URL: http://llvm.org/viewvc/llvm-project?rev=360375&view=rev
Log:
Improve step over performance by not stopping at branches that are function calls and stepping into and them out of each one

Currently when we single step over a source line, we run and stop at every branch in the source line range. We can reduce the number of times we stop when stepping over by figuring out if any of these branches are function calls, and if so, ignore these branches. Since we are stepping over we can safely ignore these calls since they will return to the next instruction. Currently the step logic would stop at those branches (1st stop), single step into the branch (2nd stop), and then set a breakpoint at the return address (3rd stop), and then continue.

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


Modified:
    lldb/trunk/include/lldb/Core/Disassembler.h
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py
    lldb/trunk/source/Core/Disassembler.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/ThreadPlanStepRange.cpp

Modified: lldb/trunk/include/lldb/Core/Disassembler.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Disassembler.h?rev=360375&r1=360374&r2=360375&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Disassembler.h (original)
+++ lldb/trunk/include/lldb/Core/Disassembler.h Thu May  9 13:39:34 2019
@@ -290,8 +290,32 @@ public:
 
   lldb::InstructionSP GetInstructionAtIndex(size_t idx) const;
 
+  //------------------------------------------------------------------
+  /// Get the index of the next branch instruction.
+  ///
+  /// Given a list of instructions, find the next branch instruction
+  /// in the list by returning an index.
+  ///
+  /// @param[in] start
+  ///     The instruction index of the first instruction to check.
+  ///
+  /// @param[in] target
+  ///     A LLDB target object that is used to resolve addresses.
+  ///    
+  /// @param[in] ignore_calls
+  ///     It true, then fine the first branch instruction that isn't
+  ///     a function call (a branch that calls and returns to the next
+  ///     instruction). If false, find the instruction index of any 
+  ///     branch in the list.
+  ///    
+  /// @return
+  ///     The instruction index of the first branch that is at or past
+  ///     \a start. Returns UINT32_MAX if no matching branches are 
+  ///     found.
+  //------------------------------------------------------------------
   uint32_t GetIndexOfNextBranchInstruction(uint32_t start,
-                                           Target &target) const;
+                                           Target &target,
+                                           bool ignore_calls) const;
 
   uint32_t GetIndexOfInstructionAtLoadAddress(lldb::addr_t load_addr,
                                               Target &target);

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py?rev=360375&r1=360374&r2=360375&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/require_hw_breakpoints/TestRequireHWBreakpoints.py Thu May  9 13:39:34 2019
@@ -79,12 +79,11 @@ class BreakpointLocationsTestCase(TestBa
         self.runCmd("settings set target.require-hardware-breakpoint true")
 
         # Step over doesn't fail immediately but fails later on.
-        self.expect("thread step-over")
         self.expect(
-            "process status",
+            "thread step-over",
+            error=True,
             substrs=[
-                'step over failed',
-                'Could not create hardware breakpoint for thread plan'
+                'error: Could not create hardware breakpoint for thread plan.'
             ])
 
     @skipIfWindows

Modified: lldb/trunk/source/Core/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=360375&r1=360374&r2=360375&view=diff
==============================================================================
--- lldb/trunk/source/Core/Disassembler.cpp (original)
+++ lldb/trunk/source/Core/Disassembler.cpp Thu May  9 13:39:34 2019
@@ -1087,13 +1087,16 @@ void InstructionList::Append(lldb::Instr
 
 uint32_t
 InstructionList::GetIndexOfNextBranchInstruction(uint32_t start,
-                                                 Target &target) const {
+                                                 Target &target,
+                                                 bool ignore_calls) const {
   size_t num_instructions = m_instructions.size();
 
   uint32_t next_branch = UINT32_MAX;
   size_t i;
   for (i = start; i < num_instructions; i++) {
     if (m_instructions[i]->DoesBranch()) {
+      if (ignore_calls && m_instructions[i]->IsCall())
+        continue;
       next_branch = i;
       break;
     }

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=360375&r1=360374&r2=360375&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Thu May  9 13:39:34 2019
@@ -5832,7 +5832,8 @@ Process::AdvanceAddressToNextBranchInstr
   }
 
   uint32_t branch_index =
-      insn_list->GetIndexOfNextBranchInstruction(insn_offset, target);
+      insn_list->GetIndexOfNextBranchInstruction(insn_offset, target,
+                                                 false /* ignore_calls*/);
   if (branch_index == UINT32_MAX) {
     return retval;
   }

Modified: lldb/trunk/source/Target/ThreadPlanStepRange.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepRange.cpp?rev=360375&r1=360374&r2=360375&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanStepRange.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanStepRange.cpp Thu May  9 13:39:34 2019
@@ -315,9 +315,10 @@ bool ThreadPlanStepRange::SetNextBranchB
     return false;
   else {
     Target &target = GetThread().GetProcess()->GetTarget();
-    uint32_t branch_index;
-    branch_index =
-        instructions->GetIndexOfNextBranchInstruction(pc_index, target);
+    const bool ignore_calls = GetKind() == eKindStepOverRange;
+    uint32_t branch_index =
+        instructions->GetIndexOfNextBranchInstruction(pc_index, target,
+                                                      ignore_calls);
 
     Address run_to_address;
 




More information about the lldb-commits mailing list