Changeset 28307
- Timestamp:
- Jun 14, 2010, 12:03:59 PM (16 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 2 edited
-
psAbort.c (modified) (3 diffs)
-
psThread.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psAbort.c
r28172 r28307 23 23 #include <stdarg.h> 24 24 #include <stdlib.h> 25 #include <string.h> 25 26 #include <unistd.h> 26 27 28 #if defined(HAVE_BACKTRACE) 29 #include <execinfo.h> 30 #define BACKTRACE_BUFFER_SIZE 256 // Maximum size of backtrace 31 #endif 32 27 33 #include "psAbort.h" 34 #include "psString.h" 35 #include "psMemory.h" 28 36 #include "psError.h" 29 37 #include "psLogMsg.h" 38 39 // Write backtrace to log 40 static inline void psBacktrace(void) 41 { 42 #ifdef HAVE_BACKTRACE 43 void **bt = psAlloc(BACKTRACE_BUFFER_SIZE * sizeof(void *)); // Backtrace information 44 if (!bt) { 45 psLogMsg("psLib.sys", PS_LOG_ABORT, "Unable to allocate memory for backtrace"); 46 return; 47 } 48 int size = backtrace(bt, BACKTRACE_BUFFER_SIZE); // Size of backtrace 49 char **strings = backtrace_symbols((void *const *)bt, size); 50 psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace depth: %d", size); 51 for (int i = 0; i < size; i++) { 52 // if the caller was an anon function then strchr won't 53 // find a '(' in the string and will return NULL 54 char *caller = strchr(strings[i], '('); 55 if (caller) { 56 // skip over the '(' 57 caller++; 58 // find the end of the symbol name 59 size_t callerLength = abs(strchr(caller, '+') - caller); 60 psString name = psStringNCopy(caller, callerLength); 61 psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace %d: %s", i, name); 62 psFree(name); 63 } else { 64 psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace %d: (unknown)", i); 65 } 66 } 67 #endif // ifdef HAVE_BACKTRACE 68 } 30 69 31 70 void p_psAbort(const char *file, … … 46 85 // Clean up stack after variable arguement has been used 47 86 va_end(argPtr); 87 88 psBacktrace(); 48 89 49 90 // Call system abort function to terminate program execution … … 72 113 va_end(argPtr); 73 114 115 psBacktrace(); 116 74 117 // Call system abort function to terminate program execution 75 118 fsync(psLogGetDestination()); -
trunk/psLib/src/sys/psThread.c
r28140 r28307 210 210 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job 211 211 psAssert(task, "Couldn't find thread task %s", job->type); 212 psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s (%ld supplied, expected %d)", task->type, job->args->n, task->nArgs); 212 psAssert(job->args->n == task->nArgs, 213 "invalid number of arguments to %s (%ld supplied, expected %d)", 214 task->type, job->args->n, task->nArgs); 213 215 bool status = task->function(job); // Status of executing task 214 216
Note:
See TracChangeset
for help on using the changeset viewer.
