Commit | Line | Data |
---|---|---|
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 | |
74bd41ce PP |
22 | # file located in HOME with the environment variable GDBHISTSIZE optionally |
23 | # set to GDBHISTSIZE_VAL. | |
ebfd00d2 | 24 | |
74bd41ce | 25 | proc test_gdbinit_history_setting { home size { gdbhistsize_val "-" } } { |
ebfd00d2 PP |
26 | global env |
27 | global INTERNAL_GDBFLAGS | |
28 | global srcdir | |
29 | global subdir | |
30 | ||
b6dafabf PP |
31 | save_vars { INTERNAL_GDBFLAGS env(GDBHISTSIZE) env(HOME) } { |
32 | set env(HOME) "$srcdir/$subdir/$home" | |
84204ed7 | 33 | |
b6dafabf PP |
34 | # The GDBHISTSIZE environment variable takes precedence over whatever |
35 | # history size is set in .gdbinit. Make sure the former is not | |
36 | # set. | |
37 | unset -nocomplain env(GDBHISTSIZE) | |
84204ed7 | 38 | |
b6dafabf PP |
39 | if { $gdbhistsize_val != "-" } { |
40 | set env(GDBHISTSIZE) $gdbhistsize_val | |
41 | } | |
74bd41ce | 42 | |
b6dafabf | 43 | set INTERNAL_GDBFLAGS [string map {"-nx" ""} $INTERNAL_GDBFLAGS] |
ebfd00d2 | 44 | |
b6dafabf PP |
45 | set prefix "home=$home" |
46 | if { $gdbhistsize_val != "-" } { | |
47 | append prefix " gdbhistsize=$gdbhistsize_val" | |
48 | } | |
74bd41ce | 49 | |
b6dafabf PP |
50 | with_test_prefix $prefix { |
51 | gdb_exit | |
52 | gdb_start | |
ebfd00d2 | 53 | |
b6dafabf | 54 | gdb_test "show history size" "The size of the command history is $size." |
ebfd00d2 | 55 | |
b6dafabf PP |
56 | if { $size == "0" } { |
57 | gdb_test_no_output "show commands" | |
58 | } elseif { $size != "1" } { | |
59 | gdb_test "show commands" " . show history size\r\n . show commands" | |
60 | } | |
158bf1b4 | 61 | } |
ebfd00d2 | 62 | } |
ebfd00d2 PP |
63 | } |
64 | ||
2093d2d3 PP |
65 | # Check that the history file does not get truncated to zero when a gdbinit |
66 | # file sets the history size to unlimited. | |
67 | ||
68 | proc test_no_truncation_of_unlimited_history_file { } { | |
69 | global env | |
70 | global INTERNAL_GDBFLAGS | |
71 | ||
b6dafabf PP |
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 | |
75 | # set. | |
76 | unset -nocomplain env(GDBHISTSIZE) | |
77 | ||
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 | |
82 | ||
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" | |
87 | close $fd | |
88 | ||
89 | append INTERNAL_GDBFLAGS " -x $temp_gdbinit" | |
90 | ||
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 | |
94 | # history file. | |
95 | with_test_prefix "truncation" { | |
96 | gdb_exit | |
97 | gdb_start | |
98 | gdb_test "print 1" | |
99 | ||
100 | with_test_prefix "creating" { | |
2093d2d3 PP |
101 | gdb_exit |
102 | gdb_start | |
103 | gdb_test "server show commands" " . print 1.*" | |
b6dafabf | 104 | } |
2093d2d3 | 105 | |
b6dafabf | 106 | with_test_prefix "appending" { |
2093d2d3 PP |
107 | gdb_exit |
108 | gdb_start | |
109 | gdb_test "server show commands" " . print 1.*" | |
b6dafabf PP |
110 | } |
111 | } | |
2093d2d3 | 112 | } |
2093d2d3 PP |
113 | } |
114 | ||
ebfd00d2 PP |
115 | test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" |
116 | test_gdbinit_history_setting "gdbinit-history/zero" "0" | |
2093d2d3 PP |
117 | |
118 | test_no_truncation_of_unlimited_history_file | |
74bd41ce PP |
119 | |
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 | |
122 | # .gdbinit file. | |
123 | test_gdbinit_history_setting "gdbinit-history/unlimited" "1000" "1000" | |
124 | test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" "foo" |