public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org, m.weghorn@posteo.de
Subject: Re: [PATCH 09/16] gdb/python: change escaping rules when setting arguments
Date: Tue, 09 Jan 2024 18:30:28 +0200	[thread overview]
Message-ID: <83frz6pizf.fsf@gnu.org> (raw)
In-Reply-To: <db6a34d69f5c9ed07f650f90eb58c9719df06971.1704809585.git.aburgess@redhat.com> (message from Andrew Burgess on Tue, 9 Jan 2024 14:26:32 +0000)

> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>, Michael Weghorn <m.weghorn@posteo.de>
> Date: Tue,  9 Jan 2024 14:26:32 +0000
> 
> It is possible to set an inferior's arguments through the Python API
> by assigning to the gdb.Inferior.arguments attribute.
> 
> This attribute can be assigned a string, in which case the string is
> taken verbatim as the inferior's argument string.  Or this attribute
> can be assigned a sequence, in which case the members of the sequence
> are combined (with some escaping applied) to create the inferior's
> argument string.
> 
> Currently, the when the arguments from a Python list are escaped, we
> use escape_shell_characters.  I suspect the reasons for this are
> mostly accidental.
> 
> When the gdb.Inferior.arguments attribute was introduced in commit:
> 
>   commit 3153113252f3b949a159439a17e88af8ff0dce30
>   Date:   Mon May 1 13:53:59 2023 -0600
> 
>       Add attributes and methods to gdb.Inferior
> 
> GDB's inferior::set_args method called construct_inferior_arguments,
> and construct_inferior_arguments didn't take an escaping function as a
> parameter, the only option was escape_shell_characters as that was the
> escaping hard-coded into construct_inferior_arguments.  The commit
> message makes no comments for or against escaping of special shell
> characters, and no tests were added that checked this behaviour.  All
> of this leads me to think that the handling of special shell
> characters wasn't really considered (an understandable oversight).
> 
> But I'd like to consider it, and I think the current behaviour is not
> ideal.
> 
> Consider this case:
> 
>   (gdb) python gdb.selected_inferior().arguments = ['$VAR']
>   (gdb) show args
>   Argument list to give program being debugged when it is started is "\$VAR".
> 
> This means that when the inferior is run it will see literal '$VAR' as
> its argument.  If instead, the user wants to pass the shell expanded
> value of $VAR to the inferior, there's no way to achieve this result
> using the list assignment method.
> 
> In this commit I propose that we change this behaviour so that we
> instead see this:
> 
>   (gdb) python gdb.selected_inferior().arguments = ['$VAR']
>   (gdb) show args
>   Argument list to give program being debugged when it is started is "$VAR".
> 
> Now the '$' character is not escaped.  If the inferior is started
> under a shell then the user will see the shell expanded value of
> '$VAR'.
> 
> Of course, if the user wants to pass a literal '$VAR' (with no
> expansion) then they can do:
> 
>   (gdb) python gdb.selected_inferior().arguments = ['\$VAR']
> 
> This actually feels more natural to me, the user writes the argument
> as they would present it to a shell.
> 
> So, after this commit, GDB only escapes quote characters and white
> space characters.  This keeps some level of backward compatibility
> with the existing behaviour (for things other than shell special
> characters), but also seems natural, from the user's point of view,
> the arguments they are providing are already quoted (by Python's
> string quotes) so there's no need to quote white space.  It's only
> when GDB converts the Python sequence into a single string that the
> white space actually needs quoting.
> 
> There are tests for the updated functionality, and I've updated the
> docs and added a NEWS entry.
> ---
>  gdb/NEWS                                 |  4 +++
>  gdb/doc/python.texi                      |  7 +++--
>  gdb/python/py-inferior.c                 |  2 +-
>  gdb/testsuite/gdb.python/py-inferior.exp | 36 ++++++++++++++++++++----
>  gdbsupport/common-inferior.cc            | 14 +++++++++
>  gdbsupport/common-inferior.h             |  5 ++++
>  6 files changed, 60 insertions(+), 8 deletions(-)

The documentation parts are okay, thanks.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

  reply	other threads:[~2024-01-09 16:30 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 14:26 [PATCH 00/16] Inferior argument (inc for remote targets) changes Andrew Burgess
2024-01-09 14:26 ` [PATCH 01/16] libiberty/buildargv: POSIX behaviour for backslash handling Andrew Burgess
2024-01-09 14:26 ` [PATCH 02/16] gdb/testsuite: add some xfail in gdb.base/startup-with-shell.exp Andrew Burgess
2024-01-09 14:26 ` [PATCH 03/16] gdb: Support some escaping of args with startup-with-shell being off Andrew Burgess
2024-01-09 14:26 ` [PATCH 04/16] gdb: remove the !startup_with_shell path from construct_inferior_arguments Andrew Burgess
2024-01-21  3:56   ` Keith Seitz
2024-01-09 14:26 ` [PATCH 05/16] gdbserver: convert program_args to a single string Andrew Burgess
2024-01-09 14:26 ` [PATCH 06/16] gdbsupport: have construct_inferior_arguments take an escape function Andrew Burgess
2024-01-09 14:26 ` [PATCH 07/16] gdbsupport: split escape_shell_characters in two Andrew Burgess
2024-01-09 14:26 ` [PATCH 08/16] gdb: move remote arg splitting and joining into gdbsupport/ Andrew Burgess
2024-01-21  3:57   ` Keith Seitz
2024-01-09 14:26 ` [PATCH 09/16] gdb/python: change escaping rules when setting arguments Andrew Burgess
2024-01-09 16:30   ` Eli Zaretskii [this message]
2024-01-09 14:26 ` [PATCH 10/16] gdb: add remote argument passing self tests Andrew Burgess
2024-01-21  3:57   ` Keith Seitz
2024-01-09 14:26 ` [PATCH 11/16] gdb/gdbserver: pass inferior arguments as a single string Andrew Burgess
2024-01-09 16:34   ` Eli Zaretskii
2024-01-09 16:35   ` Eli Zaretskii
2024-01-09 14:26 ` [PATCH 12/16] gdb/gdbserver: add a '--no-escape-args' command line option Andrew Burgess
2024-01-09 16:43   ` Eli Zaretskii
2024-01-21  3:57   ` Keith Seitz
2024-01-09 14:26 ` [PATCH 13/16] gdb: allow 'set args' and run commands to contain newlines Andrew Burgess
2024-01-09 16:44   ` Eli Zaretskii
2024-01-21  3:57   ` Keith Seitz
2024-01-09 14:26 ` [PATCH 14/16] gdb/gdbserver: remove some uses of free_vector_argv Andrew Burgess
2024-01-09 14:26 ` [PATCH 15/16] gdb: new maintenance command to help debug remote argument issues Andrew Burgess
2024-01-09 16:32   ` Eli Zaretskii
2024-01-21  3:57   ` Keith Seitz
2024-01-09 14:26 ` [PATCH 16/16] gdb/gdbserver: rework argument splitting and joining Andrew Burgess
2024-01-09 16:37   ` Eli Zaretskii
2024-01-21  3:57   ` Keith Seitz
2024-01-09 16:58 ` [PATCH 00/16] Inferior argument (inc for remote targets) changes Eli Zaretskii
2024-01-20 22:46   ` Andrew Burgess
2024-01-21 10:22     ` Eli Zaretskii
2024-01-22 10:29       ` Andrew Burgess
2024-01-10  8:28 ` Michael Weghorn
2024-01-21  3:56 ` Keith Seitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83frz6pizf.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=m.weghorn@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).