From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v3 10/29] Change type of argument to windows-nat.c:thread_rec
Date: Fri, 13 Mar 2020 13:08:36 -0600 [thread overview]
Message-ID: <20200313190855.28662-11-tromey@adacore.com> (raw)
In-Reply-To: <20200313190855.28662-1-tromey@adacore.com>
windows-nat.c:thread_rec accepts an integer parameter whose
interpretation depends on whether it is less than, equal to, or
greater than zero. I found this confusing at times, so this patch
replaces it with an enum instead.
gdb/ChangeLog
2020-03-13 Tom Tromey <tromey@adacore.com>
* windows-nat.c (enum thread_disposition_type): New.
(thread_rec): Replace "get_context" parameter with "disposition";
change type.
(windows_add_thread, windows_nat_target::fetch_registers)
(windows_nat_target::store_registers, handle_exception)
(windows_nat_target::resume, get_windows_debug_event)
(windows_nat_target::get_tib_address)
(windows_nat_target::thread_name)
(windows_nat_target::thread_alive): Update.
---
gdb/ChangeLog | 12 +++++++++
gdb/windows-nat.c | 63 ++++++++++++++++++++++++++++++++---------------
2 files changed, 55 insertions(+), 20 deletions(-)
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index ce83da0ff9f..cdc24ec7ebd 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -404,22 +404,44 @@ check (BOOL ok, const char *file, int line)
(unsigned) GetLastError ());
}
-/* Find a thread record given a thread id. If GET_CONTEXT is not 0,
- then also retrieve the context for this thread. If GET_CONTEXT is
- negative, then don't suspend the thread. */
+/* Possible values to pass to 'thread_rec'. */
+enum thread_disposition_type
+{
+ /* Do not invalidate the thread's context, and do not suspend the
+ thread. */
+ DONT_INVALIDATE_CONTEXT,
+ /* Invalidate the context, but do not suspend the thread. */
+ DONT_SUSPEND,
+ /* Invalidate the context and suspend the thread. */
+ INVALIDATE_CONTEXT
+};
+
+/* Find a thread record given a thread id. THREAD_DISPOSITION
+ controls whether the thread is suspended, and whether the context
+ is invalidated. */
static windows_thread_info *
-thread_rec (DWORD id, int get_context)
+thread_rec (DWORD id, enum thread_disposition_type disposition)
{
for (windows_thread_info *th : thread_list)
if (th->tid == id)
{
- if (!th->suspended && get_context)
+ if (!th->suspended)
{
- if (get_context > 0 && id != current_event.dwThreadId)
- th->suspend ();
- else if (get_context < 0)
- th->suspended = -1;
- th->reload_context = true;
+ switch (disposition)
+ {
+ case DONT_INVALIDATE_CONTEXT:
+ /* Nothing. */
+ break;
+ case INVALIDATE_CONTEXT:
+ if (id != current_event.dwThreadId)
+ th->suspend ();
+ th->reload_context = true;
+ break;
+ case DONT_SUSPEND:
+ th->reload_context = true;
+ th->suspended = -1;
+ break;
+ }
}
return th;
}
@@ -445,7 +467,7 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p)
id = ptid.lwp ();
- if ((th = thread_rec (id, FALSE)))
+ if ((th = thread_rec (id, DONT_INVALIDATE_CONTEXT)))
return th;
CORE_ADDR base = (CORE_ADDR) (uintptr_t) tlb;
@@ -617,7 +639,7 @@ void
windows_nat_target::fetch_registers (struct regcache *regcache, int r)
{
DWORD tid = regcache->ptid ().lwp ();
- windows_thread_info *th = thread_rec (tid, TRUE);
+ windows_thread_info *th = thread_rec (tid, INVALIDATE_CONTEXT);
/* Check if TH exists. Windows sometimes uses a non-existent
thread id in its events. */
@@ -713,7 +735,7 @@ void
windows_nat_target::store_registers (struct regcache *regcache, int r)
{
DWORD tid = regcache->ptid ().lwp ();
- windows_thread_info *th = thread_rec (tid, TRUE);
+ windows_thread_info *th = thread_rec (tid, INVALIDATE_CONTEXT);
/* Check if TH exists. Windows sometimes uses a non-existent
thread id in its events. */
@@ -1253,7 +1275,7 @@ handle_exception (struct target_waitstatus *ourstatus)
ourstatus->kind = TARGET_WAITKIND_STOPPED;
/* Record the context of the current thread. */
- thread_rec (current_event.dwThreadId, -1);
+ thread_rec (current_event.dwThreadId, DONT_SUSPEND);
switch (code)
{
@@ -1383,7 +1405,7 @@ handle_exception (struct target_waitstatus *ourstatus)
if (named_thread_id == (DWORD) -1)
named_thread_id = current_event.dwThreadId;
- named_thread = thread_rec (named_thread_id, 0);
+ named_thread = thread_rec (named_thread_id, DONT_INVALIDATE_CONTEXT);
if (named_thread != NULL)
{
int thread_name_len;
@@ -1588,7 +1610,7 @@ windows_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig)
ptid.pid (), (unsigned) ptid.lwp (), step, sig));
/* Get context for currently selected thread. */
- th = thread_rec (inferior_ptid.lwp (), FALSE);
+ th = thread_rec (inferior_ptid.lwp (), DONT_INVALIDATE_CONTEXT);
if (th)
{
#ifdef __x86_64__
@@ -1888,7 +1910,7 @@ windows_nat_target::get_windows_debug_event (int pid,
inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0);
current_thread = th;
if (!current_thread)
- current_thread = thread_rec (thread_id, TRUE);
+ current_thread = thread_rec (thread_id, INVALIDATE_CONTEXT);
}
out:
@@ -3307,7 +3329,7 @@ windows_nat_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
{
windows_thread_info *th;
- th = thread_rec (ptid.lwp (), 0);
+ th = thread_rec (ptid.lwp (), DONT_INVALIDATE_CONTEXT);
if (th == NULL)
return false;
@@ -3328,7 +3350,7 @@ windows_nat_target::get_ada_task_ptid (long lwp, long thread)
const char *
windows_nat_target::thread_name (struct thread_info *thr)
{
- return thread_rec (thr->ptid.lwp (), 0)->name.get ();
+ return thread_rec (thr->ptid.lwp (), DONT_INVALIDATE_CONTEXT)->name.get ();
}
@@ -3492,7 +3514,8 @@ windows_nat_target::thread_alive (ptid_t ptid)
gdb_assert (ptid.lwp () != 0);
tid = ptid.lwp ();
- return WaitForSingleObject (thread_rec (tid, FALSE)->h, 0) != WAIT_OBJECT_0;
+ return (WaitForSingleObject (thread_rec (tid, DONT_INVALIDATE_CONTEXT)->h, 0)
+ != WAIT_OBJECT_0);
}
void _initialize_check_for_gdb_ini ();
--
2.21.1
next prev parent reply other threads:[~2020-03-13 19:09 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-13 19:08 [PATCH v3 00/29] Windows code sharing + bug fix Tom Tromey
2020-03-13 19:08 ` [PATCH v3 01/29] Remove the "next" field from windows_thread_info Tom Tromey
2020-03-13 19:08 ` [PATCH v3 02/29] Rename win32_thread_info to windows_thread_info Tom Tromey
2020-03-13 19:08 ` [PATCH v3 03/29] Rename windows_thread_info::id to "tid" Tom Tromey
2020-03-13 19:08 ` [PATCH v3 04/29] Share windows_thread_info between gdb and gdbserver Tom Tromey
2020-03-13 19:08 ` [PATCH v3 05/29] Use new and delete for windows_thread_info Tom Tromey
2020-03-13 19:08 ` [PATCH v3 06/29] Change two windows_thread_info members to "bool" Tom Tromey
2020-03-13 19:08 ` [PATCH v3 07/29] Make windows_thread_info::name a unique_xmalloc_ptr Tom Tromey
2020-03-13 19:08 ` [PATCH v3 08/29] Use lwp, not tid, for Windows thread id Tom Tromey
2020-03-13 19:08 ` [PATCH v3 09/29] Share Windows thread-suspend and -resume code Tom Tromey
2020-03-13 19:08 ` Tom Tromey [this message]
2020-03-13 19:08 ` [PATCH v3 11/29] Handle pending stops from the Windows kernel Tom Tromey
2020-03-13 19:08 ` [PATCH v3 12/29] Call CloseHandle from ~windows_thread_info Tom Tromey
2020-03-13 19:08 ` [PATCH v3 13/29] Wrap shared windows-nat code in windows_nat namespace Tom Tromey
2020-03-13 19:08 ` [PATCH v3 14/29] Share thread_rec between gdb and gdbserver Tom Tromey
2020-03-13 19:08 ` [PATCH v3 15/29] Share get_image_name " Tom Tromey
2020-03-13 19:08 ` [PATCH v3 16/29] Share some Windows-related globals Tom Tromey
2020-03-13 19:08 ` [PATCH v3 17/29] Normalize handle_output_debug_string API Tom Tromey
2020-03-13 19:08 ` [PATCH v3 18/29] Fix up complaints.h for namespace use Tom Tromey
2020-03-13 19:08 ` [PATCH v3 19/29] Share handle_load_dll and handle_unload_dll declarations Tom Tromey
2020-03-13 19:08 ` [PATCH v3 20/29] Remove some globals from windows-nat.c Tom Tromey
2020-03-13 19:08 ` [PATCH v3 21/29] Share handle_exception Tom Tromey
2020-04-15 15:27 ` Simon Marchi
2020-04-15 16:54 ` Tom Tromey
2020-04-15 17:54 ` Simon Marchi
2020-04-15 19:13 ` Tom Tromey
2020-04-16 0:52 ` Simon Marchi
2020-03-13 19:08 ` [PATCH v3 22/29] Share some inferior-related Windows code Tom Tromey
2020-03-13 19:08 ` [PATCH v3 23/29] Introduce fetch_pending_stop Tom Tromey
2020-03-13 19:08 ` [PATCH v3 24/29] Move wait_for_debug_event to nat/windows-nat.c Tom Tromey
2020-03-13 19:08 ` [PATCH v3 25/29] Make last_wait_event static Tom Tromey
2020-03-13 19:08 ` [PATCH v3 26/29] Add read_pc / write_pc support to win32-low Tom Tromey
2020-03-13 19:08 ` [PATCH v3 27/29] Introduce win32_target_ops::decr_pc_after_break Tom Tromey
2020-03-13 19:08 ` [PATCH v3 28/29] Implement stopped_by_sw_breakpoint for Windows gdbserver Tom Tromey
2020-03-13 19:08 ` [PATCH v3 29/29] Add pending stop support to gdbserver's Windows port Tom Tromey
2020-04-16 1:11 ` [pushed] gdbserver: fix format string warning in win32-low.cc (was: Re: [PATCH v3 29/29] Add pending stop support to gdbserver's Windows port) Simon Marchi
2020-04-08 20:33 ` [PATCH v3 00/29] Windows code sharing + bug fix Tom Tromey
2020-04-08 22:17 ` Hannes Domani
2020-04-09 2:49 ` Tom Tromey
2020-04-09 14:57 ` Jon Turney
2020-04-09 15:08 ` Hannes Domani
2020-04-09 17:54 ` Tom Tromey
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=20200313190855.28662-11-tromey@adacore.com \
--to=tromey@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