gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18412 - in gnunet/src: datastore util


From: gnunet
Subject: [GNUnet-SVN] r18412 - in gnunet/src: datastore util
Date: Thu, 1 Dec 2011 10:17:27 +0100

Author: grothoff
Date: 2011-12-01 10:17:27 +0100 (Thu, 01 Dec 2011)
New Revision: 18412

Modified:
   gnunet/src/datastore/perf_plugin_datastore.c
   gnunet/src/util/winproc.c
Log:
LRN: Adding vectored exception handling for W32 (#1965)

Whenever an exception occurs, and the process is not being debugged, it will 
run a debugger specified by GNUNET_DEBUGGER environment variable, and wait for 
it to attach.
The net effect is the same as using JIT debugging (AeDebug), but without the 
stack being broken by SEH (because VEH has a priority over SEH), which allows 
for fuller backtraces for any exception, not just for GNUNET_abort() calls.



Modified: gnunet/src/datastore/perf_plugin_datastore.c
===================================================================
--- gnunet/src/datastore/perf_plugin_datastore.c        2011-12-01 01:00:29 UTC 
(rev 18411)
+++ gnunet/src/datastore/perf_plugin_datastore.c        2011-12-01 09:17:27 UTC 
(rev 18412)
@@ -37,7 +37,7 @@
  * those take too long to run them in the usual "make check"
  * sequence.  Hence the value used for shipping is tiny.
  */
-#define MAX_SIZE 1024LL * 1024 * 16 * 1
+#define MAX_SIZE 1024LL * 1024 * 16 * 10
 
 #define ITERATIONS 2
 

Modified: gnunet/src/util/winproc.c
===================================================================
--- gnunet/src/util/winproc.c   2011-12-01 01:00:29 UTC (rev 18411)
+++ gnunet/src/util/winproc.c   2011-12-01 09:17:27 UTC (rev 18412)
@@ -32,6 +32,9 @@
 #ifdef MINGW
 
 static HINSTANCE hNTDLL, hIphlpapi, hAdvapi, hNetapi;
+#ifdef W32_VEH
+static void *GNWinVEH_handle = NULL;
+#endif
 
 TNtQuerySystemInformation GNNtQuerySystemInformation;
 TGetIfEntry GNGetIfEntry;
@@ -77,7 +80,61 @@
        "%s", msg);
 }
 
+#ifdef W32_VEH
 /**
+ * Handles exceptions (useful for debugging).
+ * Issues a DebugBreak() call if the process is being debugged (not really
+ * useful - if the process is being debugged, this handler won't be invoked
+ * anyway). If it is not, runs a debugger from GNUNET_DEBUGGER env var,
+ * substituting first %u in it for PID, and the second one for the event,
+ * that should be set once the debugger attaches itself (otherwise the
+ * only way out of WaitForSingleObject() is to time out after 1 minute).
+ */
+LONG __stdcall
+GNWinVEH (PEXCEPTION_POINTERS ExceptionInfo)
+{
+  char debugger[MAX_PATH + 1];
+  char *debugger_env = NULL;
+  if (IsDebuggerPresent ())
+  {
+    DebugBreak ();
+    return EXCEPTION_CONTINUE_EXECUTION;
+  }
+  debugger_env = getenv ("GNUNET_DEBUGGER");
+  if (debugger_env != NULL)
+  {
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    HANDLE event;
+    SECURITY_ATTRIBUTES sa;
+    memset (&si, 0, sizeof (si));
+    si.cb = sizeof (si);
+    memset (&pi, 0, sizeof (pi));
+    memset (&sa, 0, sizeof (sa));
+    sa.nLength = sizeof (sa);
+    sa.bInheritHandle = TRUE;
+    event = CreateEvent (&sa, FALSE, FALSE, NULL);
+    snprintf (debugger, MAX_PATH + 1, debugger_env, GetCurrentProcessId (), 
(uintptr_t) event);
+    debugger[MAX_PATH] = '\0';
+    if (0 != CreateProcessA (NULL, debugger, NULL, NULL, TRUE, 
CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
+    {
+      CloseHandle (pi.hProcess);
+      CloseHandle (pi.hThread);
+      WaitForSingleObject (event, 60000);
+      CloseHandle (event);
+      if (IsDebuggerPresent ())
+      {
+        return EXCEPTION_CONTINUE_EXECUTION;
+      }
+    }
+    else
+      CloseHandle (event);
+  }
+  return EXCEPTION_CONTINUE_SEARCH;
+}
+#endif
+
+/**
  * @brief Initialize PlibC and set up Windows environment
  * @param logging context, NULL means stderr
  * @return Error code from winerror.h, ERROR_SUCCESS on success
@@ -95,6 +152,18 @@
   if (hNTDLL)
     return ret;
 
+#ifdef W32_VEH
+  if (GNWinVEH_handle == NULL)
+  {
+    GNWinVEH_handle = AddVectoredExceptionHandler (1, &GNWinVEH);
+    if (GNWinVEH_handle == NULL)
+    {
+      /* This is bad, but what can we do? */
+      printf ("Failed to set up an exception handler!\n");
+    }
+  }
+#endif
+
   hNTDLL = LoadLibrary ("ntdll.dll");
 
   /* Function to get CPU usage under Win NT */
@@ -242,6 +311,14 @@
 {
   plibc_shutdown ();
 
+#ifdef W32_VEH
+  if (GNWinVEH_handle != NULL)
+  {
+    RemoveVectoredExceptionHandler (GNWinVEH_handle);
+    GNWinVEH_handle = NULL;
+  }
+#endif
+
   FreeLibrary (hNTDLL);
   FreeLibrary (hIphlpapi);
   FreeLibrary (hAdvapi);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]