From patchwork Tue Jun 16 14:53:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 7205 Received: (qmail 85099 invoked by alias); 16 Jun 2015 14:53:45 -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 85089 invoked by uid 89); 16 Jun 2015 14:53:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_20, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qc0-f176.google.com Received: from mail-qc0-f176.google.com (HELO mail-qc0-f176.google.com) (209.85.216.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 16 Jun 2015 14:53:43 +0000 Received: by qcej3 with SMTP id j3so4907711qce.3 for ; Tue, 16 Jun 2015 07:53:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0GM4IgKDtm3fTOaAG5KUm+P2SXKSHFoRZ8s2cE6deNY=; b=bfNqzCar205VBA34RMbhOn33H1Y+11PYDDq2IL7JFRVBVlvYQvlsWtdIAjdhZsHIrA xALBI+7GVn2l9Wy45sFr3l+KiTYPNpeJ+79KG7sC4UZP2wIeDz3CNqjRsYsOColEE8NE vF/nxUaKQNp8AxkQG6Tm3jfUY00qJVOT3Ofe2kTTT8U5xvukCqWQ3hKb0wr//zyXFesg LDZr9lvSJb0XH5U25ZpYvjqG9ex2ubYAysAcs9Yk+WD5Qz+MjG3Y8Y4HbuONryEM2JNl RXjx3quJSK91arRGKBOWCpsxd5ZBY3Nr6HU3uT5XhTTYG/o1Bj1U6zclnMZkwdV5FDGK ez2w== X-Gm-Message-State: ALoCoQm7j/2r0BUpO4c0U8ILqyksFoPZACTE99byNEiedAxf29yKBhOyYJVLpMn6IRdeiOrgLSRk X-Received: by 10.55.27.162 with SMTP id m34mr1940214qkh.94.1434466421259; Tue, 16 Jun 2015 07:53:41 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id r75sm438609qkh.6.2015.06.16.07.53.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Jun 2015 07:53:40 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Don't truncate the history file when history size is unlimited Date: Tue, 16 Jun 2015 10:53:33 -0400 Message-Id: <1434466413-28892-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1433878062-23560-1-git-send-email-patrick@parcs.ath.cx> References: <1433878062-23560-1-git-send-email-patrick@parcs.ath.cx> We still do not handle "set history size unlimited" correctly. In particular, after writing to the history file, we truncate the history even if it is unlimited. This patch makes sure that we do not call history_truncate_file() if the history is not stifled (i.e. if it's unlimited). This bug causes the history file to be truncated to zero on exit when one has "set history size unlimited" in their gdbinit file. Although this code exists in GDB 7.8, the bug is masked by a pre-existing bug that's been only fixed in GDB 7.9 (PR gdb/17820). gdb/ChangeLog: * top.c (gdb_safe_append_history): Do not call history_truncate_file if the history is not stifled. gdb/testsuite/ChangeLog: * gdb.base/gdbinit-history.exp: Add test case to check that an unlimited history file does not get truncated on exit. --- gdb/testsuite/gdb.base/gdbinit-history.exp | 54 ++++++++++++++++++++++++++++++ gdb/top.c | 3 +- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/gdbinit-history.exp b/gdb/testsuite/gdb.base/gdbinit-history.exp index 8adfd68..83abd35 100644 --- a/gdb/testsuite/gdb.base/gdbinit-history.exp +++ b/gdb/testsuite/gdb.base/gdbinit-history.exp @@ -57,5 +57,59 @@ proc test_gdbinit_history_setting { home size } { array set env [array get old_env] } +# Check that the history file does not get truncated to zero when a gdbinit +# file sets the history size to unlimited. + +proc test_no_truncation_of_unlimited_history_file { } { + global env + global INTERNAL_GDBFLAGS + + array set old_env [array get env] + + # The HISTSIZE environment variable takes precedence over whatever + # history size is set in .gdbinit. Make sure the former is not + # set. + unset -nocomplain env(HISTSIZE) + + set saved_internal_gdbflags $INTERNAL_GDBFLAGS + + set temp_gdbinit [standard_output_file "gdbinit-history.gdbinit"] + set temp_histfile [standard_output_file "gdbinit-history.gdb_history"] + file delete $temp_gdbinit + file delete $temp_histfile + + set fd [open $temp_gdbinit "w"] + puts $fd "set history size unlimited\n" + puts $fd "set history filename $temp_histfile\n" + puts $fd "set history save\n" + close $fd + + append INTERNAL_GDBFLAGS " -x $temp_gdbinit" + + # We have to start then exit GDB twice: the first time to test the creation + # of the initial history file, and the second time to test appending to it. + # In either case the initial "print 1" command should persist through the + # history file. + with_test_prefix "truncation" { + gdb_exit + gdb_start + gdb_test "print 1" + + gdb_exit + gdb_start + gdb_test "server show commands" " . print 1.*" + + gdb_exit + gdb_start + gdb_test "server show commands" " . print 1.*" + } + + set INTERNAL_GDBFLAGS $saved_internal_gdbflags + + array set env [array get old_env] +} + test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" test_gdbinit_history_setting "gdbinit-history/zero" "0" + +test_no_truncation_of_unlimited_history_file diff --git a/gdb/top.c b/gdb/top.c index 837bf16..f5a0819 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -981,7 +981,8 @@ gdb_safe_append_history (void) else { append_history (command_count, local_history_filename); - history_truncate_file (local_history_filename, history_max_entries); + if (history_is_stifled ()) + history_truncate_file (local_history_filename, history_max_entries); } ret = rename (local_history_filename, history_filename);