From patchwork Tue Nov 26 17:11:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36222 Received: (qmail 94997 invoked by alias); 26 Nov 2019 17:12:03 -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 94790 invoked by uid 89); 26 Nov 2019 17:12:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=1997 X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2019 17:11:58 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id E625120D24; Tue, 26 Nov 2019 12:11:56 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 3413220D21 for ; Tue, 26 Nov 2019 12:11:32 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 151AF28173 for ; Tue, 26 Nov 2019 12:11:32 -0500 (EST) X-Gerrit-PatchSet: 1 Date: Tue, 26 Nov 2019 12:11:32 -0500 From: "Tom Tromey (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] Share thread_rec between gdb and gdbserver X-Gerrit-Change-Id: I128a36466e0774fe2beca1c63a6675bd91ff7b26 X-Gerrit-Change-Number: 708 X-Gerrit-ChangeURL: X-Gerrit-Commit: b612ef4ee9a7b093f5b40ece5914fd67ece17884 References: Reply-To: tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/708 ...................................................................... Share thread_rec between gdb and gdbserver This changes gdb and gdbserver to use the same calling convention for the "thread_rec" helper function. Fully merging these is difficult due to differences in how threads are managed by the enclosing applications; but sharing a declaration makes it possible for future shared code to call this method. gdb/ChangeLog 2019-11-26 Tom Tromey * windows-nat.c (enum thread_disposition_type): Move to nat/windows-nat.h. (windows_nat::thread_rec): Rename from thread_rec. No longer static. (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. * nat/windows-nat.h (enum thread_disposition_type): Move from windows-nat.c. (thread_rec): Declare. gdb/gdbserver/ChangeLog 2019-11-26 Tom Tromey * win32-low.c (windows_nat::thread_rec): Rename from thread_rec. No longer static. Change parameters. (child_add_thread, child_fetch_inferior_registers) (child_store_inferior_registers, win32_resume) (win32_get_tib_address): Update. Change-Id: I128a36466e0774fe2beca1c63a6675bd91ff7b26 --- M gdb/ChangeLog M gdb/gdbserver/ChangeLog M gdb/gdbserver/win32-low.c M gdb/nat/windows-nat.h M gdb/windows-nat.c 5 files changed, 79 insertions(+), 49 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a613484..0a6e4b8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,21 @@ 2019-11-26 Tom Tromey + * windows-nat.c (enum thread_disposition_type): Move to + nat/windows-nat.h. + (windows_nat::thread_rec): Rename from thread_rec. No longer + static. + (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. + * nat/windows-nat.h (enum thread_disposition_type): Move from + windows-nat.c. + (thread_rec): Declare. + +2019-11-26 Tom Tromey + * windows-nat.c: Add "using namespace". * nat/windows-nat.h: Wrap contents in windows_nat namespace. * nat/windows-nat.c: Wrap contents in windows_nat namespace. diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 03fcd87..4e703b8 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,5 +1,13 @@ 2019-11-26 Tom Tromey + * win32-low.c (windows_nat::thread_rec): Rename from thread_rec. + No longer static. Change parameters. + (child_add_thread, child_fetch_inferior_registers) + (child_store_inferior_registers, win32_resume) + (win32_get_tib_address): Update. + +2019-11-26 Tom Tromey + * win32-low.h: Add "using namespace". 2019-11-26 Tom Tromey diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index 9d69af7..c4e6cd2 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -177,17 +177,17 @@ } } -/* Find a thread record given a thread id. If GET_CONTEXT is set then - also retrieve the context for this thread. */ -static windows_thread_info * -thread_rec (ptid_t ptid, int get_context) +/* See nat/windows-nat.h. */ + +windows_thread_info * +windows_nat::thread_rec (ptid_t ptid, thread_disposition_type disposition) { thread_info *thread = find_thread_ptid (ptid); if (thread == NULL) return NULL; windows_thread_info *th = (windows_thread_info *) thread_target_data (thread); - if (get_context) + if (disposition != DONT_INVALIDATE_CONTEXT) win32_require_context (th); return th; } @@ -199,7 +199,7 @@ windows_thread_info *th; ptid_t ptid = ptid_t (pid, tid, 0); - if ((th = thread_rec (ptid, FALSE))) + if ((th = thread_rec (ptid, DONT_INVALIDATE_CONTEXT))) return th; th = new windows_thread_info (tid, h, (CORE_ADDR) (uintptr_t) tlb); @@ -453,7 +453,8 @@ child_fetch_inferior_registers (struct regcache *regcache, int r) { int regno; - windows_thread_info *th = thread_rec (current_thread_ptid (), TRUE); + windows_thread_info *th = thread_rec (current_thread_ptid (), + INVALIDATE_CONTEXT); if (r == -1 || r > NUM_REGS) child_fetch_inferior_registers (regcache, NUM_REGS); else @@ -467,7 +468,8 @@ child_store_inferior_registers (struct regcache *regcache, int r) { int regno; - windows_thread_info *th = thread_rec (current_thread_ptid (), TRUE); + windows_thread_info *th = thread_rec (current_thread_ptid (), + INVALIDATE_CONTEXT); if (r == -1 || r == 0 || r > NUM_REGS) child_store_inferior_registers (regcache, NUM_REGS); else @@ -924,7 +926,7 @@ /* Get context for the currently selected thread. */ ptid = debug_event_ptid (¤t_event); - th = thread_rec (ptid, FALSE); + th = thread_rec (ptid, DONT_INVALIDATE_CONTEXT); if (th) { win32_prepare_to_resume (th); @@ -1729,7 +1731,7 @@ win32_get_tib_address (ptid_t ptid, CORE_ADDR *addr) { windows_thread_info *th; - th = thread_rec (ptid, 0); + th = thread_rec (ptid, DONT_INVALIDATE_CONTEXT); if (th == NULL) return 0; if (addr != NULL) diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 2f9b181..e6eebee 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -84,6 +84,27 @@ gdb::unique_xmalloc_ptr name; }; + +/* 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. + + This function must be supplied by the embedding application. */ +extern windows_thread_info *thread_rec (ptid_t ptid, + thread_disposition_type disposition); + } #endif diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 198bb5a..935d682 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -417,26 +417,13 @@ (unsigned) GetLastError ()); } -/* 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 -}; +/* See nat/windows-nat.h. */ -/* 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, enum thread_disposition_type disposition) +windows_thread_info * +windows_nat::thread_rec (ptid_t ptid, thread_disposition_type disposition) { for (windows_thread_info *th : thread_list) - if (th->tid == id) + if (th->tid == ptid.lwp ()) { if (!th->suspended) { @@ -446,7 +433,7 @@ /* Nothing. */ break; case INVALIDATE_CONTEXT: - if (id != current_event.dwThreadId) + if (ptid.lwp () != current_event.dwThreadId) th->suspend (); th->reload_context = true; break; @@ -474,16 +461,13 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p) { windows_thread_info *th; - DWORD id; gdb_assert (ptid.lwp () != 0); - id = ptid.lwp (); - - if ((th = thread_rec (id, DONT_INVALIDATE_CONTEXT))) + if ((th = thread_rec (ptid, DONT_INVALIDATE_CONTEXT))) return th; - th = new windows_thread_info (id, h, (CORE_ADDR) (uintptr_t) tlb); + th = new windows_thread_info (ptid.lwp (), h, (CORE_ADDR) (uintptr_t) tlb); thread_list.push_back (th); /* Add this new thread to the list of threads. @@ -644,8 +628,7 @@ void windows_nat_target::fetch_registers (struct regcache *regcache, int r) { - DWORD tid = regcache->ptid ().lwp (); - windows_thread_info *th = thread_rec (tid, INVALIDATE_CONTEXT); + windows_thread_info *th = thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -714,8 +697,7 @@ void windows_nat_target::store_registers (struct regcache *regcache, int r) { - DWORD tid = regcache->ptid ().lwp (); - windows_thread_info *th = thread_rec (tid, INVALIDATE_CONTEXT); + windows_thread_info *th = thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -1213,7 +1195,8 @@ ourstatus->kind = TARGET_WAITKIND_STOPPED; /* Record the context of the current thread. */ - thread_rec (current_event.dwThreadId, DONT_SUSPEND); + thread_rec (ptid_t (current_event.dwProcessId, current_event.dwThreadId, 0), + DONT_SUSPEND); switch (code) { @@ -1329,7 +1312,9 @@ if (named_thread_id == (DWORD) -1) named_thread_id = current_event.dwThreadId; - named_thread = thread_rec (named_thread_id, DONT_INVALIDATE_CONTEXT); + named_thread = thread_rec (ptid_t (current_event.dwProcessId, + named_thread_id, 0), + DONT_INVALIDATE_CONTEXT); if (named_thread != NULL) { int thread_name_len; @@ -1527,7 +1512,7 @@ ptid.pid (), (unsigned) ptid.lwp (), step, sig)); /* Get context for currently selected thread. */ - th = thread_rec (inferior_ptid.lwp (), DONT_INVALIDATE_CONTEXT); + th = thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT); if (th) { if (step) @@ -1628,7 +1613,7 @@ current_event = iter->event; inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0); - current_thread = thread_rec (thread_id, INVALIDATE_CONTEXT); + current_thread = thread_rec (inferior_ptid, INVALIDATE_CONTEXT); current_thread->reload_context = 1; DEBUG_EVENTS (("get_windows_debug_event - " @@ -1827,7 +1812,8 @@ == EXCEPTION_BREAKPOINT) && windows_initialization_done) { - th = thread_rec (thread_id, INVALIDATE_CONTEXT); + ptid_t ptid = ptid_t (current_event.dwProcessId, thread_id, 0); + th = thread_rec (ptid, INVALIDATE_CONTEXT); th->stopped_at_breakpoint = true; } pending_stops.push_back ({thread_id, *ourstatus, current_event}); @@ -1839,7 +1825,7 @@ inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0); current_thread = th; if (!current_thread) - current_thread = thread_rec (thread_id, INVALIDATE_CONTEXT); + current_thread = thread_rec (inferior_ptid, INVALIDATE_CONTEXT); } out: @@ -3154,7 +3140,7 @@ { windows_thread_info *th; - th = thread_rec (ptid.lwp (), DONT_INVALIDATE_CONTEXT); + th = thread_rec (ptid, DONT_INVALIDATE_CONTEXT); if (th == NULL) return false; @@ -3175,7 +3161,7 @@ const char * windows_nat_target::thread_name (struct thread_info *thr) { - return thread_rec (thr->ptid.lwp (), DONT_INVALIDATE_CONTEXT)->name.get (); + return thread_rec (thr->ptid, DONT_INVALIDATE_CONTEXT)->name.get (); } @@ -3333,12 +3319,9 @@ bool windows_nat_target::thread_alive (ptid_t ptid) { - int tid; - gdb_assert (ptid.lwp () != 0); - tid = ptid.lwp (); - return (WaitForSingleObject (thread_rec (tid, DONT_INVALIDATE_CONTEXT)->h, 0) + return (WaitForSingleObject (thread_rec (ptid, DONT_INVALIDATE_CONTEXT)->h, 0) != WAIT_OBJECT_0); }