From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id McWYHN9+tmqHwQIAWB0awg (envelope-from ) for ; Fri, 25 Sep 2026 10:02:07 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ya1BGeSP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=SxzdyfzM; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wQHSrDkf; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Yv+oxbpd; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 70DDC1E06B; Fri, 25 Sep 2026 10:02:07 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DC83D1E04E for ; Fri, 25 Sep 2026 10:02:04 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A0B54BAE7ED for ; Fri, 25 Sep 2026 14:02:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A0B54BAE7ED Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ya1BGeSP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=SxzdyfzM; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wQHSrDkf; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Yv+oxbpd Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id DCC1B4BAE7ED for ; Fri, 25 Sep 2026 14:01:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCC1B4BAE7ED Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DCC1B4BAE7ED Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790344887; cv=none; b=jSxlAMFfp6dj6SX59mPibc/Oyn/P/BLAPbNkI8l0lToUK3+x+N01pk32XIlRva4ont1wb5g01O8KkZReimDaK6qFuPigtKDfcIoRPF352fKggsK6XXHJYQ4RjEsTf4E+gfocWy5cvfqVrXVAd5bQD8kZtxeSM1FSS0bMV6nC/zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790344887; c=relaxed/simple; bh=nCABHztQP4lSgEZWN/1JDrlA6Km1dn9/cCIJNN1n0eI=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=Qilmom8ZPf2Stw80cyUz5A0+sex3CfCTfBD4de/ISAdMX6/iCCvgzrR/3XcHsWC+cJDcYgWfPrpKmO05a//33KxUA7Ra4gu4L1J4TzTU4mivOYX6mIAkkA8bq3A7vfMS58CMlbRSKIUQxPv06ke94CQ8EnrYoXBQHcddROwjZR0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ya1BGeSP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=SxzdyfzM; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wQHSrDkf; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Yv+oxbpd DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCC1B4BAE7ED Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 805BB21FCE for ; Fri, 25 Sep 2026 14:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790344881; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CG5ZTE5bcBb1StEdqW/LbK6ThRcbKUNheORbOhJ2BFQ=; b=ya1BGeSP428/IHmyEECImDsfE///BKuoSBvdmwU0J2rx6X7F0vrkSZE+1IDIxEp3WNVh1U C2SBmdG1LSBu0kuL3mpz7f+uU7lJRZVQxtDbNCnMMu8z53xwcDHRRM0+7igW3Ixn12OXxA +LIXiLLHEH2ER+3+3vQ9dhy9ryeWehc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790344881; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CG5ZTE5bcBb1StEdqW/LbK6ThRcbKUNheORbOhJ2BFQ=; b=SxzdyfzMjmyjBa+LSz9lS4yyojwah6SOmaxWNNbl8YZpkAHuJGOuu9W+W6RWggJ/bWwfE3 wtAFPuu8IDE5HGDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=wQHSrDkf; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Yv+oxbpd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790344877; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CG5ZTE5bcBb1StEdqW/LbK6ThRcbKUNheORbOhJ2BFQ=; b=wQHSrDkfAVETg9TYZeYf9ChGxLErtjQ8ouakuFVxbE+Nx3XFsf2tggYLJZQaVLfFS07JtH vt6iFg6Gpcf8ibHyo58cm5lIuKH7QBxsu3fgT9yaGORu90NO5YJSfXy4PczsllrGKZyRbt rR3NLfIliOaYy2qPSh2W2jQTMMNiIv0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790344877; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CG5ZTE5bcBb1StEdqW/LbK6ThRcbKUNheORbOhJ2BFQ=; b=Yv+oxbpdQ8lIEy97op1Xhu0WpVK0w4pu8i5VPlnNmvCe8WyPjEfeQ2RqOHa/zJ6bgdROfp XP9zJ8AKn7wCh/Ag== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4873A132C9 for ; Fri, 25 Sep 2026 14:01:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wKLMLqx+tmoQUgAAD6G6ig:T3 (envelope-from ) for ; Fri, 25 Sep 2026 14:01:17 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [gdb/testsuite] Use try instead of catch Date: Fri, 25 Sep 2026 16:01:16 +0200 Message-ID: <20260925140116.1985238-3-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260925140116.1985238-1-tdevries@suse.de> References: <20260925140116.1985238-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 805BB21FCE X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:mid]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Use try instead of catch in a few places in lib/gdb.exp. --- gdb/testsuite/lib/gdb.exp | 230 +++++++++++++++++++++++--------------- 1 file changed, 139 insertions(+), 91 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 2cfdbdda09d..3496ddd4132 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -2251,15 +2251,16 @@ proc gdb_assert { condition {message ""} } { set message $condition } - set code [catch {uplevel 1 [list expr $condition]} res] - if {$code == 1} { - # If code is 1 (TCL_ERROR), it means evaluation failed and res contains - # an error message. Print the error message, and set res to 0 since we - # want to return a boolean. - warning "While evaluating expression in gdb_assert: $res" + try { + set res [uplevel 1 [list expr $condition]] + } on error {error_msg} { + # Evaluation failed. Print the error message, and return 0. + warning "While evaluating expression in gdb_assert: $error_msg" unresolved $message - set res 0 - } elseif { !$res } { + return 0 + } + + if { !$res } { fail $message } else { pass $message @@ -2719,7 +2720,10 @@ proc spawn_capture_tty_name { args } { # if it doesn't work, we want to be notified of that fact via the # normal Tcl error reporting mechanisms.) if {[tcl_version_at_least 9 0 0]} { - catch {fconfigure $spawn_id -encoding utf-8 -profile replace} + try { + fconfigure $spawn_id -encoding utf-8 -profile replace + } on error {} { + } } return $result } @@ -6514,8 +6518,10 @@ proc gdb_windows_manifest_obj {} { set cmd [list $windres -I [file dirname $rc_src] \ -i $rc_src -o $obj -O coff] verbose -log "Executing $cmd" - if {[catch {exec {*}$cmd} output]} { - verbose -log "gdb_windows_manifest_obj: windres failed: $output" + try { + exec {*}$cmd + } on error {msg} { + verbose -log "gdb_windows_manifest_obj: windres failed: $msg" return "" } @@ -7543,12 +7549,13 @@ proc send_gdb { string {type standard}} { proc send_inferior { string } { global inferior_spawn_id - # tclint-disable-next-line command-args - if {[catch "send -i $inferior_spawn_id -- \$string" errorInfo]} { - return "$errorInfo" - } else { - return "" + try { + send -i $inferior_spawn_id -- $string + } on error {msg} { + return "$msg" } + + return "" } # @@ -7856,7 +7863,10 @@ proc kill_wait_spawned_process { proc_spawn_id } { remote_exec build "kill -9 ${pid}" verbose -log "closing ${proc_spawn_id}" - catch {close -i $proc_spawn_id} + try { + close -i $proc_spawn_id + } on error {} { + } verbose -log "waiting for ${proc_spawn_id}" # If somehow GDB ends up still attached to the process here, a @@ -8765,7 +8775,10 @@ proc standard_testfile {args} { if {[info exists gdb_test_file_last_vars]} { foreach varname $gdb_test_file_last_vars { global $varname - catch {unset $varname} + try { + unset $varname + } on error {} { + } } } # 'executable' is often set by tests. @@ -9070,9 +9083,7 @@ proc gdb_get_line_number { text { file "" } } { set file "$srcdir/$subdir/$file" } - if {[catch { set fd [open "$file"] } message]} { - error "$message" - } + set fd [open "$file"] if {[tcl_version_at_least 9 0 0]} { fconfigure $fd -encoding utf-8 -profile replace @@ -9080,9 +9091,7 @@ proc gdb_get_line_number { text { file "" } } { set found -1 for { set line 1 } { 1 } { incr line } { - if {[catch { set nchar [gets "$fd" body] } message]} { - error "$message" - } + set nchar [gets "$fd" body] if {$nchar < 0} { break } @@ -9092,9 +9101,7 @@ proc gdb_get_line_number { text { file "" } } { } } - if {[catch { close "$fd" } message]} { - error "$message" - } + close "$fd" if {$found == -1} { error "undefined tag \"$text\"" @@ -9202,21 +9209,25 @@ proc rerun_to_main {} { proc exec_has_index_section { executable } { set readelf_program [gdb_find_readelf] - set res [catch {exec $readelf_program -S $executable \ - | grep -E "\.gdb_index|\.debug_names" }] - if { $res == 0 } { - return 1 + try { + exec $readelf_program -S $executable \ + | grep -E "\.gdb_index|\.debug_names" + } on error {} { + return 0 } - return 0 + + return 1 } # Return list with major and minor version of readelf, or an empty list. gdb_caching_proc readelf_version {} { set readelf_program [gdb_find_readelf] - set res [catch {exec $readelf_program --version} output] - if { $res != 0 } { + try { + set output [exec $readelf_program --version] + } on error {} { return [list] } + set lines [split $output \n] set line [lindex $lines 0] set res [regexp {[ \t]+([0-9]+)[.]([0-9]+)[^ \t]*$} \ @@ -9254,8 +9265,9 @@ proc exec_is_pie { executable } { # We're not testing readelf -d | grep "FLAGS_1.*Flags:.*PIE" # because the PIE flag is not set by all versions of gold, see PR # binutils/26039. - set res [catch {exec $readelf_program -h $executable} output] - if { $res != 0 } { + try { + set output [exec $readelf_program -h $executable] + } on error {} { return -1 } set res [regexp -line {^[ \t]*Type:[ \t]*DYN \((Position-Independent Executable|Shared object) file\)$} \ @@ -9538,22 +9550,26 @@ proc get_build_id { filename } { if { ([istarget "*-*-mingw*"] || [istarget *-*-cygwin*]) } { set objdump_program [gdb_find_objdump] - set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output] - verbose "result is $result" - verbose "output is $output" - if {$result == 1} { + try { + set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4] + } on error {msg} { + verbose "result is $msg" return "" } + verbose "output is $data" return $data } else { set tmp [standard_output_file "${filename}-tmp"] set objcopy_program [gdb_find_objcopy] - set result [catch {exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp} output] - verbose "result is $result" - verbose "output is $output" - if {$result == 1} { + try { + set output \ + [exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp] + } on error {msg} { + verbose "result is $msg" return "" } + verbose "output is $output" + set fi [open $tmp] fconfigure $fi -translation binary # Skip the NOTE header. @@ -9617,12 +9633,14 @@ proc gdb_gnu_strip_debug { dest args } { # Get rid of the debug info, and store result in stripped_file # something like gdb/testsuite/gdb.base/blah.stripped. - set result [catch {exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}} output] - verbose "result is $result" - verbose "output is $output" - if {$result == 1} { - return 1 + try { + set output \ + [exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}] + } on error {msg} { + verbose "result is $msg" + return 1 } + verbose "output is $output" # Workaround PR binutils/10802: # Preserve the 'x' bit also for PIEs (Position Independent Executables). @@ -9631,12 +9649,14 @@ proc gdb_gnu_strip_debug { dest args } { # Get rid of everything but the debug info, and store result in debug_file # This will be in the .debug subdirectory, see above. - set result [catch {exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}} output] - verbose "result is $result" - verbose "output is $output" - if {$result == 1} { - return 1 + try { + set output \ + [exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}] + } on error {msg} { + verbose "result is $msg" + return 1 } + verbose "output is $output" # If no-main is passed, strip the symbol for main from the separate # file. This is to simulate the behavior of elfutils's eu-strip, which @@ -9644,12 +9664,15 @@ proc gdb_gnu_strip_debug { dest args } { # objcopy or strip to remove the symbol table without also removing the # debugging sections, so this is as close as we can get. if {[lsearch -exact $args "no-main"] != -1} { - set result [catch {exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp} output] - verbose "result is $result" - verbose "output is $output" - if {$result == 1} { + try { + set output \ + [exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp] + } on error {msg} { + verbose "result is $msg" return 1 } + verbose "output is $output" + file delete "${debug_file}" file rename "${debug_file}-tmp" "${debug_file}" } @@ -9659,12 +9682,15 @@ proc gdb_gnu_strip_debug { dest args } { # section to the stripped_file, containing a pointer to the # debug_file. if {[lsearch -exact $args "no-debuglink"] == -1} { - set result [catch {exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${stripped_file}-tmp} output] - verbose "result is $result" - verbose "output is $output" - if {$result == 1} { + try { + set output \ + [exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${stripped_file}-tmp] + } on error {msg} { + verbose "result is $msg" return 1 } + verbose "output is $output" + file delete "${stripped_file}" file rename "${stripped_file}-tmp" "${stripped_file}" } @@ -10320,8 +10346,9 @@ proc core_find {binfile {deletefiles {}} {arg ""} {output_file "/dev/null"}} { true) \ >${output_file} 2>&1}] verbose -log "Executing on build: $cmd" - catch { + try { system $cmd + } on error {} { } # remote_exec host "${binfile}" @@ -10359,8 +10386,9 @@ proc core_find {binfile {deletefiles {}} {arg ""} {output_file "/dev/null"}} { true) \ >/dev/null 2>&1}] verbose -log "Executing on build: $cmd" - catch { + try { system $cmd + } on error {} { } foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" { @@ -10398,16 +10426,19 @@ gdb_caching_proc gdb_target_symbol_prefix {} { set prefix "" set objdump_program [gdb_find_objdump] - set result [catch {exec $objdump_program --syms $obj} output] + try { + set output [exec $objdump_program --syms $obj] + } on error {} { + return "" + } finally { + file delete $obj + } - if { $result == 0 \ - && ![regexp -lineanchor \ - { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } { + if {![regexp -lineanchor \ + { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } { verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2 } - file delete $obj - return $prefix } @@ -10941,7 +10972,10 @@ proc gdb_stdin_log_init { } { if {[info exists in_file]} { # Close existing file. - catch {close $in_file} + try { + close $in_file + } on error {} { + } } set logfile [standard_output_file_with_gdb_instance gdb.in] @@ -10992,7 +11026,10 @@ proc gdb_write_cmd_file { cmdline } { set logfile [standard_output_file_with_gdb_instance gdb.cmd] set cmd_file [open $logfile w] puts $cmd_file $cmdline - catch {close $cmd_file} + try { + close $cmd_file + } on error {} { + } } # Compare contents of FILE to string STR. Pass with MSG if equal, otherwise @@ -11004,12 +11041,11 @@ proc cmp_file_string { file str msg } { return } - set caught_error [catch { + try { set fp [open "$file" r] set file_contents [read $fp] close $fp - } error_message] - if {$caught_error} { + } on error {error_message} { error "$error_message" fail "$msg" return @@ -11128,12 +11164,13 @@ proc add_gdb_index { program {style ""} } { global srcdir GDB env set contrib_dir "$srcdir/../contrib" set env(GDB) [append_gdb_data_directory_option $GDB] - set result [catch {exec $contrib_dir/gdb-add-index.sh {*}$style $program} output] - if { $result != 0 } { - verbose -log "result is $result" - verbose -log "output is $output" + try { + set output [exec $contrib_dir/gdb-add-index.sh {*}$style $program] + } on error {msg} { + verbose -log "result is $msg" return 0 } + verbose -log "output is $output" return 1 } @@ -12108,9 +12145,12 @@ proc auto_lappend_include_files_1 {flags source {visited {}}} { return } - if {[catch {open $source r} fh err]} { - error "Failed to open file '$source': $err" + try { + set fh [open $source r] + } on error {msg} { + error "Failed to open file '$source': $msg" } + if {[tcl_version_at_least 9 0 0]} { fconfigure $fh -encoding utf-8 -profile replace } @@ -12235,12 +12275,14 @@ proc section_get {exec section} { 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} { + try { + set output [{*}$command] + } on error {msg} { + verbose -log "result is $msg" return "" } + verbose -log "output is $output" + set fi [open $tmp] fconfigure $fi -translation binary set data [read $fi] @@ -12284,13 +12326,14 @@ proc expect_build_id_in_core_file { filename } { # Use readelf to find the build-id note in FILENAME. set readelf_program [gdb_find_readelf] set cmd [list $readelf_program -WS $filename | grep ".note.gnu.build-id"] - set res [catch {exec {*}$cmd} output] verbose -log "running: $cmd" - verbose -log "result: $res" - verbose -log "output: $output" - if { $res != 0 } { + try { + set output [exec {*}$cmd] + } on error {msg} { + verbose -log "result: $msg" return false } + verbose -log "output: $output" # Extract the OFFSET from the readelf output. set res [regexp {NOTE[ \t]+([0-9a-f]+)[ \t]+([0-9a-f]+)} \ @@ -12304,7 +12347,9 @@ proc expect_build_id_in_core_file { filename } { # Now figure out the page size. This should be fine for Linux # hosts, see the istarget check above. - if {[catch {exec getconf PAGESIZE} page_size]} { + try { + set page_size [exec getconf PAGESIZE] + } on error {} { # Failed to fetch page size. return false } @@ -12380,7 +12425,10 @@ gdb_caching_proc have_startup_shell {} { proc dwz_version { } { set dwz_program "dwz" - set res [catch {exec $dwz_program --version} output] + try { + set output [exec $dwz_program --version] + } trap CHILDSTATUS {output} { + } # Don't check the exit value of 'dwz' process as 'dwz' doesn't # exit immediately after displaying the version number, and for -- 2.51.0