From patchwork Thu May 21 22:50:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 6860 Received: (qmail 12632 invoked by alias); 21 May 2015 22:51:03 -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 12623 invoked by uid 89); 21 May 2015 22:51:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qk0-f171.google.com Received: from mail-qk0-f171.google.com (HELO mail-qk0-f171.google.com) (209.85.220.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 21 May 2015 22:51:01 +0000 Received: by qkdn188 with SMTP id n188so1259047qkd.2 for ; Thu, 21 May 2015 15:50:58 -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; bh=PJIY+e1qPiO+HPYdPBBTrrLpaTyE0D2KwAq5KzFicbw=; b=YKT7uXT7Oy7B78Wr//ZEZGa48bgDhRmB1ZUvpS54iOGYhaxykXc/1ZvEQtGos5em5c 8gUgB9XSQfFWwKQbm2hqQnt+DSQNqIyA68sAI9pood7lSPOGPQkCCZR/U0WbmcnYmq+C XCK5eZN5KozR9CsfRS/TATE/ZQDN4n6/OZ5SJlUNhpklEqX64vWQbvI1TrL8fGIi83T8 +Gt8EulY6HjifMCR12v+htckzVLvd8R4o8urpkrWJaB26KXw59lsKkQaUn6NXClGyRAc pEBFzHZIel4xC/xJd1HyiyCufEe21aVsfOG/uHMNQcPFXbbfowg1dvxmmS4rOjw1Ic4o 2vdw== X-Gm-Message-State: ALoCoQktZLGZKqWXEHvWhZY3pQpad783vN6/xH47Gr70H5DlEMj7MjKqFIk4WB1bauzGetfvk1mA X-Received: by 10.140.16.173 with SMTP id 42mr7250924qgb.31.1432248658725; Thu, 21 May 2015 15:50:58 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id 17sm178815qky.29.2015.05.21.15.50.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 May 2015 15:50:57 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Tweak the handling of $HISTSIZE edge cases [PR gdb/16999] Date: Thu, 21 May 2015 18:50:48 -0400 Message-Id: <1432248648-7402-1-git-send-email-patrick@parcs.ath.cx> When GDB reads a nonsensical value for the HISTSIZE environment variable, i.e. one that is non-numeric or negative, GDB then sets its history size to 0. This behavior is annoying and also inconsistent with the behavior of bash. This patch makes the behavior of invalid HISTSIZE mostly match that of bash. When we encounter an invalid or null HISTSIZE we now set the history size to unlimited instead of 0. Whereas bash ignores a non-numeric HISTSIZE, we set the history to unlimited in that case so that an accidental typo will not potentially truncate the user's history. gdb/ChangeLog: PR gdb/16999 * top.c (init_history): For invalid HISTSIZE, set history size to unlimited. gdb/testsuite/ChangeLog: PR gdb/16999 * gdb.base/histsize-history.exp: New test. --- gdb/testsuite/gdb.base/histsize-history.exp | 60 +++++++++++++++++++++++++++++ gdb/top.c | 22 ++++++----- 2 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 gdb/testsuite/gdb.base/histsize-history.exp diff --git a/gdb/testsuite/gdb.base/histsize-history.exp b/gdb/testsuite/gdb.base/histsize-history.exp new file mode 100644 index 0000000..10fc453 --- /dev/null +++ b/gdb/testsuite/gdb.base/histsize-history.exp @@ -0,0 +1,60 @@ +# Copyright 2015 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 setting of "history size" via the HISTSIZE environment variable + + +# Check that the history size is properly set to SIZE when env(HISTSIZE) is set +# to HISTSIZE. + +proc test_histsize_history_setting { histsize size } { + global env + + set have_old_histsize 0 + if [info exists env(HISTSIZE)] { + set have_old_histsize 1 + set old_histsize $env(HISTSIZE) + } + set env(HISTSIZE) $histsize + + with_test_prefix "histsize = $histsize" { + gdb_exit + gdb_start + + gdb_test "show history size" "The size of the command history is $size." + + if { $size == "0" } { + gdb_test_no_output "show commands" + } elseif { $size != "1" } { + gdb_test "show commands" \ + " . show history size\r\n . show commands" + } + + if { $have_old_histsize } { + set env(HISTSIZE) $old_histsize + } else { + unset env(HISTSIZE) + } + } +} + +test_histsize_history_setting "" "unlimited" +test_histsize_history_setting "0" "0" +test_histsize_history_setting "20" "20" +test_histsize_history_setting "-5" "unlimited" +test_histsize_history_setting "not_an_integer" "unlimited" +test_histsize_history_setting "10zab" "unlimited" diff --git a/gdb/top.c b/gdb/top.c index 74e1e07..38b4e5d 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1684,17 +1684,21 @@ init_history (void) if (tmpenv) { int var; + char *endptr; - var = atoi (tmpenv); - if (var < 0) - { - /* Prefer ending up with no history rather than overflowing - readline's history interface, which uses signed 'int' - everywhere. */ - var = 0; - } + var = strtol (tmpenv, &endptr, 10); - history_size_setshow_var = var; + /* If HISTSIZE is the empty string, negative, or non-numeric then set the + history size to unlimited. This behavior is mostly consistent with + that of bash. Whereas bash ignores a non-numeric HISTSIZE, we set the + history to unlimited in that case to avoid potentially truncating the + user's history. */ + if (strlen (tmpenv) == 0 + || var < 0 + || *endptr != '\0') + history_size_setshow_var = -1; + else + history_size_setshow_var = var; } /* If the init file hasn't set a size yet, pick the default. */ else if (history_size_setshow_var == -2)