forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoredump.h
231 lines (187 loc) · 5.01 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* Copyright (c) 2020 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
#define ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
/* Query ID */
enum coredump_query_id {
/*
* Returns error code from backend.
*/
COREDUMP_QUERY_GET_ERROR,
/*
* Check if there is a stored coredump from backend.
*
* Returns 1 if there is a stored coredump.
* 0 if none.
* -ENOTSUP if this query is not supported.
* Otherwise, error code from backend.
*/
COREDUMP_QUERY_HAS_STORED_DUMP,
COREDUMP_QUERY_MAX
};
/* Command ID */
enum coredump_cmd_id {
/*
* Clear error code from backend.
*
* Returns 0 if successful, failed otherwise.
*/
COREDUMP_CMD_CLEAR_ERROR,
/*
* Verify that the stored coredump is valid.
*
* Returns 1 if valid.
* 0 if not valid or no stored coredump.
* -ENOTSUP if this command is not supported.
* Otherwise, error code from backend.
*/
COREDUMP_CMD_VERIFY_STORED_DUMP,
/*
* Erase the stored coredump.
*
* Returns 0 if successful.
* -ENOTSUP if this command is not supported.
* Otherwise, error code from backend.
*/
COREDUMP_CMD_ERASE_STORED_DUMP,
COREDUMP_CMD_MAX
};
#ifdef CONFIG_DEBUG_COREDUMP
#include <toolchain.h>
#include <arch/cpu.h>
#include <sys/byteorder.h>
#define COREDUMP_HDR_VER 1
#define COREDUMP_ARCH_HDR_ID 'A'
#define COREDUMP_MEM_HDR_ID 'M'
#define COREDUMP_MEM_HDR_VER 1
/* Target code */
enum coredump_tgt_code {
COREDUMP_TGT_UNKNOWN = 0,
COREDUMP_TGT_X86,
COREDUMP_TGT_X86_64,
COREDUMP_TGT_ARM_CORTEX_M,
};
/* Coredump header */
struct coredump_hdr_t {
/* 'Z', 'E' */
char id[2];
/* Header version */
uint16_t hdr_version;
/* Target code */
uint16_t tgt_code;
/* Pointer size in Log2 */
uint8_t ptr_size_bits;
uint8_t flag;
/* Coredump Reason given */
unsigned int reason;
} __packed;
/* Architecture-specific block header */
struct coredump_arch_hdr_t {
/* COREDUMP_ARCH_HDR_ID */
char id;
/* Header version */
uint16_t hdr_version;
/* Number of bytes in this block (excluding header) */
uint16_t num_bytes;
} __packed;
/* Memory block header */
struct coredump_mem_hdr_t {
/* COREDUMP_MEM_HDR_ID */
char id;
/* Header version */
uint16_t hdr_version;
/* Address of start of memory region */
uintptr_t start;
/* Address of end of memory region */
uintptr_t end;
} __packed;
void coredump(unsigned int reason, const z_arch_esf_t *esf,
struct k_thread *thread);
void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr);
void coredump_buffer_output(uint8_t *buf, size_t buflen);
int coredump_query(enum coredump_query_id query_id, void *arg);
int coredump_cmd(enum coredump_cmd_id cmd_id, void *arg);
#else
void coredump(unsigned int reason, const z_arch_esf_t *esf,
struct k_thread *thread)
{
}
void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
{
}
void coredump_buffer_output(uint8_t *buf, size_t buflen)
{
}
int coredump_query(enum coredump_query_id query_id, void *arg)
{
return -ENOTSUP;
}
int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
{
return -ENOTSUP;
}
#endif /* CONFIG_DEBUG_COREDUMP */
/**
* @defgroup coredump_apis Coredump APIs
* @brief Coredump APIs
* @{
*/
/**
* @fn void coredump(unsigned int reason, const z_arch_esf_t *esf, struct k_thread *thread);
* @brief Perform coredump.
*
* Normally, this is called inside z_fatal_error() to generate coredump
* when a fatal error is encountered. This can also be called on demand
* whenever a coredump is desired.
*
* @param reason Reason for the fatal error
* @param esf Exception context
* @param thread Thread information to dump
*/
/**
* @fn void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr);
* @brief Dump memory region
*
* @param start_addr Start address of memory region to be dumped
* @param end_addr End address of memory region to be dumped
*/
/**
* @fn int coredump_buffer_output(uint8_t *buf, size_t buflen);
* @brief Output the buffer via coredump
*
* This outputs the buffer of byte array to the coredump backend.
* For example, this can be called to output the coredump section
* containing registers, or a section for memory dump.
*
* @param buf Buffer to be send to coredump output
* @param buflen Buffer length
*/
/**
* @fn int coredump_query(enum coredump_query_id query_id, void *arg);
* @brief Perform query on coredump subsystem.
*
* Query the coredump subsystem for information, for example, if there is
* an error.
*
* @param[in] query_id Query ID
* @param[in,out] arg Pointer to argument for exchanging information
* @return Depends on the query
*/
/**
* @fn int coredump_cmd(enum coredump_cmd_id cmd_id, void *arg);
* @brief Perform command on coredump subsystem.
*
* Perform certain on coredump subsystem, for example, output the stored
* coredump via logging.
*
* @param[in] cmd_id Command ID
* @param[in,out] arg Pointer to argument for exchanging information
* @return Depends on the command
*/
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_ */