xref: /dpdk/lib/eal/linux/eal_debug.c (revision 99a2dd95)
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 <stdarg.h>
9*99a2dd95SBruce Richardson #include <signal.h>
10*99a2dd95SBruce Richardson #include <stdlib.h>
11*99a2dd95SBruce Richardson #include <stdio.h>
12*99a2dd95SBruce Richardson #include <stdint.h>
13*99a2dd95SBruce Richardson 
14*99a2dd95SBruce Richardson #include <rte_log.h>
15*99a2dd95SBruce Richardson #include <rte_debug.h>
16*99a2dd95SBruce Richardson #include <rte_common.h>
17*99a2dd95SBruce Richardson #include <rte_eal.h>
18*99a2dd95SBruce Richardson 
19*99a2dd95SBruce Richardson #define BACKTRACE_SIZE 256
20*99a2dd95SBruce Richardson 
21*99a2dd95SBruce Richardson /* dump the stack of the calling core */
22*99a2dd95SBruce Richardson void rte_dump_stack(void)
23*99a2dd95SBruce Richardson {
24*99a2dd95SBruce Richardson #ifdef RTE_BACKTRACE
25*99a2dd95SBruce Richardson 	void *func[BACKTRACE_SIZE];
26*99a2dd95SBruce Richardson 	char **symb = NULL;
27*99a2dd95SBruce Richardson 	int size;
28*99a2dd95SBruce Richardson 
29*99a2dd95SBruce Richardson 	size = backtrace(func, BACKTRACE_SIZE);
30*99a2dd95SBruce Richardson 	symb = backtrace_symbols(func, size);
31*99a2dd95SBruce Richardson 
32*99a2dd95SBruce Richardson 	if (symb == NULL)
33*99a2dd95SBruce Richardson 		return;
34*99a2dd95SBruce Richardson 
35*99a2dd95SBruce Richardson 	while (size > 0) {
36*99a2dd95SBruce Richardson 		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
37*99a2dd95SBruce Richardson 			"%d: [%s]\n", size, symb[size - 1]);
38*99a2dd95SBruce Richardson 		size --;
39*99a2dd95SBruce Richardson 	}
40*99a2dd95SBruce Richardson 
41*99a2dd95SBruce Richardson 	free(symb);
42*99a2dd95SBruce Richardson #endif /* RTE_BACKTRACE */
43*99a2dd95SBruce Richardson }
44