[Lldb-commits] [lldb] r224275 - Provide a SBFrame.register/.reg helper on the Python side of SBFrame to vend a flattened view of registers

Enrico Granata egranata at apple.com
Mon Dec 15 13:30:36 PST 2014


Author: enrico
Date: Mon Dec 15 15:30:36 2014
New Revision: 224275

URL: http://llvm.org/viewvc/llvm-project?rev=224275&view=rev
Log:
Provide a SBFrame.register/.reg helper on the Python side of SBFrame to vend a flattened view of registers

Our actual view of registers is a set of register sets, each one of which contains a subset of the actual registers
This makes trivial scripting operations tedious ("I just want to read r7!")

This helper allows things like: print lldb.frame.reg["r7"]

Fixes rdar://19185662


Modified:
    lldb/trunk/scripts/Python/interface/SBFrame.i

Modified: lldb/trunk/scripts/Python/interface/SBFrame.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFrame.i?rev=224275&r1=224274&r2=224275&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBFrame.i (original)
+++ lldb/trunk/scripts/Python/interface/SBFrame.i Mon Dec 15 15:30:36 2014
@@ -276,6 +276,24 @@ public:
             a value that represents the variable expression path'''
             return self.GetValueForVariablePath(var_expr_path)
 
+        def get_registers_access(self):
+            class registers_access(object):
+                '''A helper object that exposes a flattened view of registers, masking away the notion of register sets for easy scripting.'''
+                def __init__(self, regs):
+                    self.regs = regs
+
+                def __getitem__(self, key):
+                    if type(key) is str:
+                        for i in range(0,len(self.regs)):
+                            rs = self.regs[i]
+                            for j in range (0,rs.num_children):
+                                reg = rs.GetChildAtIndex(j)
+                                if reg.name == key: return reg
+                    else:
+                        return lldb.SBValue()
+
+            return registers_access(self.registers)
+
         __swig_getmethods__["pc"] = GetPC
         __swig_setmethods__["pc"] = SetPC
         if _newclass: pc = property(GetPC, SetPC)
@@ -346,6 +364,12 @@ public:
         __swig_getmethods__["regs"] = GetRegisters
         if _newclass: regs = property(GetRegisters, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the CPU registers for this stack frame.''')
 
+        __swig_getmethods__["register"] = get_registers_access
+        if _newclass: register = property(get_registers_access, None, doc='''A read only property that returns an helper object providing a flattened indexable view of the CPU registers for this stack frame.''')
+
+        __swig_getmethods__["reg"] = get_registers_access
+        if _newclass: reg = property(get_registers_access, None, doc='''A read only property that returns an helper object providing a flattened indexable view of the CPU registers for this stack frame''')
+
     %}
 };
 





More information about the lldb-commits mailing list