public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Option parsing in gdb python
@ 2011-10-22  1:22 Robert Lupton the Good
  2011-10-23 21:00 ` Paul_Koning
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Lupton the Good @ 2011-10-22  1:22 UTC (permalink / raw)
  To: gdb

I just spent a few minutes fiddling with optparse (deprecated in python 2.7, but I don't think I care) to make it usable from gdb python (the problem is that by default it uses sys.argv[0] for help messages, and exits on error).  With my subclass you can say e.g.

            parser = GdbOptionParser("show image [opts] [nx [ny]]")
            parser.add_option("-a", "--all", action="store_true", help="Display the whole image/mask")
            parser.add_option("-w", "--width", type="int", default=8, help="Field width for pixels")

            (opts, args) =  parser.parse_args(args)

and things "just work".  I'd be happy to donate the code to fsf/gdb

					R



import gdb
import optparse

class GdbOptionParser(optparse.OptionParser):
    def __init__(self, usage, *args, **kwargs):
        optparse.OptionParser.__init__(self, *args, **kwargs) # OptionParser is an old-style class
        self.set_usage(usage)

    def parse_args(self, args, values=None):
        """Call optparse.OptionParser.parse_args after running gdb.string_to_argv on args"""
        return optparse.OptionParser.parse_args(self, gdb.string_to_argv(args), values)

    def exit(self, status=0, msg=None):
        raise gdb.GdbError(msg)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-10-27 17:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1319403653.11425.ezmlm@sourceware.org>
2011-10-24 21:28 ` Option parsing in gdb python Robert Lupton the Good
2011-10-24 21:35   ` Joel Brobecker
2011-10-25  2:58     ` Robert Lupton the Good
2011-10-27 17:01     ` Tom Tromey
2011-10-27 19:32   ` Tom Tromey
2011-10-22  1:22 Robert Lupton the Good
2011-10-23 21:00 ` Paul_Koning

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).