[Lldb-commits] [lldb] r149684 - in /lldb/trunk: include/lldb/API/SBFrame.h scripts/Python/interface/SBFrame.i scripts/Python/interface/SBValue.i scripts/Python/interface/SBValueList.i scripts/Python/python-extensions.swig source/API/SBFrame.cpp
Greg Clayton
gclayton at apple.com
Thu Feb 2 23:02:38 PST 2012
Author: gclayton
Date: Fri Feb 3 01:02:37 2012
New Revision: 149684
URL: http://llvm.org/viewvc/llvm-project?rev=149684&view=rev
Log:
Expose more convenience functionality in the python classes.
lldb.SBValueList now exposes the len() method and also allows item access:
lldb.SBValueList[<int>] - where <int> is an integer index into the list, returns a single lldb.SBValue which might be empty if the index is out of range
lldb.SBValueList[<str>] - where <str> is the name to look for, returns a list() of lldb.SBValue objects with any matching values (the list might be empty if nothing matches)
lldb.SBValueList[<re>] - where <re> is a compiles regular expression, returns a list of lldb.SBValue objects for containing any matches or a empty list if nothing matches
lldb.SBFrame now exposes:
lldb.SBFrame.variables => SBValueList of all variables that are in scope
lldb.SBFrame.vars => see lldb.SBFrame.variables
lldb.SBFrame.locals => SBValueList of all variables that are locals in the current frame
lldb.SBFrame.arguments => SBValueList of all variables that are arguments in the current frame
lldb.SBFrame.args => see lldb.SBFrame.arguments
lldb.SBFrame.statics => SBValueList of all static variables
lldb.SBFrame.registers => SBValueList of all registers for the current frame
lldb.SBFrame.regs => see lldb.SBFrame.registers
Combine any of the above properties with the new lldb.SBValueList functionality
and now you can do:
y = lldb.frame.vars['rect.origin.y']
or
vars = lldb.frame.vars
for i in range len(vars):
print vars[i]
Also expose "lldb.SBFrame.var(<str>)" where <str> can be en expression path
for any variable or child within the variable. This makes it easier to get a
value from the current frame like "rect.origin.y". The resulting value is also
not a constant result as expressions will return, but a live value that will
continue to track the current value for the variable expression path.
lldb.SBValue now exposes:
lldb.SBValue.unsigned => unsigned integer for the value
lldb.SBValue.signed => a signed integer for the value
Modified:
lldb/trunk/include/lldb/API/SBFrame.h
lldb/trunk/scripts/Python/interface/SBFrame.i
lldb/trunk/scripts/Python/interface/SBValue.i
lldb/trunk/scripts/Python/interface/SBValueList.i
lldb/trunk/scripts/Python/python-extensions.swig
lldb/trunk/source/API/SBFrame.cpp
Modified: lldb/trunk/include/lldb/API/SBFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=149684&r1=149683&r2=149684&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFrame.h (original)
+++ lldb/trunk/include/lldb/API/SBFrame.h Fri Feb 3 01:02:37 2012
@@ -165,6 +165,20 @@
lldb::SBValue
FindVariable (const char *var_name, lldb::DynamicValueType use_dynamic);
+ // Find a value for a variable expression path like "rect.origin.x" or
+ // "pt_ptr->x", "*self", "*this->obj_ptr". The returned value is _not_
+ // and expression result and is not a constant object like
+ // SBFrame::EvaluateExpression(...) returns, but a child object of
+ // the variable value.
+ lldb::SBValue
+ GetValueForVariablePath (const char *var_expr_cstr,
+ DynamicValueType use_dynamic);
+
+ /// The version that doesn't supply a 'use_dynamic' value will use the
+ /// target's default.
+ lldb::SBValue
+ GetValueForVariablePath (const char *var_path);
+
/// Find variables, register sets, registers, or persistent variables using
/// the frame as the scope.
///
Modified: lldb/trunk/scripts/Python/interface/SBFrame.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFrame.i?rev=149684&r1=149683&r2=149684&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBFrame.i (original)
+++ lldb/trunk/scripts/Python/interface/SBFrame.i Fri Feb 3 01:02:37 2012
@@ -203,6 +203,34 @@
FindVariable (const char *var_name, lldb::DynamicValueType use_dynamic);
%feature("docstring", "
+ /// Get a lldb.SBValue for a variable path.
+ ///
+ /// Variable paths can include access to pointer or instance members:
+ /// rect_ptr->origin.y
+ /// pt.x
+ /// Pointer dereferences:
+ /// *this->foo_ptr
+ /// **argv
+ /// Address of:
+ /// &pt
+ /// &my_array[3].x
+ /// Array accesses and treating pointers as arrays:
+ /// int_array[1]
+ /// pt_ptr[22].x
+ ///
+ /// Unlike EvaluateExpression() which returns lldb.SBValue objects
+ /// with constant copies of the values at the time of evaluation,
+ /// the result of this function is a value that will continue to
+ /// track the current value of the value as execution progresses
+ /// in the current frame.
+ ") GetValueForVariablePath;
+ lldb::SBValue
+ GetValueForVariablePath (const char *var_path);
+
+ lldb::SBValue
+ GetValueForVariablePath (const char *var_path, lldb::DynamicValueType use_dynamic);
+
+ %feature("docstring", "
/// Find variables, register sets, registers, or persistent variables using
/// the frame as the scope.
///
@@ -219,6 +247,23 @@
GetDescription (lldb::SBStream &description);
%pythoncode %{
+ def get_all_variables(self):
+ return self.GetVariables(True,True,True,True)
+
+ def get_arguments(self):
+ return self.GetVariables(True,False,False,False)
+
+ def get_locals(self):
+ return self.GetVariables(False,True,False,False)
+
+ def get_statics(self):
+ return self.GetVariables(False,False,True,False)
+
+ def var(self, var_expr_path):
+ '''Calls through to lldb.SBFrame.GetValueForVariablePath() and returns
+ a value that represents the variable expression path'''
+ return self.GetValueForVariablePath(var_expr_path)
+
__swig_getmethods__["pc"] = GetPC
__swig_setmethods__["pc"] = SetPC
if _newclass: x = property(GetPC, SetPC)
@@ -265,6 +310,30 @@
__swig_getmethods__["idx"] = GetFrameID
if _newclass: x = property(GetFrameID, None)
+ __swig_getmethods__["variables"] = get_all_variables
+ if _newclass: x = property(get_all_variables, None)
+
+ __swig_getmethods__["vars"] = get_all_variables
+ if _newclass: x = property(get_all_variables, None)
+
+ __swig_getmethods__["locals"] = get_locals
+ if _newclass: x = property(get_locals, None)
+
+ __swig_getmethods__["args"] = get_arguments
+ if _newclass: x = property(get_arguments, None)
+
+ __swig_getmethods__["arguments"] = get_arguments
+ if _newclass: x = property(get_arguments, None)
+
+ __swig_getmethods__["statics"] = get_statics
+ if _newclass: x = property(get_statics, None)
+
+ __swig_getmethods__["registers"] = GetRegisters
+ if _newclass: x = property(GetRegisters, None)
+
+ __swig_getmethods__["regs"] = GetRegisters
+ if _newclass: x = property(GetRegisters, None)
+
%}
};
Modified: lldb/trunk/scripts/Python/interface/SBValue.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBValue.i?rev=149684&r1=149683&r2=149684&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBValue.i (original)
+++ lldb/trunk/scripts/Python/interface/SBValue.i Fri Feb 3 01:02:37 2012
@@ -436,6 +436,19 @@
__swig_getmethods__["num_children"] = GetNumChildren
if _newclass: x = property(GetNumChildren, None)
+ __swig_getmethods__["unsigned"] = GetValueAsUnsigned
+ if _newclass: x = property(GetValueAsUnsigned, None)
+
+ __swig_getmethods__["signed"] = GetValueAsSigned
+ if _newclass: x = property(GetValueAsSigned, None)
+
+ def get_expr_path(self):
+ s = SBStream()
+ self.GetExpressionPath (s)
+ return s.GetData()
+
+ __swig_getmethods__["path"] = get_expr_path
+ if _newclass: x = property(get_expr_path, None)
%}
};
Modified: lldb/trunk/scripts/Python/interface/SBValueList.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBValueList.i?rev=149684&r1=149683&r2=149684&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBValueList.i (original)
+++ lldb/trunk/scripts/Python/interface/SBValueList.i Fri Feb 3 01:02:37 2012
@@ -96,6 +96,43 @@
lldb::SBValue
FindValueObjectByUID (lldb::user_id_t uid);
+ %pythoncode %{
+ def __len__(self):
+ return self.GetSize()
+
+ def __getitem__(self, key):
+ count = len(self)
+ #------------------------------------------------------------
+ # Access with "int" to get Nth item in the list
+ #------------------------------------------------------------
+ if type(key) is int:
+ if key < count:
+ return self.GetValueAtIndex(key)
+ #------------------------------------------------------------
+ # Access with "str" to get values by name
+ #------------------------------------------------------------
+ elif type(key) is str:
+ matches = []
+ for idx in range(count):
+ value = self.GetValueAtIndex(idx)
+ if value.name == key:
+ matches.append(value)
+ return matches
+ #------------------------------------------------------------
+ # Match with regex
+ #------------------------------------------------------------
+ elif isinstance(key, type(re.compile('.'))):
+ matches = []
+ for idx in range(count):
+ value = self.GetValueAtIndex(idx)
+ re_match = key.search(value.name)
+ if re_match:
+ matches.append(value)
+ return matches
+
+ %}
+
+
};
} // namespace lldb
Modified: lldb/trunk/scripts/Python/python-extensions.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=149684&r1=149683&r2=149684&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-extensions.swig (original)
+++ lldb/trunk/scripts/Python/python-extensions.swig Fri Feb 3 01:02:37 2012
@@ -324,6 +324,28 @@
return Py_None;
}
}
+%extend lldb::SBValueList {
+ PyObject *lldb::SBValueList::__repr__ (){
+ lldb::SBStream description;
+ const size_t n = $self->GetSize();
+ if (n)
+ {
+ for (size_t i=0; i<n; ++i)
+ $self->GetValueAtIndex(i).GetDescription(description);
+ }
+ else
+ {
+ description.Printf("<empty> lldb.SBValueList()");
+ }
+ const char *desc = description.GetData();
+ size_t desc_len = description.GetSize();
+ if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
+ --desc_len;
+ if (desc_len > 0)
+ return PyString_FromStringAndSize (desc, desc_len);
+ return Py_None;
+ }
+}
%extend lldb::SBWatchpoint {
PyObject *lldb::SBWatchpoint::__repr__ (){
lldb::SBStream description;
Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=149684&r1=149683&r2=149684&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Fri Feb 3 01:02:37 2012
@@ -455,6 +455,39 @@
m_opaque_sp.reset();
}
+lldb::SBValue
+SBFrame::GetValueForVariablePath (const char *var_path)
+{
+ SBValue sb_value;
+ StackFrameSP frame_sp(GetFrameSP());
+ if (frame_sp)
+ {
+ lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
+ sb_value = GetValueForVariablePath (var_path, use_dynamic);
+ }
+ return sb_value;
+}
+
+lldb::SBValue
+SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
+{
+ SBValue sb_value;
+ StackFrameSP frame_sp(GetFrameSP());
+ if (frame_sp && var_path && var_path[0])
+ {
+ Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+ VariableSP var_sp;
+ Error error;
+ ValueObjectSP value_sp (frame_sp->GetValueForVariableExpressionPath (var_path,
+ use_dynamic,
+ StackFrame::eExpressionPathOptionCheckPtrVsMember,
+ var_sp,
+ error));
+ *sb_value = value_sp;
+ }
+ return sb_value;
+}
+
SBValue
SBFrame::FindVariable (const char *name)
{
@@ -467,6 +500,7 @@
}
return value;
}
+
SBValue
SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
More information about the lldb-commits
mailing list