Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [pushed] [gdb/testsuite] Make sure cleanup is run in section_get
@ 2026-10-19  9:34 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2026-10-19  9:34 UTC (permalink / raw)
  To: gdb-patches

I ran test-case gdb.tui/debuginfod-query.exp and noticed a left-over temporary
file section_get.tmp.

The problem is that the cleanup in proc section_get is not reached if the
early exit is triggered.

Fix this using try finally.

While we're at it, drop unused declaration of global subdir.

Tested on x86_64-linux.
---
 gdb/testsuite/lib/gdb.exp | 52 ++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index dca32750fbf..dba696cc130 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -12305,32 +12305,34 @@ gdb_caching_proc root_user {} {
 # for sections ".interp" or ".gnu_debuglink".
 
 proc section_get {exec section} {
-    global subdir
-    set tmp [standard_output_file section_get.tmp]
-    set objcopy_program [gdb_find_objcopy]
-
-    set command "exec $objcopy_program -O binary --set-section-flags $section=A --change-section-address $section=0 -j $section $exec $tmp"
-    verbose -log "command is $command"
-    set result [catch {{*}$command} output]
-    verbose -log "result is $result"
-    verbose -log "output is $output"
-    if {$result == 1} {
-	return ""
-    }
-    set fi [open $tmp]
-    fconfigure $fi -translation binary
-    set data [read $fi]
-    close $fi
-    file delete $tmp
-    # .interp has size $len + 1 but .gnu_debuglink contains garbage after \000.
-    set len [string first \000 $data]
-    if {$len < 0} {
-	verbose -log "section $section not found"
-	return ""
+    try {
+	set tmp [standard_output_file section_get.tmp]
+	set objcopy_program [gdb_find_objcopy]
+	set command "exec $objcopy_program -O binary --set-section-flags $section=A --change-section-address $section=0 -j $section $exec $tmp"
+	verbose -log "command is $command"
+	set result [catch {{*}$command} output]
+	verbose -log "result is $result"
+	verbose -log "output is $output"
+	if {$result == 1} {
+	    return ""
+	}
+	set fi [open $tmp]
+	fconfigure $fi -translation binary
+	set data [read $fi]
+	close $fi
+	# .interp has size $len + 1 but .gnu_debuglink contains garbage after
+	# \000.
+	set len [string first \000 $data]
+	if {$len < 0} {
+	    verbose -log "section $section not found"
+	    return ""
+	}
+	set retval [string range $data 0 [expr {$len - 1}]]
+	verbose -log "section $section is <$retval>"
+	return $retval
+    } finally {
+	file delete $tmp
     }
-    set retval [string range $data 0 [expr {$len - 1}]]
-    verbose -log "section $section is <$retval>"
-    return $retval
 }
 
 # Return true if we expect the build-id from FILENAME to be included

base-commit: b3874756227969658bd718e7ba2b152538bbb60c
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-19  9:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19  9:34 [pushed] [gdb/testsuite] Make sure cleanup is run in section_get Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox