1 # Copyright 2015 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite.
18 # Test the setting of "history size" via $HOME/.gdbinit
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.
25 proc test_gdbinit_history_setting { home size { gdbhistsize_val "-" } } {
27 global INTERNAL_GDBFLAGS
31 save_vars { INTERNAL_GDBFLAGS env(GDBHISTSIZE) env(HOME) } {
32 set env(HOME) "$srcdir/$subdir/$home"
34 # The GDBHISTSIZE environment variable takes precedence over whatever
35 # history size is set in .gdbinit. Make sure the former is not
37 unset -nocomplain env(GDBHISTSIZE)
39 if { $gdbhistsize_val != "-" } {
40 set env(GDBHISTSIZE) $gdbhistsize_val
43 set INTERNAL_GDBFLAGS [string map {"-nx" ""} $INTERNAL_GDBFLAGS]
45 set prefix "home=$home"
46 if { $gdbhistsize_val != "-" } {
47 append prefix " gdbhistsize=$gdbhistsize_val"
50 with_test_prefix $prefix {
54 gdb_test "show history size" "The size of the command history is $size."
57 gdb_test_no_output "show commands"
58 } elseif { $size != "1" } {
59 gdb_test "show commands" " . show history size\r\n . show commands"
65 # Check that the history file does not get truncated to zero when a gdbinit
66 # file sets the history size to unlimited.
68 proc test_no_truncation_of_unlimited_history_file { } {
70 global INTERNAL_GDBFLAGS
72 save_vars { INTERNAL_GDBFLAGS env(GDBHISTSIZE) } {
73 # The GDBHISTSIZE environment variable takes precedence over whatever
74 # history size is set in .gdbinit. Make sure the former is not
76 unset -nocomplain env(GDBHISTSIZE)
78 set temp_gdbinit [standard_output_file "gdbinit-history.gdbinit"]
79 set temp_histfile [standard_output_file "gdbinit-history.gdb_history"]
80 file delete $temp_gdbinit
81 file delete $temp_histfile
83 set fd [open $temp_gdbinit "w"]
84 puts $fd "set history size unlimited\n"
85 puts $fd "set history filename $temp_histfile\n"
86 puts $fd "set history save\n"
89 append INTERNAL_GDBFLAGS " -x $temp_gdbinit"
91 # We have to start then exit GDB twice: the first time to test the creation
92 # of the initial history file, and the second time to test appending to it.
93 # In either case the initial "print 1" command should persist through the
95 with_test_prefix "truncation" {
100 with_test_prefix "creating" {
103 gdb_test "server show commands" " . print 1.*"
106 with_test_prefix "appending" {
109 gdb_test "server show commands" " . print 1.*"
115 test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited"
116 test_gdbinit_history_setting "gdbinit-history/zero" "0"
118 test_no_truncation_of_unlimited_history_file
120 # A valid GDBHISTSIZE value overrides the setting inside the .gdbinit file; an
121 # invalid GDBHISTSIZE value is ignored, falling back on the setting inside the
123 test_gdbinit_history_setting "gdbinit-history/unlimited" "1000" "1000"
124 test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" "foo"