glib errors with latest gdb

Ken Brown kbrown@cornell.edu
Fri Sep 12 18:40:00 GMT 2014


Hi Corinna,

On 8/28/2014 9:57 AM, Corinna Vinschen wrote:
> On Aug 13 16:57, Corinna Vinschen wrote:
>> On Aug 13 10:28, Ken Brown wrote:
>>> I'm getting errors with the latest gdb when trying to debug programs that
>>> depend on glib.  Here's an example, run from an xterm window:
>>>
>>> $ gdb /usr/bin/gvim
>>> GNU gdb (GDB) 7.8
>>> [...]
>>> Reading symbols from /usr/bin/gvim...(no debugging symbols found)...done.
>>> (gdb) r
>>> Starting program: /usr/bin/gvim
>>> [New Thread 4860.0x1b44]
>>> Traceback (most recent call last):
>>>    File "/usr/share/gdb/auto-load/usr/bin/cyggobject-2.0-0.dll-gdb.py", line
>>> 9, in <module>
>>>      from gobject import register
>>>    File "/usr/share/glib-2.0/gdb/gobject.py", line 3, in <module>
>>>      import gdb.backtrace
>>> ImportError: No module named backtrace
>>
>> I see this error, too.  Unfortunately I'm not a python guru so this
>> is rather opaque to me.  gdb itself doesn't provide a gdb.backtrace
>> method, afaics.
>>
>> However, despite this message, gvim starts normally.  And emacs-nox as
>> well as many other CLI applications can be started just fine, too.
>>
>> But GDB hangs with emacs-X11 for some reason, even if I disable the
>> python modules.  From a quick GDB session it's not clear why this occurs :(
>
> I reported the problem upstream in a bugzilla entry already handling
> strange GDB hangs:
>
>    https://sourceware.org/bugzilla/show_bug.cgi?id=17247

That bug appears to be something different.  But I managed to fix the 
problem without actually understanding the code.  I looked at cgf's 
patches from his build of gdb-7.6.50-4, and I noticed that some of his 
changes didn't make it into your gdb-7.8-1.src.patch.  The missing ones 
are collected in the attached "cgf.patch" file.

If I apply that patch on top of your gdb-7.8-1.src.patch, the problem is 
gone.  (The python warning is still there, but it seems to be harmless.)

Ken

-------------- next part --------------
--- gdb/windows-nat.c.orig	2014-09-12 09:08:38.714405700 -0400
+++ gdb/windows-nat.c	2014-09-12 12:33:12.853775100 -0400
@@ -121,8 +121,7 @@
 #   define bad_GetModuleFileNameEx bad_GetModuleFileNameExW
 #endif
 
-static int have_saved_context;	/* True if we've saved context from a
-				   cygwin signal.  */
+static DWORD  signal_thread_id;	/* Non-zero if we saved context. */
 static CONTEXT saved_context;	/* Containes the saved context from a
 				   cygwin signal.  */
 
