Luna/kernel/include/assert.h

39 lines
3.1 KiB
C
Raw Normal View History

2022-09-05 14:13:51 +00:00
#pragma once
#include "log/Log.h"
2022-09-21 15:56:53 +00:00
#include "misc/hang.h"
#include "thread/Scheduler.h"
#include "trace/StackTracer.h"
2022-09-05 14:13:51 +00:00
2022-09-10 16:42:40 +00:00
#define __call_assert_fail(...) \
kerrorln(__VA_ARGS__); \
StackTracer tracer; \
tracer.trace(); \
2022-09-10 16:42:40 +00:00
hang();
2022-09-05 14:13:51 +00:00
2022-09-10 16:42:40 +00:00
#define ASSERT(expr) \
do { \
if (!(expr)) \
{ \
Task* cur_task = Scheduler::current_task(); \
if (cur_task) \
{ \
__call_assert_fail("Assertion failed in task %ld at %s, line %d: %s", cur_task->id, __FILE__, \
__LINE__, #expr); \
} \
else { __call_assert_fail("Assertion failed at %s, line %d: %s", __FILE__, __LINE__, #expr); } \
} \
2022-09-10 16:42:40 +00:00
} while (0)
2022-09-05 14:13:51 +00:00
#define TODO(message) \
do { \
Task* cur_task = Scheduler::current_task(); \
if (cur_task) \
{ \
__call_assert_fail("TODO in task %ld at %s, line %d: %s", cur_task->id, __FILE__, __LINE__, message); \
} \
else { __call_assert_fail("TODO at %s, line %d: %s", __FILE__, __LINE__, message); } \
} while (0)
#ifdef ___weird_hack_to_put_something_at_end_of_file
#undef ___weird_hack_to_put_something_at_end_of_file
#endif