Skip to content

Instantly share code, notes, and snippets.

@item4
Created Jun 19, 2015
Embed
What would you like to do?
Easy gdb command with Python
# IDEA by marnitto
import gdb
import os
import sys
class Command(gdb.Command):
def __init__(self, name, func):
super(Command, self).__init__(name, gdb.COMMAND_USER)
self._func = func
def invoke(self, arg, from_tty):
return self._func(arg)
def command(*names):
if not names:
print('command name is required.', file=os.stderr)
raise SystemExit()
def decorator(func):
for name in names:
_Command = type(
'Command_{}'.format(name.upper()),
(Command,),
dict(__doc__=func.__doc__)
)
_Command(name, func)
return decorator
@command('clear', 'cls')
def cmd_clear(arg):
"""Clear screen."""
if sys.platform in ['cygwin', 'win32']:
gdb.execute('shell cls')
else:
gdb.execute('shell clear')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment