src/hg/lib/web.c 1.161

1.161 2009/06/03 00:34:09 markd
added option to generate stack dumps when browser errors occur
Index: src/hg/lib/web.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/web.c,v
retrieving revision 1.160
retrieving revision 1.161
diff -b -B -U 4 -r1.160 -r1.161
--- src/hg/lib/web.c	1 Apr 2009 19:59:39 -0000	1.160
+++ src/hg/lib/web.c	3 Jun 2009 00:34:09 -0000	1.161
@@ -6,8 +6,9 @@
 #include "htmshell.h"
 #include "web.h"
 #include "hdb.h"
 #include "hui.h"
+#include "hgConfig.h"
 #include "cheapcgi.h"
 #include "dbDb.h"
 #include "hgColors.h"
 #ifndef GBROWSE
@@ -29,8 +30,46 @@
 
 /* global: a cart for use in error handlers. */
 static struct cart *errCart = NULL;
 
+static boolean stackWarnHasBeenDone = FALSE;  // prevent accidental recursion, only allow once
+
+static void webDumpStackWarnHandler(char *format, va_list args)
+/* warn handle that generates a warning and then invokes the previous error
+ * handler on the stack. */
+{
+if (!stackWarnHasBeenDone)
+    {
+    stackWarnHasBeenDone = TRUE;
+    popWarnHandler(); // remove us from the stack
+    va_list localArgs;
+    va_copy(localArgs, args);
+    vaDumpStack(format, localArgs);
+    va_end(localArgs);
+    // continue with next warn handler
+    vaWarn(format, args);
+    }
+}
+
+boolean webDumpStackEnabled(void)
+/* is browser.pstack enabled?  */
+{
+return cfgOptionBooleanDefault("browser.dumpStack", FALSE);
+}
+
+void webPushDumpStackHandler(void)
+{
+if (webDumpStackEnabled())
+    pushWarnHandler(webDumpStackWarnHandler);
+}
+
+void webPopDumpStackHandler(void)
+/* pop the stack dump handler from the stack if it's enabled */
+{
+if (webDumpStackEnabled() && !stackWarnHasBeenDone)
+    popWarnHandler();
+}
+
 void textVaWarn(char *format, va_list args)
 {
 vprintf(format, args);
 puts("\n");
@@ -40,15 +79,16 @@
 {
 exit(0);
 }
 
-void webPushErrHandlers()
+void webPushErrHandlers(void)
 /* Push warn and abort handler for errAbort(). */
 {
 if (webInTextMode)
     pushWarnHandler(textVaWarn);
 else
     pushWarnHandler(webVaWarn);
+webPushDumpStackHandler();
 pushAbortHandler(softAbort);
 }
 
 void webPushErrHandlersCart(struct cart *cart)
@@ -57,12 +97,13 @@
 errCart = cart;
 webPushErrHandlers();
 }
 
-void webPopErrHandlers()
+void webPopErrHandlers(void)
 /* Pop warn and abort handler for errAbort(). */
 {
 popWarnHandler();
+webPopDumpStackHandler();
 popAbortHandler();
 }
 
 void webSetStyle(char *style)