Skip to content

Instantly share code, notes, and snippets.

Created Jun 19, 2015
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(name, func)
return decorator
@command('clear', 'cls')
def cmd_clear(arg):
"""Clear screen."""
if sys.platform in ['cygwin', 'win32']:
gdb.execute('shell cls')
gdb.execute('shell clear')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment