public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>,
	GDB Patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH v2] Make '{add-,}symbol-file' not care about the position of command line arguments
Date: Thu, 30 Nov 2017 10:57:00 -0000	[thread overview]
Message-ID: <2fba79f1-e16e-38f2-bc0f-1c27da05e5c1@redhat.com> (raw)
In-Reply-To: <20171130042448.30882-1-sergiodj@redhat.com>

On 11/30/2017 04:24 AM, Sergio Durigan Junior wrote:
> Changes from v1:
> 
> - Commit message has been rewritten.
> 
> - Implemented position-independent argument parsing for
>   'add-symbol-file'.
> 
> - Added testcases.

Looks like you missed the comment about "--".  Take a look at
maintenance_print_symbols for an example of a command
that supports ending options with "--".  Can you add that
while you're at it, please?  For a test, I'd suggest
e.g., "symbol-file -- -non-existent-file" and confirming
gdb errors out.  That's simpler than actually creating a file.


> +      if (*arg != '-')
>  	{
> -	  /* It's an option (starting with '-') or it's an argument
> -	     to an option.  */
>  	  if (expecting_sec_name)
>  	    {
>  	      sect_opt sect = { arg, NULL };
>  	      sect_opts.push_back (sect);
> -	      expecting_sec_name = 0;
> +	      expecting_sec_name = false;
>  	    }
>  	  else if (expecting_sec_addr)
>  	    {
>  	      sect_opts.back ().value = arg;
> -	      expecting_sec_addr = 0;
> +	      expecting_sec_addr = false;
>  	    }
> -	  else if (strcmp (arg, "-readnow") == 0)
> -	    flags |= OBJF_READNOW;
> -	  else if (strcmp (arg, "-s") == 0)
> +	  else if (filename == NULL)
> +	    {
> +	      /* First non-option argument is always the filename.  */
> +	      filename.reset (tilde_expand (arg));
> +	    }
> +	  else if (!seen_addr)
>  	    {
> -	      expecting_sec_name = 1;
> -	      expecting_sec_addr = 1;
> +	      /* The second non-option argument is always the text
> +		 address at which to load the program.  */
> +	      sect_opt sect = { ".text", arg };
> +	      sect_opts.push_back (sect);
> +	      seen_addr = true;

Does this push_back directly here mean that these
two commands end up with different semantics?

 (gdb) add-symbol-file FILE 0 -s .text 0x1000
 (gdb) add-symbol-file -s .text 0x1000 FILE 0

Not sure that's a good idea.

Please add a test with "-s .text"...

> +# Check that we can pass parameters using any position in the command
> +# line.
> +gdb_test "add-symbol-file -readnow $binfile 0x0 -s .bss 0x3" \
> +    "Not confirmed\." \
> +    "add-symbol-file positionless -readnow" \
> +    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
> +    "n"
> +# When we use -s as the first argument, the section will be printed
> +# first as well.
> +gdb_test "add-symbol-file -s .bss 0x3 -readnow $binfile 0x0" \
> +    "Not confirmed\." \
> +    "add-symbol-file positionless -s" \
> +    "add symbol table from file \"${binfile}\" at\r\n\t\.bss_addr = 0x3\r\n\t\.text_addr = 0x0\r\n\\(y or n\\) " \
> +    "n"
> +gdb_test "add-symbol-file $binfile 0x0 -s .bss 0x3" \
> +    "Not confirmed\." \
> +    "add-symbol-file positionless -s, no -readnow" \
> +    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
> +    "n"

Using a number != 0x0 is a little better, since its easy for
a variable to end up always zero-initialized / zero-propagated
by mistake, and the test wouldn't notice.

> +# Since we're here, might as well test the 'symbol-file' command and
> +# if its arguments can also be passed at any position.
> +gdb_test "symbol-file -readnow $binfile" \
> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
> +    "symbol-file with -readnow first"
> +gdb_exit
> +gdb_start
> +gdb_reinitialize_dir $srcdir/$subdir

Just use clean_restart with no argument.

> +gdb_test "symbol-file $binfile -readnow" \
> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
> +    "symbol-file with -readnow second"
> +gdb_test "symbol-file -readnow" \
> +    "no symbol file name was specified" \
> +    "symbol-file without filename"
> +
> +gdb_exit
> +gdb_start
> +gdb_reinitialize_dir $srcdir/$subdir

Ditto.

> +
>  gdb_test "add-symbol-file ${binfile} 0 -s" \
>      "Missing section name after .-s." \
>      "add-symbol-file bare -s"
> 

Thanks,
Pedro Alves

  reply	other threads:[~2017-11-30 10:57 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
2016-07-12 14:27 ` Yao Qi
2016-10-04 18:07   ` Pedro Alves
2017-11-23  0:54     ` [PATCH v2] " Sergio Durigan Junior
2017-11-23 12:09       ` Pedro Alves
2017-11-23 17:21         ` Sergio Durigan Junior
2017-11-23 17:29           ` Pedro Alves
2017-11-24  4:54             ` Sergio Durigan Junior
2017-11-24 13:18               ` Pedro Alves
2017-11-24 20:27                 ` Sergio Durigan Junior
2017-11-27 19:13                   ` Pedro Alves
2017-11-29  0:59                     ` Sergio Durigan Junior
2017-11-29 12:23                       ` Pedro Alves
2017-11-23 15:59       ` Eli Zaretskii
2017-11-23 19:36         ` Sergio Durigan Junior
2016-10-04 18:06 ` [RFC/RFA] " Pedro Alves
2017-11-24 23:01 ` [PATCH v2] Add support for the --readnever command-line option Sergio Durigan Junior
2017-11-25  7:33   ` Eli Zaretskii
2017-11-25 16:41     ` Sergio Durigan Junior
2017-11-25 17:16       ` Eli Zaretskii
2017-11-29  1:21 ` [PATCH v3] Add support for the readnever concept Sergio Durigan Junior
2017-11-29  3:39   ` Eli Zaretskii
2017-11-29 12:25   ` Pedro Alves
2017-11-29 18:43     ` Sergio Durigan Junior
2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
2017-11-29 22:26       ` Pedro Alves
2017-11-29 22:42         ` Sergio Durigan Junior
2017-11-29 23:15           ` Pedro Alves
2017-11-30  0:08             ` Sergio Durigan Junior
2017-11-30  0:34               ` Pedro Alves
2017-11-30  4:07                 ` Sergio Durigan Junior
2017-11-30  4:25       ` [PATCH v2] Make '{add-,}symbol-file' " Sergio Durigan Junior
2017-11-30 10:57         ` Pedro Alves [this message]
2017-11-30 12:38           ` Sergio Durigan Junior
2017-11-30 12:49             ` Pedro Alves
2017-11-30 13:06               ` Sergio Durigan Junior
2017-11-30 13:33       ` [PATCH v3] " Sergio Durigan Junior
2017-11-30 15:01         ` Pedro Alves
2017-11-30 17:26           ` Sergio Durigan Junior
2017-11-30 17:37             ` Pedro Alves
2017-11-30 17:43               ` Sergio Durigan Junior
2017-11-30 17:50                 ` Pedro Alves
2017-11-30 20:00       ` [PATCH v4] " Sergio Durigan Junior
2017-12-01 12:11         ` Pedro Alves
2017-12-01 17:41           ` Sergio Durigan Junior
2017-12-01 21:45             ` Pedro Alves
2017-12-01 22:02               ` Sergio Durigan Junior
2017-11-30  0:25 ` [PATCH v4] Add support for the readnever concept Sergio Durigan Junior
2017-11-30 11:53   ` Pedro Alves
2017-12-01  4:35     ` Sergio Durigan Junior
2017-12-01 12:43       ` Pedro Alves
2017-12-01 17:19         ` Tom Tromey
2017-12-01 17:21           ` Sergio Durigan Junior
2017-12-01 20:00             ` Pedro Alves
2017-12-01 22:16 ` [PATCH v5] " Sergio Durigan Junior
2017-12-01 23:19   ` Pedro Alves
2017-12-02  2:31     ` Sergio Durigan Junior
2017-12-02  8:21   ` Eli Zaretskii

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=2fba79f1-e16e-38f2-bc0f-1c27da05e5c1@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.com \
    /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).