[3/4] Add a have_native_target helper function for use with require.

Message ID 20230526175742.66885-4-jhb@FreeBSD.org
State New
Headers
Series Handle null inferiors in target::read_description |

Commit Message

John Baldwin May 26, 2023, 5:57 p.m. UTC
  Move logic from auto-connect-native-target.exp into this helper.
---
 .../gdb.base/auto-connect-native-target.exp    | 18 +-----------------
 gdb/testsuite/lib/gdb.exp                      | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 17 deletions(-)
  

Comments

Simon Marchi July 6, 2023, 4:24 p.m. UTC | #1
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 133d914aff8..128c0779b69 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -9739,6 +9739,23 @@ gdb_caching_proc have_compile_and_link_flag { flag } {
>  		additional_flags=$flag]
>  }
>  
> +# Return 1 if this GDB is configured with a "native" target.
> +
> +gdb_caching_proc have_native_target {} {
> +    global gdb_prompt
> +
> +    set test "help target native"
> +    gdb_test_multiple $test $test {
> +	-re "Undefined target command.*$gdb_prompt $" {
> +	    return 0
> +	}
> +	-re "Native process.*$gdb_prompt $" {
> +	    return 1
> +	}
> +    }
> +    return 0
> +}
Touching this code would be an opportunity to modernize it.  I think
that if you do:

  gdb_test_multiple "help target native"  "" {

the command is automatically used as the test name (so, no need for the
test variable).

Then, instead of having "$gdb_prompt $", you can probably use -wrap:

  -re -wrap "Undefined target command.*"

  -re -wrap "Native process.*"

Simon
  
John Baldwin July 6, 2023, 5:18 p.m. UTC | #2
On 7/6/23 9:24 AM, Simon Marchi wrote:
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index 133d914aff8..128c0779b69 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -9739,6 +9739,23 @@ gdb_caching_proc have_compile_and_link_flag { flag } {
>>   		additional_flags=$flag]
>>   }
>>   
>> +# Return 1 if this GDB is configured with a "native" target.
>> +
>> +gdb_caching_proc have_native_target {} {
>> +    global gdb_prompt
>> +
>> +    set test "help target native"
>> +    gdb_test_multiple $test $test {
>> +	-re "Undefined target command.*$gdb_prompt $" {
>> +	    return 0
>> +	}
>> +	-re "Native process.*$gdb_prompt $" {
>> +	    return 1
>> +	}
>> +    }
>> +    return 0
>> +}
> Touching this code would be an opportunity to modernize it.  I think
> that if you do:
> 
>    gdb_test_multiple "help target native"  "" {
> 
> the command is automatically used as the test name (so, no need for the
> test variable).
> 
> Then, instead of having "$gdb_prompt $", you can probably use -wrap:
> 
>    -re -wrap "Undefined target command.*"
> 
>    -re -wrap "Native process.*"

Thanks, those all worked and did make it a bit simpler.
  

Patch

diff --git a/gdb/testsuite/gdb.base/auto-connect-native-target.exp b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
index 002a6d61126..0586cd4baf4 100644
--- a/gdb/testsuite/gdb.base/auto-connect-native-target.exp
+++ b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
@@ -22,23 +22,7 @@  if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
     return -1
 }
 
-# Whether this GDB is configured with a "native" target.
-set have_native 0
-
-set test "help target native"
-gdb_test_multiple $test $test {
-    -re "Undefined target command.*$gdb_prompt $" {
-	set have_native 0
-    }
-    -re "Native process.*$gdb_prompt $" {
-	set have_native 1
-    }
-}
-
-if { !$have_native } {
-    unsupported "no \"target native\" support."
-    return
-}
+require have_native_target
 
 # Returns the topmost target pushed on the target stack.  TEST is used
 # as test message.
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 133d914aff8..128c0779b69 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -9739,6 +9739,23 @@  gdb_caching_proc have_compile_and_link_flag { flag } {
 		additional_flags=$flag]
 }
 
+# Return 1 if this GDB is configured with a "native" target.
+
+gdb_caching_proc have_native_target {} {
+    global gdb_prompt
+
+    set test "help target native"
+    gdb_test_multiple $test $test {
+	-re "Undefined target command.*$gdb_prompt $" {
+	    return 0
+	}
+	-re "Native process.*$gdb_prompt $" {
+	    return 1
+	}
+    }
+    return 0
+}
+
 # Handle include file $srcdir/$subdir/FILE.
 
 proc include_file { file } {