Read $GDBHISTSIZE instead of $HISTSIZE
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / gdbinit-history.exp
CommitLineData
ebfd00d2
PP
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.
23
24proc test_gdbinit_history_setting { home size } {
25 global env
26 global INTERNAL_GDBFLAGS
27 global srcdir
28 global subdir
29
84204ed7
PA
30 array set old_env [array get env]
31
ebfd00d2 32 set env(HOME) "$srcdir/$subdir/$home"
84204ed7 33
b58c513b 34 # The GDBHISTSIZE environment variable takes precedence over whatever
84204ed7
PA
35 # history size is set in .gdbinit. Make sure the former is not
36 # set.
b58c513b 37 unset -nocomplain env(GDBHISTSIZE)
84204ed7 38
ebfd00d2
PP
39 set saved_internal_gdbflags $INTERNAL_GDBFLAGS
40 set INTERNAL_GDBFLAGS [string map {"-nx" ""} $INTERNAL_GDBFLAGS]
41
158bf1b4
PP
42 with_test_prefix "home=$home" {
43 gdb_exit
44 gdb_start
ebfd00d2 45
158bf1b4 46 gdb_test "show history size" "The size of the command history is $size."
ebfd00d2 47
158bf1b4
PP
48 if { $size == "0" } {
49 gdb_test_no_output "show commands"
50 } elseif { $size != "1" } {
51 gdb_test "show commands" " . show history size\r\n . show commands"
52 }
ebfd00d2
PP
53 }
54
55 set INTERNAL_GDBFLAGS $saved_internal_gdbflags
84204ed7
PA
56
57 array set env [array get old_env]
ebfd00d2
PP
58}
59
2093d2d3
PP
60# Check that the history file does not get truncated to zero when a gdbinit
61# file sets the history size to unlimited.
62
63proc test_no_truncation_of_unlimited_history_file { } {
64 global env
65 global INTERNAL_GDBFLAGS
66
67 array set old_env [array get env]
68
b58c513b 69 # The GDBHISTSIZE environment variable takes precedence over whatever
2093d2d3
PP
70 # history size is set in .gdbinit. Make sure the former is not
71 # set.
b58c513b 72 unset -nocomplain env(GDBHISTSIZE)
2093d2d3
PP
73
74 set saved_internal_gdbflags $INTERNAL_GDBFLAGS
75
76 set temp_gdbinit [standard_output_file "gdbinit-history.gdbinit"]
77 set temp_histfile [standard_output_file "gdbinit-history.gdb_history"]
78 file delete $temp_gdbinit
79 file delete $temp_histfile
80
81 set fd [open $temp_gdbinit "w"]
82 puts $fd "set history size unlimited\n"
83 puts $fd "set history filename $temp_histfile\n"
84 puts $fd "set history save\n"
85 close $fd
86
87 append INTERNAL_GDBFLAGS " -x $temp_gdbinit"
88
89 # We have to start then exit GDB twice: the first time to test the creation
90 # of the initial history file, and the second time to test appending to it.
91 # In either case the initial "print 1" command should persist through the
92 # history file.
93 with_test_prefix "truncation" {
94 gdb_exit
95 gdb_start
96 gdb_test "print 1"
97
98 with_test_prefix "creating" {
99 gdb_exit
100 gdb_start
101 gdb_test "server show commands" " . print 1.*"
102 }
103
104 with_test_prefix "appending" {
105 gdb_exit
106 gdb_start
107 gdb_test "server show commands" " . print 1.*"
108 }
109 }
110
111 set INTERNAL_GDBFLAGS $saved_internal_gdbflags
112
113 array set env [array get old_env]
114}
115
ebfd00d2
PP
116test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited"
117test_gdbinit_history_setting "gdbinit-history/zero" "0"
2093d2d3
PP
118
119test_no_truncation_of_unlimited_history_file
This page took 0.038254 seconds and 4 git commands to generate.