I am trying to create a pretty-printer for boost::multiprecision::mpfr_float_50.
This is the code I have:
import gdb
import gdb.printing
class BoostMultiprecision(object):
"Pretty Printer for boost::multiprecision::mpfr_float_50"
def __init__(self, val):
self.val = val
self.double = gdb.lookup_type('double')
def to_string(self):
eval_string = "(*("+str(self.val.type)+"*)("+str(self.val.address)+")).convert_to<double>()"
result = gdb.parse_and_eval(eval_string)
return result.cast(self.double)
def display_hint(self):
return 'mpfr_float_50'
def build_pretty_printer_mpfr_float_50():
pp = gdb.printing.RegexpCollectionPrettyPrinter("boost::multiprecision::mpfr_float_50")
pp.add_printer('mpfr_float_50', '^boost::multiprecision::mpfr_float_50$', BoostMultiprecision)
return pp
def register_printers():
gdb.printing.register_pretty_printer(gdb.current_objfile(), build_pretty_printer_mpfr_float_50())
This is my .gdbinit:
python
import sys
sys.path.insert(1, '/path/to/script')
import gdb_pretty_printers
gdb_pretty_printers.register_printers()
When I try to print my variable, I just get the following:
m_backend = {<boost::multiprecision::backends::detail::mpfr_float_imp<50,
(boost::multiprecision::mpfr_allocation_type)1>> = {m_data = {{_mpfr_prec = 168, _mpfr_sign = 1,
_mpfr_exp = -7, _mpfr_d = 0x5555558752d8}}}
How can I pretty print my boost::multiprecision::mpfr_float_50 as a double?