Changeset 9d47440 in mainline for uspace/lib/c/generic/assert.c


Ignore:
Timestamp:
2011-05-21T16:23:17Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0ff03f3
Parents:
8d308b9 (diff), 13f2461 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r8d308b9 r9d47440  
    3333#include <assert.h>
    3434#include <stdio.h>
     35#include <io/klog.h>
    3536#include <stdlib.h>
     37#include <atomic.h>
    3638#include <stacktrace.h>
    3739
    38 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)
    3948{
    40         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,
    4172            cond, file, line);
    4273        stacktrace_print();
     74
    4375        abort();
    4476}
Note: See TracChangeset for help on using the changeset viewer.