public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 04/16] gdb: remove the !startup_with_shell path from construct_inferior_arguments
Date: Sat, 20 Jan 2024 19:56:58 -0800	[thread overview]
Message-ID: <90e7d4f6-ed31-421c-a896-750fe6e382a3@redhat.com> (raw)
In-Reply-To: <f5cc99ef257169bc40a70f4d2aacaade515cc652.1704809585.git.aburgess@redhat.com>

On 1/9/24 06:26, Andrew Burgess wrote:
> diff --git a/gdbsupport/common-inferior.cc b/gdbsupport/common-inferior.cc
> index 55149ec1f13..076ddc73d51 100644
> --- a/gdbsupport/common-inferior.cc
> +++ b/gdbsupport/common-inferior.cc
> @@ -32,92 +32,66 @@ construct_inferior_arguments (gdb::array_view<char * const> argv)
>   {
>     std::string result;
>   
> -  if (startup_with_shell)
> -    {
>   #ifdef __MINGW32__
> -      /* This holds all the characters considered special to the
> -	 Windows shells.  */
> -      static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n";
> -      static const char quote = '"';
> +  /* This holds all the characters considered special to the
> +     Windows shells.  */
> +  static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n";
> +  static const char quote = '"';
>   #else
> -      /* This holds all the characters considered special to the
> -	 typical Unix shells.  We include `^' because the SunOS
> -	 /bin/sh treats it as a synonym for `|'.  */
> -      static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
> -      static const char quote = '\'';
> +  /* This holds all the characters considered special to the
> +     typical Unix shells.  We include `^' because the SunOS
> +     /bin/sh treats it as a synonym for `|'.  */
> +  static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
> +  static const char quote = '\'';
>   #endif
> -      for (int i = 0; i < argv.size (); ++i)
> +  for (int i = 0; i < argv.size (); ++i)
> +    {
> +      if (i > 0)
> +	result += ' ';
> +
> +      /* Need to handle empty arguments specially.  */
> +      if (argv[i][0] == '\0')
>   	{
> -	  if (i > 0)
> -	    result += ' ';
> +	  result += quote;
> +	  result += quote;
> +	}
> +      else
> +	{
> +#ifdef __MINGW32__
> +	  bool quoted = false;
>   
> -	  /* Need to handle empty arguments specially.  */
> -	  if (argv[i][0] == '\0')
> +	  if (strpbrk (argv[i], special))
>   	    {
> -	      result += quote;
> +	      quoted = true;
>   	      result += quote;
>   	    }
> -	  else
> +#endif
> +	  for (char *cp = argv[i]; *cp; ++cp)

Re: "*cp": Didn't we move to explicit checks some time ago?

Keith

>   	    {
> -#ifdef __MINGW32__
> -	      bool quoted = false;
> -
> -	      if (strpbrk (argv[i], special))
> +	      if (*cp == '\n')
>   		{
> -		  quoted = true;
> +		  /* A newline cannot be quoted with a backslash (it
> +		     just disappears), only by putting it inside
> +		     quotes.  */
> +		  result += quote;
> +		  result += '\n';
>   		  result += quote;
>   		}
> -#endif
> -	      for (char *cp = argv[i]; *cp; ++cp)
> +	      else
>   		{
> -		  if (*cp == '\n')
> -		    {
> -		      /* A newline cannot be quoted with a backslash (it
> -			 just disappears), only by putting it inside
> -			 quotes.  */
> -		      result += quote;
> -		      result += '\n';
> -		      result += quote;
> -		    }
> -		  else
> -		    {
>   #ifdef __MINGW32__
> -		      if (*cp == quote)
> +		  if (*cp == quote)
>   #else
> -		      if (strchr (special, *cp) != NULL)
> +		    if (strchr (special, *cp) != NULL)
>   #endif
> -			result += '\\';
> -		      result += *cp;
> -		    }
> +		      result += '\\';
> +		  result += *cp;
>   		}
> +	    }
>   #ifdef __MINGW32__
> -	      if (quoted)
> -		result += quote;
> +	  if (quoted)
> +	    result += quote;
>   #endif
> -	    }
> -	}
> -    }
> -  else
> -    {
> -      /* In this case we can't handle arguments that contain spaces,
> -	 tabs, or newlines -- see breakup_args().  */
> -      for (char *arg : argv)
> -	{
> -	  char *cp = strchr (arg, ' ');
> -	  if (cp == NULL)
> -	    cp = strchr (arg, '\t');
> -	  if (cp == NULL)
> -	    cp = strchr (arg, '\n');
> -	  if (cp != NULL)
> -	    error (_("can't handle command-line "
> -		     "argument containing whitespace"));
> -	}
> -
> -      for (int i = 0; i < argv.size (); ++i)
> -	{
> -	  if (i > 0)
> -	    result += " ";
> -	  result += argv[i];
>   	}
>       }
>   


  reply	other threads:[~2024-01-21  3:57 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 [this message]
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
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=90e7d4f6-ed31-421c-a896-750fe6e382a3@redhat.com \
    --to=keiths@redhat.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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).