Subject: Re: gdb seems to ignore threads
To: Nathan J. Williams <nathanw@wasabisystems.com>
From: John Gordon <mailing.lists@dial.pipex.com>
List: current-users
Date: 06/03/2003 01:05:08
This is a multi-part message in MIME format.
--------------080109070000070805020709
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hello again,

Here's a slightly better version that will handle the deletion of 
threads from the thread list correctly.

I've added the same things to my remote gdbserver version too, and the 
two are now working pretty much the same way on both Felix's test 
application, and my slightly more complex one.

Rgds,
John...


--------------080109070000070805020709
Content-Type: text/plain;
 name="gdb-20030602.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="gdb-20030602.patch"

Index: gnu/dist/toolchain/gdb/infrun.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/toolchain/gdb/infrun.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 infrun.c
--- gnu/dist/toolchain/gdb/infrun.c	2000/07/26 00:32:47	1.1.1.1
+++ gnu/dist/toolchain/gdb/infrun.c	2003/06/03 07:59:18
@@ -1798,7 +1798,10 @@
        all threads in order to make progress.  */
     if (ecs->new_thread_event)
       {
-	target_resume (-1, 0, TARGET_SIGNAL_0);
+        /*
+	 * Use the 'trap_expected' flag to see if we should be stepping or not
+	 */
+	target_resume (-1, (trap_expected ? 1 : 0), TARGET_SIGNAL_0);
 	prepare_to_wait (ecs);
 	return;
       }
Index: gnu/dist/toolchain/gdb/nbsd-thread.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/toolchain/gdb/nbsd-thread.c,v
retrieving revision 1.5
diff -u -r1.5 nbsd-thread.c
--- gnu/dist/toolchain/gdb/nbsd-thread.c	2003/02/27 00:55:43	1.5
+++ gnu/dist/toolchain/gdb/nbsd-thread.c	2003/06/03 07:59:20
@@ -260,7 +260,8 @@
   val = td_map_lwps (main_ta);
   if (val != 0)
     {
-      warning ("find_active_thread: td_map_lwps: %s\n", td_err_string (val));
+      if (val != TD_ERR_IO)
+        warning ("find_active_thread: td_map_lwps: %s\n", td_err_string (val));
       return -1;
     }
   if (cached_thread != 0)
@@ -304,11 +305,13 @@
   if (pid != -1)
     pid = inferior_pid;
   rtnval = child_ops.to_wait (pid, ourstatus);
-  if (rtnval == 0 && nbsd_thread_active)
+
+  /* if (rtnval == 0 && nbsd_thread_active) */
+  if (nbsd_thread_active)
     {
       rtnval = find_active_thread ();
       if (rtnval == -1)
-	error ("No active thread!\n");
+        return -1;
       if (!in_thread_list (rtnval))
 	add_thread (rtnval);
     }
@@ -585,7 +588,22 @@
 	{
 	  /* Thread found */
 	  if (td_thr_info (th, &ti) == 0)
-	    retval = 1;
+	    {
+	      switch (ti.thread_state)
+	        {
+	        default:
+	        case TD_STATE_UNKNOWN:
+	        case TD_STATE_ZOMBIE:
+		  retval = 0;
+		  break;
+	        case TD_STATE_RUNNING:
+	        case TD_STATE_RUNNABLE:
+	        case TD_STATE_BLOCKED:
+	        case TD_STATE_SLEEPING:
+	          retval = 1;
+	          break;
+		}
+	    }
 	}
     }
   else

--------------080109070000070805020709--