<div dir="ltr">Also please add `from __future__ import print_function` to the top of every new test file you create.  Sorry this didn't get caught during review, no worries.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 27, 2016 at 10:42 AM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Just a heads up, `isinstance(foo, basestring)` doesn't work in Python 3.  You need to use `isinstance(foo, six.string_types)`.  I'm checking in a fix for this, but just wanted to let you know so you can keep this in the back of your head for future.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 27, 2016 at 2:20 AM Bhushan D. Attarde via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: bhushan.attarde<br>
Date: Wed Jan 27 04:16:30 2016<br>
New Revision: 258919<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=258919&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=258919&view=rev</a><br>
Log:<br>
[LLDB][MIPS] A small fix in GetBreakableLoadAddress() for MIPS<br>
<br>
    SUMMARY:<br>
    Get the load address for the address given by symbol and function.<br>
    Earlier, this was done for function only, this patch does it for symbol too.<br>
    This patch also adds TestAvoidBreakpointInDelaySlot.py to test this change.<br>
<br>
    Reviewers: clayborg<br>
    Subscribers: labath, zturner, mohit.bhakkad, sagar, jaydeep, lldb-commits<br>
    Differential Revision: <a href="http://reviews.llvm.org/D16049" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16049</a><br>
<br>
Added:<br>
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/<br>
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile<br>
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py<br>
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c<br>
Modified:<br>
    lldb/trunk/include/lldb/API/SBInstruction.h<br>
    lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py<br>
    lldb/trunk/scripts/interface/SBInstruction.i<br>
    lldb/trunk/source/API/SBInstruction.cpp<br>
    lldb/trunk/source/Target/Target.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/API/SBInstruction.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstruction.h?rev=258919&r1=258918&r2=258919&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstruction.h?rev=258919&r1=258918&r2=258919&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/API/SBInstruction.h (original)<br>
+++ lldb/trunk/include/lldb/API/SBInstruction.h Wed Jan 27 04:16:30 2016<br>
@@ -60,6 +60,9 @@ public:<br>
     bool<br>
     DoesBranch ();<br>
<br>
+    bool<br>
+    HasDelaySlot ();<br>
+<br>
     void<br>
     Print (FILE *out);<br>
