From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yfacJsmgFGqyHxoAWB0awg (envelope-from ) for ; Mon, 25 May 2026 15:19:37 -0400 Received: by simark.ca (Postfix, from userid 112) id 966DD1E0A3; Mon, 25 May 2026 15:19:37 -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 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 EBBE91E024 for ; Mon, 25 May 2026 15:19:36 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D0104BA7987 for ; Mon, 25 May 2026 19:19:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D0104BA7987 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id B55CE4BA799F for ; Mon, 25 May 2026 19:18:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B55CE4BA799F 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 B55CE4BA799F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736727; cv=none; b=ay77vUCUExyERd1RVRFkbW1QR0ICrAdif5/h9ggJvQ9kUidxOhImE52nHFYLdOCqUs4Sqi8/nJdDMOADBmMx7LlDakTOV5fPJ2Wl/gfPHkpLASgUTApNuj4y8MkdbZDd/CMnUdpttBzo8stfiLMShqN3K4pi0mQH3fdk5NBB5eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736727; c=relaxed/simple; bh=c0fKZLlH9v3eQroP8Ib2FJWHgERT8NOrXIOPuxcAh20=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VsJssVY2xeTfo2lU6D0JxqOyGgLoXbYgyS4/vsL0+UXIVDpKqq0fuZ7fpUfpyKasCUclFGFbkGq39RJWHdTV0L/rrxyLu0gxS310ciePnaP+hu5ZSFTbgl9f8HMMUIvBxoXFNQF5Zm3VLntYrsJm3A9GLUeO7+jf4vXHewT7XpA= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B55CE4BA799F Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490686877a1so7917535e9.0 for ; Mon, 25 May 2026 12:18:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736727; x=1780341527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=cfVe1e++3qHmpb19ahKoo2ZmTKmSDZ7/AlkgP6kHjPk=; b=ThyBEm6nYkFu7ooMsKJxn3RY/xrZn9FV6igSLLhzUl7k+2CQd0jUUD1Xg2GRyZnwfQ QIp/N349TvxnT64ncNCZX2GtP8Zcjbqz69ZTu6abK+9r5bij3euRUnDBHYvNEOZnXVBP t6A0LHOHz1quOnSw4F18mVIgoVLCavOXTlLzN9uxkteoAao4VTRNwHoY+1J0vlv2O2VD 6R6YRKyHHz4Nu+ugJQCUuKAajbe7sGcy7YiR7zs9lwb0H+r3ire+T2DSjXC5epksW1D0 DKFg7dJHsiZVvO9qDVscRB8z9oLsUoC0eOavGo0vSoUrPsxiC5BrZOqSnkBui19XsICC CKmQ== X-Gm-Message-State: AOJu0Yy132yFnsLp6QNtdBcRTO85mwsFn+uZJs7JfbpUZRT4mYJh6l3T nHqMeVpxu26KasQ2ncbGrQq04FGTipJqK3TU6gd25aJ/DcmvIN3ny53NqON0mA== X-Gm-Gg: Acq92OF7+9jgpkiWP/ZJs6g/ZtfVrepHdMk4RhOlf66KoWm0sBk3mx3+uUEq/5XAfAf +RlClqi12Yth6HHwYFDUNZt4Qt9PX221dHAZZis5NaLfu1VqlqNmuetG1EIXkqgdHCxS0wBcPD3 V8X9IT+sTBbbnNCxr+OoNmizQucfK1rbnF2iKRby1uHVSTgQ/ZeBKKMqZTOLI1cp5X4oGbelmwm lMEmnJISlbBt61OOgMVQk0fRFZQBKLTyqPJ8rlPq5I+W5fVYKK8H5igAGWpXkw0wxmyQVYUovW6 fNcX4jPlWbolctHHWc1jKmFdylULw/6rSP1a7TsW1wuzu1aqtsX8ei/gUN3PC1x9hz6pAxK7Zs4 JwFexUiGBzRAcTSCEBtviRvHxbvt9/trcx/AuvJ7oJRnQsX5xbvDpBbZ8VS92NTE1tJyjlO05nf hUaD1uqTlrypcTwjbleaO30Q== X-Received: by 2002:a05:600c:8b08:b0:490:5443:621e with SMTP id 5b1f17b1804b1-49054436375mr155515495e9.12.1779736726528; Mon, 25 May 2026 12:18:46 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-49044f2bad3sm288062735e9.0.2026.05.25.12.18.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:46 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 06/11] gdb/testsuite: Add mechanism to compile Windows native programs on Cygwin Date: Mon, 25 May 2026 20:18:24 +0100 Message-ID: <20260525191829.984105-7-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> 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 This adds a new "win32" option to gdb_compile that lets us compile native Windows programs when testing Cygwin. Will be used in a following patch. The testsuite tries to find the compiler to use automatically. You can also explicitly set it with WIN32_CC_FOR_TARGET. Change-Id: I86e954494cf7f88164cdf1c9127be46d5437986f commit-id: c71b8812 --- gdb/testsuite/README | 22 ++++++++ gdb/testsuite/lib/gdb.exp | 104 +++++++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/README b/gdb/testsuite/README index 60fd322ea4d..479e81f90f5 100644 --- a/gdb/testsuite/README +++ b/gdb/testsuite/README @@ -414,6 +414,28 @@ Example: make check-gdb TESTS="gdb.multi/multi-arch.exp" RUNTESTFLAGS="ARM_CC_FOR_TARGET=arm-linux-gnueabihf-gcc" +WIN32_CC_FOR_TARGET + +The Cygwin ports of GDB and GDBserver include basic support for +debugging native Windows programs. Some tests exercise this +particular feature. + +By default, the testsuite tries to find a compiler capable of +generating native Windows executables. If no compiler is found, or if +the executable generated by the found compiler can't be executed +correctly, the tests are marked UNSUPPORTED. The list of compiler +names the testsuite tries can be found in +gdb/testsuite/lib/gdb.exp:win32_cc_for_target. + +You can set WIN32_CC_FOR_TARGET to override the search and explicitly +specify the compiler to use. This variable should contain the command +line for the compiler, including the full path to it, if the compiler +is not in $PATH. + +Example: + + make check-gdb TESTS="gdb.base/exitsignal.exp" RUNTESTFLAGS="WIN32_CC_FOR_TARGET=x86_64-w64-mingw32-gcc" + Race detection ************** diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 28709004570..e21c1c1224f 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6128,6 +6128,10 @@ proc gdb_can_simple_compile_nodebug {name code {type object} {compile_flags ""} global gdb_saved_set_unbuffered_mode_obj set gdb_saved_set_unbuffered_mode_obj "" +# The name of the set_unbuffered_mode_saved.o object. Stored in a +# global variable so it can be overridden in some cases. +set gdb_saved_set_unbuffered_mode_obj_name set_unbuffered_mode_saved.o + # Escape STR sufficiently for use on host commandline. proc escape_for_host { str } { @@ -6201,6 +6205,7 @@ proc quote_for_host { args } { # Fortran 90, Go or Rust. # - debug: Build with debug information. # - optimize: Build with optimization. +# - win32: Build a native Windows program. Cygwin only. proc gdb_compile {source dest type options} { global GDB_TESTCASE_OPTIONS @@ -6212,6 +6217,11 @@ proc gdb_compile {source dest type options} { set outdir [file dirname $dest] + # Handle compiling native Windows programs when testing Cygwin. + if { [istarget *-*-cygwin*] && [lsearch -exact $options win32] != -1} { + return [gdb_compile_win32 $source $dest $type $options] + } + # GDB doesn't support minimal symbols in AIX, so fail the compilation # if nodebug is requested for an AIX target. if { [istarget *-*-aix*] && [lsearch -exact $options nodebug] != -1} { @@ -6635,9 +6645,11 @@ proc gdb_compile {source dest type options} { return $result } if {[is_remote host]} { - set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o + set gdb_saved_set_unbuffered_mode_obj \ + $::gdb_saved_set_unbuffered_mode_obj_name } else { - set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o + set gdb_saved_set_unbuffered_mode_obj \ + ${objdir}/$::gdb_saved_set_unbuffered_mode_obj_name } # Link a copy of the output object, because the # original may be automatically deleted. @@ -7003,6 +7015,38 @@ proc gdb_compile_openmp {source dest type options} { return [gdb_compile $source $dest $type $options] } +# Build a native Windows program from SOURCE. See prefatory comment +# for gdb_compile, above, for discussion of the parameters to this +# proc. This is meant to be used on Cygwin, to smoke test debugging +# native Windows programs with the Cygwin native backend. + +proc gdb_compile_win32 {source dest type options} { + if {![istarget *-*-cygwin*]} { + error "cygwin procedure called on non-cygwin target" + } + + save_vars { + ::target_triplet + ::CC_FOR_TARGET + ::gdb_saved_set_unbuffered_mode_obj + ::gdb_saved_set_unbuffered_mode_obj_name + } { + # So we trigger the set_unbuffered_mode_obj paths. + set ::target_triplet "x86_64-w64-mingw32" + + # We need a Win32-specific compilation of the + # set_unbuffered_mode object. + set ::gdb_saved_set_unbuffered_mode_obj "" + set ::gdb_saved_set_unbuffered_mode_obj_name \ + set_unbuffered_mode_saved_win32.o + + # Do this last, as this tries compiling internally. + set ::CC_FOR_TARGET [win32_cc_for_target] + + return [gdb_compile $source $dest $type $options] + } +} + # Send a command to GDB. # For options for TYPE see gdb_stdin_log_write @@ -11248,6 +11292,62 @@ gdb_caching_proc arm_cc_for_target {} { return "" } +# Return the compiler that can generate native Windows executables. +# Used when testing basic native Windows support on Cygwin. If +# WIN32_CC_FOR_TARGET is set, use that. If not, try a few common +# compiler names, making sure that the executable they produce can +# run. Note, this assumes global state has been set to target native +# Windows programs. See gdb_compile_win32. + +gdb_caching_proc win32_cc_for_target {} { + if {[info exists ::WIN32_CC_FOR_TARGET]} { + # If the user specified the compiler explicitly, then don't + # check whether the resulting binary runs outside GDB. Assume + # that it does, and if it turns out it doesn't, then the user + # should get loud FAILs, instead of UNSUPPORTED. + return $::WIN32_CC_FOR_TARGET + } + + # Fallback to a few common compiler names. Also confirm the + # produced binary actually runs on the system before declaring + # we've found the right compiler. + + # Only one compiler for now. + set compilers { + x86_64-w64-mingw32-gcc + } + + save_vars { + ::CC_FOR_TARGET + } { + foreach compiler $compilers { + if {![is_remote host] && [which $compiler] == 0} { + # Avoid "default_target_compile: Can't find + # $compiler." warning issued from gdb_compile. + continue + } + + set ::CC_FOR_TARGET $compiler + + set src { int main() { return 0; } } + if {[gdb_simple_compile win32-test-prog $src executable]} { + set target_obj [gdb_remote_download target $obj] + set result [remote_exec target $target_obj] + set status [lindex $result 0] + set output [lindex $result 1] + + file delete $obj + + if { $output == "" && $status == 0} { + return $compiler + } + } + } + } + + return "" +} + # Step until the pattern REGEXP is found. Step at most # MAX_STEPS times, but stop stepping once REGEXP is found. # CURRENT matches current location -- 2.53.0