From d54ed0dc8b06c5d2e21371a98485403096d8d65e Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 21 Sep 2022 20:56:40 +0200 Subject: [PATCH] Make ASSERT, PANIC and TODO show a backtrace and scheduler tid if initialized --- kernel/include/assert.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/kernel/include/assert.h b/kernel/include/assert.h index 9e0da36b..daec8784 100644 --- a/kernel/include/assert.h +++ b/kernel/include/assert.h @@ -1,16 +1,49 @@ #pragma once #include "log/Log.h" #include "misc/hang.h" +#include "thread/Scheduler.h" +#include "trace/StackTracer.h" #define __call_assert_fail(...) \ kerrorln(__VA_ARGS__); \ + StackTracer tracer; \ + tracer.trace(); \ hang(); #define ASSERT(expr) \ 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) -#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) \ No newline at end of file +#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 \ No newline at end of file