From bbd140bfdf27e02cf37cefe61dd6e8a39b468288 Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Mon, 18 May 2015 12:55:54 -0700 Subject: [PATCH] Restore GDB 7.7 compatibility --- pwndbg/regs.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pwndbg/regs.py b/pwndbg/regs.py index 73d66e80..e85d18cd 100644 --- a/pwndbg/regs.py +++ b/pwndbg/regs.py @@ -218,25 +218,40 @@ arch_to_regs = { 'powerpc': powerpc, } +@pwndbg.proc.OnlyWhenRunning +def gdb77_get_register(name): + return gdb.parse_and_eval('$' + name) + +@pwndbg.proc.OnlyWhenRunning +def gdb79_get_register(name): + return gdb.newest_frame().read_register(name) + + +try: + gdb.Frame.read_register + get_register = gdb79_get_register +except AttributeError: + get_register = gdb77_get_register + class module(ModuleType): last = {} @pwndbg.memoize.reset_on_stop def __getattr__(self, attr): + attr = attr.lstrip('$') try: # Seriously, gdb? Only accepts uint32. if 'eflags' in attr: - value = gdb.parse_and_eval('$' + attr.lstrip('$')) + value = gdb77_get_register(attr) value = value.cast(pwndbg.typeinfo.uint32) else: - value = gdb.newest_frame().read_register(attr) + value = get_register(attr) value = value.cast(pwndbg.typeinfo.ptrdiff) value = int(value) return value & pwndbg.arch.ptrmask - except ValueError: - # Unknown register + except (ValueError, gdb.error): return None @pwndbg.memoize.reset_on_stop