Re: [PATCH 2/4] gdb.base/callfuncs.exp: Adjust for Windows

Andrew Burgess <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Pedro Alves <[email protected]> writes:

> A bit of self-review...
>
> I did the same mistake I did recently, again.  Here:
>
>> -if { ![prepare_for_testing "failed to prepare" $testfile $srcfile "$compile_flags additional_flags=-DPROTOTYPES"] } {
>> +if { ![prepare_for_testing "failed to prepare" $testfile-1 $srcfile "$compile_flags additional_flags=-DPROTOTYPES"] } {
>>      perform_all_tests 1
>>  }
>>  
>>  with_test_prefix "noproto" {
>> -    if { ![prepare_for_testing "failed to prepare" $testfile $srcfile \
>> +    if { ![prepare_for_testing "failed to prepare" $testfile-0 $srcfile \
>>  	       "$compile_flags additional_flags=-DNO_PROTOTYPES"] } {
>>  	perform_all_tests 0
>>      }
>
> Since rerun_and_prepare now always restart GDB, these prepare_for_testing calls
> can be turned into build_executable calls.
>
> I've done that now.  The testcase still passes cleanly.
>
> From 974b26155dd4a128a0382b3b0b08d60d78f0a0de Mon Sep 17 00:00:00 2001
> From: Pedro Alves <[email protected]>
> Date: Tue, 14 Jul 2026 19:48:30 +0100
> Subject: [PATCH] gdb.base/callfuncs.exp: Adjust for Windows
>
> On Windows, gdb.base/callfuncs.exp currently ends up skipping the
> "noproto" tests, like:
>
>  UNTESTED: gdb.base/callfuncs.exp: noproto: failed to prepare
>
> This is because the testcase tries to overwrite the executable while
> GDB has the executable still open, which doesn't work on Windows:
>
>  Executing on host: x86_64-w64-mingw32-gcc ... -o .../gdb.base/callfuncs/callfuncs
>  .../x86_64-w64-mingw32/bin/ld.exe: cannot open output file .../gdb.base/callfuncs/callfuncs.exe: Permission denied
>
> Fix this with two changes:
>
>  - Compile the prototyped and non-prototyped executables to two
>    separate executables.  This is just what we normally do, so that
>    it's convenient to test manually against either of the executables.
>
>  - Restart GDB instead of just re-running to main.
>
> Strictly speaking, either of the changes alone would fix it, but I
> think both are useful to do.

Is this true?  After the first perform_all_tests call GDB is still
running and has the executable file open.  Without the separate
filenames the second build_executable call will try to change the
executable that GDB holds open.

All you've done is split prepare_for_testing into build_executable and
clean_restart, but the order hasn't changed (and you call clean_restart
more often now).

Not that I object to these changes, I just disagree with the last
sentence as I don't think the clean_restart change alone will fix the
problem.

Reviewed-By: Andrew Burgess <[email protected]>

Thanks,
Andrew



>
> Change-Id: I496e0da65f9d484079c5d9a1222104bec39ee98b
> ---
>  gdb/testsuite/gdb.base/callfuncs.exp | 26 ++++++++++++++------------
>  1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.base/callfuncs.exp b/gdb/testsuite/gdb.base/callfuncs.exp
> index f2870c577f2..0ac1c603351 100644
> --- a/gdb/testsuite/gdb.base/callfuncs.exp
> +++ b/gdb/testsuite/gdb.base/callfuncs.exp
> @@ -334,12 +334,18 @@ proc fetch_all_registers {test} {
>  # Global used by RERUN_AND_PREPARE to make test names unique.
>  set rerun_count 0
>  
> -proc rerun_and_prepare {} {
> +proc rerun_and_prepare {prototypes} {
>      global rerun_count
>  
> +    clean_restart $::testfile-$prototypes
> +
>      incr rerun_count
>      with_test_prefix "rerun number ${rerun_count}" {
>  
> +	gdb_test_no_output "set print sevenbit-strings"
> +	gdb_test_no_output "set print address off"
> +	gdb_test_no_output "set width 0"
> +
>  	if { ![runto_main] } {
>  	    return
>  	}
> @@ -359,11 +365,7 @@ proc rerun_and_prepare {} {
>  }
>  
>  proc perform_all_tests {prototypes} {
> -    gdb_test_no_output "set print sevenbit-strings"
> -    gdb_test_no_output "set print address off"
> -    gdb_test_no_output "set width 0"
> -
> -    rerun_and_prepare
> +    rerun_and_prepare $prototypes
>  
>      # Save all register contents.
>      set old_reg_content \
> @@ -382,7 +384,7 @@ proc perform_all_tests {prototypes} {
>  	fail "gdb function calls preserve register contents"
>      }
>  
> -    rerun_and_prepare
> +    rerun_and_prepare $prototypes
>      # Save all register contents.
>      set old_reg_content \
>  	[fetch_all_registers "retrieve original register contents 2"]
> @@ -408,7 +410,7 @@ proc perform_all_tests {prototypes} {
>  		 }
>  	     }
>  
> -    rerun_and_prepare
> +    rerun_and_prepare $prototypes
>      # Set breakpoint at a function we will call from gdb.
>      gdb_breakpoint add
>      # Save all register contents.
> @@ -434,7 +436,7 @@ proc perform_all_tests {prototypes} {
>  		 }
>  	     }
>  
> -    rerun_and_prepare
> +    rerun_and_prepare $prototypes
>      # Set breakpoint at a function we will call from gdb.
>      gdb_breakpoint add
>      # Save all register contents.
> @@ -459,7 +461,7 @@ proc perform_all_tests {prototypes} {
>  		 }
>  	     }
>  
> -    rerun_and_prepare
> +    rerun_and_prepare $prototypes
>      # Set breakpoint at a function we will call from gdb.
>      gdb_breakpoint add
>      set old_reg_content \
> @@ -547,12 +549,12 @@ proc perform_all_tests {prototypes} {
>  
>  # Perform all tests with and without function prototypes.
>  
> -if { ![prepare_for_testing "failed to prepare" $testfile $srcfile "$compile_flags additional_flags=-DPROTOTYPES"] } {
> +if { ![build_executable "failed to build" $testfile-1 $srcfile "$compile_flags additional_flags=-DPROTOTYPES"] } {
>      perform_all_tests 1
>  }
>  
>  with_test_prefix "noproto" {
> -    if { ![prepare_for_testing "failed to prepare" $testfile $srcfile \
> +    if { ![build_executable "failed to build" $testfile-0 $srcfile \
>  	       "$compile_flags additional_flags=-DNO_PROTOTYPES"] } {
>  	perform_all_tests 0
>      }
>
> base-commit: 490469846dcef89fe53668bdbba73591c64bed61
> prerequisite-patch-id: f9480ec6b27aac188161579fdec6f08d5065ac6f
> -- 
> 2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.