Skip to content

Commit

Permalink
Add pretty printer for intx::uint256
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Sep 20, 2024
1 parent e890ca0 commit 56556af
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion gdb_pretty_printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ def to_string(self):
return "0x" + (''.join(f'{byte:02x}' for byte in bytes_int))


INTX_UINT_TARGET_TYPES = [
"intx::uint<256>",
"const intx::uint<256>",
]

class IntxUintPrinter:
def __init__(self, val):
self.val = val

def to_string(self):
words = self.val['words_']
words_int = [int(words[i]) for i in range(4)]
v = words_int[0] + words_int[1] * (1 << 64) + words_int[2] * (1 << 128) + words_int[3] * (
1 << 192)
return v

# In CLion these are automatically overwritten by std::* pretty printers.
# Reload this script manually (`source -v ../../gdb_pretty_printers.py`) to activate them again.
STRING_TARGET_TYPES = [
Expand Down Expand Up @@ -53,11 +69,14 @@ def register_printers(obj):

def lookup_function(val):
type_str = str(val.type.strip_typedefs())
# print("lookup " + type_str) # uncomment to see exact type requested
# print("lookup " + type_str) # uncomment to see exact type requested

if type_str in EVMC_BYTES_TARGET_TYPES:
return EvmcBytesPrinter(val)

if type_str in INTX_UINT_TARGET_TYPES:
return IntxUintPrinter(val)

if type_str in STRING_TARGET_TYPES:
return StdBasicStringUint8Printer(val)

Expand Down

0 comments on commit 56556af

Please sign in to comment.