gdb: make the code PEP-8 compliant

This commit is contained in:
Michael Olbrich 2018-12-29 16:20:54 +01:00 committed by Tim-Philipp Müller
parent 156d33f30a
commit e43a0c9943

View file

@ -7,8 +7,9 @@ from glib_gobject_helper import g_type_to_name, g_type_name_from_instance
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
long = int long = int
def is_gst_type (val, klass):
def _is_gst_type (type): def is_gst_type(val, klass):
def _is_gst_type(type):
if str(type) == klass: if str(type) == klass:
return True return True
@ -19,61 +20,63 @@ def is_gst_type (val, klass):
return False return False
fields = type.fields() fields = type.fields()
if len (fields) < 1: if len(fields) < 1:
return False return False
first_field = fields[0] first_field = fields[0]
return _is_gst_type (first_field.type) return _is_gst_type(first_field.type)
type = val.type type = val.type
if type.code != gdb.TYPE_CODE_PTR: if type.code != gdb.TYPE_CODE_PTR:
return False return False
type = type.target() type = type.target()
return _is_gst_type (type) return _is_gst_type(type)
class GstMiniObjectPrettyPrinter: class GstMiniObjectPrettyPrinter:
"Prints a GstMiniObject instance pointer" "Prints a GstMiniObject instance pointer"
def __init__ (self, val): def __init__(self, val):
self.val = val self.val = val
def to_string (self): def to_string(self):
try: try:
inst = self.val.cast (gdb.lookup_type("GstMiniObject").pointer()) inst = self.val.cast(gdb.lookup_type("GstMiniObject").pointer())
gtype = inst["type"] gtype = inst["type"]
name = g_type_to_name (gtype) name = g_type_to_name(gtype)
return "0x%x [%s]" % (long(self.val), name) return "0x%x [%s]" % (long(self.val), name)
except RuntimeError: except RuntimeError:
return "0x%x" % long(self.val) return "0x%x" % long(self.val)
class GstObjectPrettyPrinter: class GstObjectPrettyPrinter:
"Prints a GstObject instance" "Prints a GstObject instance"
def __init__ (self, val): def __init__(self, val):
self.val = val self.val = val
def to_string (self): def to_string(self):
try: try:
name = g_type_name_from_instance (self.val) name = g_type_name_from_instance(self.val)
if not name: if not name:
name = str(self.val.type.target()) name = str(self.val.type.target())
if long(self.val) != 0: if long(self.val) != 0:
inst = self.val.cast (gdb.lookup_type("GstObject").pointer()) inst = self.val.cast(gdb.lookup_type("GstObject").pointer())
inst_name = inst["name"].string() inst_name = inst["name"].string()
if inst_name: if inst_name:
name += "|" + inst_name name += "|" + inst_name
return ("0x%x [%s]") % (long(self.val), name) return ("0x%x [%s]") % (long(self.val), name)
except RuntimeError: except RuntimeError:
return "0x%x" % long(self.val) return "0x%x" % long(self.val)
class GstClockTimePrinter: class GstClockTimePrinter:
"Prints a GstClockTime / GstClockTimeDiff" "Prints a GstClockTime / GstClockTimeDiff"
def __init__ (self, val): def __init__(self, val):
self.val = val self.val = val
def to_string (self): def to_string(self):
GST_SECOND = 1000000000 GST_SECOND = 1000000000
GST_CLOCK_TIME_NONE = 2**64-1 GST_CLOCK_TIME_NONE = 2**64-1
GST_CLOCK_STIME_NONE = -2**63 GST_CLOCK_STIME_NONE = -2**63
@ -92,23 +95,26 @@ class GstClockTimePrinter:
if invalid: if invalid:
return str(n) + " [99:99:99.999999999]" return str(n) + " [99:99:99.999999999]"
return str(n) + " [%s%u:%02u:%02u.%09u]" % ( prefix, return str(n) + " [%s%u:%02u:%02u.%09u]" % (
n / (GST_SECOND * 60 * 60), prefix,
n / (GST_SECOND * 60 * 60),
(n / (GST_SECOND * 60)) % 60, (n / (GST_SECOND * 60)) % 60,
(n / GST_SECOND) % 60, (n / GST_SECOND) % 60,
n % GST_SECOND ) n % GST_SECOND)
def gst_pretty_printer_lookup (val):
if is_gst_type (val, "GstMiniObject"): def gst_pretty_printer_lookup(val):
return GstMiniObjectPrettyPrinter (val) if is_gst_type(val, "GstMiniObject"):
if is_gst_type (val, "GstObject"): return GstMiniObjectPrettyPrinter(val)
return GstObjectPrettyPrinter (val) if is_gst_type(val, "GstObject"):
return GstObjectPrettyPrinter(val)
if str(val.type) == "GstClockTime" or str(val.type) == "GstClockTimeDiff": if str(val.type) == "GstClockTime" or str(val.type) == "GstClockTimeDiff":
return GstClockTimePrinter (val) return GstClockTimePrinter(val)
return None return None
def register (obj):
if obj == None: def register(obj):
if obj is None:
obj = gdb obj = gdb
# Make sure this is always used befor the glib lookup function. # Make sure this is always used befor the glib lookup function.