diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-01-22 18:21:58 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-03-02 18:59:38 +0000 |
commit | 63e163f24fe80fe1509527e6ccfcfb9622f5e99e (patch) | |
tree | 36d85fd9d5a52b110ecfcd4dd5f70fdf4d36304d /gdb/testsuite | |
parent | 81b86b9702b5be9d022e9b0c96c1ee2ce339b5b9 (diff) | |
download | binutils-gdb-63e163f24fe80fe1509527e6ccfcfb9622f5e99e.tar.gz |
gdb: Allow GDB to _not_ load a previous command history
This commit aims to give a cleaner mechanism by which the user can
prevent GDB from trying to load any previous command history.
Currently the user can change the path to the history file, either
using a command line flag, or by setting the GDBHISTFILE environment
variable, and if the path is set to a non-existent file, then
obviously GDB wont load any command history. However, this feels like
a bit of a bodge, I'd like to add an official mechanism by which we
can disable command history loading.
Why would we want to prevent command history loading? The specific
use case I have is GDB starting with a CWD that is a network mounted
directory, and there is no command history present. Still GDB will
access the network in order to check for the file. In my particular
use case I'm actually starting a large number of GDB instances in
parallel, all in the same network mounted directory, the large number
of network accesses looking for this file introduces a noticeable
delay at GDB startup.
The approach I'm proposing here is a slight adjustment to the current
rules for setting up the history filename. Currently, if a user does
this, they see an error:
(gdb) set history filename
Argument required (filename to set it to.).
However, if a user does this:
$ GDBHISTFILE= gdb --quiet
(gdb) set history save on
(gdb) q
warning: Could not rename -gdb18416~ to : No such file or directory
So, we already have a bug in this area. My plan is to allow the empty
filename to be accepted, and for this to mean, neither load, nor save
the command history.
This does mean that we now have two mechanisms to prevent saving the
command history:
(gdb) set history filename
or
(gdb) set history save off
But the only way to prevent loading the command history is to set the
filename to the empty string _before_ you get to a GDB prompt, either
using a command line option, or the environment variable.
I've updated some of the show commands, for example this session:
(gdb) set history filename
(gdb) show history filename
There is no filename currently set for recording the command history in.
(gdb) show history save
Saving of the history record on exit is off.
(gdb) set history save on
(gdb) show history save
Saving of the history is disabled due to the value of 'history filename'.
(gdb) set history filename /tmp/hist
(gdb) show history save
Saving of the history record on exit is on.
I've updated the manual, and added some tests.
gdb/ChangeLog:
* NEWS: Mention new behaviour of the history filename.
* top.c (write_history_p): Add comment.
(show_write_history_p): Add header comment, give a different
message when history writing is on, but the history filename is
empty.
(history_filename): Add comment.
(history_filename_empty): New function.
(show_history_filename): Add header comment, give a different
message when the filename is empty.
(init_history): Compare history_filename against nullptr, and only
read history if the filename is not empty.
(set_history_filename): Add header comment, and only make
non-empty filenames absolute.
(init_main): Make the filename argument to 'set history filename'
optional.
gdb/doc/ChangeLog:
* gdb.texinfo (Command History): Extend description for
GDBHISTFILE and GDBHISTSIZE, add detail about the filename for
'set history filename' being optional. Describe the effect of an
empty history filename on 'set history save on'.
gdb/testsuite/ChangeLog:
* gdb.base/default.exp: Remove test of 'set history filename'.
* gdb.base/gdbinit-history.exp: Add tests for setting the history
filename to the empty string.
* lib/gdb.exp (gdb_init): Unset environment variables GDBHISTFILE
and GDBHISTSIZE.
Change-Id: Ia586e4311182fac99113b60f11ef8a11fbd5450b
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/default.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/gdbinit-history.exp | 151 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 6 |
4 files changed, 165 insertions, 2 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 488a3280215..55c0a3ef603 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,13 @@ 2020-03-02 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.base/default.exp: Remove test of 'set history filename'. + * gdb.base/gdbinit-history.exp: Add tests for setting the history + filename to the empty string. + * lib/gdb.exp (gdb_init): Unset environment variables GDBHISTFILE + and GDBHISTSIZE. + +2020-03-02 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.server/stop-reply-no-thread.exp: Add test where T packet is disabled. diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp index 097619d48d4..c51ec63eccf 100644 --- a/gdb/testsuite/gdb.base/default.exp +++ b/gdb/testsuite/gdb.base/default.exp @@ -497,8 +497,6 @@ gdb_test "set environment" "Argument required .environment variable and value.*" gdb_test "set height" "Argument required .integer to set it to.*" #test set history expansion gdb_test_no_output "set history expansion" "set history expansion" -#test set history filename -gdb_test "set history filename" "Argument required .filename to set it to.*" # Make sure the history ends up in the right place. gdb_test_no_output "set history filename [standard_output_file .gdb_history]" \ "set the history filename" diff --git a/gdb/testsuite/gdb.base/gdbinit-history.exp b/gdb/testsuite/gdb.base/gdbinit-history.exp index 528c07dce30..baa1b49153c 100644 --- a/gdb/testsuite/gdb.base/gdbinit-history.exp +++ b/gdb/testsuite/gdb.base/gdbinit-history.exp @@ -128,6 +128,154 @@ proc test_no_truncation_of_unlimited_history_file { } { } } +# Check that the current command history matches HIST, which is a list +# of commands, oldest fist. +proc check_history { hist } { + + # The show commands we issue here always appears last in the + # commands list. + lappend hist "show commands" + + # Number all of the entries in the HIST list and convert the list + # into a pattern to match against GDB. + set hist_lines [list] + set idx 1 + foreach h $hist { + lappend hist_lines " $idx $h" + incr idx + } + set pattern [eval multi_line $hist_lines] + + # Check the history. + gdb_test "show commands" "$pattern.*" +} + +# Run 'show history filename' and check the output contains the +# filename matching PATTERN, unless, PATTERN is the empty string, in +# which case match a different output that GDB will give if the +# history filename is the empty string. +# +# TESTNAME is the name for the test, which defaults to the command run +# in the test. +proc check_history_filename { pattern {testname ""} } { + + set cmd "show history filename" + if { $testname == "" } { + set testname $cmd + } + + if { $pattern == "" } { + gdb_test $cmd \ + "There is no filename currently set for recording the command history in." \ + $testname + } else { + gdb_test $cmd \ + "The filename in which to record the command history is \"$pattern\"\." \ + $testname + } +} + +# Tests for how GDB handles setting the history filename to the empty +# string. +proc test_empty_history_filename { } { + global env + global gdb_prompt + + set common_history [list "set height 0" "set width 0"] + + set test_dir [standard_output_file history_test] + remote_exec host "mkdir -p $test_dir" + foreach entry { { ".gdb_history" "xxxxx" } \ + { "_gdb_history" "xxxxx" } \ + { "alt_history" "yyyyy" } } { + set fn [lindex $entry 0] + set content [lindex $entry 1] + set fd [open [standard_output_file "$test_dir/$fn"] w] + puts $fd "$content" + close $fd + } + + with_cwd "$test_dir" { + with_test_prefix "load default history file" { + # Start GDB and see that the history file was loaded + # correctly. + gdb_exit + gdb_start + check_history [concat "xxxxx" $common_history] + check_history_filename ".*/.gdb_history" + } + + with_test_prefix "load GDBHISTFILE history file" { + # Now restart GDB with GDBHISTFILE set to see that the + # "other" history file is loaded. + save_vars { env(GDBHISTFILE) } { + setenv GDBHISTFILE \ + "$test_dir/alt_history" + gdb_exit + gdb_start + check_history [concat "yyyyy" $common_history] + check_history_filename ".*/alt_history" + } + } + + with_test_prefix "GDBHISTFILE is empty" { + # Now restart GDB with GDBHISTFILE set to indicate don't + # load any history file, check none was loaded. + save_vars { env(GDBHISTFILE) } { + setenv GDBHISTFILE "" + gdb_exit + gdb_start + check_history $common_history + check_history_filename "" + } + + # Check that 'show history save' does the right thing when + # the history filename is the empty string. + gdb_test_no_output "set history save off" \ + "ensure history save is off initially" + gdb_test "show history save" \ + "Saving of the history record on exit is off." \ + "Check history save is off" + gdb_test_no_output "set history save on" + gdb_test "show history save" \ + "Saving of the history is disabled due to the value of 'history filename'." \ + "Check history save is off due to filename" + gdb_test_no_output \ + "set history filename $test_dir/alt_history" \ + "set history filename at the command line" + check_history_filename ".*/alt_history" \ + "check filename after setting at the command line" + gdb_test "show history save" \ + "Saving of the history record on exit is on." \ + "Check history save is on" + gdb_test_no_output "set history filename" + gdb_test "show history save" \ + "Saving of the history is disabled due to the value of 'history filename'." \ + "Check history save is off due to filename again" + gdb_test_no_output "set history save off" + } + + with_test_prefix "Use -ex to clear history file" { + # Now restart GDB with the command line '-ex' to indicate + # no history file should be loaded. + gdb_exit + if {[gdb_spawn_with_cmdline_opts \ + "-ex \"set history filename\""] != 0} { + fail "spawn" + return + } + set test "initial prompt" + gdb_test_multiple "" $test { + -re ".*$gdb_prompt $" { + pass "$test" + } + } + check_history [list] + check_history_filename "" + } + } +} + test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" test_gdbinit_history_setting "gdbinit-history/zero" "0" @@ -138,3 +286,6 @@ test_no_truncation_of_unlimited_history_file # .gdbinit file. test_gdbinit_history_setting "gdbinit-history/unlimited" "1000" "1000" test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" "foo" + +# Check handling of empty history filename. +test_empty_history_filename diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index ab22f244360..f8f404ff26b 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5097,6 +5097,12 @@ proc gdb_init { test_file_name } { # tests. setenv TERM "dumb" + # Ensure that GDBHISTFILE and GDBHISTSIZE are removed from the + # environment, we don't want these modifications to the history + # settings. + unset -nocomplain ::env(GDBHISTFILE) + unset -nocomplain ::env(GDBHISTSIZE) + # Initialize GDB's pty with a fixed size, to make sure we avoid pagination # during startup. See "man expect" for details about stty_init. global stty_init |