aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorDoug Evans <xdje42@gmail.com>2014-09-13 15:52:15 -0700
committerDoug Evans <xdje42@gmail.com>2014-09-13 15:52:15 -0700
commit3714cea7d44e2bd9cac28a61d45fcc8c3cc6ae83 (patch)
tree073e28a136ceffb19892e4961fc39030f2f2bbe7 /gdb
parent1a8bdf69e7d1f6084af503407d6a4217b06d6ea5 (diff)
downloadgdb-3714cea7d44e2bd9cac28a61d45fcc8c3cc6ae83.zip
gdb-3714cea7d44e2bd9cac28a61d45fcc8c3cc6ae83.tar.gz
gdb-3714cea7d44e2bd9cac28a61d45fcc8c3cc6ae83.tar.bz2
Pass plain-text prompt to with_gdb_prompt.
I had occasion to use with_gdb_prompt in a test for the patch for PR 17314 and was passing the plain text prompt as the value, "(top-gdb)", instead of a regexp, "\(top-gdb\)" (expressed as "\\(top-gdb\\)" in TCL). I then discovered that in order to restore the prompt gdb passes the original value of $gdb_prompt to "set prompt", which works because "set prompt \(gdb\) " is equivalent to "set prompt (gdb) ". Perhaps I'm being overly cautious but this feels a bit subtle, but at any rate as an API choice I'd much rather pass the plain text form to with_gdb_prompt. I also discovered that the initial value of gdb_prompt is set in two places to two different values. At the global level gdb.exp sets it to "\[(\]gdb\[)\]" and default_gdb_init sets it to "\\(gdb\\)". The former form is undesirable as an argument to "set prompt", but it's not clear to me that just deleting this code won't break anything. Thus I just changed the value to be consistent and added a comment. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_prompt): Add comment and change initial value to be consistent with what default_gdb_init uses. (with_gdb_prompt): Change form of PROMPT argument from a regexp to the plain text of the prompt. Add some logging printfs. * gdb.perf/disassemble.exp: Update call to with_gdb_prompt.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/ChangeLog8
-rw-r--r--gdb/testsuite/gdb.perf/disassemble.exp2
-rw-r--r--gdb/testsuite/lib/gdb.exp31
3 files changed, 38 insertions, 3 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a296aa4..c53fae4 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2014-09-13 Doug Evans <xdje42@gmail.com>
+
+ * lib/gdb.exp (gdb_prompt): Add comment and change initial value to
+ be consistent with what default_gdb_init uses.
+ (with_gdb_prompt): Change form of PROMPT argument from a regexp to
+ the plain text of the prompt. Add some logging printfs.
+ * gdb.perf/disassemble.exp: Update call to with_gdb_prompt.
+
2014-09-12 Pedro Alves <palves@redhat.com>
* gdb.arch/gdb1558.exp: Replace uses of gdb_expect after
diff --git a/gdb/testsuite/gdb.perf/disassemble.exp b/gdb/testsuite/gdb.perf/disassemble.exp
index 07c9766..54a5bd8 100644
--- a/gdb/testsuite/gdb.perf/disassemble.exp
+++ b/gdb/testsuite/gdb.perf/disassemble.exp
@@ -41,7 +41,7 @@ PerfTest::assemble {
# When GDB is debugging GDB, the prompt is changed to "(top-gdb) ".
# In order to avoid the confusion of pattern matching, set the
# gdb_prompt to '(top-gdb)' temporarily.
- with_gdb_prompt "\\(top-gdb\\)" {
+ with_gdb_prompt "(top-gdb)" {
gdb_load ${binfile}
}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 937a949..b33a702 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -64,10 +64,12 @@ if ![info exists INTERNAL_GDBFLAGS] {
}
# The variable gdb_prompt is a regexp which matches the gdb prompt.
-# Set it if it is not already set.
+# Set it if it is not already set. This is also set by default_gdb_init
+# but it's not clear what removing one of them will break.
+# See with_gdb_prompt for more details on prompt handling.
global gdb_prompt
if ![info exists gdb_prompt] then {
- set gdb_prompt "\[(\]gdb\[)\]"
+ set gdb_prompt "\\(gdb\\)"
}
# A regexp that matches the pagination prompt.
@@ -1738,17 +1740,42 @@ proc with_test_prefix { prefix body } {
# PROMPT. When BODY is finished, restore GDB prompt and variable
# $gdb_prompt.
# Returns the result of BODY.
+#
+# Notes:
+#
+# 1) If you want to use, for example, "(foo)" as the prompt you must pass it
+# as "(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
+# TCL). PROMPT is internally converted to a suitable regexp for matching.
+# We do the conversion from "(foo)" to "\(foo\)" here for a few reasons:
+# a) It's more intuitive for callers to pass the plain text form.
+# b) We need two forms of the prompt:
+# - a regexp to use in output matching,
+# - a value to pass to the "set prompt" command.
+# c) It's easier to convert the plain text form to its regexp form.
+#
+# 2) Don't add a trailing space, we do that here.
proc with_gdb_prompt { prompt body } {
global gdb_prompt
+ # Convert "(foo)" to "\(foo\)".
+ # We don't use string_to_regexp because while it works today it's not
+ # clear it will work tomorrow: the value we need must work as both a
+ # regexp *and* as the argument to the "set prompt" command, at least until
+ # we start recording both forms separately instead of just $gdb_prompt.
+ # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
+ # regexp form.
+ regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
+
set saved $gdb_prompt
+ verbose -log "Setting gdb prompt to \"$prompt \"."
set gdb_prompt $prompt
gdb_test_no_output "set prompt $prompt " ""
set code [catch {uplevel 1 $body} result]
+ verbose -log "Restoring gdb prompt to \"$saved \"."
set gdb_prompt $saved
gdb_test_no_output "set prompt $saved " ""