<br>
<br>
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile?rev=258919&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile?rev=258919&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile (added)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/Makefile Wed Jan 27 04:16:30 2016<br>
@@ -0,0 +1,6 @@<br>
+LEVEL = ../../../make<br>
+<br>
+C_SOURCES := main.c<br>
+<br>
+include $(LEVEL)/Makefile.rules<br>
+<br>
<br>
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py?rev=258919&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py?rev=258919&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py (added)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py Wed Jan 27 04:16:30 2016<br>
@@ -0,0 +1,82 @@<br>
+"""<br>
+Test specific to MIPS<br>
+"""<br>
+<br>
+import os, time<br>
+import re<br>
+import unittest2<br>
+import lldb<br>
+import lldbsuite.test.lldbutil as lldbutil<br>
+from lldbsuite.test.lldbtest import *<br>
+<br>
+class AvoidBreakpointInDelaySlotAPITestCase(TestBase):<br>
+<br>
+    mydir = TestBase.compute_mydir(__file__)<br>
+<br>
+    @skipUnlessArch(archs=re.compile('mips*'))<br>
+    def test(self):<br>
+        self.build()<br>
+        exe = os.path.join(os.getcwd(), "a.out")<br>
+        self.expect("file " + exe,<br>
+                    patterns = [ "Current executable set to .*a.out.*" ])<br>
+<br>
+        # Create a target by the debugger.<br>
+        target = self.dbg.CreateTarget(exe)<br>
+        self.assertTrue(target, VALID_TARGET)<br>
+<br>
+        breakpoint = target.BreakpointCreateByName('main', 'a.out')<br>
+        self.assertTrue(breakpoint and<br>
+                        breakpoint.GetNumLocations() == 1,<br>
+                        VALID_BREAKPOINT)<br>
+<br>
+        # Now launch the process, and do not stop at entry point.<br>
+        process = target.LaunchSimple (None, None, self.get_process_working_directory())<br>
+        self.assertTrue(process, PROCESS_IS_VALID)<br>
+<br>
+        list = target.FindFunctions('foo', lldb.eFunctionNameTypeAuto)<br>
+        self.assertTrue(list.GetSize() == 1)<br>
+        sc = list.GetContextAtIndex(0)<br>
+        self.assertTrue(sc.GetSymbol().GetName() == "foo")<br>
+        function = sc.GetFunction()<br>
+        self.assertTrue(function)<br>
+        self.function(function, target)<br>
+<br>
+    def function (self, function, target):<br>
+        """Iterate over instructions in function and place a breakpoint on delay slot instruction"""<br>
+        # Get the list of all instructions in the function<br>
+        insts = function.GetInstructions(target)<br>
+        print insts<br>
+        i = 0<br>
+        for inst in insts:<br>
+            if (inst.HasDelaySlot()):<br>
+                # Remember the address of branch instruction.<br>
+                branchinstaddress = inst.GetAddress().GetLoadAddress(target)<br>
+<br>
+                # Get next instruction i.e delay slot instruction.<br>
+                delayinst = insts.GetInstructionAtIndex(i+1)<br>
+                delayinstaddr = delayinst.GetAddress().GetLoadAddress(target)<br>
+<br>
+                # Set breakpoint on delay slot instruction<br>
+                breakpoint = target.BreakpointCreateByAddress(delayinstaddr)<br>
+<br>
+                # Verify the breakpoint.<br>
+                self.assertTrue(breakpoint and<br>
+                                breakpoint.GetNumLocations() == 1,<br>
+                                VALID_BREAKPOINT)<br>
+                # Get the location from breakpoint<br>
+                location = breakpoint.GetLocationAtIndex(0)<br>
+<br>
+                # Get the address where breakpoint is actually set.<br>
+                bpaddr = location.GetLoadAddress()<br>
+<br>
+                # Breakpoint address should be adjusted to the address of branch instruction.<br>
+                self.assertTrue(branchinstaddress ==  bpaddr)<br>
+                i += 1<br>
+            else:<br>
+                i += 1<br>
+<br>
+if __name__ == '__main__':<br>
+    import atexit<br>
+    lldb.SBDebugger.Initialize()<br>
+    atexit.register(lambda: lldb.SBDebugger.Terminate())<br>
+    unittest2.main()<br>
<br>
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c?rev=258919&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c?rev=258919&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c (added)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/main.c Wed Jan 27 04:16:30 2016<br>
@@ -0,0 +1,21 @@<br>
+#include <stdio.h><br>
+<br>
+foo (int a, int b)<br>
+{<br>
+    int c;<br>
+    if (a<=b)<br>
+        c=b-a;<br>
+    else<br>
+        c=b+a;<br>
+    return c;<br>
+}<br>
+<br>
+int main()<br>
+{<br>
+    int a=7, b=8, c;<br>
+<br>
+    c = foo(a, b);<br>
+<br>
+return 0;<br>
+}<br>
+<br>
<br>
Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py?rev=258919&r1=258918&r2=258919&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py?rev=258919&r1=258918&r2=258919&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py (original)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py Wed Jan 27 04:16:30 2016<br>
@@ -636,6 +636,14 @@ def check_list_or_lambda(list_or_lambda,<br>
     else:<br>
         return list_or_lambda is None or value is None or list_or_lambda == value<br>
<br>
+def matchArchitectures(archs, actual_arch):<br>
+    retype = type(re.compile('hello, world'))<br>
+    list_passes = isinstance(archs, list) and actual_arch in archs<br>
+    basestring_passes = isinstance(archs, basestring) and actual_arch == archs<br>
+    regex_passes = isinstance(archs, retype) and re.match(archs, actual_arch)<br>
+<br>
+    return (list_passes or basestring_passes or regex_passes)<br>
+<br>
 # provide a function to xfail on defined oslist, compiler version, and archs<br>
 # if none is specified for any argument, that argument won't be checked and thus means for all<br>
 # for example,<br>
@@ -1029,7 +1037,7 @@ def skipUnlessHostPlatform(oslist):<br>
     return unittest2.skipUnless(getHostPlatform() in oslist,<br>
                                 "requires on of %s" % (", ".join(oslist)))<br>
<br>
-def skipUnlessArch(archlist):<br>
+def skipUnlessArch(archs):<br>
     """Decorate the item to skip tests unless running on one of the listed architectures."""<br>
     def myImpl(func):<br>
         if isinstance(func, type) and issubclass(func, unittest2.TestCase):<br>
@@ -1038,9 +1046,8 @@ def skipUnlessArch(archlist):<br>
         @wraps(func)<br>
         def wrapper(*args, **kwargs):<br>
             self = args[0]<br>
-            if self.getArchitecture() not in archlist:<br>
-                self.skipTest("skipping for architecture %s (requires one of %s)" %<br>
-                    (self.getArchitecture(), ", ".join(archlist)))<br>
+            if not matchArchitectures(archs, self.getArchitecture()):<br>
+                self.skipTest("skipping for architecture %s" % (self.getArchitecture()))<br>
             else:<br>
                 func(*args, **kwargs)<br>
         return wrapper<br>
<br>
Modified: lldb/trunk/scripts/interface/SBInstruction.i<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBInstruction.i?rev=258919&r1=258918&r2=258919&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBInstruction.i?rev=258919&r1=258918&r2=258919&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/scripts/interface/SBInstruction.i (original)<br>
+++ lldb/trunk/scripts/interface/SBInstruction.i Wed Jan 27 04:16:30 2016<br>
@@ -51,6 +51,9 @@ public:<br>
     bool<br>
     DoesBranch ();<br>
<br>
+    bool<br>
+    HasDelaySlot ();<br>
+<br>
     void<br>
     Print (FILE *out);<br>
<br>
<br>
Modified: lldb/trunk/source/API/SBInstruction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=258919&r1=258918&r2=258919&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=258919&r1=258918&r2=258919&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/API/SBInstruction.cpp (original)<br>
+++ lldb/trunk/source/API/SBInstruction.cpp Wed Jan 27 04:16:30 2016<br>
@@ -160,6 +160,14 @@ SBInstruction::DoesBranch ()<br>
     return false;<br>
 }<br>
