2013-02-26 10:14:10 +01:00
|
|
|
import gdb
|
|
|
|
import re
|
|
|
|
|
|
|
|
class IcingaStringPrinter:
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return '"' + self.val['m_Data']['_M_dataplus']['_M_p'].string() + '"'
|
|
|
|
|
|
|
|
class IcingaValuePrinter:
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
which = self.val['m_Value']['which_']
|
|
|
|
|
|
|
|
if which == 0:
|
|
|
|
return 'Empty'
|
|
|
|
elif which == 1:
|
|
|
|
return self.val['m_Value']['storage_']['data_']['buf'].cast(gdb.lookup_type('double').pointer()).dereference()
|
|
|
|
elif which == 2:
|
2014-12-12 14:58:09 +01:00
|
|
|
return self.val['m_Value']['storage_']['data_']['buf'].cast(gdb.lookup_type('bool').pointer()).dereference()
|
2013-02-26 10:14:10 +01:00
|
|
|
elif which == 3:
|
2014-12-12 14:58:09 +01:00
|
|
|
return self.val['m_Value']['storage_']['data_']['buf'].cast(gdb.lookup_type('icinga::String').pointer()).dereference()
|
|
|
|
elif which == 4:
|
2013-02-26 10:14:10 +01:00
|
|
|
return self.val['m_Value']['storage_']['data_']['buf'].cast(gdb.lookup_type('icinga::Object').pointer()).dereference()
|
|
|
|
else:
|
|
|
|
return '<INVALID>'
|
|
|
|
|
2013-08-27 12:21:41 +02:00
|
|
|
class IcingaSignalPrinter:
|
2013-02-26 10:14:10 +01:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
2013-08-27 12:21:41 +02:00
|
|
|
return '<SIGNAL>'
|
2013-02-26 10:14:10 +01:00
|
|
|
|
2013-08-27 12:21:41 +02:00
|
|
|
class IcingaMutexPrinter:
|
2013-02-26 10:14:10 +01:00
|
|
|
def __init__(self, val):
|
2013-08-27 12:21:41 +02:00
|
|
|
self.val = val
|
2013-02-26 10:14:10 +01:00
|
|
|
|
|
|
|
def to_string(self):
|
2013-08-27 12:21:41 +02:00
|
|
|
owner = self.val['__data']['__owner']
|
|
|
|
|
|
|
|
if owner == 0:
|
|
|
|
return '<unlocked>'
|
|
|
|
else:
|
2013-09-02 15:12:04 +02:00
|
|
|
return '<locked by #' + str(owner) + '>'
|
2013-02-26 10:14:10 +01:00
|
|
|
|
|
|
|
def lookup_icinga_type(val):
|
2013-03-04 15:52:42 +01:00
|
|
|
t = val.type.unqualified()
|
|
|
|
if str(t) == 'icinga::String':
|
2013-02-26 10:14:10 +01:00
|
|
|
return IcingaStringPrinter(val)
|
2013-03-04 15:52:42 +01:00
|
|
|
elif str(t) == 'icinga::Value':
|
2013-02-26 10:14:10 +01:00
|
|
|
return IcingaValuePrinter(val)
|
2013-03-04 15:52:42 +01:00
|
|
|
elif re.match('^boost::signals2::signal.*<.*>$', str(t)):
|
2013-02-26 10:14:10 +01:00
|
|
|
return IcingaSignalPrinter(val)
|
2013-08-27 12:21:41 +02:00
|
|
|
elif str(t) == 'pthread_mutex_t':
|
|
|
|
return IcingaMutexPrinter(val)
|
2013-02-26 10:14:10 +01:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def register_icinga_printers():
|
|
|
|
gdb.pretty_printers.append(lookup_icinga_type)
|