From c93bc3e70c28fcbf17c70562dd3d15aa064a2232 Mon Sep 17 00:00:00 2001 From: Artur Cygan Date: Sun, 22 Aug 2021 00:40:04 +0200 Subject: [PATCH] Add memoize command for toggling caching, useful for debugging pwndbg --- pwndbg/__init__.py | 3 ++- pwndbg/commands/memoize.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 pwndbg/commands/memoize.py diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index 004085a4e..e48742f24 100755 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -30,6 +30,7 @@ import pwndbg.commands.hexdump import pwndbg.commands.ida import pwndbg.commands.leakfind import pwndbg.commands.misc +import pwndbg.commands.memoize import pwndbg.commands.mprotect import pwndbg.commands.next import pwndbg.commands.peda @@ -161,5 +162,5 @@ signal.signal(signal.SIGWINCH, lambda signum, frame: gdb.execute("set width %i" if 1: gdb.execute('set remote search-memory-packet off') -# Reading Comment file +# Reading Comment file pwndbg.commands.comments.init() diff --git a/pwndbg/commands/memoize.py b/pwndbg/commands/memoize.py new file mode 100644 index 000000000..4ff2cb41c --- /dev/null +++ b/pwndbg/commands/memoize.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import argparse + +import pwndbg.commands +from pwndbg.color import message + +parser = argparse.ArgumentParser(description=''' +Toggles memoization (caching). Pwndbg will work slower when it's off, however +it's useful for diagnosing caching-related bugs. +''') + +@pwndbg.commands.ArgparsedCommand(parser) +def memoize(): + pwndbg.memoize.memoize.caching = not pwndbg.memoize.memoize.caching + + status = message.off('OFF (pwndbg will work slower, use only for debugging pwndbg)') + if pwndbg.memoize.memoize.caching: + status = message.on('ON') + + print("Caching is now %s" % status)