lib: use SPDX tag for Intel copyright files
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal_debug.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifdef RTE_BACKTRACE
6 #include <execinfo.h>
7 #endif
8 #include <stdarg.h>
9 #include <signal.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <stdint.h>
13
14 #include <rte_log.h>
15 #include <rte_debug.h>
16 #include <rte_common.h>
17
18 #define BACKTRACE_SIZE 256
19
20 /* dump the stack of the calling core */
21 void rte_dump_stack(void)
22 {
23 #ifdef RTE_BACKTRACE
24         void *func[BACKTRACE_SIZE];
25         char **symb = NULL;
26         int size;
27
28         size = backtrace(func, BACKTRACE_SIZE);
29         symb = backtrace_symbols(func, size);
30
31         if (symb == NULL)
32                 return;
33
34         while (size > 0) {
35                 rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
36                         "%d: [%s]\n", size, symb[size - 1]);
37                 size --;
38         }
39
40         free(symb);
41 #endif /* RTE_BACKTRACE */
42 }
43
44 /* not implemented in this environment */
45 void rte_dump_registers(void)
46 {
47         return;
48 }
49
50 /* call abort(), it will generate a coredump if enabled */
51 void __rte_panic(const char *funcname, const char *format, ...)
52 {
53         va_list ap;
54
55         rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "PANIC in %s():\n", funcname);
56         va_start(ap, format);
57         rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
58         va_end(ap);
59         rte_dump_stack();
60         rte_dump_registers();
61         abort();
62 }
63
64 /*
65  * Like rte_panic this terminates the application. However, no traceback is
66  * provided and no core-dump is generated.
67  */
68 void
69 rte_exit(int exit_code, const char *format, ...)
70 {
71         va_list ap;
72
73         if (exit_code != 0)
74                 RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
75                                 "  Cause: ", exit_code);
76
77         va_start(ap, format);
78         rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
79         va_end(ap);
80
81 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
82         exit(exit_code);
83 #else
84         rte_dump_stack();
85         rte_dump_registers();
86         abort();
87 #endif
88 }