From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14067 invoked by alias); 11 Nov 2011 19:38:49 -0000 Received: (qmail 14055 invoked by uid 22791); 11 Nov 2011 19:38:48 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from kay.astro.Princeton.EDU (HELO mail.astro.princeton.edu) (128.112.24.221) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Nov 2011 19:38:34 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astro.princeton.edu (Postfix) with ESMTP id 85F901BC00585 for ; Fri, 11 Nov 2011 14:38:33 -0500 (EST) Received: from mail.astro.princeton.edu ([127.0.0.1]) by localhost (kay.astro.princeton.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id oFEsRSeuAYfP for ; Fri, 11 Nov 2011 14:38:33 -0500 (EST) X-Submitted: to mail.astro.princeton.edu (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: rhl) with ESMTP for ; Fri, 11 Nov 2011 14:38:33 -0500 (EST) From: Robert Lupton the Good Content-Type: multipart/mixed; boundary="Apple-Mail=_B2A88F9C-A066-46CB-A0E5-D1E3A9DCF8CD" Subject: Patch to add argument parsing classes to gdb Date: Fri, 11 Nov 2011 19:38:00 -0000 Message-Id: <412F240F-46E7-4A5C-8207-721E15A58B6D@astro.princeton.edu> To: gdb@sourceware.org Mime-Version: 1.0 (Apple Message framework v1251.1) Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-11/txt/msg00081.txt.bz2 --Apple-Mail=_B2A88F9C-A066-46CB-A0E5-D1E3A9DCF8CD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 874 Dear GDB, I'm attaching a patch that implements two classes, GdbOptionParser and GdbA= rgumentParser, which are built around python's standard optparse and argpar= se but play well with gdb (e.g. don't call exit if you make a typo or ask f= or help!). The code imports with python >=3D 2.3, but only provides the ar= gparse-based parser if you actually have argparse in your path (python =3D= =3D 2.7?). The patch: Implements the classes Adds docs Adds test cases What else do you need to get this into the source tree? I'm not sure how t= o deal with copyright assignment.=20=20 The patch comes from cvs, so I could just check it in, given the magic hand= shake, but I suspect that that's not the way you do things. In git/hg I co= uld issue a pull request... R P.S. Tom: this supersedes the patch I sent you a yesterday ago, and handles= --help better --Apple-Mail=_B2A88F9C-A066-46CB-A0E5-D1E3A9DCF8CD Content-Disposition: attachment; filename=rhl.argumentParsing.patch.2 Content-Type: application/octet-stream; name="rhl.argumentParsing.patch.2" Content-Transfer-Encoding: 7bit Content-length: 27314 ? .deps ? .gdbinit ? Makefile ? ada-exp.c ? ada-lex.c ? c-exp.c ? config.cache ? config.h ? config.log ? config.status ? cp-name-parser.c ? dbg.log ? f-exp.c ? gdb ? gdbtui ? init.c ? jv-exp.c ? m2-exp.c ? objc-exp.c ? observer.h ? observer.inc ? p-exp.c ? rhl.argumentParsing.patch ? rhl.argumentParsing.patch.2 ? stamp-h ? stamp-h1 ? stamp-xml ? testrun.log ? testrun.sum ? version.c ? xml-builtin.c ? data-directory/Makefile ? data-directory/python ? data-directory/stamp-python ? data-directory/stamp-syscalls ? data-directory/syscalls ? doc/GDBvn.texi ? doc/Makefile ? doc/annotate.info ? doc/gdb.aux ? doc/gdb.bt ? doc/gdb.cp ? doc/gdb.cps ? doc/gdb.fn ? doc/gdb.info ? doc/gdb.ky ? doc/gdb.log ? doc/gdb.pdf ? doc/gdb.pg ? doc/gdb.pgs ? doc/gdb.toc ? doc/gdb.tp ? doc/gdb.vr ? doc/gdbint.info ? doc/stabs.info ? gdbserver/Makefile ? gdbserver/amd64-avx-linux.c ? gdbserver/amd64-linux.c ? gdbserver/config.h ? gdbserver/config.log ? gdbserver/config.status ? gdbserver/gdbreplay ? gdbserver/gdbserver ? gdbserver/i386-avx-linux.c ? gdbserver/i386-linux.c ? gdbserver/i386-mmx-linux.c ? gdbserver/stamp-h ? gdbserver/stamp-xml ? gdbserver/version.c ? gdbserver/xml-builtin.c ? gnulib/.deps ? gnulib/Makefile ? gnulib/arg-nonnull.h ? gnulib/c++defs.h ? gnulib/string.h ? gnulib/warn-on-use.h ? gnulib/wchar.h ? python/lib/gdb/printing.pyc ? python/lib/gdb/prompt.pyc ? python/lib/gdb/types.pyc ? python/lib/gdb/command/__init__.pyc ? python/lib/gdb/command/pretty_printers.pyc ? python/lib/gdb/command/prompt.pyc ? testsuite/.gdb_history ? testsuite/Makefile ? testsuite/bigcore.corefile ? testsuite/config.log ? testsuite/config.status ? testsuite/dbg.log ? testsuite/gdb.base1 ? testsuite/gdb.base2 ? testsuite/gdb.log ? testsuite/gdb.sum ? testsuite/site.exp ? testsuite/tracecommandsscript ? testsuite/gdb.ada/Makefile ? testsuite/gdb.ada/gdb.log ? testsuite/gdb.ada/gdb.sum ? testsuite/gdb.ada/info_types ? testsuite/gdb.arch/Makefile ? testsuite/gdb.arch/amd64-byte ? testsuite/gdb.arch/amd64-disp-step ? testsuite/gdb.arch/amd64-dword ? testsuite/gdb.arch/amd64-entry-value ? testsuite/gdb.arch/amd64-i386-address ? testsuite/gdb.arch/amd64-prologue-xmm ? testsuite/gdb.arch/amd64-word ? testsuite/gdb.arch/gcore.test ? testsuite/gdb.arch/gdb.log ? testsuite/gdb.arch/gdb.sum ? testsuite/gdb.arch/i386-dr3-watch ? testsuite/gdb.arch/i386-permbkpt ? testsuite/gdb.arch/i386-signal ? testsuite/gdb.arch/i386-sse ? testsuite/gdb.arch/system-gcore ? testsuite/gdb.asm/Makefile ? testsuite/gdb.asm/asm-source ? testsuite/gdb.asm/gdb.log ? testsuite/gdb.asm/gdb.sum ? testsuite/gdb.base/Makefile ? testsuite/gdb.base/attach ? testsuite/gdb.base/bigcore ? testsuite/gdb.base/bigcore.corefile ? testsuite/gdb.base/break ? testsuite/gdb.base/breakpoint-shadow ? testsuite/gdb.base/complex ? testsuite/gdb.base/gcore ? testsuite/gdb.base/gcore.test ? testsuite/gdb.base/gdbvars ? testsuite/gdb.base/jump ? testsuite/gdb.base/multi-forks ? testsuite/gdb.base/opaque ? testsuite/gdb.base/pending ? testsuite/gdb.base/pendshr.sl ? testsuite/gdb.base/printcmds ? testsuite/gdb.base/prologue ? testsuite/gdb.base/randomize ? testsuite/gdb.base/restore ? testsuite/gdb.base/return ? testsuite/gdb.base/return-nodebug-int ? testsuite/gdb.base/return-nodebug-long ? testsuite/gdb.base/return-nodebug-long-long ? testsuite/gdb.base/return-nodebug-short ? testsuite/gdb.base/return-nodebug-signed-char ? testsuite/gdb.base/savedregs ? testsuite/gdb.base/setvar ? testsuite/gdb.base/siginfo-obj ? testsuite/gdb.base/signals ? testsuite/gdb.base/signest ? testsuite/gdb.base/so-impl-ld ? testsuite/gdb.base/solib1.sl ? testsuite/gdb.base/start ? testsuite/gdb.base/structs2 ? testsuite/gdb.base/tui-layout ? testsuite/gdb.base/ui-redirect ? testsuite/gdb.base/varargs ? testsuite/gdb.base/watch-read ? testsuite/gdb.base/watchpoint ? testsuite/gdb.base/watchpoint-cond-gone ? testsuite/gdb.base/watchpoints ? testsuite/gdb.cell/Makefile ? testsuite/gdb.cell/gdb.log ? testsuite/gdb.cell/gdb.sum ? testsuite/gdb.cp/Makefile ? testsuite/gdb.cp/abstract-origin ? testsuite/gdb.cp/annota2 ? testsuite/gdb.cp/annota3 ? testsuite/gdb.cp/anon-ns ? testsuite/gdb.cp/anon-struct ? testsuite/gdb.cp/anon-union ? testsuite/gdb.cp/arg-reference ? testsuite/gdb.cp/bool ? testsuite/gdb.cp/breakpoint ? testsuite/gdb.cp/bs15503 ? testsuite/gdb.cp/call-c ? testsuite/gdb.cp/casts ? testsuite/gdb.cp/class2 ? testsuite/gdb.cp/classes ? testsuite/gdb.cp/cmpd-minsyms ? testsuite/gdb.cp/converts ? testsuite/gdb.cp/cpexprs ? testsuite/gdb.cp/cplusfuncs ? testsuite/gdb.cp/cttiadd ? testsuite/gdb.cp/gdb.log ? testsuite/gdb.cp/gdb.sum ? testsuite/gdb.cp/pr9594 ? testsuite/gdb.disasm/Makefile ? testsuite/gdb.disasm/gdb.log ? testsuite/gdb.disasm/gdb.sum ? testsuite/gdb.dwarf2/Makefile ? testsuite/gdb.dwarf2/clztest ? testsuite/gdb.dwarf2/dup-psym.x ? testsuite/gdb.dwarf2/dw2-ada-ffffffff.x ? testsuite/gdb.dwarf2/dw2-anonymous-func.x ? testsuite/gdb.dwarf2/dw2-bad-parameter-type.x ? testsuite/gdb.dwarf2/dw2-basic.x ? testsuite/gdb.dwarf2/dw2-case-insensitive ? testsuite/gdb.dwarf2/dw2-compressed.x ? testsuite/gdb.dwarf2/dw2-const.x ? testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static ? testsuite/gdb.dwarf2/dw2-cu-size.x ? testsuite/gdb.dwarf2/dw2-double-set-die-type.x ? testsuite/gdb.dwarf2/dw2-empty-namespace.x ? testsuite/gdb.dwarf2/dw2-empty-pc-range.x ? testsuite/gdb.dwarf2/dw2-entry-value ? testsuite/gdb.dwarf2/dw2-filename.x ? testsuite/gdb.dwarf2/dw2-ifort-parameter ? testsuite/gdb.dwarf2/dw2-inheritance.x ? testsuite/gdb.dwarf2/dw2-inline-param ? testsuite/gdb.dwarf2/dw2-intercu.x ? testsuite/gdb.dwarf2/dw2-intermix.x ? testsuite/gdb.dwarf2/gdb.log ? testsuite/gdb.dwarf2/gdb.sum ? testsuite/gdb.fortran/Makefile ? testsuite/gdb.hp/Makefile ? testsuite/gdb.hp/gdb.aCC/Makefile ? testsuite/gdb.hp/gdb.base-hp/Makefile ? testsuite/gdb.hp/gdb.compat/Makefile ? testsuite/gdb.hp/gdb.defects/Makefile ? testsuite/gdb.hp/gdb.objdbg/Makefile ? testsuite/gdb.java/Makefile ? testsuite/gdb.mi/Makefile ? testsuite/gdb.modula2/Makefile ? testsuite/gdb.multi/Makefile ? testsuite/gdb.objc/Makefile ? testsuite/gdb.opencl/Makefile ? testsuite/gdb.opt/Makefile ? testsuite/gdb.pascal/Makefile ? testsuite/gdb.python/Makefile ? testsuite/gdb.python/py-prettyprint ? testsuite/gdb.python/py-prettyprint-cxx ? testsuite/gdb.python/py-prettyprint-rhl.exp ? testsuite/gdb.reverse/Makefile ? testsuite/gdb.server/Makefile ? testsuite/gdb.stabs/Makefile ? testsuite/gdb.threads/Makefile ? testsuite/gdb.trace/Makefile ? testsuite/gdb.xml/Makefile cvs diff: Diffing . Index: utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.265 diff -a -c -w -r1.265 utils.c *** utils.c 4 Nov 2011 16:45:12 -0000 1.265 --- utils.c 11 Nov 2011 19:20:09 -0000 *************** *** 729,736 **** --- 729,740 ---- struct timeval now_wall_time, delta_wall_time; gettimeofday (&now_wall_time, NULL); + #if 0 /* no timeval_sub */ timeval_sub (&delta_wall_time, &now_wall_time, &start_stats->start_wall_time); + #else + delta_wall_time.tv_sec = delta_wall_time.tv_usec = 0; /* HACK */ + #endif printf_unfiltered (msg_type == 0 ? _("Startup time: %ld.%06ld (cpu), %ld.%06ld (wall)\n") cvs diff: Diffing cli cvs diff: Diffing common cvs diff: Diffing config cvs diff: Diffing config/alpha cvs diff: Diffing config/arm cvs diff: Diffing config/djgpp cvs diff: Diffing config/i386 cvs diff: Diffing config/ia64 cvs diff: Diffing config/m32r cvs diff: Diffing config/m68k cvs diff: Diffing config/m88k cvs diff: Diffing config/mips cvs diff: Diffing config/pa cvs diff: Diffing config/powerpc cvs diff: Diffing config/rs6000 cvs diff: Diffing config/s390 cvs diff: Diffing config/sh cvs diff: Diffing config/sparc cvs diff: Diffing config/vax cvs diff: Diffing config/xtensa cvs diff: Diffing data-directory cvs diff: Diffing doc Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.890 diff -a -c -w -r1.890 gdb.texinfo *** doc/gdb.texinfo 8 Nov 2011 21:34:18 -0000 1.890 --- doc/gdb.texinfo 11 Nov 2011 19:20:12 -0000 *************** *** 21394,21399 **** --- 21394,21400 ---- * Events In Python:: Listening for events from @value{GDBN}. * Threads In Python:: Accessing inferior threads from Python. * Commands In Python:: Implementing new commands in Python. + * Argument Parsing In Python:: How to parse commands arguments in Python. * Parameters In Python:: Adding new @value{GDBN} parameters. * Functions In Python:: Writing new convenience functions. * Progspaces In Python:: Program spaces. *************** *** 22962,22967 **** --- 22963,22972 ---- ['1', '2 "3', '4 "5', "6 '7"] @end smallexample + If your arguments are more complicated, you might want to use GDB's versions + of Python's standard @code{optparse} or @code{argparse} modules; + @xref{Argument Parsing In Python}. + @end defun @cindex completion of Python commands *************** *** 23152,23157 **** --- 23157,23259 ---- Python code is read into @value{GDBN}, you may need to import the @code{gdb} module explicitly. + @node Argument Parsing In Python + @subsubsection Argument Parsing In Python + + @cindex argument parsing in python + @cindex python commands + There are two standard modules for parsing arguments in modern Pythons; + @code{optparse} and @code{argparse}. + @footnote{@code{optparse} appeared in Python 2.3, but is deprecated in favor of + @code{argparse} in Python 2.7} + GDB supports both, but doesn't emulate either --- you will have to write your + scripts to use whichever you prefer and is available to you. If you use an + unsupported parser an @code{ImportError} is thrown when you try to initialise it. + + It isn't possible to simply import one of Python's modules, as they + both exit if asked for help or if they detect an error parsing a + string --- and you don't want a typo to dump you out of GDB. Instead, + a @code{SyntaxWarning} is generated which you can catch. + + The two command parser classes are @code{gdb.printing.GdbOptionParser} + and @code{gdb.printing.GdbArgumentParser}. For details refer to the Python + manuals, but two simple examples are: + + @findex GdbOptionParser + @findex gdb.printing.GdbOptionParser + @smallexample + from gdb.printing import GdbOptionParser + + parser = GdbOptionParser("show image") + parser.add_option("-a", "--all", action="store_true", + help="Display the whole image") + + try: + (opts, args) = parser.parse_args(args) + catch SyntaxWarning: + return + @end smallexample + + and + + @findex GdbArgumentParser + @findex gdb.printing.GdbArgumentParser + @smallexample + from gdb.printing import GdbArgumentParser + + parser = GdbArgumentParser("show image") + parser.add_argument("-a", "--all", action="store_true", + help="Display the whole image") + parser.add_argument("image", help="Expression giving image to show") + + try: + opts = parser.parse_args(args) + except SyntaxWarning: + return + @end smallexample + + An example of [part of] a command (utilizing @code{GdbArgumentParser}) is: + + @smallexample + class PrintEigenCommand(gdb.Command): + """Print an eigen Matrix or Vector""" + + def __init__ (self): + super (PrintEigenCommand, self).__init__ ("show eigen", + gdb.COMMAND_DATA, + gdb.COMPLETE_SYMBOL) + + def invoke (self, args, fromTty): + self.dont_repeat() + + parser = GdbArgumentParser("show eigen") + parser.add_argument("-d", "--dataFmt", default="%.2f", help="Format") + parser.add_argument("eigenObject", help="Our Eigen::@{Matrix,Vector@}") + parser.add_argument("nx", help="Width of patch to print", + type=int, default=0, nargs="?") + parser.add_argument("ny", help="Height of patch to print", + type=int, default=0, nargs="?") + + try: + opts = parser.parse_args(args) + catch SyntaxWarning: + return + + var = gdb.parse_and_eval(opts.eigenObject) + nx = opts.nx + ny = opts.ny + # etc. + + PrintEigenCommand() + @end smallexample + after which we may issue commands such as: + @smallexample + show eigen --help + show eigen -d "%g" vec + show eigen *m->getVector() + show eigen *m->getVector() 5 + @end smallexample + @node Parameters In Python @subsubsection Parameters In Python cvs diff: Diffing features cvs diff: Diffing features/i386 cvs diff: Diffing features/rs6000 cvs diff: Diffing gdbserver cvs diff: Diffing gdbtk cvs diff: Diffing gdbtk/generic cvs diff: Diffing gdbtk/library cvs diff: Diffing gdbtk/library/help cvs diff: Diffing gdbtk/library/help/images cvs diff: Diffing gdbtk/library/help/trace cvs diff: Diffing gdbtk/library/images cvs diff: Diffing gdbtk/library/images2 cvs diff: Diffing gdbtk/plugins cvs diff: Diffing gdbtk/plugins/intel-pentium cvs diff: Diffing gdbtk/plugins/rhabout cvs diff: Diffing gnulib cvs diff: Diffing gnulib/extra cvs diff: Diffing gnulib/m4 cvs diff: Diffing mi cvs diff: Diffing osf-share cvs diff: Diffing osf-share/AT386 cvs diff: Diffing osf-share/HP800 cvs diff: Diffing osf-share/RIOS cvs diff: Diffing po cvs diff: Diffing python cvs diff: Diffing python/lib cvs diff: Diffing python/lib/gdb Index: python/lib/gdb/printing.py =================================================================== RCS file: /cvs/src/src/gdb/python/lib/gdb/printing.py,v retrieving revision 1.6 diff -a -c -w -r1.6 printing.py *** python/lib/gdb/printing.py 7 Oct 2011 22:46:14 -0000 1.6 --- python/lib/gdb/printing.py 11 Nov 2011 19:20:13 -0000 *************** *** 19,25 **** import gdb import gdb.types import re ! class PrettyPrinter(object): """A basic pretty-printer. --- 19,25 ---- import gdb import gdb.types import re ! import sys class PrettyPrinter(object): """A basic pretty-printer. *************** *** 206,208 **** --- 206,304 ---- # Cannot find a pretty printer. Return None. return None + # + # Now two argument parsers for users to use, based on python's (old) optparse + # and (new) argparse + # + # optparse first + # + try: + import optparse + + class GdbOptionParser(optparse.OptionParser): + """A subclass of the standard optparse OptionParser for gdb + + GdbOptionParser raises SyntaxWarning rather than exiting when asked for help, or + when given an illegal value. E.g. + + parser = gdb.printing.GdbOptionParser("show image") + parser.add_option("-a", "--all", action="store_true", + help="Display the whole image") + parser.add_option("-w", "--width", type="int", default=8, + help="Field width for pixels") + + try: + (opts, args) = parser.parse_args(args) + except SyntaxWarning: + return + """ + + def __init__(self, prog, *args, **kwargs): + """ + Like optparse.OptionParser's API, but with an initial command name argument + """ + # OptionParser is an old-style class, so no super + if not kwargs.get("prog"): + kwargs["prog"] = prog + optparse.OptionParser.__init__(self, *args, **kwargs) + + def parse_args(self, args, values=None): + """Call OptionParser.parse_args after running gdb.string_to_argv""" + if args is None: # defaults to sys.argv + args = "" + try: + args = gdb.string_to_argv(args) + except TypeError: + pass + + return optparse.OptionParser.parse_args(self, args, values) + + def exit(self, status=0, msg=""): + """Raise GdbError rather than exiting""" + raise SyntaxWarning(msg) + + except ImportError: + class GdbOptionParser(object): + def __init__(self, usage, *args, **kwargs): + raise ImportError("Unable to import optparse") + # + # Now argparse + # + try: + import argparse + + class GdbArgumentParser(argparse.ArgumentParser): + """A subclass of the standard argparse ArgumentParser for gdb + + GdbArgumentParser raises SyntaxWarning rather than exiting when asked for help, + or when given an illegal value. E.g. + + parser = gdb.printing.GdbArgumentParser("show image") + parser.add_argument("-a", "--all", action="store_true", + help="Display the whole image") + parser.add_argument("-f", "--formatWidth", type=int, default=8, + help="Field width for values") + parser.add_argument("image", help="Expression giving image to show") + + try: + opts = parser.parse_args(args) + except SyntaxWarning: + return + """ + def parse_args(self, args=None, namespace=None): + """Call ArgumentParser.parse_args after running gdb.string_to_argv""" + if args: + args = gdb.string_to_argv(args) + opts = argparse.ArgumentParser.parse_args(self, args, namespace) + + return argparse.ArgumentParser.parse_args(self, args, namespace) + + def exit(self, status=0, msg=None): + """Raise SyntaxWarning rather than exiting""" + raise SyntaxWarning(msg) + + except ImportError: + + class GdbArgumentParser(object): + def __init__(self, usage, *args, **kwargs): + raise ImportError("Unable to import argparse") cvs diff: Diffing python/lib/gdb/command cvs diff: Diffing regformats cvs diff: Diffing regformats/i386 cvs diff: Diffing regformats/rs6000 cvs diff: Diffing syscalls cvs diff: Diffing testsuite cvs diff: Diffing testsuite/config cvs diff: Diffing testsuite/gdb.ada cvs diff: Diffing testsuite/gdb.ada/array_bounds cvs diff: Diffing testsuite/gdb.ada/array_return cvs diff: Diffing testsuite/gdb.ada/array_subscript_addr cvs diff: Diffing testsuite/gdb.ada/arrayidx cvs diff: Diffing testsuite/gdb.ada/arrayparam cvs diff: Diffing testsuite/gdb.ada/arrayptr cvs diff: Diffing testsuite/gdb.ada/atomic_enum cvs diff: Diffing testsuite/gdb.ada/call_pn cvs diff: Diffing testsuite/gdb.ada/catch_ex cvs diff: Diffing testsuite/gdb.ada/char_enum cvs diff: Diffing testsuite/gdb.ada/char_param cvs diff: Diffing testsuite/gdb.ada/complete cvs diff: Diffing testsuite/gdb.ada/cond_lang cvs diff: Diffing testsuite/gdb.ada/dyn_loc cvs diff: Diffing testsuite/gdb.ada/exec_changed cvs diff: Diffing testsuite/gdb.ada/exprs cvs diff: Diffing testsuite/gdb.ada/fixed_cmp cvs diff: Diffing testsuite/gdb.ada/fixed_points cvs diff: Diffing testsuite/gdb.ada/formatted_ref cvs diff: Diffing testsuite/gdb.ada/frame_args cvs diff: Diffing testsuite/gdb.ada/fun_addr cvs diff: Diffing testsuite/gdb.ada/fun_in_declare cvs diff: Diffing testsuite/gdb.ada/funcall_param cvs diff: Diffing testsuite/gdb.ada/homonym cvs diff: Diffing testsuite/gdb.ada/int_deref cvs diff: Diffing testsuite/gdb.ada/interface cvs diff: Diffing testsuite/gdb.ada/lang_switch cvs diff: Diffing testsuite/gdb.ada/mi_catch_ex cvs diff: Diffing testsuite/gdb.ada/mi_task_info cvs diff: Diffing testsuite/gdb.ada/mod_from_name cvs diff: Diffing testsuite/gdb.ada/nested cvs diff: Diffing testsuite/gdb.ada/null_array cvs diff: Diffing testsuite/gdb.ada/null_record cvs diff: Diffing testsuite/gdb.ada/packed_array cvs diff: Diffing testsuite/gdb.ada/packed_tagged cvs diff: Diffing testsuite/gdb.ada/print_chars cvs diff: Diffing testsuite/gdb.ada/ptr_typedef cvs diff: Diffing testsuite/gdb.ada/ptype_field cvs diff: Diffing testsuite/gdb.ada/ptype_tagged_param cvs diff: Diffing testsuite/gdb.ada/rec_return cvs diff: Diffing testsuite/gdb.ada/ref_param cvs diff: Diffing testsuite/gdb.ada/ref_tick_size cvs diff: Diffing testsuite/gdb.ada/same_enum cvs diff: Diffing testsuite/gdb.ada/start cvs diff: Diffing testsuite/gdb.ada/str_ref_cmp cvs diff: Diffing testsuite/gdb.ada/sym_print_name cvs diff: Diffing testsuite/gdb.ada/taft_type cvs diff: Diffing testsuite/gdb.ada/tagged cvs diff: Diffing testsuite/gdb.ada/tasks cvs diff: Diffing testsuite/gdb.ada/tick_last_segv cvs diff: Diffing testsuite/gdb.ada/type_coercion cvs diff: Diffing testsuite/gdb.ada/uninitialized_vars cvs diff: Diffing testsuite/gdb.ada/variant_record_packed_array cvs diff: Diffing testsuite/gdb.ada/watch_arg cvs diff: Diffing testsuite/gdb.ada/widewide cvs diff: Diffing testsuite/gdb.arch cvs diff: Diffing testsuite/gdb.asm cvs diff: Diffing testsuite/gdb.base cvs diff: Diffing testsuite/gdb.base/comp-dir cvs diff: Diffing testsuite/gdb.base/comp-dir/subdir cvs diff: Diffing testsuite/gdb.cell cvs diff: Diffing testsuite/gdb.cp cvs diff: Diffing testsuite/gdb.disasm cvs diff: Diffing testsuite/gdb.dwarf2 cvs diff: Diffing testsuite/gdb.fortran cvs diff: Diffing testsuite/gdb.gdb cvs diff: Diffing testsuite/gdb.gdbtk cvs diff: Diffing testsuite/gdb.hp cvs diff: Diffing testsuite/gdb.hp/gdb.aCC cvs diff: Diffing testsuite/gdb.hp/gdb.base-hp cvs diff: Diffing testsuite/gdb.hp/gdb.compat cvs diff: Diffing testsuite/gdb.hp/gdb.defects cvs diff: Diffing testsuite/gdb.hp/gdb.objdbg cvs diff: Diffing testsuite/gdb.hp/gdb.objdbg/objdbg01 cvs diff: Diffing testsuite/gdb.hp/gdb.objdbg/objdbg02 cvs diff: Diffing testsuite/gdb.hp/gdb.objdbg/objdbg03 cvs diff: Diffing testsuite/gdb.hp/gdb.objdbg/objdbg04 cvs diff: Diffing testsuite/gdb.hp/gdb.objdbg/tools cvs diff: Diffing testsuite/gdb.hp/tools cvs diff: Diffing testsuite/gdb.java cvs diff: Diffing testsuite/gdb.mi cvs diff: Diffing testsuite/gdb.modula2 cvs diff: Diffing testsuite/gdb.multi cvs diff: Diffing testsuite/gdb.objc cvs diff: Diffing testsuite/gdb.opencl cvs diff: Diffing testsuite/gdb.opt cvs diff: Diffing testsuite/gdb.pascal cvs diff: Diffing testsuite/gdb.python Index: testsuite/gdb.python/py-prettyprint.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-prettyprint.exp,v retrieving revision 1.22 diff -a -c -w -r1.22 py-prettyprint.exp *** testsuite/gdb.python/py-prettyprint.exp 26 Jul 2011 18:38:55 -0000 1.22 --- testsuite/gdb.python/py-prettyprint.exp 11 Nov 2011 19:20:16 -0000 *************** *** 150,153 **** --- 150,212 ---- gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \ "print ss enabled #2" + # + # Tests for argument parsing + # + gdb_test_no_output "python from gdb.printing import GdbOptionParser" + + if [have_python_module "optparse"] { + gdb_test_no_output "python parser = GdbOptionParser(\"foo\")" + gdb_test_no_output "python parser.add_option('-a')" + gdb_test_no_output "python parser.add_option('--bool', action='store_true')" + + gdb_test "python opts, args = parser.parse_args('-h opt')" \ + "usage: foo .options.\r\n\r\noptions:\r\n -h, --help show this help message and exit\r\n -a A *\r\n --bool *\r.*" + + gdb_test_no_output "python opts, args = parser.parse_args(\[\])" + + gdb_test_no_output "python opts, args = parser.parse_args('-a AAA --bool opt')" + gdb_test "python print opts.a" "AAA" + gdb_test "python print opts.bool" "True" + gdb_test "python print ' '.join(args)" "opt" + gdb_test "python testOptionParsing(parser, '--bool arg1')" "arg1" + + gdb_test "python testOptionParsing(parser, '-x')" \ + "error: no such option: -x" + gdb_test "python testOptionParsing(parser, '-a')" \ + "foo: error: -a option requires an argument" + } + + # + # Now GdbArgumentParser + # + gdb_test_no_output "python from gdb.printing import GdbArgumentParser" + + if [have_python_module "argparse"] { + gdb_test_no_output "python parser = GdbArgumentParser(\"foo\")" + + gdb_test_no_output "python parser = GdbArgumentParser(\"foo\")" + gdb_test_no_output "python parser.add_argument('-a')" + gdb_test_no_output "python parser.add_argument('--bool', action='store_true')" + + gdb_test "python args = parser.parse_args('-h')" \ + "usage: foo .-h. .-a A. .--bool.\r\n\r\noptional arguments:\r\n -h, --help show this help message and exit\r\n -a A\r\n --bool\r.*" + + gdb_test_no_output "python args = parser.parse_args(\[\])" + + gdb_test_no_output "python parser.add_argument('opt')" + + gdb_test_no_output "python args = parser.parse_args('-a AAA --bool option')" + gdb_test "python print args.a" "AAA" + gdb_test "python print args.bool" "True" + gdb_test "python print args.opt" "option" + + gdb_test "python testArgumentParsing(parser, '')" \ + "error: too few arguments" + gdb_test "python testArgumentParsing(parser, '-x option')" \ + "error: unrecognized arguments: -x" + gdb_test "python testArgumentParsing(parser, '-a')" \ + "error: argument -a: expected one argument" + } + remote_file host delete ${remote_python_file} Index: testsuite/gdb.python/py-prettyprint.py =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-prettyprint.py,v retrieving revision 1.12 diff -a -c -w -r1.12 py-prettyprint.py *** testsuite/gdb.python/py-prettyprint.py 28 Jul 2011 10:36:40 -0000 1.12 --- testsuite/gdb.python/py-prettyprint.py 11 Nov 2011 19:20:16 -0000 *************** *** 280,282 **** --- 280,304 ---- register_pretty_printers () gdb.pretty_printers.append (lookup_function) + + def testOptionParsing(parser, argv=""): + """A helper routine for testing option parsing""" + try: + opts, args = parser.parse_args(argv) + except SyntaxWarning, e: + print e + return + + print " ".join(args) + + def testArgumentParsing(parser, argv=""): + """A helper routine for testing argument parsing""" + try: + opts = parser.parse_args(argv) + if opts.help: + return + except SyntaxWarning, e: + print e + return + + print "" cvs diff: Diffing testsuite/gdb.reverse cvs diff: Diffing testsuite/gdb.server cvs diff: Diffing testsuite/gdb.stabs cvs diff: Diffing testsuite/gdb.threads cvs diff: Diffing testsuite/gdb.trace cvs diff: Diffing testsuite/gdb.xml cvs diff: Diffing testsuite/lib Index: testsuite/lib/gdb.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v retrieving revision 1.192 diff -a -c -w -r1.192 gdb.exp *** testsuite/lib/gdb.exp 8 Nov 2011 08:23:49 -0000 1.192 --- testsuite/lib/gdb.exp 11 Nov 2011 19:20:17 -0000 *************** *** 1465,1470 **** --- 1465,1486 ---- return 0 } + # Return 1 if we can import a python module + + proc have_python_module {module} { + global gdb_prompt + + gdb_test_multiple "python import $module" "verify python has $module" { + -re "ImportError.*$gdb_prompt $" { + unsupported "$module is not available." + return 0 + } + -re "$gdb_prompt $" {} + } + + return 1 + } + # Return a 1 if we should skip shared library tests. proc skip_shlib_tests {} { cvs diff: Diffing tui --Apple-Mail=_B2A88F9C-A066-46CB-A0E5-D1E3A9DCF8CD Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Content-length: 2 --Apple-Mail=_B2A88F9C-A066-46CB-A0E5-D1E3A9DCF8CD--