Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2015-2016 Free Software Foundation, Inc. |
ebfd00d2 PP |
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 | ||
5d978e17 SL |
20 | # This test depends on being able to set $HOME and $GDBHISTSIZE. |
21 | # We cannot expect remote hosts to see environment variables set on the | |
22 | # local machine. | |
23 | ||
24 | if { [is_remote host] } { | |
25 | unsupported "can't set environment variables on remote host" | |
26 | return -1 | |
27 | } | |
ebfd00d2 PP |
28 | |
29 | # Check that the history size is properly set to SIZE when reading the .gdbinit | |
74bd41ce PP |
30 | # file located in HOME with the environment variable GDBHISTSIZE optionally |
31 | # set to GDBHISTSIZE_VAL. | |
ebfd00d2 | 32 | |
74bd41ce | 33 | proc test_gdbinit_history_setting { home size { gdbhistsize_val "-" } } { |
ebfd00d2 PP |
34 | global env |
35 | global INTERNAL_GDBFLAGS | |
36 | global srcdir | |
37 | global subdir | |
38 | ||
b6dafabf PP |
39 | save_vars { INTERNAL_GDBFLAGS env(GDBHISTSIZE) env(HOME) } { |
40 | set env(HOME) "$srcdir/$subdir/$home" | |
84204ed7 | 41 | |
b6dafabf PP |
42 | # The GDBHISTSIZE environment variable takes precedence over whatever |
43 | # history size is set in .gdbinit. Make sure the former is not | |
44 | # set. | |
45 | unset -nocomplain env(GDBHISTSIZE) | |
84204ed7 | 46 | |
b6dafabf PP |
47 | if { $gdbhistsize_val != "-" } { |
48 | set env(GDBHISTSIZE) $gdbhistsize_val | |
49 | } | |
74bd41ce | 50 | |
b6dafabf | 51 | set INTERNAL_GDBFLAGS [string map {"-nx" ""} $INTERNAL_GDBFLAGS] |
ebfd00d2 | 52 | |
b6dafabf PP |
53 | set prefix "home=$home" |
54 | if { $gdbhistsize_val != "-" } { | |
55 | append prefix " gdbhistsize=$gdbhistsize_val" | |
56 | } | |
74bd41ce | 57 | |
b6dafabf PP |
58 | with_test_prefix $prefix { |
59 | gdb_exit | |
60 | gdb_start | |
ebfd00d2 | 61 | |
b6dafabf | 62 | gdb_test "show history size" "The size of the command history is $size." |
ebfd00d2 | 63 | |
b6dafabf PP |
64 | if { $size == "0" } { |
65 | gdb_test_no_output "show commands" | |
66 | } elseif { $size != "1" } { | |
67 | gdb_test "show commands" " . show history size\r\n . show commands" | |
68 | } | |
158bf1b4 | 69 | } |
ebfd00d2 | 70 | } |
ebfd00d2 PP |
71 | } |
72 | ||
2093d2d3 PP |
73 | # Check that the history file does not get truncated to zero when a gdbinit |
74 | # file sets the history size to unlimited. | |
75 | ||
76 | proc test_no_truncation_of_unlimited_history_file { } { | |
77 | global env | |
78 | global INTERNAL_GDBFLAGS | |
79 | ||
b6dafabf PP |
80 | save_vars { INTERNAL_GDBFLAGS env(GDBHISTSIZE) } { |
81 | # The GDBHISTSIZE environment variable takes precedence over whatever | |
82 | # history size is set in .gdbinit. Make sure the former is not | |
83 | # set. | |
84 | unset -nocomplain env(GDBHISTSIZE) | |
85 | ||
86 | set temp_gdbinit [standard_output_file "gdbinit-history.gdbinit"] | |
87 | set temp_histfile [standard_output_file "gdbinit-history.gdb_history"] | |
88 | file delete $temp_gdbinit | |
89 | file delete $temp_histfile | |
90 | ||
91 | set fd [open $temp_gdbinit "w"] | |
92 | puts $fd "set history size unlimited\n" | |
93 | puts $fd "set history filename $temp_histfile\n" | |
94 | puts $fd "set history save\n" | |
95 | close $fd | |
96 | ||
97 | append INTERNAL_GDBFLAGS " -x $temp_gdbinit" | |
98 | ||
99 | # We have to start then exit GDB twice: the first time to test the creation | |
100 | # of the initial history file, and the second time to test appending to it. | |
101 | # In either case the initial "print 1" command should persist through the | |
102 | # history file. | |
103 | with_test_prefix "truncation" { | |
104 | gdb_exit | |
105 | gdb_start | |
106 | gdb_test "print 1" | |
107 | ||
108 | with_test_prefix "creating" { | |
2093d2d3 PP |
109 | gdb_exit |
110 | gdb_start | |
111 | gdb_test "server show commands" " . print 1.*" | |
b6dafabf | 112 | } |
2093d2d3 | 113 | |
b6dafabf | 114 | with_test_prefix "appending" { |
2093d2d3 PP |
115 | gdb_exit |
116 | gdb_start | |
117 | gdb_test "server show commands" " . print 1.*" | |
b6dafabf PP |
118 | } |
119 | } | |
2093d2d3 | 120 | } |
2093d2d3 PP |
121 | } |
122 | ||
ebfd00d2 PP |
123 | test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" |
124 | test_gdbinit_history_setting "gdbinit-history/zero" "0" | |
2093d2d3 PP |
125 | |
126 | test_no_truncation_of_unlimited_history_file | |
74bd41ce PP |
127 | |
128 | # A valid GDBHISTSIZE value overrides the setting inside the .gdbinit file; an | |
129 | # invalid GDBHISTSIZE value is ignored, falling back on the setting inside the | |
130 | # .gdbinit file. | |
131 | test_gdbinit_history_setting "gdbinit-history/unlimited" "1000" "1000" | |
132 | test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" "foo" |