Changeset 13f2461 in mainline for uspace/lib/c/generic/assert.c


Ignore:
Timestamp:
2011-05-21T15:45:48Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9d47440, e06e2716
Parents:
faeb7cc
Message:

Merge the functionality of assert_abort() and assert_static_abort() into
assert_abort().

Print the unexpanded message to klog first. Then try to print the
message and the stack trace to standard output using printf. Use the
same unabbreviated message wording for both klog and stdout. If a
nested or a parallel assert is detected, send the message only to klog
and then abort.

Re-introduce malloc_assert() to up the malloc_futex. This appears to be
inevitable if we want to print to stdout. To prevent undesired macro
expansion, call assert_abort() from malloc_assert() directly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/assert.c

    rfaeb7cc r13f2461  
    3535#include <io/klog.h>
    3636#include <stdlib.h>
     37#include <atomic.h>
    3738#include <stacktrace.h>
    3839
    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
     45static atomic_t failed_asserts;
     46
     47void assert_abort(const char *cond, const char *file, const char *line)
    4048{
    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,
    4272            cond, file, line);
    4373        stacktrace_print();
    44         abort();
    45 }
    4674
    47 void assert_static_abort(const char *msg)
    48 {
    49         klog_write(msg, str_size(msg));
    5075        abort();
    5176}
Note: See TracChangeset for help on using the changeset viewer.