public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] gdb/testsuite: use gdb_test in gdb.gdb/python-helper.exp
Date: Fri, 23 Sep 2022 10:18:00 -0400	[thread overview]
Message-ID: <20220923141801.1106678-3-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20220923141801.1106678-1-simon.marchi@polymtl.ca>

If some command in there gives the wrong answer, we currently have to
wait for a timeout for the test to continue.  For instance, I currently
see:

    print *val->type
    $1 = Python Exception <class 'gdb.error'>: Cannot take address of method length.

    (outer-gdb) FAIL: gdb.gdb/python-helper.exp: pretty print type (timeout)

We can avoid this and modernize the test at the same time by using the
-prompt option of gdb_test.

gdb_test_no_output currently accepts a -prompt_re option (the variable
name passed to parse_args defines the option name), but I think
it's a typo.  It's supposed to be -prompt, like gdb_test.  I can't find
anything using -prompt_re using grep.  Change it to just "prompt".

Change-Id: Icc0a9a0ef482e62460c708bccdd544c11d711eca
---
 gdb/testsuite/gdb.gdb/python-helper.exp | 88 +++++--------------------
 gdb/testsuite/lib/gdb.exp               |  8 +--
 2 files changed, 21 insertions(+), 75 deletions(-)

diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
index 6db8bf0df507..ea362ef693d9 100644
--- a/gdb/testsuite/gdb.gdb/python-helper.exp
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -82,13 +82,11 @@ proc test_python_helper {} {
     # binary into the inner GDB.
     gdb_test_no_output "disable breakpoints"
 
+    set outer_prompt_re "\\(outer-gdb\\) $"
+
     # Adjust the prompt on the outer gdb, this just makes things a
     # little clearer when trying to unpick which GDB is active.
-    gdb_test_multiple "set prompt (outer-gdb) " "set outer gdb prompt" {
-	-re "\[(\]outer-gdb\[)\].*\[(\]outer-gdb\[)\] $" {
-	    pass $gdb_test_name
-	}
-    }
+    gdb_test_no_output -prompt $outer_prompt_re  "set prompt (outer-gdb) " "set outer gdb prompt"
 
     # Send a command to the outer GDB to continue the inner GDB.  The
     # stop is being detected from the inner GDB, hence the use of -i
@@ -113,18 +111,10 @@ proc test_python_helper {} {
     # Send Ctrl-C to the inner GDB, this should kick us back to the
     # prompt of the outer GDB.
     send_inferior "\003"
-    gdb_test_multiple "" "interrupted the inner" {
-	-re ".*\\(outer-gdb\\) $" {
-	    pass $gdb_test_name
-	}
-    }
+    gdb_test -prompt $outer_prompt_re "" "" "interrupted the inner"
 
     # Now enable all breakpoints within the outer GDB.
-    gdb_test_multiple "enable breakpoints" "" {
-	-re "\\(outer-gdb\\) $" {
-	    pass $gdb_test_name
-	}
-    }
+    gdb_test_no_output -prompt $outer_prompt_re "enable breakpoints"
 
     # We need to resume the inner GDB after interrupting it, this is
     # done by sending 'continue'.  However, GDB will not redisplay the
@@ -137,11 +127,7 @@ proc test_python_helper {} {
     # GDB, this should result in the outer GDB stopping at one of the
     # breakpoints we created..
     send_inferior "print 1\n"
-    gdb_test_multiple "" "hit breakpoint in outer gdb" {
-	-re "Breakpoint $decimal, value_print.*\\(outer-gdb\\) $" {
-	    pass $gdb_test_name
-	}
-    }
+    gdb_test -prompt $outer_prompt_re "" "Breakpoint $decimal, value_print.*" "hit breakpoint in outer gdb"
 
     # Now inspect the type of parameter VAL, this should trigger the
     # pretty printers.
@@ -152,16 +138,8 @@ proc test_python_helper {} {
 		    " chain = 0x0," \
 		    " instance_flags = 0," \
 		    " length = $decimal," \
-		    " main_type = $hex}" \
-		    "\\(outer-gdb\\) $"]
-    gdb_test_multiple "print *val->type" "pretty print type" {
-	-re "$answer" {
-	    pass $gdb_test_name
-	}
-	-re "There is no member named.*\r\n\\(outer-gdb\\) $" {
-	    fail $gdb_test_name
-	}
-    }
+		    " main_type = $hex}"]
+    gdb_test -prompt $outer_prompt_re "print *val->type" $answer "pretty print type"
 
     set answer [multi_line \
 		    "$decimal = " \
@@ -170,16 +148,8 @@ proc test_python_helper {} {
 		    " flags = \[^\r\n\]+," \
 		    " owner = $hex \\(gdbarch\\)," \
 		    " target_type = 0x0," \
-		    " type_specific_field = TYPE_SPECIFIC_NONE}" \
-		    "\\(outer-gdb\\) $"]
-    gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type" {
-	-re "$answer" {
-	    pass $gdb_test_name
-	}
-	-re "There is no member named.*\r\n\\(outer-gdb\\) $" {
-	    fail $gdb_test_name
-	}
-    }
+		    " type_specific_field = TYPE_SPECIFIC_NONE}"]
+    gdb_test -prompt $outer_prompt_re "print *val->type->main_type" $answer "pretty print type->main_type"
 
     # Send the continue to the outer GDB, which resumes the inner GDB,
     # we then detect the prompt from the inner GDB, hence the use of
@@ -195,12 +165,8 @@ proc test_python_helper {} {
     # information, this will include the TYPE_SPECIFIC_INT
     # information.
     send_inferior "print global_c.m_val\n"
-    gdb_test_multiple "" "print integer from DWARF info" {
-	-re "Breakpoint $decimal, value_print.*\\(outer-gdb\\) $" {
-	    pass $gdb_test_name
-	}
-    }
-
+    gdb_test -prompt $outer_prompt_re "" "Breakpoint $decimal, value_print.*" "print integer from DWARF info"
+	
     set answer [multi_line \
 		    "$decimal = " \
 		    "{name = $hex \"int\"," \
@@ -208,16 +174,8 @@ proc test_python_helper {} {
 		    " flags = \[^\r\n\]+," \
 		    " owner = $hex \\(objfile\\)," \
 		    " target_type = 0x0," \
-		    " int_stuff = { bit_size = $decimal, bit_offset = $decimal }}" \
-		    "\\(outer-gdb\\) $"]
-    gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type for DWARF type" {
-	-re "$answer" {
-	    pass $gdb_test_name
-	}
-	-re "There is no member named.*\r\n\\(outer-gdb\\) $" {
-	    fail $gdb_test_name
-	}
-    }
+		    " int_stuff = { bit_size = $decimal, bit_offset = $decimal }}"]
+    gdb_test -prompt $outer_prompt_re "print *val->type->main_type" $answer "pretty print type->main_type for DWARF type"
 
     # Send the continue to the outer GDB, which resumes the inner GDB,
     # we then detect the prompt from the inner GDB, hence the use of
@@ -232,11 +190,7 @@ proc test_python_helper {} {
     # Send a command to the inner GDB, this should result in the outer
     # GDB stopping at the value_print breakpoint again.
     send_inferior "ptype global_c\n"
-    gdb_test_multiple "" "hit breakpoint in outer gdb again" {
-	-re "Breakpoint $decimal, c_print_type .*\\(outer-gdb\\) $" {
-	    pass $gdb_test_name
-	}
-    }
+    gdb_test -prompt $outer_prompt_re "" "Breakpoint $decimal, c_print_type.*" "hit breakpoint in outer gdb again"
 
     set answer [multi_line \
 		    "$decimal = " \
@@ -251,16 +205,8 @@ proc test_python_helper {} {
 		    "   m_loc_kind = FIELD_LOC_KIND_BITPOS," \
 		    "   bitsize = 0," \
 		    "   bitpos = 0}," \
-		    " cplus_stuff = $hex}" \
-		    "\\(outer-gdb\\) $"]
-    gdb_test_multiple "print *type->main_type" "" {
-	-re "$answer" {
-	    pass $gdb_test_name
-	}
-	-re "\r\n\\(outer-gdb\\) $" {
-	    fail $gdb_test_name
-	}
-    }
+		    " cplus_stuff = $hex}"]
+    gdb_test -prompt $outer_prompt_re "print *type->main_type" $answer
 
     return 0
 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 68536b00f146..5ab4df1bcf3c 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1478,17 +1478,17 @@ proc gdb_test_no_output { args } {
     global gdb_prompt
 
     parse_args {
-	{prompt_re ""}
+	{prompt ""}
 	{nopass}
     }
 
     lassign $args command message
 
-    set prompt_re [fill_in_default_prompt $prompt_re]
+    set prompt [fill_in_default_prompt $prompt]
 
     set command_regex [string_to_regexp $command]
-    gdb_test_multiple $command $message -prompt $prompt_re {
-	-re "^$command_regex\r\n$prompt_re" {
+    gdb_test_multiple $command $message -prompt $prompt {
+	-re "^$command_regex\r\n$prompt" {
 	    if {!$nopass} {
 		pass $gdb_test_name
 	    }
-- 
2.37.3


  parent reply	other threads:[~2022-09-23 14:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 14:17 [PATCH 0/3] Fix gdb.gdb/python-helper.exp + cleanups Simon Marchi
2022-09-23 14:17 ` [PATCH 1/3] gdb/testsuite: bump duration for the whole test in do_self_tests Simon Marchi
2022-09-23 14:18 ` Simon Marchi [this message]
2022-09-23 14:18 ` [PATCH 3/3] gdb/testsuite: update field names in gdb-gdb.py.in Simon Marchi
2022-09-23 17:02 ` [PATCH 0/3] Fix gdb.gdb/python-helper.exp + cleanups Luis Machado
2022-09-23 21:35   ` Tom de Vries
2022-09-26 18:01     ` Simon Marchi
2022-09-26 18:39       ` Tom de Vries
2022-09-26 21:33         ` Simon Marchi
2022-09-27 10:34       ` Bruno Larsen
2022-09-27 10:42         ` Luis Machado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220923141801.1106678-3-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).