Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix windows_nat_target::fake_create_process ptid
Date: Mon, 25 Mar 2024 19:36:04 +0000	[thread overview]
Message-ID: <2544bf99-997c-4065-8ae9-4dfb0b07d17b@palves.net> (raw)
In-Reply-To: <86wmptzc2f.fsf@gnu.org>

On 2024-03-23 06:39, Eli Zaretskii wrote:
>> From: Pedro Alves <pedro@palves.net>
>> Date: Fri, 22 Mar 2024 19:30:30 +0000
>>
>> While working on Windows non-stop mode, I managed to introduce a bug
>> that led to fake_create_process being called.  That then resulted in
>> GDB crashes later on, because fake_create_process added a thread with
>> an incorrect ptid for this target.  It is putting dwThreadId in the
>> tid field of the ptid instead of on the lwp field.  This is fixed by
>> this patch.
>>
>> I do however wonder why nobody has seen it this long.
> 
> AFAIU, to actually see the bug, one would need to attach GDB to a
> process whose main thread has exited, is that true?  If so, I'm not
> surprised this bug was not reported: it's unusual for the main thread
> to exit without shutting down the process, and the need to attach to
> such a process (as opposed to having it run from GDB to begin with)
> makes that even more rare.  And finally, not every bug is reported by
> the first person who sees it the first time, right?

Yes, that could be the reason.  But it could also be because the brokenness with the
Windows debug API that Chris was seeing only happens on Windows versions we no
longer claim support for (i.e., earlier than Windows XP).

Anyhow, the patch is pretty obvious on its own, so I went ahead and merged it
without that blurb in the commit log, like below.

I also wrote a testcase that exercises the scenario in question.  I'll post
that next.

Here's what I merged.

From ccf3148e3133f016a8e1484e85e5e4d8c271c4f0 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Fri, 22 Mar 2024 19:28:55 +0000
Subject: [PATCH] Fix windows_nat_target::fake_create_process ptid

While working on Windows non-stop mode, I managed to introduce a bug
that led to fake_create_process being called.  That then resulted in
GDB crashes later on, because fake_create_process added a thread with
an incorrect ptid for this target.  It is putting dwThreadId in the
tid field of the ptid instead of on the lwp field.  This is fixed by
this patch.

Change-Id: Iaee5d2deaa57c501f7e6909f8ac242af9b183215
---
 gdb/windows-nat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index ee38b985efa..b123a66ef0f 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1371,8 +1371,8 @@ windows_nat_target::fake_create_process ()
       throw_winerror_with_name (_("OpenProcess call failed"), err);
       /*  We can not debug anything in that case.  */
     }
-  add_thread (ptid_t (windows_process.current_event.dwProcessId, 0,
-			      windows_process.current_event.dwThreadId),
+  add_thread (ptid_t (windows_process.current_event.dwProcessId,
+		      windows_process.current_event.dwThreadId, 0),
 		      windows_process.current_event.u.CreateThread.hThread,
 		      windows_process.current_event.u.CreateThread.lpThreadLocalBase,
 		      true /* main_thread_p */);

base-commit: f9ee45c3a95ac37cf1c3f4ac6be34b9a53e306f4
-- 
2.43.2



  reply	other threads:[~2024-03-25 19:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 19:30 Pedro Alves
2024-03-23  6:39 ` Eli Zaretskii
2024-03-25 19:36   ` Pedro Alves [this message]
2024-03-25 19:57     ` [PATCH] New testcase gdb.threads/leader-exit-attach.exp (PR threads/8153) Pedro Alves
2024-03-26 15:26       ` Tom Tromey
2024-03-26 19:27         ` Pedro Alves
2024-03-26 20:04           ` Tom Tromey
2024-04-12 17:45       ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2544bf99-997c-4065-8ae9-4dfb0b07d17b@palves.net \
    --to=pedro@palves.net \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox