From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24109 invoked by alias); 24 May 2010 16:27:19 -0000 Received: (qmail 24062 invoked by uid 22791); 24 May 2010 16:27:17 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,TW_RG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 May 2010 16:27:08 +0000 Received: from wpaz33.hot.corp.google.com (wpaz33.hot.corp.google.com [172.24.198.97]) by smtp-out.google.com with ESMTP id o4OGR5DY000481 for ; Mon, 24 May 2010 09:27:05 -0700 Received: from pwj9 (pwj9.prod.google.com [10.241.219.73]) by wpaz33.hot.corp.google.com with ESMTP id o4OGQS9E015695 for ; Mon, 24 May 2010 09:27:00 -0700 Received: by pwj9 with SMTP id 9so2693905pwj.38 for ; Mon, 24 May 2010 09:26:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.141.107.14 with SMTP id j14mr4223280rvm.181.1274718419684; Mon, 24 May 2010 09:26:59 -0700 (PDT) Received: by 10.140.255.14 with HTTP; Mon, 24 May 2010 09:26:59 -0700 (PDT) In-Reply-To: References: <20100522165438.5D5A48439A@ruffy.mtv.corp.google.com> Date: Mon, 24 May 2010 18:04:00 -0000 Message-ID: Subject: Re: [RFA] new python features: gdb.GdbError, gdb.string_to_argv From: Doug Evans To: Tom Tromey Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-05/txt/msg00549.txt.bz2 On Mon, May 24, 2010 at 8:35 AM, Tom Tromey wrote: >>>>>> "Doug" =3D=3D Doug Evans writes: > > Tom> I think you can use the built-in shlex.split for this. > > Doug> Depends I guess. > Doug> I remembered you saying we want to be able to write compatible > Doug> replacements for gdb commands in python, and some gdb commands use > Doug> libiberty's buildargv. > Doug> Ergo I wanted a 100% identical version of buildargv that I know I c= an > Doug> "just use" (e.g. without any needed extra, manual, error-prone setu= p), > Doug> and not worry about any differences between the behavior. > > Yeah, I definitely think that would be useful for some commands. > > When we talked about it on irc, I wasn't aware of the existence of the > shlex module. > > There isn't really any setup to speak of: > > import shlex > argv =3D shlex.split(arg) > > Doug> So, setting aside the implementation (i.e. maybe gdb.string_to_argv > Doug> could be implemented with shlex, or anything else), I still think > Doug> having it is reasonable. > Doug> But whatever, it's not that important. > > I think that in general we ought to provide gdb-specific facilities and > defer to the Python library when equivalent things already exist there. > That's one of the big benefits of picking a large popular language like > Python. > > I did not check to see that shlex.split is completely compatible with > buildargv. =A0I suspect it is. =A0But if not, I suppose that would be an > argument for including a new function. For reference sake shlex.split is not 100% compatible. There is support to write a compatible version, e.g. it has shlex.escapedquotes, but users shouldn't have to do that each time. OTOH, one could decide the difference isn't worth it. One issue I see is \ handling inside '. shell command parsing treats escapes differently in " vs '. (gdb) python print gdb.string_to_argv ("'a\ b'") ['a b'] (gdb) python print shlex.split ("'a\ b'") ['a\\ b'] OTOOH there's commands that use parse_to_comma. If gdb needs to provide that (if only implemented as a wrapper around some python-provided module, users should only ever have to import a function and invoke it), then I think it should provide both parse_to_comma and libiberty's buildargv. [for completeness sake there's also gdb commands that take / options, I'm not sure they need special parsing though] > If shlex.split fits the bill, I think it would be worthwhile to mention > this in the "Commands In Python" node. I think mentioning *something* in the docs is mandatory. GDB needs to provide guidance on how command arguments are to be parsed (at least by by convention). Otherwise every user-written command will parse its argument slightly differently.