Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
coredump.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
8#define ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
9
10#include <stddef.h>
11#include <stdint.h>
12#include <sys/types.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/*
19 * Define COREDUMP_*_STR as public to allow coredump_backend_other to re-use
20 * these strings if necessary
21 */
22#define COREDUMP_BEGIN_STR "BEGIN#"
23#define COREDUMP_END_STR "END#"
24#define COREDUMP_ERROR_STR "ERROR CANNOT DUMP#"
25
26/*
27 * Need to prefix coredump strings to make it easier to parse
28 * as log module adds its own prefixes.
29 */
30#define COREDUMP_PREFIX_STR "#CD:"
31
42
43
74
132
144
145#ifdef CONFIG_DEBUG_COREDUMP
146
147#include <zephyr/toolchain.h>
148#include <zephyr/arch/cpu.h>
149#include <zephyr/sys/byteorder.h>
150
151#define COREDUMP_HDR_VER 2
152
153#define COREDUMP_ARCH_HDR_ID 'A'
154
155#define THREADS_META_HDR_ID 'T'
156#define THREADS_META_HDR_VER 1
157
158#define COREDUMP_MEM_HDR_ID 'M'
159#define COREDUMP_MEM_HDR_VER 1
160
161#define COREDUMP_CPU_SNAPSHOT_HDR_ID 'F'
162#define COREDUMP_CPU_SNAPSHOT_HDR_VER 1
163
164/* Target code */
165enum coredump_tgt_code {
166 COREDUMP_TGT_UNKNOWN = 0,
167 COREDUMP_TGT_X86,
168 COREDUMP_TGT_X86_64,
169 COREDUMP_TGT_ARM_CORTEX_M,
170 COREDUMP_TGT_RISC_V,
171 COREDUMP_TGT_XTENSA,
172 COREDUMP_TGT_ARM64,
173};
174
175/* Coredump header */
176struct coredump_hdr_t {
177 /* 'Z', 'E' */
178 char id[2];
179
180 /* Header version */
181 uint16_t hdr_version;
182
183 /* Target code */
184 uint16_t tgt_code;
185
186 /* Pointer size in Log2 */
187 uint8_t ptr_size_bits;
188
189 uint8_t flag;
190
191 /* Coredump Reason given */
192 unsigned int reason;
193} __packed;
194
195/* Architecture-specific block header */
196struct coredump_arch_hdr_t {
197 /* COREDUMP_ARCH_HDR_ID */
198 char id;
199
200 /* Header version */
201 uint16_t hdr_version;
202
203 /* Number of bytes in this block (excluding header) */
204 uint16_t num_bytes;
205} __packed;
206
207/* Threads metadata header */
208struct coredump_threads_meta_hdr_t {
209 /* THREADS_META_HDR_ID */
210 char id;
211
212 /* Header version */
213 uint16_t hdr_version;
214
215 /* Number of bytes in this block (excluding header) */
216 uint16_t num_bytes;
217} __packed;
218
219/* Memory block header */
220struct coredump_mem_hdr_t {
221 /* COREDUMP_MEM_HDR_ID */
222 char id;
223
224 /* Header version */
225 uint16_t hdr_version;
226
227 /* Address of start of memory region */
228 uintptr_t start;
229
230 /* Address of end of memory region */
231 uintptr_t end;
232} __packed;
233
234/*
235 * Live per-CPU register snapshot header (CONFIG_DEBUG_COREDUMP_SMP_FREEZE_CPUS).
236 *
237 * One of these precedes each frozen CPU's register block (same arch-specific
238 * payload layout as the COREDUMP_ARCH_HDR_ID block for the panicking thread,
239 * e.g. arm64_arch_block on ARM64), letting tooling show a correct backtrace
240 * for a thread that was actively running on another CPU at panic time,
241 * instead of falling back to its stale last-swapped-out saved context.
242 */
243struct coredump_cpu_snapshot_hdr_t {
244 /* COREDUMP_CPU_SNAPSHOT_HDR_ID */
245 char id;
246
247 /* Header version */
248 uint16_t hdr_version;
249
250 /* Number of bytes in the arch-specific payload that follows */
251 uint16_t num_bytes;
252
253 /* CPU index (0..CONFIG_MP_MAX_NUM_CPUS-1) this snapshot came from */
254 uint32_t cpu_id;
255
256 /* The k_thread that was .current on that CPU when it was frozen */
257 uintptr_t thread_ptr;
258} __packed;
259
260typedef void (*coredump_backend_start_t)(void);
261typedef void (*coredump_backend_end_t)(void);
262typedef void (*coredump_backend_buffer_output_t)(uint8_t *buf, size_t buflen);
263typedef int (*coredump_backend_query_t)(enum coredump_query_id query_id,
264 void *arg);
265typedef int (*coredump_backend_cmd_t)(enum coredump_cmd_id cmd_id,
266 void *arg);
267
268struct coredump_backend_api {
269 /* Signal to backend of the start of coredump. */
270 coredump_backend_start_t start;
271
272 /* Signal to backend of the end of coredump. */
273 coredump_backend_end_t end;
274
275 /* Raw buffer output */
276 coredump_backend_buffer_output_t buffer_output;
277
278 /* Perform query on backend */
279 coredump_backend_query_t query;
280
281 /* Perform command on backend */
282 coredump_backend_cmd_t cmd;
283};
284
285void coredump(unsigned int reason, const struct arch_esf *esf,
286 struct k_thread *thread);
287void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr);
288void coredump_buffer_output(uint8_t *buf, size_t buflen);
289
290int coredump_query(enum coredump_query_id query_id, void *arg);
291int coredump_cmd(enum coredump_cmd_id cmd_id, void *arg);
292
293#else
294
295static inline void coredump(unsigned int reason, const struct arch_esf *esf,
296 struct k_thread *thread)
297{
298 ARG_UNUSED(reason);
299 ARG_UNUSED(esf);
300 ARG_UNUSED(thread);
301}
302
303static inline void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
304{
305 ARG_UNUSED(start_addr);
306 ARG_UNUSED(end_addr);
307}
308
309static inline void coredump_buffer_output(uint8_t *buf, size_t buflen)
310{
311 ARG_UNUSED(buf);
312 ARG_UNUSED(buflen);
313}
314
315static inline int coredump_query(enum coredump_query_id query_id, void *arg)
316{
317 ARG_UNUSED(query_id);
318 ARG_UNUSED(arg);
319 return -ENOTSUP;
320}
321
322static inline int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
323{
324 ARG_UNUSED(query_id);
325 ARG_UNUSED(arg);
326 return -ENOTSUP;
327}
328
329#endif /* CONFIG_DEBUG_COREDUMP */
330
343
351
363
375
387
391
392#ifdef __cplusplus
393}
394#endif
395
396#endif /* ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_ */
coredump_query_id
Query ID.
Definition coredump.h:45
coredump_cmd_id
Command ID.
Definition coredump.h:76
static int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
Perform command on coredump subsystem.
Definition coredump.h:322
static int coredump_query(enum coredump_query_id query_id, void *arg)
Perform query on coredump subsystem.
Definition coredump.h:315
static void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
Dump memory region.
Definition coredump.h:303
static void coredump(unsigned int reason, const struct arch_esf *esf, struct k_thread *thread)
Perform coredump.
Definition coredump.h:295
static void coredump_buffer_output(uint8_t *buf, size_t buflen)
Output the buffer via coredump.
Definition coredump.h:309
@ COREDUMP_QUERY_HAS_STORED_DUMP
Check if there is a stored coredump from backend.
Definition coredump.h:59
@ COREDUMP_QUERY_GET_STORED_DUMP_SIZE
Returns:
Definition coredump.h:67
@ COREDUMP_QUERY_MAX
Max value for query ID.
Definition coredump.h:72
@ COREDUMP_QUERY_GET_ERROR
Returns error code from backend.
Definition coredump.h:49
@ COREDUMP_CMD_COPY_STORED_DUMP
Copy the raw stored coredump.
Definition coredump.h:114
@ COREDUMP_CMD_MAX
Max value for command ID.
Definition coredump.h:130
@ COREDUMP_CMD_INVALIDATE_STORED_DUMP
Invalidate the stored coredump.
Definition coredump.h:125
@ COREDUMP_CMD_ERASE_STORED_DUMP
Erase the stored coredump.
Definition coredump.h:103
@ COREDUMP_CMD_VERIFY_STORED_DUMP
Verify that the stored coredump is valid.
Definition coredump.h:93
@ COREDUMP_CMD_CLEAR_ERROR
Clear error code from backend.
Definition coredump.h:82
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
#define ENOTSUP
Unsupported value.
Definition errno.h:115
__INTPTR_TYPE__ off_t
Definition types.h:36
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Exception Stack Frame.
Definition exception.h:60
Coredump copy command (COREDUMP_CMD_COPY_STORED_DUMP) argument definition.
Definition coredump.h:134
off_t offset
Copy offset.
Definition coredump.h:136
uint8_t * buffer
Copy destination buffer.
Definition coredump.h:139
size_t length
Copy length.
Definition coredump.h:142
Thread Structure.
Definition thread.h:259
Byte order helpers.
Macros to abstract toolchain specific capabilities.