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 #ifndef _RTE_DEBUG_H_ 6*99a2dd95SBruce Richardson #define _RTE_DEBUG_H_ 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson /** 9*99a2dd95SBruce Richardson * @file 10*99a2dd95SBruce Richardson * 11*99a2dd95SBruce Richardson * Debug Functions in RTE 12*99a2dd95SBruce Richardson * 13*99a2dd95SBruce Richardson * This file defines a generic API for debug operations. Part of 14*99a2dd95SBruce Richardson * the implementation is architecture-specific. 15*99a2dd95SBruce Richardson */ 16*99a2dd95SBruce Richardson 17*99a2dd95SBruce Richardson #include "rte_log.h" 18*99a2dd95SBruce Richardson #include "rte_branch_prediction.h" 19*99a2dd95SBruce Richardson 20*99a2dd95SBruce Richardson #ifdef __cplusplus 21*99a2dd95SBruce Richardson extern "C" { 22*99a2dd95SBruce Richardson #endif 23*99a2dd95SBruce Richardson 24*99a2dd95SBruce Richardson /** 25*99a2dd95SBruce Richardson * Dump the stack of the calling core to the console. 26*99a2dd95SBruce Richardson */ 27*99a2dd95SBruce Richardson void rte_dump_stack(void); 28*99a2dd95SBruce Richardson 29*99a2dd95SBruce Richardson /** 30*99a2dd95SBruce Richardson * Provide notification of a critical non-recoverable error and terminate 31*99a2dd95SBruce Richardson * execution abnormally. 32*99a2dd95SBruce Richardson * 33*99a2dd95SBruce Richardson * Display the format string and its expanded arguments (printf-like). 34*99a2dd95SBruce Richardson * 35*99a2dd95SBruce Richardson * In a linux environment, this function dumps the stack and calls 36*99a2dd95SBruce Richardson * abort() resulting in a core dump if enabled. 37*99a2dd95SBruce Richardson * 38*99a2dd95SBruce Richardson * The function never returns. 39*99a2dd95SBruce Richardson * 40*99a2dd95SBruce Richardson * @param ... 41*99a2dd95SBruce Richardson * The format string, followed by the variable list of arguments. 42*99a2dd95SBruce Richardson */ 43*99a2dd95SBruce Richardson #define rte_panic(...) rte_panic_(__func__, __VA_ARGS__, "dummy") 44*99a2dd95SBruce Richardson #define rte_panic_(func, format, ...) __rte_panic(func, format "%.0s", __VA_ARGS__) 45*99a2dd95SBruce Richardson 46*99a2dd95SBruce Richardson #ifdef RTE_ENABLE_ASSERT 47*99a2dd95SBruce Richardson #define RTE_ASSERT(exp) RTE_VERIFY(exp) 48*99a2dd95SBruce Richardson #else 49*99a2dd95SBruce Richardson #define RTE_ASSERT(exp) do {} while (0) 50*99a2dd95SBruce Richardson #endif 51*99a2dd95SBruce Richardson #define RTE_VERIFY(exp) do { \ 52*99a2dd95SBruce Richardson if (unlikely(!(exp))) \ 53*99a2dd95SBruce Richardson rte_panic("line %d\tassert \"%s\" failed\n", __LINE__, #exp); \ 54*99a2dd95SBruce Richardson } while (0) 55*99a2dd95SBruce Richardson 56*99a2dd95SBruce Richardson /* 57*99a2dd95SBruce Richardson * Provide notification of a critical non-recoverable error and stop. 58*99a2dd95SBruce Richardson * 59*99a2dd95SBruce Richardson * This function should not be called directly. Refer to rte_panic() macro 60*99a2dd95SBruce Richardson * documentation. 61*99a2dd95SBruce Richardson */ 62*99a2dd95SBruce Richardson void __rte_panic(const char *funcname , const char *format, ...) 63*99a2dd95SBruce Richardson #ifdef __GNUC__ 64*99a2dd95SBruce Richardson #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) 65*99a2dd95SBruce Richardson __rte_cold 66*99a2dd95SBruce Richardson #endif 67*99a2dd95SBruce Richardson #endif 68*99a2dd95SBruce Richardson __rte_noreturn 69*99a2dd95SBruce Richardson __rte_format_printf(2, 3); 70*99a2dd95SBruce Richardson 71*99a2dd95SBruce Richardson #ifdef __cplusplus 72*99a2dd95SBruce Richardson } 73*99a2dd95SBruce Richardson #endif 74*99a2dd95SBruce Richardson 75*99a2dd95SBruce Richardson #endif /* _RTE_DEBUG_H_ */ 76