From patchwork Fri Dec 5 00:19:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 4075 Received: (qmail 20443 invoked by alias); 5 Dec 2014 00:19:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 20425 invoked by uid 89); 5 Dec 2014 00:19:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mail-qg0-f48.google.com Received: from mail-qg0-f48.google.com (HELO mail-qg0-f48.google.com) (209.85.192.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 05 Dec 2014 00:19:34 +0000 Received: by mail-qg0-f48.google.com with SMTP id q107so13602988qgd.35 for ; Thu, 04 Dec 2014 16:19:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=hm+1y6pJtR+K2bHvtQ/hjC8ag7rAcdfQiqg+lFutDvc=; b=KfVVjbCpUo0OVLOiaeJqfVIUToA6bSvbtI9vJPva3RyugLwXiMDZQVzMLUmO6P3sdT 3rrxvYzluawsAihnDg5P/40rfJBPpiz2kO9labwqTwLGFgT8+0oOf4t40DSLzYVz3bNl HfcHbNJN5O23/50ZG7Q19MKIVnDqC44F1DjM36yutblyVP1cNdbyDx81bs5keTwpx8Qh VM03nXqyusRVbOhbzbDklm+kFTFqCqYamkrE08QnZ0pQjDEorwhaYgo5kgg7uoDmx1MK msdeN0BR7Sm+KozBn0Wv6qxLcV/B8XAnJmkqE4+6cXGLquZWSXoDuZ/97BxtqehlEdFS OKpA== X-Gm-Message-State: ALoCoQkYdpcqc/cyfEPs+G0DnQoZOxgxsg17CU4S7VIkZc3Is0y9yJoiPP23KyTLje5viqmcmqY+ X-Received: by 10.224.38.71 with SMTP id a7mr21284879qae.24.1417738772356; Thu, 04 Dec 2014 16:19:32 -0800 (PST) Received: from [192.168.1.130] (ool-4353af5c.dyn.optonline.net. [67.83.175.92]) by mx.google.com with ESMTPSA id s3sm28232966qat.4.2014.12.04.16.19.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Dec 2014 16:19:31 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 4 Dec 2014 19:19:18 -0500 (EST) To: Pedro Alves cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Append to input history file instead of overwriting it In-Reply-To: <54808956.9070507@redhat.com> Message-ID: References: <1417226462-11254-1-git-send-email-patrick@parcs.ath.cx> <54808956.9070507@redhat.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 X-IsSubscribed: yes On Thu, 4 Dec 2014, Pedro Alves wrote: > On 11/29/2014 02:01 AM, Patrick Palka wrote: >> This patch makes readline append new history lines to the GDB history >> file on exit instead of overwriting the entire history file on exit. >> This change allows us to run multiple simultaneous GDB sessions without >> having each session overwrite the added history of each other session on >> exit. It is particularly helpful when debugging GDB with GDB. >> >> Does this look OK to commit? Tested on x86_64-unknown-linux-gnu. > > Does this mean the history file will keep growing forever, rather than > be trimmed by the history size? That it does... my .gdb_history is up to 2200 lines already! Looks like we have to explicitly truncate the history file on exit after appending to it. Here's v2 of the patch that initializes the static variable command_count, and calls history_truncate_file() appropriately. Does it look OK? > > Thanks, > Pedro Alves > > -- >8 -- Subject: [PATCH] Append to input history file instead of overwriting it This patch makes readline append new history lines to the GDB history file on exit instead of overwriting the entire history file on exit. This change allows us to run multiple simultaneous GDB sessions without having each session overwrite the added history of each other session on exit. It is particularly helpful when debugging GDB with GDB. gdb/ChangeLog: * top.h (gdb_add_history): Declare. * top.c (command_count): New variable. (gdb_add_history): New function. (quit_force): Append to history file instead of overwriting it. Truncate the history file afterwards. (command_line_input): Use gdb_add_history instead of add_history. * event-top.c (command_line_handler): Likewise. --- gdb/event-top.c | 2 +- gdb/top.c | 20 +++++++++++++++++--- gdb/top.h | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index cb438ac..490bca6 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -667,7 +667,7 @@ command_line_handler (char *rl) /* Add line to history if appropriate. */ if (*linebuffer && input_from_terminal_p ()) - add_history (linebuffer); + gdb_add_history (linebuffer); /* Note: lines consisting solely of comments are added to the command history. This is useful when you type a command, and then diff --git a/gdb/top.c b/gdb/top.c index c4b5c2c..9a5ed1e 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -895,7 +895,20 @@ gdb_rl_operate_and_get_next (int count, int key) return rl_newline (1, key); } - + +/* Number of user commands executed during this session. */ + +static int command_count = 0; + +/* Add the user command COMMAND to the input history list. */ + +void +gdb_add_history (const char *command) +{ + add_history (command); + command_count++; +} + /* Read one line from the command input stream `instream' into the local static buffer `linebuffer' (whose current length is `linelength'). @@ -1090,7 +1103,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix) /* Add line to history if appropriate. */ if (*linebuffer && input_from_terminal_p ()) - add_history (linebuffer); + gdb_add_history (linebuffer); /* Save into global buffer if appropriate. */ if (repeat) @@ -1441,7 +1454,8 @@ quit_force (char *args, int from_tty) { if (write_history_p && history_filename && input_from_terminal_p ()) - write_history (history_filename); + append_history (command_count, history_filename); + history_truncate_file (history_filename, history_max_entries); } DO_PRINT_EX; diff --git a/gdb/top.h b/gdb/top.h index 94f6c48..d8baea8 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -79,6 +79,8 @@ extern int history_expansion_p; extern int server_command; extern char *lim_at_start; +extern void gdb_add_history (const char *); + extern void show_commands (char *args, int from_tty); extern void set_history (char *, int);