31 lines · python
1import lldb2 3 4def pyobj_summary(value, unused):5 if value is None or not value.IsValid() or value.GetValueAsUnsigned(0) == 0:6 return "<invalid>"7 refcnt = value.GetChildMemberWithName("ob_refcnt")8 expr = "(char*)PyString_AsString( (PyObject*)PyObject_Str( (PyObject*)0x%x) )" % (9 value.GetValueAsUnsigned(0)10 )11 expr_summary = value.target.EvaluateExpression(12 expr, lldb.SBExpressionOptions()13 ).GetSummary()14 refcnt_value = "rc = %d" % (refcnt.GetValueAsUnsigned(0))15 return "%s (%s)" % (expr_summary, refcnt_value)16 17 18def __lldb_init_module(debugger, unused):19 debugger.HandleCommand(20 "type summary add PyObject --python-function pysummary.pyobj_summary"21 )22 debugger.HandleCommand(23 "type summary add lldb_private::PythonObject -s ${var.m_py_obj%S}"24 )25 debugger.HandleCommand(26 "type summary add lldb_private::PythonDictionary -s ${var.m_py_obj%S}"27 )28 debugger.HandleCommand(29 "type summary add lldb_private::PythonString -s ${var.m_py_obj%S}"30 )31