[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.dwarf2

Fix clean_restart <absolute filename> in the test-cases in gdb.dwarf2.

Tested on x86_64-linux using gcc-14.

Tested these test-cases on x86_64-linux with target board unix/-m32:
- gdb.dwarf2/valop.exp
- gdb.dwarf2/callframecfa.exp
- gdb.dwarf2/implptr.exp
- gdb.dwarf2/watch-notconst.exp
- gdb.dwarf2/pieces.exp
- gdb.dwarf2/pieces-optimized-out.exp

Tested these test-cases on x86_64-linux with target board fission-dwp:
- gdb.dwarf2/dwp-symlink.exp
- gdb.dwarf2/dwp-sepdebug.exp

Tested test-case gdb.dwarf2/gdb-index-tilde.exp on x86_64-linux by disabling a
too strict home directory check, see PR testsuite/33364.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
index 8d941ba..0dd59bb 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
@@ -32,7 +32,8 @@
     }
 }
 
-if { [prepare_for_testing "failed to prepare" $binfile  [list $asm_file $srcfile ]] } {
+if { [prepare_for_testing "failed to prepare" $testfile \
+	  [list $asm_file $srcfile ]] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
index fa9d000..ed03c27 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
@@ -170,7 +170,7 @@
 proc run_test { goto_main } {
     global binfile decimal hex
 
-    clean_restart ${binfile}
+    clean_restart ${::testfile}
 
     if { $goto_main } {
 	if ![runto_main] {
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp
index 49091f7..ff91d63 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp
@@ -179,7 +179,7 @@
 # through.  This is checking that the is-stmt marked lines are
 # displayed differently (without addresses) to addresses that are
 # mid-way through a line, or not marked as is-stmt.
-clean_restart $binfile
+clean_restart $::testfile
 runto_main
 
 foreach entry $locs {
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp
index 65d9559..d304963 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp
@@ -116,7 +116,7 @@
 
 # Restart the test.  This time, stop at a location we know is marked
 # as a statement.
-clean_restart ${binfile}
+clean_restart ${::testfile}
 runto_main
 
 gdb_breakpoint "*line_label_3"
@@ -129,7 +129,7 @@
 
 # Restart the test, this time, step through line by line, ensure we
 # only stop at the places where is-stmt is true.
-clean_restart ${binfile}
+clean_restart ${::testfile}
 runto_main
 
 # Get the values of the labels where we expect to stop.
@@ -161,7 +161,7 @@
 
 # Now restart the test, and place a breakpoint by line number.  GDB
 # should select the location that is marked as is-stmt.
-clean_restart ${binfile}
+clean_restart ${::testfile}
 runto_main
 set linum [gdb_get_line_number "main, set var to 0"]
 gdb_breakpoint "$srcfile:$linum"
@@ -171,7 +171,7 @@
 
 # Restart the test again, this time we will test stepping by
 # instruction.
-clean_restart ${binfile}
+clean_restart ${::testfile}
 runto_main
 
 # We will be at line_label_1 at this point - we already tested this
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-multiple-debug-info.exp b/gdb/testsuite/gdb.dwarf2/dw2-multiple-debug-info.exp
index a8fa524..0092969 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-multiple-debug-info.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-multiple-debug-info.exp
@@ -31,6 +31,6 @@
     return -1
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 gdb_test "ptype a" "type = class sp1::A .*"
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp
index 486a4e8..870c8c1 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp
@@ -134,7 +134,7 @@
 proc do_console_test {} {
     global binfile
 
-    clean_restart $binfile
+    clean_restart $::testfile
 
     with_test_prefix "console" {
 	gdb_test_no_output "set print object on"
@@ -173,7 +173,7 @@
     global binfile
     
     with_test_prefix "mi" {
-	if {[mi_clean_restart $binfile]} {
+	if {[mi_clean_restart $::testfile]} {
 	    return
 	}
 	
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp b/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp
index 23d8c26..070865b 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp
@@ -91,7 +91,7 @@
 gdb_test "frame" ".*main \\\(\\\) at \[^\r\n\]*:$prologue_end_line\r\n.*"
 
 with_test_prefix "ignore-prologue-end" {
-    clean_restart $binfile
+    clean_restart $::testfile
     gdb_test_no_output "maintenance set ignore-prologue-end-flag on"
 
     if ![runto_main] {
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-var-zero-addr.exp b/gdb/testsuite/gdb.dwarf2/dw2-var-zero-addr.exp
index f021f42..c6234d5 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-var-zero-addr.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-var-zero-addr.exp
@@ -34,7 +34,7 @@
 
 save_vars { GDBFLAGS } {
     set GDBFLAGS "$GDBFLAGS --readnow"
-    clean_restart ${binfile}
+    clean_restart ${::testfile}
 }
 
 with_test_prefix "readnow" {
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
index 221bf7b..1d20688 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
@@ -26,7 +26,8 @@
 # Test for presence of complaint, with the lib relocated.
 
 proc_with_prefix test_relocated { exec_path lib_path complaint_re readnow_p } {
-    clean_restart $exec_path
+    clean_restart
+    gdb_load $exec_path
     gdb_load_shlib $lib_path
 
     if { ![runto_main] } {
diff --git a/gdb/testsuite/gdb.dwarf2/entry-value-typedef.exp b/gdb/testsuite/gdb.dwarf2/entry-value-typedef.exp
index 44d58a8..f84f0f3 100644
--- a/gdb/testsuite/gdb.dwarf2/entry-value-typedef.exp
+++ b/gdb/testsuite/gdb.dwarf2/entry-value-typedef.exp
@@ -31,7 +31,7 @@
     return
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 if {![runto_main]} {
     return
diff --git a/gdb/testsuite/gdb.dwarf2/fission-base.exp b/gdb/testsuite/gdb.dwarf2/fission-base.exp
index 4d18ea0..9f70f30 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-base.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-base.exp
@@ -35,7 +35,7 @@
     return -1
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 if ![runto_main] {
     return -1
diff --git a/gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp b/gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp
index 4f5867c..7072b7e 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp
@@ -83,6 +83,6 @@
     gdb_remote_download host $dwo_file
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 gdb_test "ptype global_var" "type = int"
diff --git a/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp b/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
index 5be2e8e..aa54718 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
@@ -40,7 +40,7 @@
     return -1
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 if ![runto_main] {
     return -1
diff --git a/gdb/testsuite/gdb.dwarf2/fission-loclists.exp b/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
index 95c1fac..59cd10b 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
@@ -35,7 +35,7 @@
     return -1
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 if ![runto_main] {
     return -1
diff --git a/gdb/testsuite/gdb.dwarf2/fission-mix.exp b/gdb/testsuite/gdb.dwarf2/fission-mix.exp
index e4741c3..e6a430c 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-mix.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-mix.exp
@@ -35,7 +35,7 @@
     return -1
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 gdb_test "break -q main" "Breakpoint .*"
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
index 44e72d6..78f2798 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
@@ -203,7 +203,7 @@
     return -1
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 if ![runto_main] {
     return -1
diff --git a/gdb/testsuite/gdb.dwarf2/fission-reread.exp b/gdb/testsuite/gdb.dwarf2/fission-reread.exp
index 6821747..238afb1 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-reread.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-reread.exp
@@ -62,7 +62,7 @@
 remote_file target delete $dwo
 save_vars { GDBFLAGS } {
     append GDBFLAGS " -iex \"maint set dwarf synchronous on\""
-    clean_restart $binfile
+    clean_restart $::testfile
 }
 set output_dir [standard_output_file ""]
 set cmd "save gdb-index"
diff --git a/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp b/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp
index ef7cf92..6857a08 100644
--- a/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp
+++ b/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp
@@ -106,7 +106,7 @@
     return
 }
 
-clean_restart $binfile
+clean_restart $::testfile
 
 if { [gdb_starti_cmd] != 0 } {
     fail "failed to run to first instruction"
diff --git a/gdb/testsuite/gdb.dwarf2/gdb-add-index-symlink.exp b/gdb/testsuite/gdb.dwarf2/gdb-add-index-symlink.exp
index cd05925..9233637 100644
--- a/gdb/testsuite/gdb.dwarf2/gdb-add-index-symlink.exp
+++ b/gdb/testsuite/gdb.dwarf2/gdb-add-index-symlink.exp
@@ -56,7 +56,8 @@
 # Ok, we have a copy of $binfile with an index.
 # Restart gdb and verify the index was used.
 
-clean_restart $symlink
+clean_restart
+gdb_load $symlink
 gdb_test "mt print objfiles ${testfile}" \
     "(gdb_index|debug_names).*" \
     "index used"
diff --git a/gdb/testsuite/gdb.dwarf2/gdb-add-index.exp b/gdb/testsuite/gdb.dwarf2/gdb-add-index.exp
index 3285d1c..0fbd3a2 100644
--- a/gdb/testsuite/gdb.dwarf2/gdb-add-index.exp
+++ b/gdb/testsuite/gdb.dwarf2/gdb-add-index.exp
@@ -33,7 +33,7 @@
 # Ok, we have a copy of $binfile with an index.
 # Restart gdb and verify the index was used.
 
-clean_restart ${binfile}
+clean_restart ${::testfile}
 gdb_test "mt print objfiles ${testfile}" \
     "(gdb_index|debug_names).*" \
     "index used"
diff --git a/gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp b/gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp
index c0d5225..a8c5c39 100644
--- a/gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp
+++ b/gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp
@@ -47,7 +47,7 @@
 }
 
 # Start GDB and load in the executable.
-clean_restart ${binfile}
+clean_restart ${::testfile}
 
 # If the executable was built with an index, or lacks the debug
 # information required to create an index, then we'll not be able to
diff --git a/gdb/testsuite/gdb.dwarf2/gdb-index-types-dwarf5.exp b/gdb/testsuite/gdb.dwarf2/gdb-index-types-dwarf5.exp
index d6f5e48..effa127 100644
--- a/gdb/testsuite/gdb.dwarf2/gdb-index-types-dwarf5.exp
+++ b/gdb/testsuite/gdb.dwarf2/gdb-index-types-dwarf5.exp
@@ -29,7 +29,7 @@
     return -1
 }
 
-clean_restart ${binfile}
+clean_restart ${::testfile}
 
 # Verify that .gdb_index section is not ignored.
 set index [have_index $binfile]
diff --git a/gdb/testsuite/gdb.dwarf2/gdb-index.exp b/gdb/testsuite/gdb.dwarf2/gdb-index.exp
index ebeb62b..f7c3337 100644
--- a/gdb/testsuite/gdb.dwarf2/gdb-index.exp
+++ b/gdb/testsuite/gdb.dwarf2/gdb-index.exp
@@ -98,20 +98,24 @@
 set filter "gdb_index|debug_names|Psymtabs|Cooked"
 set cmd "pipe mt print objfiles ${testfile} | grep -E \"$filter\""
 set cmd_re [string_to_regexp $cmd]
+set testfile_with_index bla
 gdb_test_multiple $cmd $test {
     -re ^$cmd_re {
 	exp_continue
     }
     -re "gdb_index.*${gdb_prompt} $" {
-	set binfile_with_index $binfile
+	set testfile_with_index $testfile
+	set binfile_with_index [standard_output_file $testfile_with_index]
 	set host_binfile_with_index [gdb_remote_download host $binfile]
     }
     -re "debug_names.*${gdb_prompt} $" {
-	set binfile_with_index $binfile
+	set testfile_with_index $testfile
+	set binfile_with_index [standard_output_file $testfile_with_index]
 	set host_binfile_with_index [gdb_remote_download host $binfile]
     }
     -re "(Psymtabs|Cooked).*${gdb_prompt} $" {
 	lassign [local_add_gdb_index $binfile] binfile_with_index host_binfile_with_index
+	set testfile_with_index [file tail $binfile_with_index]
 	if { ${binfile_with_index} == "" } {
 	    return -1
 	}
@@ -124,7 +128,7 @@
 # Ok, we have a copy of $binfile with an index.
 # Restart gdb and verify the index was used.
 
-clean_restart ${binfile_with_index}
+clean_restart $testfile_with_index
 gdb_test "mt print objfiles ${testfile}" \
     "(gdb_index|debug_names).*" \
     "index used"
diff --git a/gdb/testsuite/gdb.dwarf2/imported-unit-runto-main.exp b/gdb/testsuite/gdb.dwarf2/imported-unit-runto-main.exp
index c4bacb1..cdcb810 100644
--- a/gdb/testsuite/gdb.dwarf2/imported-unit-runto-main.exp
+++ b/gdb/testsuite/gdb.dwarf2/imported-unit-runto-main.exp
@@ -77,6 +77,6 @@
     return -1
 }
 
-clean_restart ${binfile}
+clean_restart ${::testfile}
 
 runto main
diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
index ea871d6..7665680 100644
--- a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
+++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
@@ -330,7 +330,7 @@
 ### Second GDB session.
 
 with_test_prefix "second session" {
-    clean_restart $binfile
+    clean_restart $::testfile
 
     # Again, do whatever is necessary to make sure that the shared library is
     # loaded for remote targets.