Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: mbilal <mbilal@codesourcery.com>
Cc: gdb-patches@sourceware.org, jan.kratochvil@redhat.com
Subject: Re: [PATCH 1/7] PR gdb/15224 "set history filename" to by immediately converted to absolute path
Date: Wed, 22 May 2013 17:51:00 -0000	[thread overview]
Message-ID: <519D05A1.8030509@redhat.com> (raw)
In-Reply-To: <5193676B.7000008@codesourcery.com>

On 05/15/2013 11:46 AM, mbilal wrote:

> On Wednesday, May 08, 2013 10:25 PM Pedro wrote:
>> In addition to my previous comments,  I realized that this will do the
>>wrong thing with "set history filename ~/foo".  Best use tilde_expand
>>and gdb_realpath
> 
> 'set history filename ~/foo' is working because following code is doing
> same as you described . I have also attached test case for this.

Ah, good.

> 2013-05-15  Muhammad Bilal <mbilal@codesourcery.com>
> 
>     PR gdb/15224

It would have been better to file a different PR for this
one, and then making 15224 depend on it.  This is a preexisting
bug, after all, that can be triggered no matter what the
default history filename is.

>     * top.c (set_history_filename): New function.

This is incomplete.  You must have done something with
the new function.  :-)

> 2013-05-15  Muhammad Bilal <mbilal@codesourcery.com>
> 
>     PR gdb/15224
>     * gdb.base/setshow.exp: Test 'set history filename' relative
>     path.

I think you meant "with a relative path".  But this tests more now.
Please make it complete.


> diff --git a/gdb/top.c b/gdb/top.c
> index 480b67e..45b83d7 100644
> --- a/gdb/top.c
> +++ b/gdb/top.c
> @@ -48,6 +48,7 @@
>  #include "interps.h"
>  #include "observer.h"
>  #include "maint.h"
> +#include "filenames.h"
>  
>  /* readline include files.  */
>  #include "readline/readline.h"
> @@ -1693,6 +1694,17 @@ show_exec_done_display_p (struct ui_file *file, int from_tty,
>                     value);
>  }
>  
> +static void
> +set_history_filename (char *args, int from_tty, struct cmd_list_element *c)
> +{
> +  /* We include the current directory so that if the user changes
> +     directories the file written will be the same as the one
> +     that was read.  */
> +  if (!IS_ABSOLUTE_PATH (history_filename))
> +    history_filename = concat (current_directory, "/", history_filename,
> +                              (char *) NULL);
> +}

This leaks the previous history_filename.  You can use reconcat
instead to address that.

> +
>  /* "set" command for the gdb_datadir configuration variable.  */
>  
>  static void
> @@ -1777,7 +1789,7 @@ variable \"HISTSIZE\", or to 256 if this variable is not set."),
>  Set the filename in which to record the command history"), _("\
>  Show the filename in which to record the command history"), _("\
>  (the list of previous commands of which a record is kept)."),
> -                           NULL,
> +                           set_history_filename,
>                             show_history_filename,
>                             &sethistlist, &showhistlist);
> diff --git a/gdb/testsuite/gdb.base/setshow.exp b/gdb/testsuite/gdb.base/setshow.exp
> index 6d250c0..5345b4b 100644
> --- a/gdb/testsuite/gdb.base/setshow.exp
> +++ b/gdb/testsuite/gdb.base/setshow.exp
> @@ -169,11 +169,24 @@ gdb_test_no_output "set height unlimited"
>  gdb_test_no_output "set history expansion on" "set history expansion on" 
>  #test show history expansion on
>  gdb_test "show history expansion on" "History expansion on command input is on.*" "show history expansion" 
> +#get home directory path
> +gdb_test_multiple "show environment HOME" "show home directory" {
> +    -re "\nHOME = (.*).\n.*$gdb_prompt $" {
> +       set HOME $expect_out(1,string)    
> +    }
> +}
> +#test set history filename ~/foobar.baz
> +gdb_test_no_output "set history filename ~/foobar.baz" \
> +    "set history filename ~/foobar.baz" 
> +#test show history filename ~/foobar.baz
> +gdb_test "show history filename" "The filename in which to record the command history is \"[file join $HOME foobar.baz]\"..*" \
> +    "show history filename ([file join $HOME foobar.baz])"     

The gdb_test_multiple above only sets HOME on success.  That means this will
explode with an access to an unknown symbol ($HOME) if the gdb_test_multiple
fails.

You can put the result of [file join $HOME foobar.baz] in a
variable and use that, instead of doing that twice:

  set filename [file join $HOME foobar.baz]

Actually, "file join" uses the build system's directory separator, but we
want the host's.  Actually^2, GDB always uses '/' here, so we can ignore
that and just do:

  set filename "$HOME/foobar.baz"

Also,

+gdb_test "show history filename" "The filename in which to record the command history is \"[file join $HOME foobar.baz]\"..*" \
+    "show history filename ([file join $HOME foobar.baz])"

Don't put that "([file join $HOME foobar.baz])" in the gdb.sum message,
as that will make the message depend on system/whoever runs it.

