Author: nitesh.jain Date: Thu May 4 06:34:42 2017 New Revision: 302139 URL: http://llvm.org/viewvc/llvm-project?rev=302139&view=rev Log: [LLDB][MIPS] Fix TestStepOverBreakpoint.py failure.
Reviewers: jingham, labath Subscribers: jaydeep, bhushan, lldb-commits, slthakur Differential Revision: https://reviews.llvm.org/D32168 Modified: lldb/trunk/include/lldb/API/SBAddress.h lldb/trunk/include/lldb/API/SBInstruction.h lldb/trunk/include/lldb/API/SBInstructionList.h lldb/trunk/include/lldb/Core/Disassembler.h lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py lldb/trunk/scripts/interface/SBInstruction.i lldb/trunk/scripts/interface/SBInstructionList.i lldb/trunk/source/API/SBAddress.cpp lldb/trunk/source/API/SBInstruction.cpp lldb/trunk/source/API/SBInstructionList.cpp lldb/trunk/source/Core/Disassembler.cpp Modified: lldb/trunk/include/lldb/API/SBAddress.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBAddress.h?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBAddress.h (original) +++ lldb/trunk/include/lldb/API/SBAddress.h Thu May 4 06:34:42 2017 @@ -103,6 +103,8 @@ protected: 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 @@ private: std::unique_ptr<lldb_private::Address> m_opaque_ap; }; +bool operator==(const SBAddress &lhs, const SBAddress &rhs); + } // namespace lldb #endif // LLDB_SBAddress_h_ Modified: lldb/trunk/include/lldb/API/SBInstruction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstruction.h?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBInstruction.h (original) +++ lldb/trunk/include/lldb/API/SBInstruction.h Thu May 4 06:34:42 2017 @@ -53,6 +53,8 @@ public: bool HasDelaySlot(); + bool CanSetBreakpoint(); + void Print(FILE *out); bool GetDescription(lldb::SBStream &description); Modified: lldb/trunk/include/lldb/API/SBInstructionList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstructionList.h?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBInstructionList.h (original) +++ lldb/trunk/include/lldb/API/SBInstructionList.h Thu May 4 06:34:42 2017 @@ -32,6 +32,15 @@ public: lldb::SBInstruction GetInstructionAtIndex(uint32_t idx); + // ---------------------------------------------------------------------- + // Returns the number of instructions between the start and end address. + // If canSetBreakpoint is true then the count will be the number of + // instructions on which a breakpoint can be set. + // ---------------------------------------------------------------------- + size_t GetInstructionsCount(const SBAddress &start, + const SBAddress &end, + bool canSetBreakpoint = false); + void Clear(); void AppendInstruction(lldb::SBInstruction inst); Modified: lldb/trunk/include/lldb/Core/Disassembler.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Disassembler.h?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Disassembler.h (original) +++ lldb/trunk/include/lldb/Core/Disassembler.h Thu May 4 06:34:42 2017 @@ -173,6 +173,8 @@ public: virtual bool HasDelaySlot(); + bool CanSetBreakpoint (); + virtual size_t Decode(const Disassembler &disassembler, const DataExtractor &data, lldb::offset_t data_offset) = 0; Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py (original) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py Thu May 4 06:34:42 2017 @@ -62,12 +62,11 @@ class StepOverBreakpointsTestCase(TestBa instructions = function.GetInstructions(self.target) addr_1 = self.breakpoint1.GetLocationAtIndex(0).GetAddress() addr_4 = self.breakpoint4.GetLocationAtIndex(0).GetAddress() - for i in range(instructions.GetSize()) : - addr = instructions.GetInstructionAtIndex(i).GetAddress() - if (addr == addr_1) : index_1 = i - if (addr == addr_4) : index_4 = i - steps_expected = index_4 - index_1 + # if third argument is true then the count will be the number of + # instructions on which a 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: Modified: lldb/trunk/scripts/interface/SBInstruction.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBInstruction.i?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/scripts/interface/SBInstruction.i (original) +++ lldb/trunk/scripts/interface/SBInstruction.i Thu May 4 06:34:42 2017 @@ -54,6 +54,9 @@ public: bool HasDelaySlot (); + bool + CanSetBreakpoint (); + void Print (FILE *out); Modified: lldb/trunk/scripts/interface/SBInstructionList.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBInstructionList.i?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/scripts/interface/SBInstructionList.i (original) +++ lldb/trunk/scripts/interface/SBInstructionList.i Thu May 4 06:34:42 2017 @@ -44,6 +44,9 @@ public: lldb::SBInstruction GetInstructionAtIndex (uint32_t idx); + size_t GetInstructionsCount(const SBAddress &start, const SBAddress &end, + bool canSetBreakpoint); + void Clear (); Modified: lldb/trunk/source/API/SBAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/source/API/SBAddress.cpp (original) +++ lldb/trunk/source/API/SBAddress.cpp Thu May 4 06:34:42 2017 @@ -55,6 +55,12 @@ const SBAddress &SBAddress::operator=(co 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(); } Modified: lldb/trunk/source/API/SBInstruction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/source/API/SBInstruction.cpp (original) +++ lldb/trunk/source/API/SBInstruction.cpp Thu May 4 06:34:42 2017 @@ -176,6 +176,13 @@ bool SBInstruction::HasDelaySlot() { return false; } +bool SBInstruction::CanSetBreakpoint () { + lldb::InstructionSP inst_sp(GetOpaque()); + if (inst_sp) + return inst_sp->CanSetBreakpoint(); + return false; +} + lldb::InstructionSP SBInstruction::GetOpaque() { if (m_opaque_sp) return m_opaque_sp->GetSP(); Modified: lldb/trunk/source/API/SBInstructionList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstructionList.cpp?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/source/API/SBInstructionList.cpp (original) +++ lldb/trunk/source/API/SBInstructionList.cpp Thu May 4 06:34:42 2017 @@ -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,31 @@ SBInstruction SBInstructionList::GetInst 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) { + SBInstruction insn = GetInstructionAtIndex(i); + if (!insn.CanSetBreakpoint()) + ++instructions_to_skip; + } + return upper_index - lower_index - instructions_to_skip; +} + void SBInstructionList::Clear() { m_opaque_sp.reset(); } void SBInstructionList::AppendInstruction(SBInstruction insn) {} Modified: lldb/trunk/source/Core/Disassembler.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=302139&r1=302138&r2=302139&view=diff ============================================================================== --- lldb/trunk/source/Core/Disassembler.cpp (original) +++ lldb/trunk/source/Core/Disassembler.cpp Thu May 4 06:34:42 2017 @@ -759,6 +759,10 @@ bool Instruction::DumpEmulation(const Ar return false; } +bool Instruction::CanSetBreakpoint () { + return !HasDelaySlot(); +} + bool Instruction::HasDelaySlot() { // Default is false. return false; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits