<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">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>