From patchwork Fri Mar 3 14:06:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 65973 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9DCB038582BE for ; Fri, 3 Mar 2023 14:06:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DCB038582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677852388; bh=Qx4vqaC+mVB2GTLUCe5cRtsW0tjLMYhHtFmZvtDegFY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FJzq960xwKOEsUkCSvdWHTV264SNCY3mA3do61zvQTXMG41CZ/sMi1EP2pZlrRsA6 HVFvZB7i4Td2dHi7Nue+Fe2qF+aplkMbJKeeVMGyCHh0lbx/bGG/00iThNDrTZyi7u 5U7VSZALa7TdtWrlVLeqKVpLS0qXcczzLHkvNGEM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 7B1093858D37 for ; Fri, 3 Mar 2023 14:06:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B1093858D37 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AF88321CDE for ; Fri, 3 Mar 2023 14:06:03 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 98C991329E for ; Fri, 3 Mar 2023 14:06:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hCYNJMv+AWSwDQAAMHmgww (envelope-from ) for ; Fri, 03 Mar 2023 14:06:03 +0000 To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/testsuite] Allow args in gdb_caching_proc Date: Fri, 3 Mar 2023 15:06:02 +0100 Message-Id: <20230303140602.9477-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Test-case gdb.base/morestack.exp contains: ... require {have_compile_flag -fsplit-stack} ... and I want to cache the result of have_compile_flag. Currently gdb_caching_proc doesn't allow args, so I could add: ... gdb_caching_proc have_compile_flag_fsplit_stack { return [have_compile_flag -fsplit-stack] } ... and then use that proc instead, but I find this cumbersome and maintenance-unfriendly. Instead, allow args in a gdb_caching_proc, such that I can simply do: ... -proc have_compile_flag { flag } { +gdb_caching_proc have_compile_flag { flag } { ... Note that gdb_caching_procs with args do not work with the gdb.base/gdb-caching-procs.exp test-case, so those procs are skipped. Tested on x86_64-linux. --- gdb/testsuite/gdb.base/gdb-caching-proc.exp | 11 +++-- gdb/testsuite/lib/cache.exp | 50 ++++++++++++++++----- gdb/testsuite/lib/gdb.exp | 2 +- 3 files changed, 48 insertions(+), 15 deletions(-) base-commit: 6a208145d24c47912c8beb4f1f4b9abeb8d51134 diff --git a/gdb/testsuite/gdb.base/gdb-caching-proc.exp b/gdb/testsuite/gdb.base/gdb-caching-proc.exp index 6610c25157a..c8ffcca3797 100644 --- a/gdb/testsuite/gdb.base/gdb-caching-proc.exp +++ b/gdb/testsuite/gdb.base/gdb-caching-proc.exp @@ -63,10 +63,15 @@ proc test_file { file } { set fp [open $file] while { [gets $fp line] >= 0 } { - if [regexp -- "^gdb_caching_proc \[ \t\]*(\[^ \t\]*)" $line \ - match procname] { - lappend procnames $procname + if { ![regexp -- "^gdb_caching_proc \[ \t\]*(\[^ \t\]*)" $line \ + match procname] } { + continue } + if { [regexp -- "{\[ \t\]*\[^ \t\].*}" $line] } { + # With args. + continue + } + lappend procnames $procname } close $fp diff --git a/gdb/testsuite/lib/cache.exp b/gdb/testsuite/lib/cache.exp index b9f64837e66..212dab06729 100644 --- a/gdb/testsuite/lib/cache.exp +++ b/gdb/testsuite/lib/cache.exp @@ -23,7 +23,7 @@ proc ignore_pass { msg } { } # Call proc real_name and return the result, while ignoring calls to pass. -proc gdb_do_cache_wrap {real_name} { +proc gdb_do_cache_wrap {real_name args} { if { [info procs save_pass] != "" } { return [uplevel 2 $real_name] } @@ -31,7 +31,7 @@ proc gdb_do_cache_wrap {real_name} { rename pass save_pass rename ignore_pass pass - set code [catch {uplevel 2 $real_name} result] + set code [catch {uplevel 2 $real_name {*}$args} result] rename pass ignore_pass rename save_pass pass @@ -48,7 +48,7 @@ proc gdb_do_cache_wrap {real_name} { # A helper for gdb_caching_proc that handles the caching. -proc gdb_do_cache {name} { +proc gdb_do_cache {name args} { global gdb_data_cache objdir global GDB_PARALLEL @@ -68,6 +68,9 @@ proc gdb_do_cache {name} { # (e.g. unix/{-m32,-64}) correctly. We use "file join" here # because we later use this in a real filename. set cache_name [file join [target_info name] $name] + foreach arg $args { + set cache_name [file join $cache_name $arg] + } set is_cached 0 if {[info exists gdb_data_cache($cache_name)]} { @@ -95,7 +98,7 @@ proc gdb_do_cache {name} { } set real_name gdb_real__$name - set gdb_data_cache($cache_name) [gdb_do_cache_wrap $real_name] + set gdb_data_cache($cache_name) [gdb_do_cache_wrap $real_name {*}$args] if { $cache_verify == 1 && $is_cached == 1 } { set computed $gdb_data_cache($cache_name) if { $cached != $computed } { @@ -116,16 +119,41 @@ proc gdb_do_cache {name} { return $gdb_data_cache($cache_name) } -# Define a new proc named NAME that takes no arguments. BODY is the -# body of the proc. The proc will evaluate BODY and cache the -# results, both in memory and, if GDB_PARALLEL is defined, in the -# filesystem for use across invocations of dejagnu. +# Helper function for gdb_caching_proc. -proc gdb_caching_proc {name body} { +proc gdb_caching_proc_1 { name args body } { # Define the underlying proc that we'll call. set real_name gdb_real__$name - proc $real_name {} $body + proc $real_name $args $body # Define the advertised proc. - proc $name {} [list gdb_do_cache $name] + set body [list "gdb_do_cache" "$name"] + foreach arg $args { + lappend body $$arg + } + set body [join $body] + proc $name $args $body +} + +# Define a new proc named NAME, with optional args ARGS. BODY is the body of +# the proc. The proc will evaluate BODY and cache the results, both in memory +# and, if GDB_PARALLEL is defined, in the filesystem for use across +# invocations of dejagnu. +# +# Valid forms: +# gdb_caching_proc NAME BODY +# gdb_caching_proc NAME ARGS BODY + +proc gdb_caching_proc { name args } { + if { [llength $args] == 1 } { + set body [lindex $args 0] + set args {} + } elseif { [llength $args] == 2 } { + set body [lindex $args 1] + set args [lindex $args 0] + } else { + error "Incorrect number of arguments" + } + + gdb_caching_proc_1 $name $args $body } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 19c782bea46..01f04121c0b 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -9427,7 +9427,7 @@ proc have_syscall { name } { # Return 1 if compile flag FLAG is supported. -proc have_compile_flag { flag } { +gdb_caching_proc have_compile_flag { flag } { set src { void foo () {} } return [gdb_can_simple_compile have_compile_flag_$flag $src object \ additional_flags=$flag]