Patch to add argument parsing classes to gdb

Tom Tromey tromey@redhat.com
Tue Dec 13 19:19:00 GMT 2011


>>>>> "Robert" == Robert Lupton the Good <rhl@astro.princeton.edu> writes:

Robert> I'm attaching a patch that implements two classes,
Robert> GdbOptionParser and GdbArgumentParser, which are built around
Robert> python's standard optparse and argparse but play well with gdb
Robert> (e.g. don't call exit if you make a typo or ask for help!).  The
Robert> code imports with python >= 2.3, but only provides the
Robert> argparse-based parser if you actually have argparse in your path
Robert> (python == 2.7?).

Thanks.

Robert> The patch:
Robert> 	Implements the classes
Robert> 	Adds docs
Robert> 	Adds test cases

Robert> What else do you need to get this into the source tree?  I just
Robert> faxed the copyright assignment to FSF.

We can't put it in until we hear back from the FSF that your paperwork
is complete.  I haven't seen anything yet, have you?

Robert> + 	* doc/gdb.texinfo: Document Gdb{Argument,Option}Parser
Robert> + 	* python/lib/gdb/printing.py: Implement Gdb{Argument,Option}Parser

We don't usually use the {,} syntax in ChangeLog.  Just write out the
text.

Robert> + If your arguments are more complicated, you might want to use GDB's versions
Robert> + of Python's standard @code{optparse} or @code{argparse} modules;
Robert> + @xref{Argument Parsing In Python}.

I think after a ";" you want @ref, not @xref.
In this case you have to write "see @ref{...}".  See the texinfo manual
for details.

Robert> + There are two standard modules for parsing arguments in modern Pythons;

I suggest "modern versions of Python".

Robert> + @footnote{@code{optparse} appeared in Python 2.3, but is deprecated in favor of

I think this line is too long.

Robert> + GDB supports both, but doesn't emulate either --- you will have to write your

Instead of "GDB", we write @value{GDBN}.
This happens a couple of times.

Robert> + unsupported parser an @code{ImportError} is thrown when you try to initialise it.

We usually use US spelling, so "initialize".

Robert> Instead,
Robert> + a @code{SyntaxWarning} is generated which you can catch.

It seems to me that somewhat friendlier-for-gdb behavior would be to
throw gdb.GdbError if the parse fails.  That would do the right thing
for a typical command implementation.

Robert> Index: python/lib/gdb/printing.py

I think a new file would be preferable.
printing is for pretty-printing-related stuff, which this isn't.

How about "argparse.py"?  Or something along those lines?

Robert> Index: testsuite/gdb.python/py-prettyprint.exp

Likewise.

Tom



More information about the Gdb-patches mailing list