Re: [PATCH 1/7] PR gdb/15224 "set history filename" to by immediately converted to absolute path

mbilal
2013-05-15T10:46:09Z

[-- Attachment #1: Type: text/plain, Size: 1487 bytes --]

Hi,
Please find attached updated patch.

On Wednesday, May 08, 2013 8:47 PM Pedro wrote:

>Missing space before NULL. That's a lot of casting. We can just refer
>to history_filename directly. It'd be very good to have a comment here
with the
>rationale for this -- there's one in init_history we can reuse. So:

Fixed

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.

if (arg != NULL)
{
/* Clear trailing whitespace of filename. */
char *ptr = arg + strlen (arg) - 1;

while (ptr >= arg && (*ptr == ' ' || *ptr == '\t'))
ptr--;
*(ptr + 1) = '\0';

val = tilde_expand (arg);
}
else
val = xstrdup ("");

if (*(char **) c->var == NULL
|| strcmp (*(char **) c->var, val) != 0)
{
xfree (*(char **) c->var);
*(char **) c->var = val;

option_changed = 1;

2013-05-15 Muhammad Bilal <mbilal@codesourcery.com>

PR gdb/15224
* top.c (set_history_filename): New function.

2013-05-15 Muhammad Bilal <mbilal@codesourcery.com>

PR gdb/15224
* gdb.base/setshow.exp: Test 'set history filename' relative
path.

Thanks,
-Bilal

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 3041 bytes --]

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);
+}
+
/* "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])"
#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])"
#test set history save on
gdb_test_no_output "set history save on" "set history save on"
#test show history save on