From patchwork Sun Nov 18 16:46:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Zaretskii X-Patchwork-Id: 30181 Received: (qmail 7067 invoked by alias); 18 Nov 2018 16:46:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 7057 invoked by uid 89); 18 Nov 2018 16:46:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=probe, fopen, *filename, probing X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 18 Nov 2018 16:46:19 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gOQD8-0001ED-Ja for gdb-patches@sourceware.org; Sun, 18 Nov 2018 11:46:17 -0500 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:58221) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gOQD8-0001Dd-GT for gdb-patches@sourceware.org; Sun, 18 Nov 2018 11:46:14 -0500 Received: from [176.228.60.248] (port=3128 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gOQD8-00051G-45 for gdb-patches@sourceware.org; Sun, 18 Nov 2018 11:46:14 -0500 Date: Sun, 18 Nov 2018 18:46:17 +0200 Message-Id: <838t1qtjty.fsf@gnu.org> From: Eli Zaretskii To: gdb-patches@sourceware.org Subject: "Invalid parameter passed to C runtime function" from MinGW GDB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-IsSubscribed: yes While debugging the issue with internal_error when stepping out of 'main', I noticed that GDB emits the above warning many times. It turns out the warning is triggered by this: common/filestuff.c: gdb_file_up gdb_fopen_cloexec (const char *filename, const char *opentype) { FILE *result; /* Probe for "e" support once. But, if we can tell the operating system doesn't know about close on exec mode "e" without probing, skip it. E.g., the Windows runtime issues an "Invalid parameter passed to C runtime function" OutputDebugString warning for unknown modes. Assume that if O_CLOEXEC is zero, then "e" isn't supported. */ static int fopen_e_ever_failed_einval = O_CLOEXEC == 0; <<<<<<<<<<<< if (!fopen_e_ever_failed_einval) { char *copy; copy = (char *) alloca (strlen (opentype) + 2); strcpy (copy, opentype); /* This is a glibc extension but we try it unconditionally on this path. */ strcat (copy, "e"); result = fopen (filename, copy); <<<<<<<<<<<<<<<<<< MinGW doesn't support the "e" mode. As you see, we try to be smart about that, but that trick no longer works, because Gnulib does this: build-gnulib/import/fcntl.h: #if !defined O_CLOEXEC && defined O_NOINHERIT /* Mingw spells it 'O_NOINHERIT'. */ # define O_CLOEXEC O_NOINHERIT #endif and O_CLOEXEC is no longer zero. I propose to fix this as below. Any objections to committing this to master (with a suitable ChangeLog, of course)? diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c index d4bd1a8..3fa035a 100644 --- a/gdb/common/filestuff.c +++ b/gdb/common/filestuff.c @@ -300,8 +300,10 @@ gdb_fopen_cloexec (const char *filename, const char *opentype) skip it. E.g., the Windows runtime issues an "Invalid parameter passed to C runtime function" OutputDebugString warning for unknown modes. Assume that if O_CLOEXEC is zero, then "e" isn't - supported. */ - static int fopen_e_ever_failed_einval = O_CLOEXEC == 0; + supported. On MinGW, O_CLOEXEC is an alias of O_NOINHERIT, and + "e" isn't supported. */ + static int fopen_e_ever_failed_einval = + O_CLOEXEC == 0 || O_CLOEXEC == O_NOINHERIT; if (!fopen_e_ever_failed_einval) {