<br>
+bool<br>
+SBInstruction::HasDelaySlot ()<br>
+{<br>
+    if (m_opaque_sp)<br>
+        return m_opaque_sp->HasDelaySlot ();<br>
+    return false;<br>
+}<br>
+<br>
 void<br>
 SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp)<br>
 {<br>
<br>
Modified: lldb/trunk/source/Target/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=258919&r1=258918&r2=258919&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=258919&r1=258918&r2=258919&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Target/Target.cpp (original)<br>
+++ lldb/trunk/source/Target/Target.cpp Wed Jan 27 04:16:30 2016<br>
@@ -2442,18 +2442,18 @@ Target::GetBreakableLoadAddress (lldb::a<br>
             SymbolContext sc;<br>
             uint32_t resolve_scope = eSymbolContextFunction | eSymbolContextSymbol;<br>
             temp_addr_module_sp->ResolveSymbolContextForAddress(resolved_addr, resolve_scope, sc);<br>
+            Address sym_addr;<br>
             if (sc.function)<br>
-            {<br>
-                function_start = sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress(this);<br>
-                if (function_start == LLDB_INVALID_ADDRESS)<br>
-                    function_start = sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();<br>
-            }<br>
+                sym_addr = sc.function->GetAddressRange().GetBaseAddress();<br>
             else if (sc.symbol)<br>
-            {<br>
-                Address sym_addr = sc.symbol->GetAddress();<br>
+                sym_addr = sc.symbol->GetAddress();<br>
+<br>
+            function_start = sym_addr.GetLoadAddress(this);<br>
+            if (function_start == LLDB_INVALID_ADDRESS)<br>
                 function_start = sym_addr.GetFileAddress();<br>
-            }<br>
-            current_offset = addr - function_start;<br>
+<br>
+            if (function_start)<br>
+                current_offset = addr - function_start;<br>
         }<br>
<br>
         // If breakpoint address is start of function then we dont have to do anything.<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div></blockquote></div>