@@ -304,7 +303,8 @@
       {
 	if (!th->suspended && get_context)
 	  {
-	    if (get_context > 0 && id != current_event.dwThreadId)
+	    if (get_context > 0 && id != current_event.dwThreadId
+		&& id != signal_thread_id)
 	      {
 		if (SuspendThread (th->h) == (DWORD) -1)
 		  {
@@ -438,7 +438,7 @@ do_windows_fetch_inferior_registers (str
 
   if (current_thread->reload_context)
     {
-      if (have_saved_context)
+      if (signal_thread_id)
 	{
 	  /* Lie about where the program actually is stopped since
 	     cygwin has informed us that we should consider the signal
@@ -446,7 +446,7 @@ do_windows_fetch_inferior_registers (str
 	     "saved_context.  */
 	  memcpy (&current_thread->context, &saved_context,
 		  __COPY_CONTEXT_SIZE);
-	  have_saved_context = 0;
+	  signal_thread_id = 0;
 	}
       else
 	{
@@ -934,8 +934,12 @@
 					 &saved_context,
 					 __COPY_CONTEXT_SIZE, &n)
 		   && n == __COPY_CONTEXT_SIZE)
-	    have_saved_context = 1;
-	  current_event.dwThreadId = retval;
+	    {
+	      signal_thread_id = retval;
+	      saved_context.ContextFlags = 0;  /* Don't attempt to call SetContext */
+	    }
+	  else
+	    retval = 0;
 	}
     }
 
@@ -1402,7 +1406,7 @@
   DWORD continue_status, event_code;
   thread_info *th;
   static thread_info dummy_thread_info;
-  int retval = 0;
+  DWORD thread_id = 0;
 
   last_sig = GDB_SIGNAL_0;
 
@@ -1415,7 +1419,6 @@
   event_code = current_event.dwDebugEventCode;
   ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
   th = NULL;
-  have_saved_context = 0;
 
   switch (event_code)
     {
@@ -1433,14 +1436,14 @@
 	      /* Kludge around a Windows bug where first event is a create
 		 thread event.  Caused when attached process does not have
 		 a main thread.  */
-	      retval = fake_create_process ();
-	      if (retval)
+	      thread_id = fake_create_process ();
+	      if (thread_id)
 		saw_create++;
 	    }
 	  break;
 	}
       /* Record the existence of this thread.  */
-      retval = current_event.dwThreadId;
+      thread_id = current_event.dwThreadId;
       th = windows_add_thread (ptid_build (current_event.dwProcessId, 0,
 					 current_event.dwThreadId),
 			     current_event.u.CreateThread.hThread,
@@ -1483,7 +1486,7 @@
 					   current_event.dwThreadId),
 	     current_event.u.CreateProcessInfo.hThread,
 	     current_event.u.CreateProcessInfo.lpThreadLocalBase);
-      retval = current_event.dwThreadId;
+      thread_id = current_event.dwThreadId;
       break;
 
     case EXIT_PROCESS_DEBUG_EVENT:
@@ -1502,7 +1505,7 @@
 	{
 	  ourstatus->kind = TARGET_WAITKIND_EXITED;
 	  ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
-	  retval = main_thread_id;
+	  thread_id = main_thread_id;
 	}
       break;
 
@@ -1517,7 +1520,7 @@
       catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL);
       ourstatus->kind = TARGET_WAITKIND_LOADED;
       ourstatus->value.integer = 0;
-      retval = main_thread_id;
+      thread_id = main_thread_id;
       break;
 
     case UNLOAD_DLL_DEBUG_EVENT:
@@ -1530,7 +1533,7 @@
       catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL);
       ourstatus->kind = TARGET_WAITKIND_LOADED;
       ourstatus->value.integer = 0;
-      retval = main_thread_id;
+      thread_id = main_thread_id;
       break;
 
     case EXCEPTION_DEBUG_EVENT:
@@ -1546,7 +1549,7 @@
 	  continue_status = DBG_EXCEPTION_NOT_HANDLED;
 	  break;
 	case 1:
-	  retval = current_event.dwThreadId;
+	  thread_id = current_event.dwThreadId;
 	  break;
 	case -1:
 	  last_sig = 1;
@@ -1562,7 +1565,7 @@
 		     "OUTPUT_DEBUG_STRING_EVENT"));
       if (saw_create != 1)
 	break;
-      retval = handle_output_debug_string (ourstatus);
+      thread_id = handle_output_debug_string (ourstatus);
       break;
 
     default:
@@ -1576,7 +1579,7 @@
       break;
     }
 
-  if (!retval || saw_create != 1)
+  if (!thread_id || saw_create != 1)
     {
       if (continue_status == -1)
 	windows_resume (ops, minus_one_ptid, 0, 1);
@@ -1586,12 +1589,12 @@
   else
     {
       inferior_ptid = ptid_build (current_event.dwProcessId, 0,
-				  retval);
-      current_thread = th ?: thread_rec (current_event.dwThreadId, TRUE);
+				  thread_id);
+      current_thread = th ?: thread_rec (thread_id, TRUE);
     }
 
 out:
-  return retval;
+  return (int) thread_id;
 }
 
 /* Wait for interesting events to occur in the target process.  */
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list