2016-09-28 09:56:06 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
2016-11-18 15:44:25 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-09-28 09:56:06 +02:00
|
|
|
#include "assert.h"
|
2022-06-17 17:19:49 +02:00
|
|
|
#include "architecture.h"
|
2022-06-12 14:18:53 +02:00
|
|
|
#include "cpu.h"
|
2023-03-09 13:51:25 +01:00
|
|
|
#include "debug.h"
|
2024-04-26 14:16:17 +02:00
|
|
|
#include "irq.h"
|
2022-01-26 12:37:30 +01:00
|
|
|
#include "panic.h"
|
2022-10-13 17:42:49 +02:00
|
|
|
#if IS_USED(MODULE_BACKTRACE)
|
|
|
|
#include "backtrace.h"
|
|
|
|
#endif
|
2016-09-28 09:56:06 +02:00
|
|
|
|
2024-04-26 14:07:24 +02:00
|
|
|
__NORETURN static inline void _assert_common(void)
|
2016-09-28 09:56:06 +02:00
|
|
|
{
|
2022-10-13 17:42:49 +02:00
|
|
|
#if IS_USED(MODULE_BACKTRACE)
|
2024-04-26 14:07:24 +02:00
|
|
|
#ifdef DEBUG_ASSERT_VERBOSE
|
2022-10-13 17:42:49 +02:00
|
|
|
printf("failed assertion. Backtrace:\n");
|
2024-04-26 14:07:24 +02:00
|
|
|
#endif
|
2022-10-13 17:42:49 +02:00
|
|
|
backtrace_print();
|
|
|
|
#endif
|
2023-06-27 17:02:35 +02:00
|
|
|
#ifdef DEBUG_ASSERT_BREAKPOINT
|
2023-03-09 13:51:25 +01:00
|
|
|
DEBUG_BREAKPOINT(1);
|
2023-06-27 17:02:35 +02:00
|
|
|
#endif
|
2024-04-26 14:16:17 +02:00
|
|
|
if (DEBUG_ASSERT_NO_PANIC && !irq_is_in() && irq_is_enabled()) {
|
|
|
|
puts("FAILED ASSERTION.");
|
|
|
|
while (1) {
|
|
|
|
thread_sleep();
|
|
|
|
}
|
|
|
|
}
|
2022-01-26 12:37:30 +01:00
|
|
|
core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION.");
|
|
|
|
}
|
|
|
|
|
2024-04-26 14:07:24 +02:00
|
|
|
__NORETURN void _assert_failure(const char *file, unsigned line)
|
|
|
|
{
|
|
|
|
printf("%s:%u => ", file, line);
|
|
|
|
_assert_common();
|
|
|
|
}
|
|
|
|
|
2022-01-26 12:37:30 +01:00
|
|
|
__NORETURN void _assert_panic(void)
|
|
|
|
{
|
2022-06-17 17:19:49 +02:00
|
|
|
printf("%" PRIxTXTPTR "\n", cpu_get_caller_pc());
|
2024-04-26 14:07:24 +02:00
|
|
|
_assert_common();
|
2016-09-28 09:56:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|