From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21035 invoked by alias); 8 Sep 2009 20:37:07 -0000 Received: (qmail 20945 invoked by uid 22791); 8 Sep 2009 20:37:06 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Sep 2009 20:36:55 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n88KapUW013200; Tue, 8 Sep 2009 16:36:51 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n88KamVQ009081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 8 Sep 2009 16:36:50 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n88KalkN017143; Tue, 8 Sep 2009 22:36:47 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id n88Kajef017140; Tue, 8 Sep 2009 22:36:45 +0200 Date: Tue, 08 Sep 2009 20:37:00 -0000 From: Jan Kratochvil To: Eli Zaretskii Cc: gdb@sourceware.org, gdb-patches@sourceware.org Subject: Re: [patch] Save the history by default Message-ID: <20090908203645.GA16820@host0.dyn.jankratochvil.net> References: <20090908200537.GA14676@host0.dyn.jankratochvil.net> <83fxax2num.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <83fxax2num.fsf@gnu.org> User-Agent: Mutt/1.5.19 (2009-01-05) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-09/txt/msg00226.txt.bz2 On Tue, 08 Sep 2009 22:17:05 +0200, Eli Zaretskii wrote: > > Date: Tue, 8 Sep 2009 22:05:37 +0200 > > From: Jan Kratochvil > > 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 *,