This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Less verbose Python commands
- From: Daniel Colascione <daniel at censorshipresearch dot org>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 10 Jan 2010 03:00:52 -0500
- Subject: Less verbose Python commands
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
import os, sys, gdb
# Using this
def command(*init_args):
def decorator(func):
def init_func(self):
gdb.Command.__init__(self, *init_args)
def invoke_func(self, argument, from_tty):
func(argument, from_tty)
type('Command_' + init_args[0].replace(' ', '_'),
(gdb.Command,),
{ '__init__': init_func,
'invoke': invoke_func })()
return func
return decorator
# We can more easily write commands that look like this:
def register():
@command('fiber', gdb.COMMAND_DATA, gdb.COMPLETE_NONE, True)
def func(argument, from_tty):
print "Hi, I'm a fiber prefix!"
@command('fiber list', gdb.COMMAND_DATA)
def func(argument, from_tty):
print "List fibers here"
# Less verbose, isn't it?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
iEYEARECAAYFAktJiTQACgkQ17c2LVA10VsB+wCg27MtSJmw7sQAuJsTW5u/gPQ8
pAQAn0F/2oOW/r5M1iDY8AQOl6ZaWPVh
=cbAs
-----END PGP SIGNATURE-----