mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[backtrace] add otSysRegisterCrashCallback to register crash callback function (#12552)
This commit adds `otSysRegisterCrashCallback` function which can be used to register the callback function to be called when openthread crashes.
This commit is contained in:
@@ -40,10 +40,15 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <openthread/openthread-system.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/logging.hpp"
|
||||
|
||||
#if OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE
|
||||
static otSysCrashCallback sCrashCallback = nullptr;
|
||||
|
||||
void otSysRegisterCrashCallback(otSysCrashCallback aCallback) { sCrashCallback = aCallback; }
|
||||
#if OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE || defined(__GLIBC__)
|
||||
#if OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE
|
||||
#include <log/log.h>
|
||||
@@ -156,6 +161,11 @@ static void signalCritical(int sig, siginfo_t *info, void *ucontext)
|
||||
|
||||
otLogCritPlat("------------------ END OF CRASH ------------------");
|
||||
|
||||
if (sCrashCallback != nullptr)
|
||||
{
|
||||
sCrashCallback();
|
||||
}
|
||||
|
||||
resetSignalActions();
|
||||
raise(sig);
|
||||
}
|
||||
|
||||
@@ -330,6 +330,23 @@ void otSysTrelDeinit(void);
|
||||
*/
|
||||
void otSysSetRcpRestorationEnabled(bool aEnabled);
|
||||
|
||||
/**
|
||||
* Represents a callback function to be called when openthread crashes.
|
||||
*
|
||||
* @note This callback is invoked from a signal handler context. The callback implementation must only use
|
||||
* async-signal-safe functions.
|
||||
*/
|
||||
typedef void (*otSysCrashCallback)(void);
|
||||
|
||||
/**
|
||||
* Registers the callback function to be called when openthread crashes.
|
||||
*
|
||||
* Requires `OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE`.
|
||||
*
|
||||
* @param[in] aCallback The callback function.
|
||||
*/
|
||||
void otSysRegisterCrashCallback(otSysCrashCallback aCallback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end of extern "C"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user