From patchwork Mon Oct 14 16:15:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 34952 Received: (qmail 15649 invoked by alias); 14 Oct 2019 16:22:43 -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 15624 invoked by uid 89); 14 Oct 2019 16:22:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=controls, accepts X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Oct 2019 16:22:41 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 36A525604F; Mon, 14 Oct 2019 12:15:26 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id uNDLiAYDXDH2; Mon, 14 Oct 2019 12:15:26 -0400 (EDT) Received: from murgatroyd.Home (174-29-53-230.hlrn.qwest.net [174.29.53.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id D4A2156043; Mon, 14 Oct 2019 12:15:25 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 9/9] Change type of argument to windows-nat.c:thread_rec Date: Mon, 14 Oct 2019 10:15:20 -0600 Message-Id: <20191014161520.13150-10-tromey@adacore.com> In-Reply-To: <20191014161520.13150-1-tromey@adacore.com> References: <20191014161520.13150-1-tromey@adacore.com> MIME-Version: 1.0 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. 2019-10-14 Tom Tromey * 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 e6a97f8b8c3..f038772d0e9 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -365,22 +365,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; } @@ -406,7 +428,7 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p) id = ptid.tid (); - if ((th = thread_rec (id, FALSE))) + if ((th = thread_rec (id, DONT_INVALIDATE_CONTEXT))) return th; th = new windows_thread_info (id, h, (CORE_ADDR) (uintptr_t) tlb); @@ -546,7 +568,7 @@ void windows_nat_target::fetch_registers (struct regcache *regcache, int r) { DWORD pid = regcache->ptid ().tid (); - windows_thread_info *th = thread_rec (pid, TRUE); + windows_thread_info *th = thread_rec (pid, INVALIDATE_CONTEXT); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -616,7 +638,7 @@ void windows_nat_target::store_registers (struct regcache *regcache, int r) { DWORD pid = regcache->ptid ().tid (); - windows_thread_info *th = thread_rec (pid, TRUE); + windows_thread_info *th = thread_rec (pid, INVALIDATE_CONTEXT); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -1114,7 +1136,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) { @@ -1230,7 +1252,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; @@ -1402,7 +1424,7 @@ windows_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig) ptid.pid (), ptid.tid (), step, sig)); /* Get context for currently selected thread. */ - th = thread_rec (inferior_ptid.tid (), FALSE); + th = thread_rec (inferior_ptid.tid (), DONT_INVALIDATE_CONTEXT); if (th) { if (step) @@ -1656,7 +1678,7 @@ get_windows_debug_event (struct target_ops *ops, inferior_ptid = ptid_t (current_event.dwProcessId, 0, thread_id); current_thread = th; if (!current_thread) - current_thread = thread_rec (thread_id, TRUE); + current_thread = thread_rec (thread_id, INVALIDATE_CONTEXT); } out: @@ -2956,7 +2978,7 @@ windows_nat_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr) { windows_thread_info *th; - th = thread_rec (ptid.tid (), 0); + th = thread_rec (ptid.tid (), DONT_INVALIDATE_CONTEXT); if (th == NULL) return false; @@ -2977,7 +2999,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.tid (), 0)->name.get (); + return thread_rec (thr->ptid.tid (), DONT_INVALIDATE_CONTEXT)->name.get (); } @@ -3140,7 +3162,8 @@ windows_nat_target::thread_alive (ptid_t ptid) gdb_assert (ptid.tid () != 0); tid = ptid.tid (); - 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