Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed] [gdb/testsuite] Make sure cleanup is run in section_get
Date: Mon, 19 Oct 2026 11:34:18 +0200	[thread overview]
Message-ID: <20261019093418.353429-1-tdevries@suse.de> (raw)

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


                 reply	other threads:[~2026-10-19  9:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261019093418.353429-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox