Browse Source

HPCC-16644 Improve reporting of segfaults

Skip leading lines of backtrace that serve only to confuse...

Move the backtrace higher so it's more likely that we get it (the registers
and hex dump of stack frame tend to be less interesting).

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 years ago
parent
commit
29763cc7ae
2 changed files with 25 additions and 7 deletions
  1. 24 6
      system/jlib/jexcept.cpp
  2. 1 1
      system/jlib/jexcept.hpp

+ 24 - 6
system/jlib/jexcept.cpp

@@ -1013,7 +1013,6 @@ void excsighandler(int signum, siginfo_t *info, void *extra)
     __int64 ip = uc->uc_mcontext.gregs[REG_RIP];
     __int64 ip = uc->uc_mcontext.gregs[REG_RIP];
     __int64 sp = uc->uc_mcontext.gregs[REG_RSP];
     __int64 sp = uc->uc_mcontext.gregs[REG_RSP];
 #endif
 #endif
-    
     excsignal = signum;
     excsignal = signum;
     s.appendf("SIG: %s(%d), accessing " I64X ", IP=" I64X, strsignal(signum),signum, (__int64)info->si_addr, ip);
     s.appendf("SIG: %s(%d), accessing " I64X ", IP=" I64X, strsignal(signum),signum, (__int64)info->si_addr, ip);
     
     
@@ -1021,6 +1020,10 @@ void excsighandler(int signum, siginfo_t *info, void *extra)
     PROGLOG("Signal:    %d %s",signum,strsignal(signum));
     PROGLOG("Signal:    %d %s",signum,strsignal(signum));
     PROGLOG("Fault IP:  " I64X "", ip);
     PROGLOG("Fault IP:  " I64X "", ip);
     PROGLOG("Accessing: " I64X "", (unsigned __int64) info->si_addr);
     PROGLOG("Accessing: " I64X "", (unsigned __int64) info->si_addr);
+#ifdef _EXECINFO_H
+    printStackReport(ip);
+#endif
+
     PROGLOG("Registers:" );
     PROGLOG("Registers:" );
     PROGLOG("EAX:" I64X "  EBX:" I64X "  ECX:" I64X "  EDX:" I64X "  ESI:" I64X "  EDI:" I64X "",
     PROGLOG("EAX:" I64X "  EBX:" I64X "  ECX:" I64X "  EDX:" I64X "  ESI:" I64X "  EDI:" I64X "",
 #ifdef __APPLE__
 #ifdef __APPLE__
@@ -1060,6 +1063,10 @@ void excsighandler(int signum, siginfo_t *info, void *extra)
     PROGLOG("Signal:    %d %s",signum,strsignal(signum));
     PROGLOG("Signal:    %d %s",signum,strsignal(signum));
     PROGLOG("Fault IP:  %08X", ip);
     PROGLOG("Fault IP:  %08X", ip);
     PROGLOG("Accessing: %08X", (unsigned) info->si_addr);
     PROGLOG("Accessing: %08X", (unsigned) info->si_addr);
+#ifdef _EXECINFO_H
+    printStackReport(ip);
+#endif
+
     PROGLOG("Registers:" );
     PROGLOG("Registers:" );
     PROGLOG("EAX:%08X  EBX:%08X  ECX:%08X  EDX:%08X  ESI:%08X  EDI:%08X",
     PROGLOG("EAX:%08X  EBX:%08X  ECX:%08X  EDX:%08X  ESI:%08X  EDI:%08X",
         uc->uc_mcontext.gregs[REG_EAX], uc->uc_mcontext.gregs[REG_EBX], 
         uc->uc_mcontext.gregs[REG_EAX], uc->uc_mcontext.gregs[REG_EBX], 
@@ -1190,9 +1197,6 @@ void excsighandler(int signum, siginfo_t *info, void *extra)
 
 
 #endif
 #endif
 
 
-#ifdef _EXECINFO_H
-    printStackReport();
-#endif  
     StringBuffer threadlist;
     StringBuffer threadlist;
     PROGLOG( "ThreadList:\n%s",getThreadList(threadlist).str());
     PROGLOG( "ThreadList:\n%s",getThreadList(threadlist).str());
     queryLogMsgManager()->flushQueue(10*1000);
     queryLogMsgManager()->flushQueue(10*1000);
@@ -1376,7 +1380,7 @@ void jlib_decl serializeException(IException * e, MemoryBuffer & out)
 }
 }
 
 
 
 
-void printStackReport()
+void printStackReport(__int64 startIP)
 {
 {
     if (!queryLogMsgManager())
     if (!queryLogMsgManager())
         return;
         return;
@@ -1388,7 +1392,21 @@ void printStackReport()
     void *btarray[100];
     void *btarray[100];
     unsigned btn = backtrace (btarray, 100);
     unsigned btn = backtrace (btarray, 100);
     char **strings = backtrace_symbols (btarray, btn);
     char **strings = backtrace_symbols (btarray, btn);
-    for (unsigned i=0; i<btn; i++)
+    unsigned i;
+    unsigned firstReal = 0;
+    if (startIP)
+    {
+        VStringBuffer iptext("[%p]", (void *) startIP);
+        for (i=0; i<btn; i++)
+        {
+            if (strstr(strings[i], iptext) != nullptr)
+            {
+                firstReal = i;
+                break;
+            }
+        }
+    }
+    for (i=firstReal; i<btn; i++)
         DBGLOG("  %s", strings[i]);
         DBGLOG("  %s", strings[i]);
     free (strings);
     free (strings);
 #endif
 #endif

+ 1 - 1
system/jlib/jexcept.hpp

@@ -142,7 +142,7 @@ __declspec(noreturn) void jlib_decl throwUnexpectedException(const char * where,
 IException jlib_decl * deserializeException(MemoryBuffer & in); 
 IException jlib_decl * deserializeException(MemoryBuffer & in); 
 void jlib_decl serializeException(IException * e, MemoryBuffer & out); 
 void jlib_decl serializeException(IException * e, MemoryBuffer & out); 
 
 
-void  jlib_decl printStackReport();
+void  jlib_decl printStackReport(__int64 startIP = 0);
 // Macro for legacy name of above function
 // Macro for legacy name of above function
 #define PrintStackReport printStackReport
 #define PrintStackReport printStackReport