Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb@sourceware.org, gdb-patches@sourceware.org
Subject: Re: [patch] Save the history by default
Date: Tue, 08 Sep 2009 20:37:00 -0000	[thread overview]
Message-ID: <20090908203645.GA16820@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <83fxax2num.fsf@gnu.org>

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


  reply	other threads:[~2009-09-08 20:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-08 20:05 Jan Kratochvil
2009-09-08 20:20 ` Eli Zaretskii
2009-09-08 20:37   ` Jan Kratochvil [this message]
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

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=20090908203645.GA16820@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=gdb@sourceware.org \
    /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