From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hI5LOkffm2hR+AEAWB0awg (envelope-from ) for ; Tue, 12 Aug 2025 20:41:43 -0400 Received: by simark.ca (Postfix, from userid 112) id DF73D1E0B3; Tue, 12 Aug 2025 20:41:43 -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.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 2D9F61E093 for ; Tue, 12 Aug 2025 20:41:43 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 905A43858C2D for ; Wed, 13 Aug 2025 00:41:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 905A43858C2D Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by sourceware.org (Postfix) with ESMTPS id 9CBFF3858D37 for ; Wed, 13 Aug 2025 00:41:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CBFF3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9CBFF3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1755045668; cv=none; b=ARKkc6Fja/W0Gp9SIIG3TMFHXxDCksGMsfvsMVc9CmO4gPIFUig7W0IN6VIf72BsIx+gsoJPsd1Q08MMUDoXGIqOhVYLHnCMW5yz6vAgBjySOLkGIeZUne5FMfhBPN4Kq/8YztbTqc1uqGCzA3bWzBq+EQM/FCqGf0LBh1WqOBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1755045668; c=relaxed/simple; bh=SBYIV0XBmwCSTHXmdjLCqvaqhPYCEU1dWGauLYJm3rA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WqPrPcnmm8cog/79xDm5C0QmFBYl+cC1R2IfjnXcODt5Fw8DoYlIAR3bzIA4XOyYCbWNP3eCkUSJbpsdouNTDSeDda7JoM25qGgP0TAoDbyi+8xoEEjSu20E77ROozVtBl7U6NduSpZ2dMO2Q6JAjbfM6izgSTgTe6FFwAvnlc0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CBFF3858D37 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3b7886bee77so4263949f8f.0 for ; Tue, 12 Aug 2025 17:41:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755045667; x=1755650467; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FrBdxrT+3lThVNa9EDPL2vekhMwK4oyuduRGk3C4oXg=; b=miRy8pmETdJ9ygFP0xQsk6tfLYrIIG9RSe4MEucfFDD+9zGh+ugbIAjXOS+IhzOd+p BQHhYSvJyHnvjOvM44gngtVpug2L5ZedSsEWDPaSLn0PSnhDgLPYCgfBaIFpZd+hElCs XOEh1Z3/VFct51+ObDKKSHJ+Rdri7g+L8Rs3Lf2Yp29CJFyQKEgo4vWvjSldFmBOzpbu EW+tzWump9svJ/ohXhuEP9CQR8H1nAQMBauvppozJm9IA5zcxZaGimoMoNNVOcCZmuYK 0L8knecZaVuJR/4utgnkJTivKzrCGg3JMJgrS+LBUfmgOxj6hTrYsBcibsf9bile3LRE eMgQ== X-Gm-Message-State: AOJu0YwL8McJvHJ9ATr3KV3S+H3/Pz+nj+lwKyGgfMbeJwhq36LFBgVY cNUshB/GsYKf0AC71pZtJOCu9859RgsDDjG4K271wB7VMW0z/U/0PPDwVhIYtsYH X-Gm-Gg: ASbGnctqWAu0VR0t4gN6rRbfs5Nzt4I/jJtcgv9QGizIsAgB23adO/FVa3+9snL6y1f hAHT0L4ymWM3b31jW/QaKyEqMxycnZlHGm1VlJTtNpMGssdBgMazUGRnF3FxAq57aNisYHCC3d1 B9RchWi59bFWjuN5zdofKwEn7lYwuI/JBvtGwN7tbQZZhV+b9m9qhkC0W7p3NDia2OITSxOMDZ4 JzJqwCRc7EgRaE/C6qkuEJV6zIdClAn7UJmQj9mpmrVlY7873EZafyMt6XoGCnltFr+PULaDQsr yve6h2mosa4uW4r1xNyE0KEmKLnvq3Y2Js7OjzYIGbrtquFbnguU9ImPdvFWxK87ALsBhMG/HQa 4tM5AhjpXNPgBUpqTM6v2ukxTJCoYy19Vi/liovvwExlEJbcF/LMwUGM= X-Google-Smtp-Source: AGHT+IE1dFzo/YJf8GnmFmjGudhK4kA9pXKwBJOZgvE5SNisU/UxsVW92XHrbTmx2R8XAPxiJnLVyw== X-Received: by 2002:a05:6000:4284:b0:3a3:65b5:51d7 with SMTP id ffacd0b85a97d-3b917e4f617mr738302f8f.26.1755045667014; Tue, 12 Aug 2025 17:41:07 -0700 (PDT) Received: from localhost (bl21-214-172.dsl.telepac.pt. [2.82.214.172]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3b79c3abec8sm47768665f8f.8.2025.08.12.17.41.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Aug 2025 17:41:05 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Automatically handle includes in testsuite/lib/ Date: Wed, 13 Aug 2025 01:41:00 +0100 Message-ID: <20250813004100.2525141-1-pedro@palves.net> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Instead of manually calling lappend_include_file in every testcase that needs to include a file in testsuite/lib/, handle testsuite/lib/ includes automatically in gdb_compile. As an example, gdb.base/backtrace.exp is adjusted to no longer explicitly call lappend_include_file for testsuite/lib/attributes.h. Tested on x86-64 GNU/Linux with both: $ make check RUNTESTFLAGS=" \ --host_board=local-remote-host-native \ --target_board=local-remote-host-native \ HOST_DIR=/tmp/foo/" \ TESTS="gdb.base/backtrace.exp" and: $ make check TESTS="gdb.base/backtrace.exp" and confirming that the testcase still compiles and passes cleanly. Also ran full testsuite on x86-64 GNU/Linux in normal mode. Change-Id: I5ca77426ea4a753a995c3ad125618c02cd952576 --- gdb/testsuite/gdb.base/backtrace.exp | 6 +-- gdb/testsuite/lib/gdb.exp | 63 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/gdb/testsuite/gdb.base/backtrace.exp b/gdb/testsuite/gdb.base/backtrace.exp index 35784b413cf..3020666d741 100644 --- a/gdb/testsuite/gdb.base/backtrace.exp +++ b/gdb/testsuite/gdb.base/backtrace.exp @@ -17,11 +17,7 @@ standard_testfile -set flags {} -lappend flags debug -lappend_include_file flags $srcdir/lib/attributes.h - -if { [prepare_for_testing "failed to prepare" $testfile $srcfile $flags] } { +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { return -1 } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 98691dfce25..0361f10b9a6 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6311,6 +6311,9 @@ proc gdb_compile {source dest type options} { } } + # Automatically handle includes in testsuite/lib/. + auto_lappend_include_files options $source + cond_wrap [expr $pie != -1 || $nopie != -1] \ with_PIE_multilib_flags_filtered { set result [target_compile $source $dest $type $options] @@ -11114,6 +11117,66 @@ proc lappend_include_file { flags file } { } } +# Helper for auto_lappend_include_files that handles one source file, +# and tracks the list of already-visited files. + +proc auto_lappend_include_files_1 {flags source {visited {}}} { + upvar $flags up_flags + upvar $visited up_visited + global srcdir + + set ext [string tolower [file extension $source]] + if {$ext ni {".c" ".cpp" ".cc" ".h" ".s"}} { + return + } + + if {[catch {open $source r} fh err]} { + error "Failed to open file '$source': $err" + } + set contents [read $fh] + close $fh + + lappend up_visited $source + + # Match lines like: + # #include "gdb_foo.h" + set re "^\\s*#include\\s+\"(.*)\"" + + foreach line [split $contents "\n"] { + if {[regexp $re $line -> basename]} { + set lib_file "$srcdir/lib/$basename" + + # If already processed, skip. + if {[lsearch -exact $up_visited $lib_file] != -1} { + continue + } + + if {![file exists $lib_file]} { + continue + } + + # Append to include list, and recurse into the included + # file. + lappend_include_file up_flags $lib_file + auto_lappend_include_files_1 up_flags $lib_file up_visited + } + } +} + +# Automatically handle includes under gdb/testsuite/lib/. +# +# For each source file in SOURCES, look for #include directives +# including files that live in testsuite/lib/. For each such included +# file, call lappend_include_file for it. + +proc auto_lappend_include_files {flags sources} { + upvar $flags up_flags + set visited {} + foreach src $sources { + auto_lappend_include_files_1 up_flags $src visited + } +} + # Return a list of supported host locales. gdb_caching_proc host_locales { } { base-commit: f5b1b0288a97965bd71668b046fa35a85c4cea04 -- 2.50.1