Make ASSERT, PANIC and TODO show a backtrace and scheduler tid if initialized
This commit is contained in:
parent
af8e5aca64
commit
d54ed0dc8b
@ -1,16 +1,49 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
#include "misc/hang.h"
|
#include "misc/hang.h"
|
||||||
|
#include "thread/Scheduler.h"
|
||||||
|
#include "trace/StackTracer.h"
|
||||||
|
|
||||||
#define __call_assert_fail(...) \
|
#define __call_assert_fail(...) \
|
||||||
kerrorln(__VA_ARGS__); \
|
kerrorln(__VA_ARGS__); \
|
||||||
|
StackTracer tracer; \
|
||||||
|
tracer.trace(); \
|
||||||
hang();
|
hang();
|
||||||
|
|
||||||
#define ASSERT(expr) \
|
#define ASSERT(expr) \
|
||||||
do { \
|
do { \
|
||||||
if (!(expr)) { __call_assert_fail("Assertion failed at %s, line %d: %s", __FILE__, __LINE__, #expr) } \
|
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); } \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TODO(message) __call_assert_fail("TODO at %s, line %d: %s", __FILE__, __LINE__, message)
|
#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)
|
||||||
|
|
||||||
#define PANIC(message) __call_assert_fail("PANIC at %s, line %d: %s", __FILE__, __LINE__, message)
|
#define PANIC(message) \
|
||||||
|
do { \
|
||||||
|
Task* cur_task = Scheduler::current_task(); \
|
||||||
|
if (cur_task) \
|
||||||
|
{ \
|
||||||
|
__call_assert_fail("PANIC in task %ld at %s, line %d: %s", cur_task->id, __FILE__, __LINE__, message); \
|
||||||
|
} \
|
||||||
|
else { __call_assert_fail("PANIC 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
|
Loading…
Reference in New Issue
Block a user