From 1c51fceb5c2801b6abadcc48fab56b9abd15ae92 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 23 Sep 2022 09:29:47 -0400 Subject: [PATCH] gdb/testsuite: use gdb_test in gdb.gdb/python-helper.exp 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 : 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 6db8bf0df50..ea362ef693d 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 68536b00f14..5ab4df1bcf3 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.30.2