diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-11 18:34:21 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-11 18:45:43 +0300 |
commit | c124712cface453ca6d106cdc0bf0680c556fa66 (patch) | |
tree | f76f262a61376aa512238d5a097a6b2131dc1059 /src | |
parent | 47a1aa9870c5187b1f5417bae8485e20e08f962d (diff) | |
download | manaverse-c124712cface453ca6d106cdc0bf0680c556fa66.tar.gz manaverse-c124712cface453ca6d106cdc0bf0680c556fa66.tar.bz2 manaverse-c124712cface453ca6d106cdc0bf0680c556fa66.tar.xz manaverse-c124712cface453ca6d106cdc0bf0680c556fa66.zip |
Extend checkutils functions.
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/checkutils.cpp | 47 | ||||
-rw-r--r-- | src/utils/checkutils.h | 54 |
2 files changed, 65 insertions, 36 deletions
diff --git a/src/utils/checkutils.cpp b/src/utils/checkutils.cpp index 275c4e447..661e3efa2 100644 --- a/src/utils/checkutils.cpp +++ b/src/utils/checkutils.cpp @@ -32,33 +32,54 @@ #include "debug.h" -void reportStack(const char *const file, - const unsigned int line, - const char *const func, - const char *const name, - const char *const text) +void reportAssertStack(const char *const file, + const unsigned int line, + const char *const func, + const char *const name, + const char *const text) { + logger->log("--- Assert: %s --------------------------------------------", + name); + logger->assertLog("%s:%u: '%s' in function `%s'", + file, + line, + text, + func); #ifndef ANDROID #if defined __linux__ || defined __linux - void *array[15]; - int size; - char **strings; - int i; + reportStack(); #endif // defined __linux__ || defined __linux #endif // ANDROID +} +void reportLogStack(const char *const file, + const unsigned int line, + const char *const func, + const char *const name, + const char *const text) +{ logger->log("--- Assert: %s --------------------------------------------", name); - logger->assertLog("%s:%u: '%s' in function `%s'", + logger->log("%s:%u: '%s' in function `%s'", file, line, text, func); #ifndef ANDROID #if defined __linux__ || defined __linux - size = static_cast<int>(backtrace(array, 15)); - strings = backtrace_symbols(array, size); - for (i = 0; i < size; i++) + reportStack(); +#endif // defined __linux__ || defined __linux +#endif // ANDROID +} + +void reportStack() +{ +#ifndef ANDROID +#if defined __linux__ || defined __linux + void *array[15]; + const int size = static_cast<int>(backtrace(array, 15)); + char **strings = backtrace_symbols(array, size); + for (int i = 0; i < size; i++) logger->log1(strings[i]); free(strings); #endif // defined __linux__ || defined __linux diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h index 0210747c3..c742dc91b 100644 --- a/src/utils/checkutils.h +++ b/src/utils/checkutils.h @@ -24,21 +24,21 @@ #ifdef ENABLE_ASSERTS #define reportFalseReal(val) \ - (val ? true : (reportStack(__FILE__, __LINE__, __func__, \ + (val ? true : (reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val), false)) #define reportTrueReal(val) \ - (val ? (reportStack(__FILE__, __LINE__, __func__, \ + (val ? (reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val), true) : false) #define reportAlwaysReal(val) \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", val); #define returnFalseVReal(val) \ if (!val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val); \ return; \ } @@ -46,7 +46,7 @@ #define returnTrueVReal(val) \ if (val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected true value", #val); \ return; \ } @@ -54,7 +54,7 @@ #define returnFalseReal(ret, val) \ if (!val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val); \ return ret; \ } @@ -62,7 +62,7 @@ #define returnTrueReal(ret, val) \ if (val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected true value", #val); \ return ret; \ } @@ -70,7 +70,7 @@ #define returnNullptrVReal(val) \ if ((val) == nullptr) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected null value", #val); \ return; \ } @@ -78,25 +78,25 @@ #define returnNullptrReal(ret, val) \ if ((val) == nullptr) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected null value", #val); \ return ret; \ } #define failFalse(val) \ - (val ? true : (reportStack(__FILE__, __LINE__, __func__, \ + (val ? true : (reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val), \ throw new std::exception(), false)) #define failTrue(val) \ - (val ? (reportStack(__FILE__, __LINE__, __func__, \ + (val ? (reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val), \ throw new std::exception(), true) : false) #define returnFailFalseV(val) \ if (!val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val); \ throw new std::exception(); \ } @@ -104,7 +104,7 @@ #define returnFailTrueV(val) \ if (val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected true value", #val); \ throw new std::exception(); \ } @@ -112,7 +112,7 @@ #define returnFailFalse(ret, val) \ if (!val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val); \ throw new std::exception(); \ } @@ -120,7 +120,7 @@ #define returnFailTrue(ret, val) \ if (val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected true value", #val); \ throw new std::exception(); \ } @@ -128,7 +128,7 @@ #define returnFailNullptrV(val) \ if ((val) == nullptr) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected null value", #val); \ throw new std::exception(); \ } @@ -136,23 +136,31 @@ #define returnFailNullptr(ret, val) \ if ((val) == nullptr) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected null value", #val); \ throw new std::exception(); \ } #define failAlways(val) \ { \ - reportStack(__FILE__, __LINE__, __func__, \ + reportAssertStack(__FILE__, __LINE__, __func__, \ "Detected false value", val); \ throw new std::exception(); \ } -void reportStack(const char *const file, - const unsigned int line, - const char *const func, - const char *const name, - const char *const text); +void reportAssertStack(const char *const file, + const unsigned int line, + const char *const func, + const char *const name, + const char *const text); + +void reportLogStack(const char *const file, + const unsigned int line, + const char *const func, + const char *const name, + const char *const text); + +void reportStack(); #else // ENABLE_ASSERTS |