20 #if !defined(NX_KIT_API) 34 NX_KIT_API std::string srcFileRelativePath(
const std::string& file);
39 NX_KIT_API std::string srcFileBaseNameWithoutExt(
const std::string& file);
45 #if defined(NX_PRINT_TO_QDEBUG) 46 #define NX_DEBUG_STREAM qDebug().nospace().noquote() 48 static inline QDebug operator<<(QDebug d,
const std::string& s)
50 return d << QString::fromStdString(s);
54 #if !defined(NX_DEBUG_INI) 56 #define NX_DEBUG_INI ini(). 59 #if !defined(NX_DEBUG_ENABLE_OUTPUT) 61 #define NX_DEBUG_ENABLE_OUTPUT NX_DEBUG_INI enableOutput 64 #if !defined(NX_PRINT_PREFIX) 66 #define NX_PRINT_PREFIX ::nx::kit::debug::detail::printPrefix(__FILE__) 69 #if !defined(NX_DEBUG_STREAM) 71 #define NX_DEBUG_STREAM *::nx::kit::debug::stream() 74 #if !defined(NX_DEBUG_ENDL) 76 #define NX_DEBUG_ENDL << std::endl 83 NX_KIT_API std::ostream*& stream();
85 #if !defined(NX_PRINT) 92 ( []() { struct Endl { ~Endl() { NX_DEBUG_STREAM NX_DEBUG_ENDL; } }; \ 93 return std::make_shared<Endl>(); }() ) , \ 94 NX_DEBUG_STREAM << NX_PRINT_PREFIX 102 int NX_KIT_DEBUG_DETAIL_CONCAT(nxOutput_, __line__) = 0; \ 103 NX_KIT_DEBUG_DETAIL_CONCAT(nxOutput_, __line__) != 1 && (NX_DEBUG_ENABLE_OUTPUT); \ 104 ++NX_KIT_DEBUG_DETAIL_CONCAT(nxOutput_, __line__) \ 125 #define NX_KIT_ASSERT( ...) \ 126 NX_KIT_DEBUG_DETAIL_MSVC_EXPAND(NX_KIT_DEBUG_DETAIL_GET_3RD_ARG( \ 127 __VA_ARGS__, NX_KIT_DEBUG_DETAIL_ASSERT2, NX_KIT_DEBUG_DETAIL_ASSERT1, \ 128 args_required)(__VA_ARGS__)) 134 NX_KIT_API
void intentionallyCrash(
const char* message);
143 NX_PRINT << "####### LL line " + ::nx::kit::utils::toString(__LINE__) \ 144 + NX_KIT_DEBUG_DETAIL_THREAD_ID \ 145 + ", " + ::nx::kit::debug::srcFileRelativePath(__FILE__) \ 151 #define NX_PRINT_VALUE(VALUE) \ 152 NX_PRINT << "####### " #VALUE ": " + ::nx::kit::utils::toString(VALUE) 157 #define NX_PRINT_HEX_DUMP(CAPTION, BYTES, SIZE) \ 158 ::nx::kit::debug::detail::printHexDump( \ 159 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, (CAPTION), (const char*) (BYTES), (int) (SIZE)) 164 NX_KIT_API std::string hexDumpLine(
const char* bytes,
int size,
int bytesPerLine = 0);
166 #if !defined(NX_DEBUG_SAVE_DIR) 168 #define NX_DEBUG_SAVE_DIR ::nx::kit::IniConfig::iniFilesDir() 176 #define NX_SAVE_STR(FILENAME, STR) \ 177 ::nx::kit::debug::detail::saveStr( \ 178 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, (NX_DEBUG_SAVE_DIR), (FILENAME), #STR, (STR)) 183 #define NX_SAVE_BIN(FILENAME, BYTES, SIZE) \ 184 ::nx::kit::debug::detail::saveBin( \ 185 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, (NX_DEBUG_SAVE_DIR), (FILENAME), (BYTES), (SIZE)) 190 #if !defined(NX_DEBUG_ENABLE_TIME) 192 #define NX_DEBUG_ENABLE_TIME NX_DEBUG_INI enableTime 198 #define NX_TIME_BEGIN(TAG) \ 199 ::nx::kit::debug::detail::Timer nxTimer_##TAG( \ 200 (NX_DEBUG_ENABLE_TIME), NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #TAG) 206 #define NX_TIME_MARK(TAG, MARK) do \ 208 if (NX_DEBUG_ENABLE_TIME) \ 209 nxTimer_##TAG.mark((MARK)); \ 215 #define NX_TIME_END(TAG) do \ 217 if (NX_DEBUG_ENABLE_TIME) \ 218 nxTimer_##TAG.finish(); \ 224 #if !defined(NX_DEBUG_ENABLE_FPS) 226 #define NX_DEBUG_ENABLE_FPS NX_DEBUG_INI enableFps 233 #define NX_FPS(TAG, ...) do \ 235 if (NX_KIT_DEBUG_DETAIL_CONCAT(NX_DEBUG_ENABLE_FPS, TAG)) \ 237 static ::nx::kit::debug::detail::Fps fps( \ 238 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #TAG); \ 239 fps.mark(__VA_ARGS__); \ 248 typedef std::function<void(const char*)> PrintFunc;
250 #define NX_KIT_DEBUG_DETAIL_PRINT_FUNC ([&](const char* message) { NX_PRINT << message; }) 256 #define NX_KIT_DEBUG_DETAIL_MSVC_EXPAND(ARG) ARG 259 #define NX_KIT_DEBUG_DETAIL_GET_3RD_ARG(ARG1, ARG2, ARG3, ...) ARG3 261 #define NX_KIT_DEBUG_DETAIL_ASSERT1(CONDITION) \ 262 ::nx::kit::debug::detail::doAssert( \ 263 !!(CONDITION), NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #CONDITION, "", __FILE__, __LINE__) 265 #define NX_KIT_DEBUG_DETAIL_ASSERT2(CONDITION, MESSAGE) \ 266 ::nx::kit::debug::detail::doAssert( \ 267 !!(CONDITION), NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #CONDITION, MESSAGE, __FILE__, __LINE__) 269 NX_KIT_API
void assertionFailed(
270 PrintFunc printFunc,
const char* conditionStr,
const std::string& message,
271 const char* file,
int line);
273 inline bool doAssert(
274 bool condition, PrintFunc printFunc,
const char* conditionStr,
const std::string& message,
275 const char* file,
int line)
278 assertionFailed(printFunc, conditionStr, message, file, line);
282 #define NX_KIT_DEBUG_DETAIL_CONCAT(X, Y) NX_KIT_DEBUG_DETAIL_CONCAT2(X, Y) 283 #define NX_KIT_DEBUG_DETAIL_CONCAT2(X, Y) X##Y 286 NX_KIT_API std::string printPrefix(
const char* file);
291 Timer(
bool enabled, PrintFunc printFunc,
const char* tag);
293 void mark(
const char* markStr);
304 Fps(PrintFunc printFunc,
const char* tag);
306 void mark(
const char* markStr =
nullptr);
313 NX_KIT_API
void printHexDump(
314 PrintFunc printFunc,
const char* caption,
const char* bytes,
int size);
316 NX_KIT_API
void saveStr(
318 const char* originDir,
319 const char* filename,
320 const char* strCaption,
321 const std::string& str);
323 NX_KIT_API
void saveBin(
325 const char* originDir,
326 const char* filename,
337 #if defined(__linux__) 338 #if defined(__has_include) //< This C++17 feature was available in GCC/Clang long before. 339 #if __has_include(<pthread.h>) 341 #define NX_KIT_DEBUG_DETAIL_THREAD_ID \ 342 ::nx::kit::utils::format(", thread %llx", (long long) pthread_self()) 345 #elif defined(QT_CORE_LIB) 346 #include <QtCore/QThread> 347 #define NX_KIT_DEBUG_DETAIL_THREAD_ID \ 348 ::nx::kit::utils::format(", thread %llx", (long long) QThread::currentThreadId()) 350 #if !defined(NX_KIT_DEBUG_DETAIL_THREAD_ID) 352 #define NX_KIT_DEBUG_DETAIL_THREAD_ID ""
Definition: debug.cpp:309
Definition: debug.cpp:234
Definition: apple_utils.h:6