From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 6CA9B3858401; Mon, 29 Apr 2024 15:21:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CA9B3858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1714404065; bh=sqSeYxHY40xntbEISEVg4D2bBEMVj7iqTqtp7OIptgs=; h=From:To:Subject:Date:From; b=acb1LyNLwz5uMXSAIlyhzVTxRhkXqGR+18yN+Wg9JpddhRR56+ygOUnFC0aXv4P/u R3gKKVGmhkgeqk7pI1aa6XNVQB+u3a1JeipnZc2TwjmAMl+uC/ziqzm7j8IjvAxfGq HOq50r3cCYGN/hbkdfToxgvbu8gww+ZMHljPt/wg= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/Cygwin: Fix attach pid error message X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: 2fb3ca4e88a8266427475596de8c667c9862e953 X-Git-Newrev: 43ca4ec2996a6bfbb8726f1c753aeb85fe0f92a4 Message-Id: <20240429152105.6CA9B3858401@sourceware.org> Date: Mon, 29 Apr 2024 15:21:05 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D43ca4ec2996a= 6bfbb8726f1c753aeb85fe0f92a4 commit 43ca4ec2996a6bfbb8726f1c753aeb85fe0f92a4 Author: Pedro Alves Date: Fri Jun 2 23:40:23 2023 +0100 gdb/Cygwin: Fix attach pid error message =20 On Cygwin, with "attach PID": =20 - GDB first tries to interpret PID as a Windows native PID, and tries to attach to that. =20 - if the attach fails, GDB then tries to interpret the PID as a Cygwin PID, and attach to that. =20 If converting the user-provided PID from a Cygwin PID to a Windows PID fails, you get this: =20 (gdb) attach 12345 Can't attach to process 0 (error 2: The system cannot find the file sp= ecified.) =20 Note "process 0". =20 With the fix in this commit, we'll now get: =20 (gdb) attach 12345 Can't attach to process 12345 (error 2: The system cannot find the fil= e specified.) =20 I noticed this while looking at gdb.log after running gdb.base/attach.exp on Cygwin. =20 Change-Id: I05b9dc1f3a634a822ea49bb5c61719f5e62c8514 Approved-By: Luis Machado Diff: --- gdb/windows-nat.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 3b3239ab938..70f955d9797 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2048,11 +2048,20 @@ windows_nat_target::attach (const char *args, int f= rom_tty) #ifdef __CYGWIN__ if (!ok) { - /* Try fall back to Cygwin pid. */ - pid =3D cygwin_internal (CW_CYGWIN_PID_TO_WINPID, pid); + /* Maybe PID was a Cygwin PID. Try the corresponding native + Windows PID. */ + DWORD winpid =3D cygwin_internal (CW_CYGWIN_PID_TO_WINPID, pid); =20 - if (pid > 0) - ok =3D DebugActiveProcess (pid); + if (winpid !=3D 0) + { + /* It was indeed a Cygwin PID. Fully switch to the + Windows PID from here on. We don't do this + unconditionally to avoid ending up with PID=3D0 in the + error message below. */ + pid =3D winpid; + + ok =3D DebugActiveProcess (winpid); + } } #endif