Bug 16999 - HISTSIZE behavior should match Bash's
Summary: HISTSIZE behavior should match Bash's
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 17820 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-05-30 03:36 UTC by Edward Z. Yang
Modified: 2015-06-17 18:30 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch to make GDB honor HISTSIZE=-1 in the same way as bash (unlimited history size). (256 bytes, patch)
2014-07-11 11:05 UTC, Jason Vas Dias
Details | Diff
Updated patch for gdb-7.9, which STILL does not honor HISTSIZE=-1 . (457 bytes, patch)
2015-05-01 11:41 UTC, Jason Vas Dias
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Edward Z. Yang 2014-05-30 03:36:22 UTC
Currently, if a HISTSIZE is passed to gdb which atoi cannot parse, gdb decides that the desired history size is zero. This is not so great; usually people want their history size to be infinite and not zero, especially seeing as this behavior is different from that of bash, which assumes /infinite/ history size when the value of HISTSIZE is empty. Thus, there is an annoying situation where 'export HISTSIZE=INFINITE' causes Bash to keep infinite history, but gdb to keep zero history! To make matters worse, the environment variable overrides the setting in .gdbinit. Please consider setting history_size_setshow_var to the maximum signed integer (since readline uses a signed int) when it is not parseable.
Comment 1 Chris Matteri 2014-06-13 19:53:26 UTC
In bash version 4.3.18 (I don't know exactly when this feature was introduced) negative values of HISTSIZE also result in unlimited history, while gdb sets history_size_setshow_var to zero on negative HISTSIZE.
Comment 2 Jason Vas Dias 2014-07-11 11:05:20 UTC
Created attachment 7695 [details]
Patch to make GDB honor HISTSIZE=-1 in the same way as bash (unlimited history size).

patch was against gdb-7.2 ( the version in RHEL-6 I have to use) but
should be easily portable to latest version.
Comment 3 Jason Vas Dias 2015-05-01 11:41:24 UTC
Created attachment 8293 [details]
Updated patch for gdb-7.9, which STILL does not honor HISTSIZE=-1 .

Here is a patch to make GDB 7.9 also honor the HISTSIZE=-1 setting, which modern readline also honors.
Comment 4 dje 2015-05-01 15:55:21 UTC
*** Bug 17820 has been marked as a duplicate of this bug. ***
Comment 5 cvs-commit@gcc.gnu.org 2015-06-17 18:14:04 UTC
The master branch has been updated by Patrick Palka <ppalka@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b58c513b7932cfb9852d66e07282b9c2379197ed

commit b58c513b7932cfb9852d66e07282b9c2379197ed
Author: Patrick Palka <patrick@parcs.ath.cx>
Date:   Wed Jun 17 13:31:56 2015 -0400

    Read $GDBHISTSIZE instead of $HISTSIZE
    
    The HISTSIZE environment variable is generally expected to be read by
    shells, not by applications.  Some distros for example globally export
    HISTSIZE in /etc/profile -- with the intention that it only affects
    shells -- and by doing so it renders useless GDB's own mechanism for
    setting the history size via .gdbinit.  Also, annoyances may arise when
    HISTSIZE is not interpreted the same way by the shell and by GDB, e.g.
    PR gdb/16999.  That can always be fixed on a shell-by-shell basis but it
    may be impossible to be consistent with the behavior of all shells at
    once.  Finally it just makes sense to not confound shell environment
    variables with application environment variables.
    
    gdb/ChangeLog:
    
    	* NEWS: Mention that GDBHISTSIZE is read instead of HISTSIZE.
    	* top.c (init_history): Read from GDBHISTSIZE instead of
    	HISTSIZE.
    	(init_main): Refer to GDBHISTSIZE instead of HISTSIZE.
    
    gdb/doc/ChangeLog:
    
    	* gdb.texinfo (Command History): Replace occurrences of HISTSIZE
    	with GDBHISTSIZE.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/gdbinit-history.exp: Replace occurrences of HISTSIZE
    	with GDBHISTSIZE.
    	* gdb.base/readline.exp: Likewise.
Comment 6 cvs-commit@gcc.gnu.org 2015-06-17 18:14:09 UTC
The master branch has been updated by Patrick Palka <ppalka@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bc460514b9db46a491c2c39cd118b02608742968

commit bc460514b9db46a491c2c39cd118b02608742968
Author: Patrick Palka <patrick@parcs.ath.cx>
Date:   Tue May 12 06:50:26 2015 -0400

    Tweak the handling of $GDBHISTSIZE edge cases [PR gdb/16999]
    
    When GDB reads a nonsensical value for the GDBHISTSIZE 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 GDBHISTSIZE consistent with how
    bash handles HISTSIZE.  When we encounter a null or out-of-range
    GDBHISTSIZE (outside of [0, INT_MAX]) we now set the history size to
    unlimited instead of 0.  When we encounter a non-numeric GDBHISTSIZE we
    do nothing.
    
    gdb/ChangeLog:
    
    	PR gdb/16999
    	* NEWS: Mention new GDBHISTSIZE behavior.
    	* top.c (init_history): For null or out-of-range GDBHISTSIZE,
    	set history size to unlimited.  Ignore non-numeric GDBHISTSIZE.
    
    gdb/doc/ChangeLog:
    
    	PR gdb/16999
    	* gdb.texinfo (Command History): Mention new GDBHISTSIZE
    	behavior.
    
    gdb/testsuite/ChangeLog:
    
    	PR gdb/16999
    	* gdb.base/gdbhistsize-history.exp: New test.
Comment 7 patrick 2015-06-17 18:30:10 UTC
The next version of GDB will no longer read HISTSIZE at all because doing so causes more problems than it solves.  Instead GDBHISTSIZE is read for the same purpose.  And for good measure, the behavior of GDBHISTSIZE will match how bash reads HISTSIZE, so setting GDBHISTSIZE to -1 will cause GDB's history size to be unlimited.

Hope these changes are sensible.  Let us know if you disagree.