Home | History | Annotate | Line # | Download | only in gdb.base
gdbinit-history.exp revision 1.1.1.1.2.2
      1 # Copyright 2015 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 # This file is part of the gdb testsuite.
     17 
     18 # Test the setting of "history size" via $HOME/.gdbinit
     19 
     20 
     21 # Check that the history size is properly set to SIZE when reading the .gdbinit
     22 # file located in HOME with the environment variable GDBHISTSIZE optionally
     23 # set to GDBHISTSIZE_VAL.
     24 
     25 proc test_gdbinit_history_setting { home size { gdbhistsize_val "-" } } {
     26     global env
     27     global INTERNAL_GDBFLAGS
     28     global srcdir
     29     global subdir
     30 
     31     array set old_env [array get env]
     32 
     33     set env(HOME) "$srcdir/$subdir/$home"
     34 
     35     # The GDBHISTSIZE environment variable takes precedence over whatever
     36     # history size is set in .gdbinit.  Make sure the former is not
     37     # set.
     38     unset -nocomplain env(GDBHISTSIZE)
     39 
     40     if { $gdbhistsize_val != "-" } {
     41 	set env(GDBHISTSIZE) $gdbhistsize_val
     42     }
     43 
     44     set saved_internal_gdbflags $INTERNAL_GDBFLAGS
     45     set INTERNAL_GDBFLAGS [string map {"-nx" ""} $INTERNAL_GDBFLAGS]
     46 
     47     set prefix "home=$home"
     48     if { $gdbhistsize_val != "-" } {
     49 	append prefix " gdbhistsize=$gdbhistsize_val"
     50     }
     51 
     52     with_test_prefix $prefix {
     53 	gdb_exit
     54 	gdb_start
     55 
     56 	gdb_test "show history size" "The size of the command history is $size."
     57 
     58 	if { $size == "0" } {
     59 	    gdb_test_no_output "show commands"
     60 	} elseif { $size != "1" } {
     61 	    gdb_test "show commands" "    .  show history size\r\n    .  show commands"
     62 	}
     63     }
     64 
     65     set INTERNAL_GDBFLAGS $saved_internal_gdbflags
     66 
     67     unset -nocomplain env(GDBHISTSIZE)
     68     array set env [array get old_env]
     69 }
     70 
     71 # Check that the history file does not get truncated to zero when a gdbinit
     72 # file sets the history size to unlimited.
     73 
     74 proc test_no_truncation_of_unlimited_history_file { } {
     75     global env
     76     global INTERNAL_GDBFLAGS
     77 
     78     array set old_env [array get env]
     79 
     80     # The GDBHISTSIZE environment variable takes precedence over whatever
     81     # history size is set in .gdbinit.  Make sure the former is not
     82     # set.
     83     unset -nocomplain env(GDBHISTSIZE)
     84 
     85     set saved_internal_gdbflags $INTERNAL_GDBFLAGS
     86 
     87     set temp_gdbinit [standard_output_file "gdbinit-history.gdbinit"]
     88     set temp_histfile [standard_output_file "gdbinit-history.gdb_history"]
     89     file delete $temp_gdbinit
     90     file delete $temp_histfile
     91 
     92     set fd [open $temp_gdbinit "w"]
     93     puts $fd "set history size unlimited\n"
     94     puts $fd "set history filename $temp_histfile\n"
     95     puts $fd "set history save\n"
     96     close $fd
     97 
     98     append INTERNAL_GDBFLAGS " -x $temp_gdbinit"
     99 
    100     # We have to start then exit GDB twice: the first time to test the creation
    101     # of the initial history file, and the second time to test appending to it.
    102     # In either case the initial "print 1" command should persist through the
    103     # history file.
    104     with_test_prefix "truncation" {
    105 	gdb_exit
    106 	gdb_start
    107 	gdb_test "print 1"
    108 
    109 	with_test_prefix "creating" {
    110 		gdb_exit
    111 		gdb_start
    112 		gdb_test "server show commands" "    .  print 1.*"
    113 	}
    114 
    115 	with_test_prefix "appending" {
    116 		gdb_exit
    117 		gdb_start
    118 		gdb_test "server show commands" "    .  print 1.*"
    119 	}
    120     }
    121 
    122     set INTERNAL_GDBFLAGS $saved_internal_gdbflags
    123 
    124     array set env [array get old_env]
    125 }
    126 
    127 test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited"
    128 test_gdbinit_history_setting "gdbinit-history/zero" "0"
    129 
    130 test_no_truncation_of_unlimited_history_file
    131 
    132 # A valid GDBHISTSIZE value overrides the setting inside the .gdbinit file; an
    133 # invalid GDBHISTSIZE value is ignored, falling back on the setting inside the
    134 # .gdbinit file.
    135 test_gdbinit_history_setting "gdbinit-history/unlimited" "1000" "1000"
    136 test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" "foo"
    137