nitesh.jain updated this revision to Diff 96722.
nitesh.jain added a comment.

Update diff as per suggestion


https://reviews.llvm.org/D32168

Files:
  include/lldb/API/SBAddress.h
  include/lldb/API/SBInstructionList.h
  
packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py
  scripts/interface/SBInstructionList.i
  source/API/SBAddress.cpp
  source/API/SBInstructionList.cpp

Index: source/API/SBInstructionList.cpp
===================================================================
--- source/API/SBInstructionList.cpp
+++ source/API/SBInstructionList.cpp
@@ -9,6 +9,7 @@
 
 #include "lldb/API/SBInstructionList.h"
 #include "lldb/API/SBInstruction.h"
+#include "lldb/API/SBAddress.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/Core/Disassembler.h"
 #include "lldb/Core/Module.h"
@@ -49,6 +50,34 @@
   return inst;
 }
 
+size_t SBInstructionList::GetInstructionsCount(const SBAddress &start,
+                                              const SBAddress &end, 
+                                              bool canSetBreakpoint) {
+  size_t num_instructions = GetSize();
+  size_t i = 0;
+  SBAddress addr;
+  size_t lower_index = 0;
+  size_t upper_index = 0;
+  size_t instructions_to_skip = 0;
+  for (i = 0; i < num_instructions; ++i) {
+    addr = GetInstructionAtIndex(i).GetAddress();
+    if (start == addr)
+      lower_index = i;
+    if (end == addr)
+      upper_index = i;
+  }
+  if (canSetBreakpoint)
+    for (i = lower_index; i <= upper_index; ++i) {
+      if (!CanSetBreakpoint(i))
+        ++instructions_to_skip;
+    }
+  return upper_index - lower_index - instructions_to_skip;
+}
+
+bool SBInstructionList::CanSetBreakpoint(size_t index) {
+  return !GetInstructionAtIndex(index).HasDelaySlot();
+}
+
 void SBInstructionList::Clear() { m_opaque_sp.reset(); }
 
 void SBInstructionList::AppendInstruction(SBInstruction insn) {}
Index: source/API/SBAddress.cpp
===================================================================
--- source/API/SBAddress.cpp
+++ source/API/SBAddress.cpp
@@ -55,6 +55,12 @@
   return *this;
 }
 
+bool lldb::operator==(const SBAddress &lhs, const SBAddress &rhs) {
+  if (lhs.IsValid() && rhs.IsValid())
+    return lhs.ref() == rhs.ref();
+  return false;
+}
+
 bool SBAddress::IsValid() const {
   return m_opaque_ap.get() != NULL && m_opaque_ap->IsValid();
 }
Index: scripts/interface/SBInstructionList.i
===================================================================
--- scripts/interface/SBInstructionList.i
+++ scripts/interface/SBInstructionList.i
@@ -44,6 +44,11 @@
     lldb::SBInstruction
     GetInstructionAtIndex (uint32_t idx);
 
+    size_t GetInstructionsCount(const SBAddress &start, const SBAddress &end,
+                                bool canSetBreakpoint);
+
+    bool CanSetBreakpoint(size_t index);
+
     void
     Clear ();
 
Index: packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py
+++ packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py
@@ -62,19 +62,11 @@
         instructions = function.GetInstructions(self.target)
         addr_1 = self.breakpoint1.GetLocationAtIndex(0).GetAddress()
         addr_4 = self.breakpoint4.GetLocationAtIndex(0).GetAddress()
-        delay_slot = 0
-        addr_1_load_address = addr_1.GetLoadAddress(self.target)
-        addr_4_load_address = addr_4.GetLoadAddress(self.target)
-        for i in range(instructions.GetSize()) :
-            addr = instructions.GetInstructionAtIndex(i).GetAddress()
-            addr_load_address = addr.GetLoadAddress(self.target)
-            if (addr == addr_1) : index_1 = i
-            if (addr == addr_4) : index_4 = i
-            if (addr_1_load_address <= addr_load_address <= addr_4_load_address):
-                if (instructions.GetInstructionAtIndex(i).HasDelaySlot()) :
-                    delay_slot = delay_slot + 1
-
-        steps_expected = index_4 - index_1 - delay_slot
+
+        # if third argument is true then the count correspond to the 
+        # number of instructions on which breakpoint can be set.
+        # start = addr_1, end = addr_4, canSetBreakpoint = True
+        steps_expected = instructions.GetInstructionsCount(addr_1, addr_4, True)
         step_count = 0
         # Step from breakpoint_1 to breakpoint_4
         while True:
Index: include/lldb/API/SBInstructionList.h
===================================================================
--- include/lldb/API/SBInstructionList.h
+++ include/lldb/API/SBInstructionList.h
@@ -32,6 +32,12 @@
 
   lldb::SBInstruction GetInstructionAtIndex(uint32_t idx);
 
+  size_t GetInstructionsCount(const SBAddress &start,
+                             const SBAddress &end,
+                             bool canSetBreakpoint = false);
+
+  bool CanSetBreakpoint(size_t index);                                    
+
   void Clear();
 
   void AppendInstruction(lldb::SBInstruction inst);
Index: include/lldb/API/SBAddress.h
===================================================================
--- include/lldb/API/SBAddress.h
+++ include/lldb/API/SBAddress.h
@@ -103,6 +103,8 @@
 
   const lldb_private::Address *operator->() const;
 
+  friend bool operator==(const SBAddress &lhs, const SBAddress &rhs);
+
   lldb_private::Address *get();
 
   lldb_private::Address &ref();
@@ -117,6 +119,8 @@
   std::unique_ptr<lldb_private::Address> m_opaque_ap;
 };
 
+bool operator==(const SBAddress &lhs, const SBAddress &rhs);
+
 } // namespace lldb
 
 #endif // LLDB_SBAddress_h_
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to