[Lldb-commits] [lldb] r131144 - in /lldb/trunk/test: lldbutil.py python_api/lldbutil/TestRegistersIterator.py
Johnny Chen
johnny.chen at apple.com
Tue May 10 12:21:13 PDT 2011
Author: johnny
Date: Tue May 10 14:21:13 2011
New Revision: 131144
URL: http://llvm.org/viewvc/llvm-project?rev=131144&view=rev
Log:
Add a utility function get_registers(frame, kind) to get the registers of a given frame and of a given kind.
Also add three convenience functions get_GPRs(frame), get_FPRs(frame), and get_ESRs(frame) to get the general
purpose registers, the floating point registers, and the exception state registers.
Add TestRegistersIterator.py to test these added functions of lldbutil.py.
Added:
lldb/trunk/test/python_api/lldbutil/TestRegistersIterator.py
Modified:
lldb/trunk/test/lldbutil.py
Modified: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=131144&r1=131143&r2=131144&view=diff
==============================================================================
--- lldb/trunk/test/lldbutil.py (original)
+++ lldb/trunk/test/lldbutil.py Tue May 10 14:21:13 2011
@@ -416,9 +416,9 @@
print >> output, "Register sets for " + repr(frame)
- registerList = frame.GetRegisters()
- print >> output, "Frame registers (size of register set = %d):" % registerList.GetSize()
- for value in registerList:
+ registerSet = frame.GetRegisters() # Return type of SBValueList.
+ print >> output, "Frame registers (size of register set = %d):" % registerSet.GetSize()
+ for value in registerSet:
#print >> output, value
print >> output, "%s (number of children = %d):" % (value.GetName(), value.GetNumChildren())
for child in value:
@@ -426,3 +426,36 @@
if string_buffer:
return output.getvalue()
+
+def get_registers(frame, kind):
+ """Returns the registers given the frame and the kind of registers desired.
+
+ Returns None if there's no such kind.
+ """
+ registerSet = frame.GetRegisters() # Return type of SBValueList.
+ for value in registerSet:
+ if kind.lower() in value.GetName().lower():
+ return value
+
+ return None
+
+def get_GPRs(frame):
+ """Returns the general purpose registers of the frame as an SBValue.
+
+ The returned SBValue object is iterable.
+ """
+ return get_registers(frame, "general purpose")
+
+def get_FPRs(frame):
+ """Returns the floating point registers of the frame as an SBValue.
+
+ The returned SBValue object is iterable.
+ """
+ return get_registers(frame, "floating point")
+
+def get_ESRs(frame):
+ """Returns the exception state registers of the frame as an SBValue.
+
+ The returned SBValue object is iterable.
+ """
+ return get_registers(frame, "exception state")
Added: lldb/trunk/test/python_api/lldbutil/TestRegistersIterator.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/lldbutil/TestRegistersIterator.py?rev=131144&view=auto
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/TestRegistersIterator.py (added)
+++ lldb/trunk/test/python_api/lldbutil/TestRegistersIterator.py Tue May 10 14:21:13 2011
@@ -0,0 +1,72 @@
+"""
+Test the iteration protocol for frame registers.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb
+from lldbtest import *
+
+class RegistersIteratorTestCase(TestBase):
+
+ mydir = "python_api/lldbutil"
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside main().
+ self.line1 = line_number('main.cpp', '// Set break point at this line.')
+
+ def test_iter_registers(self):
+ """Test iterator works correctly for lldbutil.iter_registers()."""
+ self.buildDefault()
+ self.iter_registers()
+
+ def iter_registers(self):
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target.IsValid(), VALID_TARGET)
+
+ breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)
+ self.assertTrue(breakpoint.IsValid(), 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():
+ self.fail("SBTarget.LaunchProcess() failed")
+
+ import lldbutil
+ for thread in self.process:
+ if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
+ for frame in thread:
+ # Dump the registers of this frame using iter_registers().
+ if self.TraceOn():
+ print frame
+
+ for kind in ["General Purpose Registers",
+ "Floating Point Registers",
+ "Exception State Registers"]:
+ REGs = lldbutil.get_registers(frame, kind)
+ if self.TraceOn():
+ print "%s:" % kind
+ for reg in REGs:
+ self.assertTrue(reg.IsValid())
+ if self.TraceOn():
+ print "%s => %s" % (reg.GetName(), reg.GetValue(frame))
+
+ # And these should also work.
+ self.assertTrue(lldbutil.get_GPRs(frame))
+ self.assertTrue(lldbutil.get_FPRs(frame))
+ self.assertTrue(lldbutil.get_ESRs(frame))
+ break
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
More information about the lldb-commits
mailing list