2020-03-13 14:11:58 +01:00
|
|
|
|
2020-08-17 21:40:52 +02:00
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
2020-03-13 14:11:58 +01:00
|
|
|
|
|
|
|
|
2021-05-08 11:34:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-04-25 11:59:07 +02:00
|
|
|
#if defined(CLOVER_BUILD) || !defined(_MSC_VER)
|
2020-03-13 14:11:58 +01:00
|
|
|
void abort(void)
|
|
|
|
{
|
2020-10-12 13:51:08 +02:00
|
|
|
printf("A fatal error happened. System halted\n");
|
|
|
|
while (1) { // tis will avoid warning : Function declared 'noreturn' should not return
|
|
|
|
CpuDeadLoop();
|
|
|
|
}
|
2020-03-21 14:12:26 +01:00
|
|
|
}
|
2020-04-25 11:59:07 +02:00
|
|
|
#endif
|
2020-04-24 08:36:29 +02:00
|
|
|
|
2021-05-08 11:34:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-24 08:36:29 +02:00
|
|
|
bool stop_at_panic = true;
|
|
|
|
bool i_have_panicked = false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Function panic_ seems useless. It's same as panic(). It's to be able to put a breakpoint in gdb with br panic_(). This is done in gdb_launch script in Qemu
|
|
|
|
*/
|
2020-08-15 22:39:25 +02:00
|
|
|
static void panic_(const char* format, VA_LIST va)
|
|
|
|
#ifndef PANIC_CAN_RETURN
|
|
|
|
__attribute__ ((noreturn));
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2020-10-12 13:51:08 +02:00
|
|
|
#ifdef CLOVER_BUILD
|
2021-09-28 10:28:45 +02:00
|
|
|
extern void egSetGraphicsModeEnabled(XBool);
|
2020-10-22 15:55:30 +02:00
|
|
|
extern const LString8 gBuildId;
|
2020-10-12 13:51:08 +02:00
|
|
|
#endif
|
2020-09-23 15:47:47 +02:00
|
|
|
|
2020-09-03 23:35:36 +02:00
|
|
|
#define FATAL_ERROR_MSG "\nA fatal error happened. System halted.\n"
|
2020-04-24 08:36:29 +02:00
|
|
|
static void panic_(const char* format, VA_LIST va)
|
|
|
|
{
|
2020-10-12 13:51:08 +02:00
|
|
|
#ifdef CLOVER_BUILD
|
|
|
|
egSetGraphicsModeEnabled(false);
|
2020-10-22 15:55:30 +02:00
|
|
|
printf("Clover build id: %s\n", gBuildId.c_str());
|
2020-11-02 14:45:11 +01:00
|
|
|
#endif
|
2020-10-12 13:51:08 +02:00
|
|
|
if ( format ) {
|
2021-05-06 08:23:07 +02:00
|
|
|
// vprintf(format, va);
|
|
|
|
// #ifdef DEBUG_ON_SERIAL_PORT
|
|
|
|
// char buf[500];
|
|
|
|
// vsnprintf(buf, sizeof(buf)-1, format, va);
|
|
|
|
// SerialPortWrite((UINT8*)buf, strlen(buf));
|
|
|
|
// #endif
|
2020-10-12 13:51:08 +02:00
|
|
|
char buf[500];
|
|
|
|
vsnprintf(buf, sizeof(buf)-1, format, va);
|
2021-05-06 08:23:07 +02:00
|
|
|
DebugLog(2, "%s", buf);
|
2020-10-12 13:51:08 +02:00
|
|
|
}
|
2021-05-06 08:23:07 +02:00
|
|
|
// printf(FATAL_ERROR_MSG);
|
|
|
|
// #ifdef DEBUG_ON_SERIAL_PORT
|
|
|
|
// SerialPortWrite((UINT8*)FATAL_ERROR_MSG, strlen(FATAL_ERROR_MSG));
|
|
|
|
// #endif
|
|
|
|
DebugLog(2, "%s", FATAL_ERROR_MSG);
|
|
|
|
DebugLog(2, "\n");
|
2020-10-12 13:51:08 +02:00
|
|
|
while (1) { // this will avoid warning : Function declared 'noreturn' should not return
|
|
|
|
CpuDeadLoop();
|
|
|
|
}
|
2020-04-24 08:36:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void panic(const char* format, ...)
|
|
|
|
{
|
2020-08-15 22:39:25 +02:00
|
|
|
#ifdef PANIC_CAN_RETURN
|
2020-10-12 13:51:08 +02:00
|
|
|
if ( stop_at_panic ) {
|
|
|
|
VA_LIST va;
|
|
|
|
VA_START(va, format);
|
|
|
|
panic_(format, va); // panic doesn't return
|
|
|
|
// VA_END(va);
|
|
|
|
}else{
|
|
|
|
i_have_panicked = true;
|
|
|
|
}
|
2020-08-15 22:39:25 +02:00
|
|
|
#else
|
|
|
|
VA_LIST va;
|
|
|
|
VA_START(va, format);
|
|
|
|
panic_(format, va); // panic doesn't return
|
|
|
|
#endif
|
2020-04-24 08:36:29 +02:00
|
|
|
}
|
|
|
|
|
2021-05-08 11:34:17 +02:00
|
|
|
|
2021-04-06 23:45:58 +02:00
|
|
|
/*
|
2021-05-08 11:34:17 +02:00
|
|
|
* Future version to log about pontential technical bugs
|
2021-04-06 23:45:58 +02:00
|
|
|
* It's not done yes. So far, it's just panic
|
|
|
|
* TODO:
|
|
|
|
*/
|
2021-05-08 11:34:17 +02:00
|
|
|
static void panic__(const char* format, VA_LIST va)
|
2021-04-06 23:45:58 +02:00
|
|
|
{
|
2021-05-08 11:34:17 +02:00
|
|
|
#ifdef CLOVER_BUILD
|
|
|
|
egSetGraphicsModeEnabled(false);
|
|
|
|
printf("Clover build id: %s\n", gBuildId.c_str());
|
2021-04-06 23:45:58 +02:00
|
|
|
#endif
|
2021-05-08 11:34:17 +02:00
|
|
|
if ( format ) {
|
|
|
|
// vprintf(format, va);
|
|
|
|
// #ifdef DEBUG_ON_SERIAL_PORT
|
|
|
|
// char buf[500];
|
|
|
|
// vsnprintf(buf, sizeof(buf)-1, format, va);
|
|
|
|
// SerialPortWrite((UINT8*)buf, strlen(buf));
|
|
|
|
// #endif
|
|
|
|
char buf[500];
|
|
|
|
vsnprintf(buf, sizeof(buf)-1, format, va);
|
|
|
|
DebugLog(2, "%s", buf);
|
|
|
|
}
|
|
|
|
// printf(FATAL_ERROR_MSG);
|
|
|
|
// #ifdef DEBUG_ON_SERIAL_PORT
|
|
|
|
// SerialPortWrite((UINT8*)FATAL_ERROR_MSG, strlen(FATAL_ERROR_MSG));
|
|
|
|
// #endif
|
|
|
|
DebugLog(2, "%s", FATAL_ERROR_MSG);
|
|
|
|
DebugLog(2, "\n");
|
|
|
|
for (size_t i = 0 ; i < SIZE_T_MAX ; i++ ) { // this will avoid warning : Function declared 'noreturn' should not return
|
|
|
|
CpuDeadLoop();
|
|
|
|
}
|
2021-04-06 23:45:58 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 14:20:48 +02:00
|
|
|
void log_technical_bug(const char* format, ...)
|
|
|
|
{
|
|
|
|
#ifdef PANIC_CAN_RETURN
|
|
|
|
if ( stop_at_panic ) {
|
|
|
|
VA_LIST va;
|
|
|
|
VA_START(va, format);
|
2021-05-08 11:34:17 +02:00
|
|
|
panic__(format, va); // panic doesn't return
|
2021-04-23 14:20:48 +02:00
|
|
|
// VA_END(va);
|
|
|
|
}else{
|
|
|
|
i_have_panicked = true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
VA_LIST va;
|
|
|
|
VA_START(va, format);
|
2021-05-08 11:34:17 +02:00
|
|
|
panic__(format, va); // panic doesn't return
|
2021-04-23 14:20:48 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 08:36:29 +02:00
|
|
|
void panic(void)
|
|
|
|
{
|
2020-10-12 13:51:08 +02:00
|
|
|
panic(nullptr);
|
2020-04-24 08:36:29 +02:00
|
|
|
}
|
2020-10-17 15:01:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
void _assert(bool b, const char* format, ...)
|
|
|
|
{
|
|
|
|
if ( !b ) {
|
|
|
|
VA_LIST va;
|
|
|
|
VA_START(va, format);
|
|
|
|
panic_(format, va); // panic doesn't return
|
|
|
|
}
|
|
|
|
}
|