-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCoreDump.h
103 lines (81 loc) · 2.66 KB
/
CoreDump.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef _CORE_DUMP_H
#define _CORE_DUMP_H
#include "Options.h"
#include <stdint.h>
// A marker used to indicate the top of the stack
#define STACK_MARKER 0xEFEFEFEF
// A unique key to determine if a core dump data structure is valid
#define KEY_CORE_DUMP_STORED 0xDEADBEEF
// Software application version number
#define SOFTWARE_VERSION 1234
// Maximum file length name stored in core dump
#define FILE_NAME_LEN 128
// The depth of the core dump call stack stored
#define CALL_STACK_SIZE 8
// How far back into the stack to search in 32-bit words.
// e.g. 1024 x 4 = 4k search depth
#define MAX_STACK_DEPTH_SEARCH 1024
// TODO: Define the RAM start and stop addresses. Platform specific detail.
// See your processor memory map for values.
#define RAM_BEGIN 0x20000000
#define RAM_END 0x20004FFF
// TODO: Define the flash start and stop addresses. Platform specific detail.
// See your processor memory map for values.
#define FLASH_BASE 0x08000000
#define FLASH_END 0x0801FFFF
// TODO: How many operating system tasks to store within the core dump.
#define OS_TASKCNT 5
#if (SIZE_MAX == UINT32_MAX)
#define INTEGER_TYPE int32_t
#elif (SIZE_MAX == UINT64_MAX)
#define INTEGER_TYPE int64_t
#else
#error "Unsupported platform: unable to determine the size of uintptr_t"
#endif
enum FaultType
{
FAULT_EXCEPTION, // Hardware exception
SOFTWARE_ASSERTION // Software assertion
};
/// Core dump data structure
class CoreDumpData
{
public:
uint32_t Key;
uint32_t NotKey;
uint32_t SoftwareVersion;
uint32_t AuxCode;
FaultType Type;
uint32_t LineNumber;
char FileName[FILE_NAME_LEN];
#ifdef USE_HARDWARE
uint32_t R0_register;
uint32_t R1_register;
uint32_t R2_register;
uint32_t R3_register;
uint32_t R12_register;
uint32_t LR_register;
uint32_t PC_register;
uint32_t XPSR_register;
#endif
INTEGER_TYPE ActiveCallStack[CALL_STACK_SIZE];
#ifdef USE_OPERATING_SYSTEM
INTEGER_TYPE ThreadCallStacks[OS_TASKCNT][CALL_STACK_SIZE];
#endif
};
/// Store core dump data.
/// @param[in] stackPointer - the current call stack pointer or 0.
/// @param[in] fileName - file name causing error
/// @param[in] lineNumber - line number causing error
/// @param[in] auxCode - any additional number, or 0
void CoreDumpStore(INTEGER_TYPE* stackPointer, const char* fileName,
uint32_t lineNumber, uint32_t auxCode);
/// Get the core dump saved state
/// @return Returns true if core dump data is saved.
bool IsCoreDumpSaved();
/// Get core dump data structure
/// @return A pointer to the core dump data structure.
CoreDumpData* CoreDumpGet();
/// Reset core dump data structure.
void CoreDumpReset();
#endif