>  #test set history filename foobar.baz
>  gdb_test_no_output "set history filename foobar.baz" \
>      "set history filename foobar.baz" 
>  #test show history filename foobar.baz
> -gdb_test "show history filename" "The filename in which to record the command history is \"foobar.baz\"..*"  "show history filename (foobar.baz)" 
> +gdb_test "show history filename" "The filename in which to record the command history is \"[file join [pwd] foobar.baz]\"..*" \
> +    "show history filename ([file join [pwd] foobar.baz])" 

Another instance of the same problem mentioned before.  [pwd]
returns the current working directory on the build machine,
not the host's.  Use gdb's "pwd", not tcl's.

As long as we're breaking the long line with a \, please do it
before "The filename" too, so the line ends up a little shorter.

>  #test set history save on
>  gdb_test_no_output "set history save on" "set history save on" 
>  #test show history save on
> 

-- 
Pedro Alves


  reply	other threads:[~2013-05-22 17:51 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-06  9:39 [PATCH 0/7] PR gdb/15224 should "set history save on" by default mbilal
2013-05-06  9:40 ` [PATCH 1/7] " mbilal
2013-05-06  9:42   ` [PATCH 2/7] " mbilal
2013-05-06  9:43   ` [PATCH 3/7] " mbilal
     [not found]     ` <51877BC6.6080007@codesourcery.com>
2013-05-06  9:47       ` [PATCH 4/7] " mbilal
2013-05-07  9:40         ` Abid, Hafiz
2013-05-08 17:14         ` Pedro Alves
2013-05-06  9:48       ` [PATCH 5/7] " mbilal
2013-05-08  8:24         ` mbilal
2013-05-15 11:08           ` [PATCH 5/7] PR gdb/15224 , Change the default set history filename to ~/.gdb_history mbilal
2013-05-15 11:31             ` Eli Zaretskii
2013-05-15 12:07             ` mbilal
2013-05-15 13:27               ` Eli Zaretskii
2013-05-22 17:24                 ` Pedro Alves
2013-05-22 17:49                   ` Eli Zaretskii
2013-05-22 18:08                     ` Pedro Alves
2013-05-22 19:18                       ` Eli Zaretskii
2013-05-22 19:39                         ` Pedro Alves
2013-08-01 12:43                           ` Muhammad Bilal
2013-08-01 15:41                           ` Tom Tromey
2013-08-01 22:17                             ` Doug Evans
2013-05-22 12:02             ` mbilal
2013-05-08 17:05         ` [PATCH 5/7] PR gdb/15224 should "set history save on" by default Pedro Alves
2013-05-06  9:49       ` [PATCH 6/7] " mbilal
2013-05-06  9:51       ` [PATCH 7/7] " mbilal
2013-05-07 10:17         ` Abid, Hafiz
2013-05-08 17:08           ` Pedro Alves
2013-05-08  8:25         ` mbilal
2013-05-08 16:51           ` Eli Zaretskii
2013-05-08 17:18           ` Pedro Alves
2013-05-08  8:23       ` [PATCH 4/7] " mbilal
2013-05-09 11:12         ` mbilal
2013-05-09 12:05           ` Pedro Alves
     [not found]         ` <51936853.7050106@codesourcery.com>
     [not found]           ` <51936944.80108@codesourcery.com>
2013-05-15 10:56             ` [PATCH 4/7] Disable history saving for testsuit mbilal
2013-05-22 12:02               ` mbilal
2013-05-22 17:27               ` Pedro Alves
2013-05-08  8:23     ` [PATCH 3/7] PR gdb/15224 should "set history save on" by default mbilal
2013-05-08 16:24     ` Pedro Alves
2013-05-06 11:26   ` [PATCH 1/7] " Pedro Alves
     [not found]   ` <5188AA15.5010904@codesourcery.com>
2013-05-07  7:19     ` [PATCH 1/7] PR gdb/15224 "set history filename" to by immediately converted to absolute path mbilal
2013-05-07  8:39       ` Pedro Alves
     [not found]     ` <5188AC27.1050407@codesourcery.com>
2013-05-07  7:26       ` [PATCH 2/7] PR gdb/15224 fix for Unify interactivity tests to use input_from_terminal_p mbilal
2013-05-08  8:22         ` mbilal
2013-05-08 16:21           ` Pedro Alves
2013-05-09 11:08           ` mbilal
2013-05-09 11:32             ` Pedro Alves
2013-05-07 12:44     ` [PATCH 1/7] PR gdb/15224 "set history filename" to by immediately converted to absolute path mbilal
2013-05-08  8:22       ` mbilal
     [not found]         ` <519366E2.90105@codesourcery.com>
2013-05-15 10:46           ` mbilal
2013-05-22 17:51             ` Pedro Alves [this message]
2013-05-22 12:04           ` mbilal
2013-05-08 15:46       ` Pedro Alves
2013-05-08 17:25         ` Pedro Alves
2013-05-07 10:01 ` [PATCH 0/7] PR gdb/15224 should "set history save on" by default Abid, Hafiz
2013-08-06 16:35 ` Jan Kratochvil

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=519D05A1.8030509@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=mbilal@codesourcery.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