From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA 2/2][master only] gdb/windows-nat.c: Get rid of main_thread_id global
Date: Tue, 16 Apr 2019 22:33:00 -0000 [thread overview]
Message-ID: <1555453982-77808-3-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1555453982-77808-1-git-send-email-brobecker@adacore.com>
Hello,
This global is meant to point to the "main" thread of execution of
the program we are debugging. It is set when attaching to a process
or when receiving a CREATE_PROCESS_DEBUG_EVENT event. The theory at
the time was that this was also going to be the thread receiving
the EXIT_PROCESS_DEBUG_EVENT event.
Unfortunately, we have discovered since then that this is actually
not guaranteed. What this means in practice is that there is moderate
risk that main_thread_id refers to a thread which no longer exists.
This global is used in 3 situations:
- OUTPUT_DEBUG_STRING_EVENT
- LOAD_DLL_DEBUG_EVENT
- UNLOAD_DLL_DEBUG_EVENT
It's not clear why we would need to use the main_thread_id in those cases
instead of using the thread ID provided by the kernel events itself.
So this patch implements this approach, which then allows us to delete
the main_thread_id global.
gdb/testsuite:
* windows-nat.c (main_thread_id): Delete.
(handle_output_debug_string): Replace main_thread_id by
current_event.dwThreadId.
(fake_create_process): Likewise.
(get_windows_debug_event) <CREATE_PROCESS_DEBUG_EVENT>:
Do not set main_thread_id.
<LOAD_DLL_DEBUG_EVENT>: Replace main_thread_id by
current_event.dwThreadId.
<UNLOAD_DLL_DEBUG_EVENT>: Likewise.
Tested on x86-windows and x86_64-windows using AdaCore's testsuite.
I'd like to observe this patch in our nightly testing environment
for at least a week before pushing it to master here. But it doesn't
preclude us from reviewing the patch, IMO.
Thoughts? OK for master (after a week of AdaCore testing)?
Thanks
--
Joel
---
gdb/windows-nat.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 039eb13..d188ed0 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -237,7 +237,6 @@ static DEBUG_EVENT current_event; /* The current debug event from
WaitForDebugEvent */
static HANDLE current_process_handle; /* Currently executing process */
static windows_thread_info *current_thread; /* Info on currently selected thread */
-static DWORD main_thread_id; /* Thread ID of the main thread */
/* Counts of things. */
static int exception_count = 0;
@@ -1026,7 +1025,7 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
ourstatus->kind = TARGET_WAITKIND_STOPPED;
retval = strtoul (p, &p, 0);
if (!retval)
- retval = main_thread_id;
+ retval = current_event.dwThreadId;
else if ((x = (LPCVOID) (uintptr_t) strtoull (p, NULL, 0))
&& ReadProcessMemory (current_process_handle, x,
&saved_context,
@@ -1402,13 +1401,12 @@ fake_create_process (void)
(unsigned) GetLastError ());
/* We can not debug anything in that case. */
}
- main_thread_id = current_event.dwThreadId;
current_thread
= windows_add_thread (ptid_t (current_event.dwProcessId, 0,
current_event.dwThreadId),
current_event.u.CreateThread.hThread,
current_event.u.CreateThread.lpThreadLocalBase);
- return main_thread_id;
+ return current_event.dwThreadId;
}
void
@@ -1604,7 +1602,6 @@ get_windows_debug_event (struct target_ops *ops,
break;
current_process_handle = current_event.u.CreateProcessInfo.hProcess;
- main_thread_id = current_event.dwThreadId;
/* Add the main thread. */
th = windows_add_thread
(ptid_t (current_event.dwProcessId, 0,
@@ -1648,7 +1645,7 @@ get_windows_debug_event (struct target_ops *ops,
catch_errors (handle_load_dll);
ourstatus->kind = TARGET_WAITKIND_LOADED;
ourstatus->value.integer = 0;
- thread_id = main_thread_id;
+ thread_id = current_event.dwThreadId;
break;
case UNLOAD_DLL_DEBUG_EVENT:
@@ -1661,7 +1658,7 @@ get_windows_debug_event (struct target_ops *ops,
catch_errors (handle_unload_dll);
ourstatus->kind = TARGET_WAITKIND_LOADED;
ourstatus->value.integer = 0;
- thread_id = main_thread_id;
+ thread_id = current_event.dwThreadId;
break;
case EXCEPTION_DEBUG_EVENT:
--
next prev parent reply other threads:[~2019-04-16 22:33 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-16 22:33 Windows native GDB event handling enhancement Joel Brobecker
2019-04-16 22:33 ` Joel Brobecker [this message]
[not found] ` <83imvcg0ud.fsf@gnu.org>
2019-04-17 17:38 ` [RFA 2/2][master only] gdb/windows-nat.c: Get rid of main_thread_id global Joel Brobecker
2019-04-17 18:29 ` Eli Zaretskii
2019-04-17 22:17 ` Joel Brobecker
2019-04-18 12:52 ` Eli Zaretskii
2019-04-18 14:54 ` Joel Brobecker
2019-04-18 16:27 ` Pedro Alves
2019-04-19 20:43 ` Joel Brobecker
2019-04-22 14:24 ` Pedro Alves
2019-04-22 15:20 ` André Pönitz
2019-04-22 17:29 ` Pedro Alves
2019-04-22 21:42 ` André Pönitz
2019-04-23 5:54 ` Eli Zaretskii
2019-04-24 20:10 ` André Pönitz
2019-04-25 5:39 ` Eli Zaretskii
2019-04-23 11:42 ` Pedro Alves
2019-04-16 22:33 ` [RFA 1/2][master+8.3] (Windows) fix thr != nullptr assert failure in delete_thread_1 Joel Brobecker
2019-04-18 14:52 ` Pedro Alves
2019-04-18 15:04 ` Pedro Alves
2019-04-28 16:58 ` [v2] Windows native GDB event handling enhancement Joel Brobecker
2019-04-28 16:58 ` [RFA v2 1/2][master+8.3] (Windows) fix thr != nullptr assert failure in delete_thread_1 Joel Brobecker
2019-04-28 16:58 ` [RFA v2 2/2][master only] gdb/windows-nat.c: Get rid of main_thread_id global Joel Brobecker
2019-04-30 13:00 ` [v2] Windows native GDB event handling enhancement Pedro Alves
2019-04-30 21:04 ` pushed(master+8.3): " Joel Brobecker
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=1555453982-77808-3-git-send-email-brobecker@adacore.com \
--to=brobecker@adacore.com \
--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