2021-08-20 19:48:05 +02:00
|
|
|
import gdb.printing
|
|
|
|
|
2021-08-22 23:46:02 +02:00
|
|
|
def digits_to_num(digits):
|
|
|
|
res = 0
|
|
|
|
for d in reversed(digits):
|
|
|
|
res *= 10
|
|
|
|
res += d
|
|
|
|
return res
|
|
|
|
|
2021-08-20 19:48:05 +02:00
|
|
|
class BigNumPrinter(object):
|
|
|
|
"Print a abacus::bignum::BigNum"
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
digits = self.val['digits_']
|
|
|
|
begin, end = digits['_M_impl']['_M_start'], digits['_M_impl']['_M_finish']
|
2021-08-22 23:46:02 +02:00
|
|
|
val = []
|
2021-08-20 19:48:05 +02:00
|
|
|
while begin != end:
|
2021-08-22 23:46:02 +02:00
|
|
|
val += [begin.dereference()]
|
2021-08-20 19:48:05 +02:00
|
|
|
begin += 1
|
2021-08-22 23:46:02 +02:00
|
|
|
val = digits_to_num(val)
|
2021-08-20 19:48:05 +02:00
|
|
|
val *= self.val['sign_']
|
|
|
|
return str(val)
|
|
|
|
|
|
|
|
def display_hint(self):
|
|
|
|
return 'string'
|
|
|
|
|
|
|
|
def build_pretty_printer():
|
|
|
|
pp = gdb.printing.RegexpCollectionPrettyPrinter('abacus')
|
|
|
|
|
|
|
|
pp.add_printer('BigNum', '^abacus::bignum::BigNum$', BigNumPrinter)
|
|
|
|
|
|
|
|
return pp
|
|
|
|
|
|
|
|
gdb.printing.register_pretty_printer(gdb.current_objfile(), build_pretty_printer(), True)
|