From patchwork Sat Sep 6 19:15:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 2666 Received: (qmail 7488 invoked by alias); 6 Sep 2014 19:15:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 7475 invoked by uid 89); 6 Sep 2014 19:15:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f173.google.com Received: from mail-pd0-f173.google.com (HELO mail-pd0-f173.google.com) (209.85.192.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 06 Sep 2014 19:15:48 +0000 Received: by mail-pd0-f173.google.com with SMTP id ft15so2133004pdb.18 for ; Sat, 06 Sep 2014 12:15:46 -0700 (PDT) X-Received: by 10.67.1.195 with SMTP id bi3mr32823039pad.74.1410030946666; Sat, 06 Sep 2014 12:15:46 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-50-sfba.hfc.comcastbusiness.net. [173.13.178.50]) by mx.google.com with ESMTPSA id hs8sm4935210pbc.35.2014.09.06.12.15.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Sep 2014 12:15:46 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH] Change form of prompt argument to with_gdb_prompt. Date: Sat, 06 Sep 2014 12:15:00 -0700 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. 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. The comments added to with_gdb_prompt feel a bit wordy ... excessive FAOD? 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. 2014-09-06 Doug Evans * 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. 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 1019ecd..1713f32 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. @@ -1753,17 +1755,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 " ""