xref: /dpdk/lib/eal/linux/eal_debug.c (revision 30a1de10)
1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2*99a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3*99a2dd95SBruce Richardson  */
4*99a2dd95SBruce Richardson 
5*99a2dd95SBruce Richardson #ifdef RTE_BACKTRACE
6*99a2dd95SBruce Richardson #include <execinfo.h>
7*99a2dd95SBruce Richardson #endif
8*99a2dd95SBruce Richardson #include <stdlib.h>
9*99a2dd95SBruce Richardson #include <stdio.h>
10*99a2dd95SBruce Richardson 
11*99a2dd95SBruce Richardson #include <rte_log.h>
12*99a2dd95SBruce Richardson #include <rte_debug.h>
13*99a2dd95SBruce Richardson 
14*99a2dd95SBruce Richardson #define BACKTRACE_SIZE 256
15*99a2dd95SBruce Richardson 
16*99a2dd95SBruce Richardson /* dump the stack of the calling core */
rte_dump_stack(void)17*99a2dd95SBruce Richardson void rte_dump_stack(void)
18*99a2dd95SBruce Richardson {
19*99a2dd95SBruce Richardson #ifdef RTE_BACKTRACE
20*99a2dd95SBruce Richardson 	void *func[BACKTRACE_SIZE];
21*99a2dd95SBruce Richardson 	char **symb = NULL;
22*99a2dd95SBruce Richardson 	int size;
23*99a2dd95SBruce Richardson 
24*99a2dd95SBruce Richardson 	size = backtrace(func, BACKTRACE_SIZE);
25*99a2dd95SBruce Richardson 	symb = backtrace_symbols(func, size);
26*99a2dd95SBruce Richardson 
27*99a2dd95SBruce Richardson 	if (symb == NULL)
28*99a2dd95SBruce Richardson 		return;
29*99a2dd95SBruce Richardson 
30*99a2dd95SBruce Richardson 	while (size > 0) {
31*99a2dd95SBruce Richardson 		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
32*99a2dd95SBruce Richardson 			"%d: [%s]\n", size, symb[size - 1]);
33*99a2dd95SBruce Richardson 		size --;
34*99a2dd95SBruce Richardson 	}
35*99a2dd95SBruce Richardson 
36*99a2dd95SBruce Richardson 	free(symb);
37*99a2dd95SBruce Richardson #endif /* RTE_BACKTRACE */
38*99a2dd95SBruce Richardson }
39