Index: /trunk/psLib/src/sys/psAbort.c
===================================================================
--- /trunk/psLib/src/sys/psAbort.c	(revision 28306)
+++ /trunk/psLib/src/sys/psAbort.c	(revision 28307)
@@ -23,9 +23,48 @@
 #include <stdarg.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
+#if defined(HAVE_BACKTRACE)
+#include <execinfo.h>
+#define BACKTRACE_BUFFER_SIZE 256       // Maximum size of backtrace
+#endif
+
 #include "psAbort.h"
+#include "psString.h"
+#include "psMemory.h"
 #include "psError.h"
 #include "psLogMsg.h"
+
+// Write backtrace to log
+static inline void psBacktrace(void)
+{
+#ifdef HAVE_BACKTRACE
+    void **bt = psAlloc(BACKTRACE_BUFFER_SIZE * sizeof(void *)); // Backtrace information
+    if (!bt) {
+        psLogMsg("psLib.sys", PS_LOG_ABORT, "Unable to allocate memory for backtrace");
+        return;
+    }
+    int size = backtrace(bt, BACKTRACE_BUFFER_SIZE);             // Size of backtrace
+    char **strings = backtrace_symbols((void *const *)bt, size);
+    psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace depth: %d", size);
+    for (int i = 0; i < size; i++) {
+        // if the caller was an anon function then strchr won't
+        // find a '(' in the string and will return NULL
+        char *caller = strchr(strings[i], '(');
+        if (caller) {
+            // skip over the '('
+            caller++;
+            // find the end of the symbol name
+            size_t callerLength = abs(strchr(caller, '+') - caller);
+            psString name = psStringNCopy(caller, callerLength);
+            psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace %d: %s", i, name);
+            psFree(name);
+        } else {
+            psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace %d: (unknown)", i);
+        }
+    }
+#endif // ifdef HAVE_BACKTRACE
+}
 
 void p_psAbort(const char *file,
@@ -46,4 +85,6 @@
     // Clean up stack after variable arguement has been used
     va_end(argPtr);
+
+    psBacktrace();
 
     // Call system abort function to terminate program execution
@@ -72,4 +113,6 @@
     va_end(argPtr);
 
+    psBacktrace();
+
     // Call system abort function to terminate program execution
     fsync(psLogGetDestination());
Index: /trunk/psLib/src/sys/psThread.c
===================================================================
--- /trunk/psLib/src/sys/psThread.c	(revision 28306)
+++ /trunk/psLib/src/sys/psThread.c	(revision 28307)
@@ -210,5 +210,7 @@
         psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job
         psAssert(task, "Couldn't find thread task %s", job->type);
-        psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s (%ld supplied, expected %d)", task->type, job->args->n, task->nArgs);
+        psAssert(job->args->n == task->nArgs,
+                 "invalid number of arguments to %s (%ld supplied, expected %d)",
+                 task->type, job->args->n, task->nArgs);
         bool status = task->function(job); // Status of executing task
 
