Add backtrace debugging facility that doesn't add linebreaks
[citadel.git] / citadel / citserver.c
index cfe5c1b1a13984a4df6bb0163051d476b663bcb7..71ec7e05e935dfcf5a1b945fdc9729ba367c61d8 100644 (file)
@@ -106,6 +106,32 @@ void cit_backtrace(void)
 #endif
 }
 
+void cit_oneline_backtrace(void)
+{
+#ifdef HAVE_BACKTRACE
+       void *stack_frames[50];
+       size_t size, i;
+       char **strings;
+       StrBuf *Buf;
+
+       size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
+       strings = backtrace_symbols(stack_frames, size);
+       if (size > 0)
+       {
+               Buf = NewStrBuf();
+               for (i = 1; i < size; i++) {
+                       if (strings != NULL)
+                               StrBufAppendPrintf(Buf, "%s : ", strings[i]);
+                       else
+                               StrBufAppendPrintf(Buf, "%p : ", stack_frames[i]);
+               }
+               free(strings);
+               CtdlLogPrintf(CTDL_ALERT, "%s\n", ChrPtr(Buf));
+               FreeStrBuf(&Buf);
+       }
+#endif
+}
+
 /*
  * print the actual stack frame.
  */