This is the mail archive of the gdb-patches@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]

Re: [patch] Save the history by default


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 *,


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