summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/scripts/Python/modify-python-lldb.py38
-rw-r--r--lldb/test/python_api/lldbutil/frame/TestFrameUtils.py8
-rw-r--r--lldb/test/python_api/lldbutil/iter/TestLLDBIterator.py18
-rw-r--r--lldb/test/python_api/lldbutil/iter/TestRegistersIterator.py14
-rw-r--r--lldb/test/python_api/lldbutil/process/TestPrintStackTraces.py6
5 files changed, 56 insertions, 28 deletions
diff --git a/lldb/scripts/Python/modify-python-lldb.py b/lldb/scripts/Python/modify-python-lldb.py
index da395c5c623..5b7578920e2 100644
--- a/lldb/scripts/Python/modify-python-lldb.py
+++ b/lldb/scripts/Python/modify-python-lldb.py
@@ -34,22 +34,24 @@ def lldb_iter(obj, getsize, getelem):
'''
-#
# This supports the iteration protocol.
-#
iter_def = " def __iter__(self): return lldb_iter(self, '%s', '%s')"
module_iter = " def module_iter(self): return lldb_iter(self, '%s', '%s')"
breakpoint_iter = " def breakpoint_iter(self): return lldb_iter(self, '%s', '%s')"
-#
+
# Called to implement the built-in function len().
# Eligible objects are those containers with unambiguous iteration support.
-#
len_def = " def __len__(self): return self.%s()"
-#
+
# This supports the rich comparison methods of __eq__ and __ne__.
eq_def = " def __eq__(self, other): return isinstance(other, %s) and %s"
ne_def = " def __ne__(self, other): return not self.__eq__(other)"
+# Called to implement truth value testing and the built-in operation bool();
+# should return False or True, or their integer equivalents 0 or 1.
+# Delegate to self.IsValid() if it is defined for the current lldb object.
+nonzero_def = " def __nonzero__(self): return self.IsValid()"
+
#
# The dictionary defines a mapping from classname to (getsize, getelem) tuple.
#
@@ -109,6 +111,9 @@ class_pattern = re.compile("^class (SB.*)\(_object\):$")
# The pattern for recognizing the beginning of the __init__ method definition.
init_pattern = re.compile("^ def __init__\(self, \*args\):")
+# The pattern for recognizing the beginning of the IsValid method definition.
+isvalid_pattern = re.compile("^ def IsValid\(\*args\):")
+
# These define the states of our finite state machine.
NORMAL = 0
DEFINING_ITERATOR = 1
@@ -117,13 +122,32 @@ DEFINING_EQUALITY = 2
# The lldb_iter_def only needs to be inserted once.
lldb_iter_defined = False;
+# Our FSM begins its life in the NORMAL state, and transitions to the
+# DEFINING_ITERATOR and/or DEFINING_EQUALITY state whenever it encounters the
+# beginning of certain class definitions, see dictionaries 'd' and 'e' above.
+#
+# Note that the two states DEFINING_ITERATOR and DEFINING_EQUALITY are
+# orthogonal in that our FSM can be in one, the other, or both states at the
+# same time. During such time, the FSM is eagerly searching for the __init__
+# method definition in order to insert the appropriate method(s) into the lldb
+# module.
+#
+# Assuming that SWIG puts out the __init__ method definition before other method
+# definitions, the FSM, while in NORMAL state, also checks the current input for
+# IsValid() definition, and inserts a __nonzero__() method definition to
+# implement truth value testing and the built-in operation bool().
state = NORMAL
for line in content.splitlines():
if state == NORMAL:
match = class_pattern.search(line)
+ # Inserts the lldb_iter() definition before the first class definition.
if not lldb_iter_defined and match:
print >> new_content, lldb_iter_def
lldb_iter_defined = True
+
+ # If we are at the beginning of the class definitions, prepare to
+ # transition to the DEFINING_ITERATOR/DEFINING_EQUALITY state for the
+ # right class names.
if match:
cls = match.group(1)
if cls in d:
@@ -132,6 +156,10 @@ for line in content.splitlines():
if cls in e:
# Adding support for eq and ne for the matched SB class.
state = (state | DEFINING_EQUALITY)
+ # Look for 'def IsValid(*args):', and once located, add implementation
+ # of truth value testing for objects by delegation.
+ elif isvalid_pattern.search(line):
+ print >> new_content, nonzero_def
elif state > NORMAL:
match = init_pattern.search(line)
if match:
diff --git a/lldb/test/python_api/lldbutil/frame/TestFrameUtils.py b/lldb/test/python_api/lldbutil/frame/TestFrameUtils.py
index cd4ba09fac1..d5811044e42 100644
--- a/lldb/test/python_api/lldbutil/frame/TestFrameUtils.py
+++ b/lldb/test/python_api/lldbutil/frame/TestFrameUtils.py
@@ -27,15 +27,15 @@ class FrameUtilsTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
- self.assertTrue(target.IsValid(), VALID_TARGET)
+ self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
- self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
# Now launch the process, and do not stop at entry point.
self.process = target.LaunchSimple(None, None, os.getcwd())
- if not self.process.IsValid():
+ if not self.process:
self.fail("SBTarget.LaunchProcess() failed")
self.assertTrue(self.process.GetState() == lldb.eStateStopped,
PROCESS_STOPPED)
@@ -45,7 +45,7 @@ class FrameUtilsTestCase(TestBase):
frame0 = thread.GetFrameAtIndex(0)
frame1 = thread.GetFrameAtIndex(1)
parent = lldbutil.get_parent_frame(frame0)
- self.assertTrue(parent.IsValid() and parent.GetFrameID() == frame1.GetFrameID())
+ self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID())
frame0_args = lldbutil.get_args_as_string(frame0)
parent_args = lldbutil.get_args_as_string(parent)
self.assertTrue(frame0_args and parent_args)
diff --git a/lldb/test/python_api/lldbutil/iter/TestLLDBIterator.py b/lldb/test/python_api/lldbutil/iter/TestLLDBIterator.py
index e71dcf9540b..cc941578666 100644
--- a/lldb/test/python_api/lldbutil/iter/TestLLDBIterator.py
+++ b/lldb/test/python_api/lldbutil/iter/TestLLDBIterator.py
@@ -38,16 +38,16 @@ class LLDBIteratorTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
- self.assertTrue(target.IsValid(), VALID_TARGET)
+ self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)
- self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
# Now launch the process, and do not stop at entry point.
rc = lldb.SBError()
self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc)
- if not rc.Success() or not self.process.IsValid():
+ if not rc.Success() or not self.process:
self.fail("SBTarget.LaunchProcess() failed")
from lldbutil import get_description
@@ -70,12 +70,12 @@ class LLDBIteratorTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
- self.assertTrue(target.IsValid(), VALID_TARGET)
+ self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)
- self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line2)
- self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
self.assertTrue(target.GetNumBreakpoints() == 2)
@@ -99,16 +99,16 @@ class LLDBIteratorTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
- self.assertTrue(target.IsValid(), VALID_TARGET)
+ self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)
- self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
# Now launch the process, and do not stop at entry point.
rc = lldb.SBError()
self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc)
- if not rc.Success() or not self.process.IsValid():
+ if not rc.Success() or not self.process:
self.fail("SBTarget.LaunchProcess() failed")
from lldbutil import print_stacktrace
diff --git a/lldb/test/python_api/lldbutil/iter/TestRegistersIterator.py b/lldb/test/python_api/lldbutil/iter/TestRegistersIterator.py
index 2fffd27770d..8e66d37d5f8 100644
--- a/lldb/test/python_api/lldbutil/iter/TestRegistersIterator.py
+++ b/lldb/test/python_api/lldbutil/iter/TestRegistersIterator.py
@@ -27,16 +27,16 @@ class RegistersIteratorTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
- self.assertTrue(target.IsValid(), VALID_TARGET)
+ self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)
- self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
# Now launch the process, and do not stop at entry point.
rc = lldb.SBError()
self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc)
- if not rc.Success() or not self.process.IsValid():
+ if not rc.Success() or not self.process:
self.fail("SBTarget.LaunchProcess() failed")
import lldbutil
@@ -52,7 +52,7 @@ class RegistersIteratorTestCase(TestBase):
if self.TraceOn():
print "\nNumber of general purpose registers: %d" % num
for reg in REGs:
- self.assertTrue(reg.IsValid())
+ self.assertTrue(reg)
if self.TraceOn():
print "%s => %s" % (reg.GetName(), reg.GetValue(frame))
@@ -61,7 +61,7 @@ class RegistersIteratorTestCase(TestBase):
if self.TraceOn():
print "\nNumber of floating point registers: %d" % num
for reg in REGs:
- self.assertTrue(reg.IsValid())
+ self.assertTrue(reg)
if self.TraceOn():
print "%s => %s" % (reg.GetName(), reg.GetValue(frame))
@@ -70,7 +70,7 @@ class RegistersIteratorTestCase(TestBase):
if self.TraceOn():
print "\nNumber of exception state registers: %d" % num
for reg in REGs:
- self.assertTrue(reg.IsValid())
+ self.assertTrue(reg)
if self.TraceOn():
print "%s => %s" % (reg.GetName(), reg.GetValue(frame))
@@ -79,7 +79,7 @@ class RegistersIteratorTestCase(TestBase):
"Floating Point Registers",
"Exception State Registers"]:
REGs = lldbutil.get_registers(frame, kind)
- self.assertTrue(REGs.IsValid())
+ self.assertTrue(REGs)
# We've finished dumping the registers for frame #0.
break
diff --git a/lldb/test/python_api/lldbutil/process/TestPrintStackTraces.py b/lldb/test/python_api/lldbutil/process/TestPrintStackTraces.py
index 32ff8acf406..43bf1eb6c71 100644
--- a/lldb/test/python_api/lldbutil/process/TestPrintStackTraces.py
+++ b/lldb/test/python_api/lldbutil/process/TestPrintStackTraces.py
@@ -28,16 +28,16 @@ class ThreadsStackTracesTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
- self.assertTrue(target.IsValid(), VALID_TARGET)
+ self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
- self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
# Now launch the process, and do not stop at entry point.
rc = lldb.SBError()
self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc)
- if not rc.Success() or not self.process.IsValid():
+ if not rc.Success() or not self.process:
self.fail("SBTarget.LaunchProcess() failed")
import lldbutil
OpenPOWER on IntegriCloud