From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IfKDMsjlzGomzDoAWB0awg (envelope-from ) for ; Mon, 12 Oct 2026 09:51:04 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=oDL8M0aT; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C91DD1E04E; Mon, 12 Oct 2026 09:51:04 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 0B39D1E04E for ; Mon, 12 Oct 2026 09:51:03 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E40F4BA23DA for ; Mon, 12 Oct 2026 13:51:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E40F4BA23DA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=oDL8M0aT Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by sourceware.org (Postfix) with ESMTPS id 45B124BA23DF for ; Mon, 12 Oct 2026 13:50:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45B124BA23DF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 45B124BA23DF Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791813028; cv=none; b=k77bQuZZvGx3N/3ZB4T8Z1EFXLbANzhSov0qM+3TTe4zO7DYDzvkj1GVqXWihjihPFwxziMBsowp2ma4ISbKgB3elHZLvm9puoM6VPJ64WpibvcbUp1MXYm7ISfLdsIwBXFZeotY5HPmCmGFiwTVct8lLxANlQwE97mRrE5qM5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791813028; c=relaxed/simple; bh=6IUJfDgg+c8Cqj2DnjWRmMU1SMbptQUS94HBZYhOa7c=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=A83J7UOom3wtzTp2DnfpopN7JHJHF8792IeYmoVgMZycIndsSqPTNlYc8xGl3Cov06vfhWtbe3jpfK5iok16dauK7qw+ZD79HNaYDBZpszqNqFXAo18to+AICvIHNpUJokVq+K+oRZ5NrW/KIkZ2MJfKuQVNTk3CX3f+5mEAL38= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=oDL8M0aT DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45B124BA23DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791813023; x=1823349023; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=6IUJfDgg+c8Cqj2DnjWRmMU1SMbptQUS94HBZYhOa7c=; b=oDL8M0aTP+9SN9AbN3IBioK0BUFDgnz+PhJ0G5MSw481Vcz1BFccPg/C UBUrELh26RHiBTq9oSJzLRAXd3IA8qKj+1k2IHAy554YtR/jH3nALeB7a Na7okstjqY9tRuo0WnS5bBDfawgUYc9Ap79tjqzeomY+g71EksjkJjw5f 6EKmnL5Txh0lhBlsHV8yupNh0LGE6q0X+/gTD3f2e+cPBpQRukArUi54q 17k7YP+Ow42a3LnUQK820CCibc35n1cEG9AWjl9kStsUXc8wb5PFQF8Vm L/Vaqsyf4o64erl5RtGfaWOn1HWd62ZsqNmJfrX0a+anaJ7Te0sPTbfNk g==; X-CSE-ConnectionGUID: 7niT4FE7Qe2A2GXQ9CI3lg== X-CSE-MsgGUID: mJUvk7GkQLC4qFURdEXnMA== X-IronPort-AV: E=McAfee;i="6800,10657,11933"; a="526171" X-IronPort-AV: E=Sophos;i="6.27,153,1787036400"; d="scan'208";a="526171" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2026 06:50:21 -0700 X-CSE-ConnectionGUID: phx55gwJRj2+6MzWg3WByA== X-CSE-MsgGUID: Td14EppcQlSXl8ouaanJjw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,153,1787036400"; d="scan'208";a="1376987" Received: from bconlan-mobl.ger.corp.intel.com (HELO localhost) ([10.245.113.120]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2026 06:50:20 -0700 From: Abdul Basit Ijaz To: gdb-patches@sourceware.org Cc: abdul.b.ijaz@intel.com Subject: [PATCH 1/1] testsuite: Fix expected corefiles output folder for native-gdbserver boardfile Date: Mon, 12 Oct 2026 15:50:03 +0200 Message-Id: <20261012135003.7922-1-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 Tests that use set_inferior_cwd_to_output_dir and depend on a gdbserver-launched inferior crashing need this fix. These tests expect the kernel-generated core file to be created in the output directory. Tests using core_find are unaffected because core_find runs the program in a controlled directory. For example, gdb.base/bigcore.exp is affected. On the native-gdbserver board, core files generated by inferiors launched through gdbserver are written to gdb/testsuite/ rather than the output directory, causing them to be reported in gdb.sum as unexpected core files. set_inferior_cwd_to_output_dir uses "set cwd", which only takes effect when GDB starts the inferior. With "target remote", gdbserver has already created the inferior at startup, and the inferior inherits gdbserver's own working directory, which is gdb/testsuite/. gdb.base/auxv.exp has the same problem: it uses "set cwd" directly to make a temporary directory the inferior's working directory. Its core file ends up in gdb/testsuite/ instead, so the test does not find it and reports the native core tests as UNSUPPORTED. Fix this by recording the directory in ::inferior_cwd in set_inferior_cwd_to_output_dir. When gdbserver is spawned locally and ::inferior_cwd is set, gdbserver_start adds "--wrapper env -C --", so that only the inferior starts in that directory, and its core files are no longer reported as unexpected in the gdb.sum file. gdbserver itself still runs from gdb/testsuite/, so a crash of gdbserver still dumps core there and is reported as an unexpected core file. ::inferior_cwd is cleared in gdb_exit, so it does not carry over to later tests. gdb.base/auxv.exp sets ::inferior_cwd to its temporary directory itself, since it cannot use the output directory: that also holds the gcore-created file, which would match the test's "*core*" glob. The wrapper is not added, and a warning is printed instead, if: - the target is mingw or cygwin, where gdbserver does not support --wrapper, - the caller already passes --wrapper, since gdbserver does not handle multiple --wrapper options correctly, or - "env" on the target does not support -C (checked once and cached). The wrapper is also not added when gdbserver is started with --multi (extended-remote), since GDB then starts the inferior with "run" and passes the "set cwd" value itself. Tests that do not set ::inferior_cwd are not affected: gdbserver is started exactly as before. Ideally, the only core files left in gdb/testsuite/ after a test run come from crashes of GDB or gdbserver. With this fix, inferior core files that tests expect no longer end up there, but a few unexpected ones still do because of known bugs, e.g. gdb.base/foll-vfork.exp leaves 12 of them (PR gdb/14766, PR gdb/30574). Tested on x86_64-linux with the native-gdbserver and native-extended-gdbserver boards: gdb.base/bigcore.exp and gdb.base/auxv.exp now produce core files in the output directory, and gdb.server/wrapper.exp still passes. --- gdb/testsuite/gdb.base/auxv.exp | 5 ++++ gdb/testsuite/lib/gdb.exp | 13 +++++++-- gdb/testsuite/lib/gdbserver-support.exp | 37 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.base/auxv.exp b/gdb/testsuite/gdb.base/auxv.exp index 9d32cee8552..24a57997316 100644 --- a/gdb/testsuite/gdb.base/auxv.exp +++ b/gdb/testsuite/gdb.base/auxv.exp @@ -49,6 +49,11 @@ if {$core_works} { if {[gdb_test_no_output "set cwd $coredir" \ "set cwd to temporary directory for core dumps"]} { set core_works 0 + } else { + # "set cwd" has no effect on the inferior that gdbserver + # creates at startup with "target remote". Have + # gdbserver_start pass the directory to it instead. + set ::inferior_cwd $coredir } } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index a77063b0bf0..d0e3c615209 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7761,6 +7761,9 @@ proc gdb_start { } { } proc gdb_exit { } { + # The INFERIOR_CWD set by set_inferior_cwd_to_output_dir should not + # outlive the GDB session. + unset -nocomplain ::inferior_cwd catch default_gdb_exit } @@ -10261,13 +10264,19 @@ if {[info exists GDB_PARALLEL]} { proc set_inferior_cwd_to_output_dir {} { # Note this sets the inferior's cwd ("set cwd"), not GDB's ("cd"). - # If GDB crashes, we want its core dump in gdb/testsuite/, not in - # the testcase's dir, so we can detect the unexpected core at the + # If GDB or GDBSERVER crashes, we want its core dump in gdb/testsuite/, + # not in the testcase's dir, so we can detect the unexpected core at the # end of the test run. if {![is_remote host]} { set output_dir [standard_output_file ""] gdb_test_no_output "set cwd $output_dir" \ "set inferior cwd to test directory" + + # With "target remote", the inferior that gdbserver creates + # at startup inherits gdbserver's CWD, and "set cwd" has no + # effect on it. Record the requested CWD so that + # gdbserver_start can pass it to the inferior. + set ::inferior_cwd $output_dir } } diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp index f7fb9258649..5de065bcea2 100644 --- a/gdb/testsuite/lib/gdbserver-support.exp +++ b/gdb/testsuite/lib/gdbserver-support.exp @@ -293,6 +293,13 @@ proc gdbserver_default_get_comm_port { port } { return "$port" } +# Return 1 if "env" on the target supports the -C (--chdir) option. + +gdb_caching_proc gdbserver_env_has_chdir {} { + set status [lindex [remote_exec target "env -C / true"] 0] + return [expr {$status == 0}] +} + # Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS. # The port will be filled in between them automatically. # @@ -346,6 +353,33 @@ proc gdbserver_start { options arguments } { set gdbserver [find_gdbserver] + # An inferior that gdbserver creates at startup inherits the CWD + # of gdbserver, so "set cwd" does not apply to it. Start the + # inferior in the requested CWD through a wrapper instead. This + # way gdbserver itself stays in the testsuite directory, and its + # own core dumps are still detected. gdbserver concatenates + # multiple --wrapper options incorrectly, so don't add one if the + # caller already passes a wrapper. With --multi (extended-remote), + # GDB starts the inferior with "run" and sends the "set cwd" value + # itself, so no wrapper is needed. + set cwd_wrapper "" + if { [info exists ::inferior_cwd] && ![is_remote target] + && [string first "--multi" $options] == -1 } { + if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } { + warning "gdbserver does not support --wrapper on this target\ + (PR server/15967), core files may not be generated in\ + $::inferior_cwd" + } elseif { [string first "--wrapper" $options] != -1 } { + warning "gdbserver already has a --wrapper, core files\ + may not be generated in $::inferior_cwd" + } elseif { ![gdbserver_env_has_chdir] } { + warning "env does not support -C, core files may not be\ + generated in $::inferior_cwd" + } else { + set cwd_wrapper "--wrapper env -C $::inferior_cwd --" + } + } + # Loop till we find a free port. while 1 { # Fire off the debug agent. @@ -398,6 +432,9 @@ proc gdbserver_start { options arguments } { } } + if { $cwd_wrapper != "" } { + append gdbserver_command " $cwd_wrapper" + } if { $options != "" } { append gdbserver_command " $options" } -- 2.34.1 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.