Changeset 13f2461 in mainline for uspace/lib/c/generic/assert.c
- Timestamp:
- 2011-05-21T15:45:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9d47440, e06e2716
- Parents:
- faeb7cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/assert.c
rfaeb7cc r13f2461 35 35 #include <io/klog.h> 36 36 #include <stdlib.h> 37 #include <atomic.h> 37 38 #include <stacktrace.h> 38 39 39 void assert_abort(const char *cond, const char *file, unsigned int line) 40 #define MSG_START "Assertion failed (" 41 #define MSG_FILE ") in file \"" 42 #define MSG_LINE "\", line " 43 #define MSG_END ".\n" 44 45 static atomic_t failed_asserts; 46 47 void assert_abort(const char *cond, const char *file, const char *line) 40 48 { 41 printf("Assertion failed (%s) in file \"%s\", line %u.\n", 49 /* 50 * Send the message safely to klog. Nested asserts should not occur. 51 */ 52 klog_write(MSG_START, str_size(MSG_START)); 53 klog_write(cond, str_size(cond)); 54 klog_write(MSG_FILE, str_size(MSG_FILE)); 55 klog_write(file, str_size(file)); 56 klog_write(MSG_LINE, str_size(MSG_LINE)); 57 klog_write(line, str_size(line)); 58 klog_write(MSG_END, str_size(MSG_END)); 59 60 /* 61 * Check if this is a nested or parallel assert. 62 */ 63 if (atomic_postinc(&failed_asserts)) 64 abort(); 65 66 /* 67 * Attempt to print the message to standard output and display 68 * the stack trace. These operations can theoretically trigger nested 69 * assertions. 70 */ 71 printf(MSG_START "%s" MSG_FILE "%s" MSG_LINE "%s" MSG_END, 42 72 cond, file, line); 43 73 stacktrace_print(); 44 abort();45 }46 74 47 void assert_static_abort(const char *msg)48 {49 klog_write(msg, str_size(msg));50 75 abort(); 51 76 }
Note:
See TracChangeset
for help on using the changeset viewer.