* [patch] Save the history by default
@ 2009-09-08 20:05 Jan Kratochvil
2009-09-08 20:20 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2009-09-08 20:05 UTC (permalink / raw)
To: gdb; +Cc: gdb-patches
Hi,
as 7.0 is close I hope this FAQ item fix can pass flawlessly:
#gdb@irc.freenode.net:
(2008-06-10 00:23:22) matthewf: is there a way to have my gdb session history preserved?
(2008-06-10 00:23:49) matthewf: so that I can quit a gdb session, start a new one, and press up arrow to see my previous commands?
(2009-05-15 12:58:19) Guest75615: is the a way to display the gdb command history?
(2009-05-15 13:22:47) Guest75615 left the room.
(2009-05-15 19:54:46) Bircoph: hello, all; is there any way to save gdb CLI history, so after restarting gdb I'll have all it available?
The attached patch breaks backward compatibility with reading project's
specific ./.gdb_history files. I believe if someone is using such files
(me not) (s)he can add there appropriate `set history filename' to local
`.gdbinit' there. Tried a patch defaulting to ./.gdb_history and falling back
to $HOME/.gdb_history but I find it needlessly tricky. Experienced user can
set it straightforward way according to the needs, just the default should IMO
cover the major user base.
Following bash'es default of ~/.gdb_history or the readline's default of
~/.history. These GNU projects also do not use ./*history files by default.
Another related change is to save the history by default. I find already
inconsistent that history is being read by default but not written by default.
No regressions on {x86_64,i686}-fedora11-linux-gnu.
Thanks,
Jan
gdb/
2009-09-08 Jan Kratochvil <jan.kratochvil@redhat.com>
Save the command history by default and use a file in $HOME.
* NEWS: New note on the history file defaults change.
* top.c (init_history): Remove using current_directory. New
initialization of history_filename from $HOME.
(init_main): Initialize write_history_p by 1.
gdb/doc/
2009-09-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (set history filename @var{fname}): Use $HOME there.
(set history save): The default is now enabled.
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -81,6 +81,8 @@ registers on ARM targets. Both ARM GNU/Linux native GDB and gdbserver
can provide these registers (requires Linux 2.6.30 or later). Remote
and simulator targets may also provide them.
+* GDB now defaults to save the command history and using a file in $HOME.
+
* New remote packets
qSearch:memory:
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17722,15 +17722,15 @@ list, and where it writes the command history from this session when it
exits. You can access this list through history expansion or through
the history command editing characters listed below. This file defaults
to the value of the environment variable @code{GDBHISTFILE}, or to
-@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
-is not set.
+@file{$HOME/.gdb_history} (@file{$HOME/_gdb_history} on MS-DOS) if this
+variable is not set.
@cindex save command history
@kindex set history save
@item set history save
@itemx set history save on
Record command history in a file, whose name may be specified with the
-@code{set history filename} command. By default, this option is disabled.
+@code{set history filename} command. By default, this option is enabled.
@item set history save off
Stop recording command history in a file.
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1495,17 +1495,16 @@ init_history (void)
history_filename = xstrdup (tmpenv);
else if (!history_filename)
{
- /* 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. */
+ const char *homedir = getenv ("HOME");
#ifdef __MSDOS__
/* No leading dots in file names are allowed on MSDOS. */
- history_filename = concat (current_directory, "/_gdb_history",
- (char *)NULL);
+ const char append[] = "/_gdb_history";
#else
- history_filename = concat (current_directory, "/.gdb_history",
- (char *)NULL);
+ const char append[] = "/.gdb_history";
#endif
+
+ if (homedir)
+ history_filename = concat (homedir, append, (char *) NULL);
}
read_history (history_filename);
}
@@ -1567,7 +1566,7 @@ init_main (void)
/* Set the important stuff up for command editing. */
command_editing_p = 1;
history_expansion_p = 0;
- write_history_p = 0;
+ write_history_p = 1;
/* Setup important stuff for command line editing. */
rl_completion_word_break_hook = gdb_completion_word_break_characters;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] Save the history by default
2009-09-08 20:05 [patch] Save the history by default Jan Kratochvil
@ 2009-09-08 20:20 ` Eli Zaretskii
2009-09-08 20:37 ` Jan Kratochvil
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2009-09-08 20:20 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb, gdb-patches
> Date: Tue, 8 Sep 2009 22:05:37 +0200
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: gdb-patches@sourceware.org
>
> The attached patch breaks backward compatibility with reading project's
> specific ./.gdb_history files. I believe if someone is using such files
> (me not) (s)he can add there appropriate `set history filename' to local
> `.gdbinit' there. Tried a patch defaulting to ./.gdb_history and falling back
> to $HOME/.gdb_history but I find it needlessly tricky. Experienced user can
> set it straightforward way according to the needs, just the default should IMO
> cover the major user base.
How about trying both, like we do with .gdbinit?
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -81,6 +81,8 @@ registers on ARM targets. Both ARM GNU/Linux native GDB and gdbserver
> can provide these registers (requires Linux 2.6.30 or later). Remote
> and simulator targets may also provide them.
>
> +* GDB now defaults to save the command history and using a file in $HOME.
> +
> * New remote packets
>
> qSearch:memory:
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -17722,15 +17722,15 @@ list, and where it writes the command history from this session when it
> exits. You can access this list through history expansion or through
> the history command editing characters listed below. This file defaults
> to the value of the environment variable @code{GDBHISTFILE}, or to
> -@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
> -is not set.
> +@file{$HOME/.gdb_history} (@file{$HOME/_gdb_history} on MS-DOS) if this
> +variable is not set.
>
> @cindex save command history
> @kindex set history save
> @item set history save
> @itemx set history save on
> Record command history in a file, whose name may be specified with the
> -@code{set history filename} command. By default, this option is disabled.
> +@code{set history filename} command. By default, this option is enabled.
>
> @item set history save off
> Stop recording command history in a file.
These two parts are okay (assuming the code is accepted).
Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] Save the history by default
2009-09-08 20:20 ` Eli Zaretskii
@ 2009-09-08 20:37 ` Jan Kratochvil
2009-09-09 16:42 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2009-09-08 20:37 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb, gdb-patches
On Tue, 08 Sep 2009 22:17:05 +0200, Eli Zaretskii wrote:
> > Date: Tue, 8 Sep 2009 22:05:37 +0200
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> > Cc: gdb-patches@sourceware.org
> >
> > The attached patch breaks backward compatibility with reading project's
> > specific ./.gdb_history files. I believe if someone is using such files
> > (me not) (s)he can add there appropriate `set history filename' to local
> > `.gdbinit' there. Tried a patch defaulting to ./.gdb_history and falling back
> > to $HOME/.gdb_history but I find it needlessly tricky. Experienced user can
> > set it straightforward way according to the needs, just the default should IMO
> > cover the major user base.
>
> How about trying both, like we do with .gdbinit?
.gdbinit is being only read, multiple such files can be read.
History file should be (also) written to. History file should never be
readonly.
Formerly I had the patch below (this mail is not a submit for approval).
Modulo some stat() vs. access() it may be what you suggest? Still I find such
behavior too complicated to be convenient and therefore useful for this case.
One will get rather surprised why randomly this or that time (s)he has or does
not have the history available. (Tried at least the suggestive message
there.)
> These two parts are okay (assuming the code is accepted).
Thanks for the doc approval.
Thanks,
Jan
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -864,7 +864,7 @@ Can't attach to process and specify a core file at the same time."));
xfree (cmdarg);
/* Read in the old history after all the command files have been read. */
- init_history ();
+ init_history (quiet);
if (batch)
{
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1478,7 +1478,7 @@ set_verbose (char *args, int from_tty, struct cmd_list_element *c)
*/
void
-init_history (void)
+init_history (int quiet)
{
char *tmpenv;
@@ -1495,17 +1495,31 @@ init_history (void)
history_filename = xstrdup (tmpenv);
else if (!history_filename)
{
- /* 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. */
+ const char *homedir = getenv ("HOME");
#ifdef __MSDOS__
/* No leading dots in file names are allowed on MSDOS. */
- history_filename = concat (current_directory, "/_gdb_history",
- (char *)NULL);
+ const char append[] = "/_gdb_history";
#else
- history_filename = concat (current_directory, "/.gdb_history",
- (char *)NULL);
+ const char append[] = "/.gdb_history";
#endif
+
+ /* 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. */
+ history_filename = concat (current_directory, append, (char *) NULL);
+
+ if (homedir && strcmp (homedir, current_directory) != 0
+ && access (history_filename, F_OK) == 0)
+ {
+ if (!quiet)
+ printf_filtered (_("Using the local history file \"%s\".\n"),
+ history_filename);
+ }
+ else if (homedir)
+ {
+ xfree (history_filename);
+ history_filename = concat (homedir, append, (char *) NULL);
+ }
}
read_history (history_filename);
}
@@ -1567,7 +1581,7 @@ init_main (void)
/* Set the important stuff up for command editing. */
command_editing_p = 1;
history_expansion_p = 0;
- write_history_p = 0;
+ write_history_p = 1;
/* Setup important stuff for command line editing. */
rl_completion_word_break_hook = gdb_completion_word_break_characters;
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -38,7 +38,7 @@ extern void print_gdb_version (struct ui_file *);
extern void source_script (char *, int);
extern void cd_command (char *, int);
extern void read_command_file (FILE *);
-extern void init_history (void);
+extern void init_history (int quiet);
extern void command_loop (void);
extern void simplified_command_loop (char *(*read_input_func) (char *),
void (*execute_command_func) (char *,
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] Save the history by default
2009-09-08 20:37 ` Jan Kratochvil
@ 2009-09-09 16:42 ` Eli Zaretskii
0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2009-09-09 16:42 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb, gdb-patches
> Date: Tue, 8 Sep 2009 22:36:45 +0200
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: gdb@sourceware.org, gdb-patches@sourceware.org
>
> > How about trying both, like we do with .gdbinit?
>
> .gdbinit is being only read, multiple such files can be read.
>
> History file should be (also) written to. History file should never be
> readonly.
I didn't mean to use more than a single history file. What I meant
was to look for that file in both places, and use the first one you
find.
> Formerly I had the patch below (this mail is not a submit for approval).
> Modulo some stat() vs. access() it may be what you suggest?
Looks like it, yes.
> Still I find such behavior too complicated to be convenient and
> therefore useful for this case. One will get rather surprised why
> randomly this or that time (s)he has or does not have the history
> available.
How could that happen? If the file will be found with your suggested
code, it will certainly be found with what I suggest. Or am I missing
something?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] Save the history by default
2009-09-09 19:55 ` Mark Kettenis
@ 2009-09-09 22:32 ` Tom Tromey
0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2009-09-09 22:32 UTC (permalink / raw)
To: Mark Kettenis; +Cc: jan.kratochvil, gdb, gdb-patches
>>>>> "Mark" == Mark Kettenis <mark.kettenis@xs4all.nl> writes:
Mark> But I'm far less enthousiastic about changing things like "set
Mark> print object" that affect the output GDB generates for commands.
Why is that?
The reason I single this one out is that it is a very common user
question. I've answered it many times already.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] Save the history by default
2009-09-09 19:40 ` Tom Tromey
@ 2009-09-09 19:55 ` Mark Kettenis
2009-09-09 22:32 ` Tom Tromey
0 siblings, 1 reply; 7+ messages in thread
From: Mark Kettenis @ 2009-09-09 19:55 UTC (permalink / raw)
To: tromey; +Cc: jan.kratochvil, gdb, gdb-patches
> From: Tom Tromey <tromey@redhat.com>
> Date: Wed, 09 Sep 2009 13:40:22 -0600
>
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
>
> Jan> 2009-09-08 Jan Kratochvil <jan.kratochvil@redhat.com>
> Jan> Save the command history by default and use a file in $HOME.
>
> This idea is fine by me.
>
> I wouldn't mind changing other defaults too.
> We've discussed changing "set print object" a couple of times...
>
> I did not research this, but please make sure that this patch doesn't
> result in gdb saving history:
>
> 1. When in MI mode
> 2. When running the test suite
>
> Other than those possibilities, this seems fine.
>
> I think for changes to defaults it makes sense to wait a little while to
> let other maintainers speak up in case they have an objection. So
> please wait a little while before going ahead.
I have no objection to change *this* default since it doesn't really
change how you interact with GDB. But I'm far less enthousiastic
about changing things like "set print object" that affect the output
GDB generates for commands.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] Save the history by default
[not found] <20090908200537.GA14676__29508.7702492767$1252440377$gmane$org@host0.dyn.jankratochvil.net>
@ 2009-09-09 19:40 ` Tom Tromey
2009-09-09 19:55 ` Mark Kettenis
0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2009-09-09 19:40 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb, gdb-patches
>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
Jan> 2009-09-08 Jan Kratochvil <jan.kratochvil@redhat.com>
Jan> Save the command history by default and use a file in $HOME.
This idea is fine by me.
I wouldn't mind changing other defaults too.
We've discussed changing "set print object" a couple of times...
I did not research this, but please make sure that this patch doesn't
result in gdb saving history:
1. When in MI mode
2. When running the test suite
Other than those possibilities, this seems fine.
I think for changes to defaults it makes sense to wait a little while to
let other maintainers speak up in case they have an objection. So
please wait a little while before going ahead.
thanks,
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-09-09 22:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-08 20:05 [patch] Save the history by default Jan Kratochvil
2009-09-08 20:20 ` Eli Zaretskii
2009-09-08 20:37 ` Jan Kratochvil
2009-09-09 16:42 ` Eli Zaretskii
[not found] <20090908200537.GA14676__29508.7702492767$1252440377$gmane$org@host0.dyn.jankratochvil.net>
2009-09-09 19:40 ` Tom Tromey
2009-09-09 19:55 ` Mark Kettenis
2009-09-09 22:32 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox