This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Save the history by default


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]