From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by sourceware.org (Postfix) with ESMTPS id C438B3858D38 for ; Sun, 29 Jan 2023 16:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C438B3858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id 711651004824A for ; Sun, 29 Jan 2023 16:21:23 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id MAQlpch6Nc5SPMAQlpElVi; Sun, 29 Jan 2023 16:21:23 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=e7bD9Yl/ c=1 sm=1 tr=0 ts=63d69d03 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=RvmDmJFTN0MA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=mDV3o1hIAAAA:8 a=Chy_cNCYEP2WvqLK1q8A:9 a=ul9cdbp4aOFLsgKbc677:22 a=_FVE-zBwftR9WsbkzFJk:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=6Ko3gcQpFXu2iL/4Lbixw1epHaVJhXpMvG08Oju48OA=; b=ZCOOpE5Z/Gt2CzpbGL2Q8dB14n EyU57VFgcZgxJE4MfbPp9L/FVTWPhYq59AzXAjn5vM5kdq4/xQ/YOFA+mgRry+DiLP8ojm4uECrDD eWpBT7O4xJ/HhH9Fyyab7YIVy; Received: from 75-166-146-144.hlrn.qwest.net ([75.166.146.144]:59376 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pMAQl-001fCo-1N; Sun, 29 Jan 2023 09:21:23 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/5] Add "save history" command Date: Sun, 29 Jan 2023 09:21:05 -0700 Message-Id: <20230129162105.526266-6-tom@tromey.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230129162105.526266-1-tom@tromey.com> References: <20230129162105.526266-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.146.144 X-Source-L: No X-Exim-ID: 1pMAQl-001fCo-1N X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-146-144.hlrn.qwest.net (localhost.localdomain) [75.166.146.144]:59376 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_SHORT,RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: PR cli/23664 points out that it would sometimes be convenient to immediately save the current history to a file. This patch implements this feature. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23664 --- gdb/NEWS | 3 +++ gdb/doc/gdb.texinfo | 8 ++++++ gdb/testsuite/gdb.base/save-history.exp | 36 +++++++++++++++++++++++++ gdb/top.c | 18 +++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 gdb/testsuite/gdb.base/save-history.exp diff --git a/gdb/NEWS b/gdb/NEWS index a5b6f8df2ff..0003dfc9bcb 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -17,6 +17,9 @@ maintenance print record-instruction [ N ] prints how GDB would undo the N-th previous instruction, and if N is positive, it prints how GDB will redo the N-th following instruction. +save history FILENAME + Save the command history to the given file. + save skip FILENAME Save all current "skip"s to the given file. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 31f73c33894..5ba8fbc5d16 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -26588,6 +26588,14 @@ removal of duplicate history entries is disabled. Only history entries added during the current session are considered for removal. This option is set to 0 by default. +@kindex save history +@item save history @var{filename} +Occasionally you may want to save your history to a file. This +command will do just that, saving the commands in your current session +to the named file. Note that you should normally edit the saved +history before using @code{source} to reload it, as the @code{save +history} command itself will be at the end of the file. + @end table History expansion assigns special meaning to the character @kbd{!}. diff --git a/gdb/testsuite/gdb.base/save-history.exp b/gdb/testsuite/gdb.base/save-history.exp new file mode 100644 index 00000000000..bb7a56b2a72 --- /dev/null +++ b/gdb/testsuite/gdb.base/save-history.exp @@ -0,0 +1,36 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is part of the gdb testsuite. + +# Test the "save history" command. + +require {!is_remote host} + +gdb_start + +# Get something in history. +gdb_test "print 23" " = 23" + +set filename [standard_output_file histfile] +gdb_test_no_output "save history $filename" \ + "save history" + +set expected "set height 0\n" +append expected "set width 0\n" +append expected "print 23\n" +append expected "save history $filename\n" + +cmp_file_string $filename $expected "check history contents" diff --git a/gdb/top.c b/gdb/top.c index 205eb360ba3..f0c285e5989 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1325,6 +1325,18 @@ gdb_safe_append_history (void) } } +/* Implementation of 'save history' command. */ + +static void +save_history_command (const char *filename, int from_tty) +{ + if (filename == nullptr || *filename == '\0') + error (_("Argument required (file name in which to save)")); + + gdb::unique_xmalloc_ptr expanded_filename (tilde_expand (filename)); + write_history (expanded_filename.get ()); +} + /* Read one line from the command input stream `instream'. CMD_LINE_BUFFER is a buffer that the function may use to store the result, if @@ -2277,6 +2289,12 @@ Without an argument, saving is enabled."), show_write_history_p, &sethistlist, &showhistlist); + c = add_cmd ("history", no_class, save_history_command, _("\ +Save current history as a script.\n\ +Usage: save history FILE"), + &save_cmdlist); + set_cmd_completer (c, filename_completer); + add_setshow_zuinteger_unlimited_cmd ("size", no_class, &history_size_setshow_var, _("\ Set the size of the command history."), _("\ -- 2.39.1