public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [review] Change type of argument to windows-nat.c:thread_rec
@ 2019-10-29 17:58 Tom Tromey (Code Review)
  2019-11-04 14:33 ` Luis Machado (Code Review)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom Tromey (Code Review) @ 2019-10-29 17:58 UTC (permalink / raw)
  To: gdb-patches

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/413
......................................................................

Change type of argument to windows-nat.c:thread_rec

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
2019-10-29  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.

Change-Id: I06acddba162573bd5f0d2f6f5b36f16a0b652916
---
M gdb/ChangeLog
M gdb/windows-nat.c
2 files changed, 55 insertions(+), 20 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 904a322..9e7aa7b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@
 2019-10-29  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.
+
+2019-10-29  Tom Tromey  <tromey@adacore.com>
+
 	* windows-nat.c (thread_rec): Use windows_thread_info::suspend.
 	(windows_continue): Use windows_continue::resume.
 	* nat/windows-nat.h (struct windows_thread_info) <suspend,
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 26e5343..b07da3b 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -365,22 +365,44 @@
 		     (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 @@
 
   id = ptid.lwp ();
 
-  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 @@
 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.  */
@@ -616,7 +638,7 @@
 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.  */
@@ -1114,7 +1136,7 @@
   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 @@
 	  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 @@
 	       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)
     {
       if (step)
@@ -1656,7 +1678,7 @@
       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:
@@ -2956,7 +2978,7 @@
 {
   windows_thread_info *th;
 
-  th = thread_rec (ptid.lwp (), 0);
+  th = thread_rec (ptid.lwp (), DONT_INVALIDATE_CONTEXT);
   if (th == NULL)
     return false;
 
@@ -2977,7 +2999,7 @@
 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 ();
 }
 
 
@@ -3140,7 +3162,8 @@
   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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I06acddba162573bd5f0d2f6f5b36f16a0b652916
Gerrit-Change-Number: 413
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newchange

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [review] Change type of argument to windows-nat.c:thread_rec
  2019-10-29 17:58 [review] Change type of argument to windows-nat.c:thread_rec Tom Tromey (Code Review)
@ 2019-11-04 14:33 ` Luis Machado (Code Review)
  2019-11-26 17:31 ` [review v2] " Tom Tromey (Code Review)
  2019-11-29 18:36 ` Pedro Alves (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Luis Machado (Code Review) @ 2019-11-04 14:33 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

Luis Machado has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/413
......................................................................


Patch Set 1: Code-Review+1


-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I06acddba162573bd5f0d2f6f5b36f16a0b652916
Gerrit-Change-Number: 413
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Luis Machado <luis.machado@linaro.org>
Gerrit-Comment-Date: Mon, 04 Nov 2019 14:33:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [review v2] Change type of argument to windows-nat.c:thread_rec
  2019-10-29 17:58 [review] Change type of argument to windows-nat.c:thread_rec Tom Tromey (Code Review)
  2019-11-04 14:33 ` Luis Machado (Code Review)
@ 2019-11-26 17:31 ` Tom Tromey (Code Review)
  2019-11-29 18:36 ` Pedro Alves (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey (Code Review) @ 2019-11-26 17:31 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/413
......................................................................

Change type of argument to windows-nat.c:thread_rec

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
2019-11-26  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.

Change-Id: I06acddba162573bd5f0d2f6f5b36f16a0b652916
---
M gdb/ChangeLog
M gdb/windows-nat.c
2 files changed, 55 insertions(+), 20 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6862a12..14cb238 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@
 2019-11-26  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.
+
+2019-11-26  Tom Tromey  <tromey@adacore.com>
+
 	* windows-nat.c (thread_rec): Use windows_thread_info::suspend.
 	(windows_continue): Use windows_continue::resume.
 	* nat/windows-nat.h (struct windows_thread_info) <suspend,
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index a85b9ff..abd9d55 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -365,22 +365,44 @@
 		     (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 @@
 
   id = ptid.lwp ();
 
-  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 @@
 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.  */
@@ -616,7 +638,7 @@
 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.  */
@@ -1114,7 +1136,7 @@
   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 @@
 	  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 @@
 	       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)
     {
       if (step)
@@ -1656,7 +1678,7 @@
       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:
@@ -2957,7 +2979,7 @@
 {
   windows_thread_info *th;
 
-  th = thread_rec (ptid.lwp (), 0);
+  th = thread_rec (ptid.lwp (), DONT_INVALIDATE_CONTEXT);
   if (th == NULL)
     return false;
 
@@ -2978,7 +3000,7 @@
 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 ();
 }
 
 
@@ -3141,7 +3163,8 @@
   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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I06acddba162573bd5f0d2f6f5b36f16a0b652916
Gerrit-Change-Number: 413
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Luis Machado <luis.machado@linaro.org>
Gerrit-MessageType: newpatchset

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [review v2] Change type of argument to windows-nat.c:thread_rec
  2019-10-29 17:58 [review] Change type of argument to windows-nat.c:thread_rec Tom Tromey (Code Review)
  2019-11-04 14:33 ` Luis Machado (Code Review)
  2019-11-26 17:31 ` [review v2] " Tom Tromey (Code Review)
@ 2019-11-29 18:36 ` Pedro Alves (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves (Code Review) @ 2019-11-29 18:36 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Luis Machado

Pedro Alves has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/413
......................................................................


Patch Set 2: Code-Review+2


-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I06acddba162573bd5f0d2f6f5b36f16a0b652916
Gerrit-Change-Number: 413
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Luis Machado <luis.machado@linaro.org>
Gerrit-Reviewer: Pedro Alves <palves@redhat.com>
Gerrit-Comment-Date: Fri, 29 Nov 2019 18:36:34 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-29 18:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-29 17:58 [review] Change type of argument to windows-nat.c:thread_rec Tom Tromey (Code Review)
2019-11-04 14:33 ` Luis Machado (Code Review)
2019-11-26 17:31 ` [review v2] " Tom Tromey (Code Review)
2019-11-29 18:36 ` Pedro Alves (Code Review)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).