Changeset 28484 for branches/pap/psLib/src/sys/psAbort.c
- Timestamp:
- Jun 24, 2010, 2:59:09 PM (16 years ago)
- Location:
- branches/pap
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/sys/psAbort.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/psLib/src/sys/psAbort.c
r28172 r28484 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());
Note:
See TracChangeset
for help on using the changeset viewer.
