~aleteoryx/muditaos

ref: 7cc452503e95b269eedb1b1545d351e10d830426 muditaos/module-os/board/rt1051/include/exit_backtrace.h -rw-r--r-- 1.5 KiB
7cc45250 — Przemyslaw Brudny Merge remote-tracking branch 'origin/stable' 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif


/** This is a extension for standard function @see exit which stop the system
 * and optionaly takes a backtrace
 * @param[in] code Standard terminate exit code
 * @param[in] bt_dump If true backtrace will be created
 * @note Function never returns
 */
void __attribute__((noreturn, used)) _exit_backtrace(int code, bool bt_dump);


/** This is a standard function @see exit which stop the system
 * and optionaly takes a backtrace
 * @param[in] code Standard terminate exit code
 * @note Function never returns and dump backtrace when code is not equal EXIT_SUCCESS
 */
void __attribute__((noreturn, used)) _exit(int code);


/** This is internal backtrce function
 * @note In never shouldn't to be called directly in the user code
 */
static inline void __attribute__((always_inline)) _StackTrace_Dump_stage_1(void)
{
    // Redirect to the save stacktrace syscall (1)
    __asm volatile("svc #1\n");
}

/** This is internal backtrce function
 * @note In never shouldn't to be called directly in the user code
 */
extern void _StackTrace_Dump_stage_2(void);


/** This function save a backtrace on the disk and stop the system by abort
 */
static inline void __attribute__((always_inline)) _StackTrace_Dump_And_Abort(void)
{
    _StackTrace_Dump_stage_1();
    _StackTrace_Dump_stage_2();
}

#ifdef __cplusplus
}
#endif