This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] new python features: gdb.GdbError, gdb.string_to_argv


On Mon, May 24, 2010 at 8:35 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Doug" == Doug Evans <dje@google.com> 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 can
> Doug> "just use" (e.g. without any needed extra, manual, error-prone setup),
> 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 = 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. ?I suspect it is. ?But 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]