diff options
author | Sven Gothel <[email protected]> | 2020-09-20 21:21:10 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-09-20 21:21:10 +0200 |
commit | 31253c2e7b9026f6647e3c85ae4ef1a80c96b243 (patch) | |
tree | 69f431c64247cf91f7013a126068ff652e9e87d6 | |
parent | 215429f50008ae83825c7d17d136724a1c73943c (diff) |
Handle abort() via dbt_debug's new ABORT(..), ensure a message is being send and process aborted; Use it.
-rw-r--r-- | api/direct_bt/LFRingbuffer.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/dbt_debug.hpp | 6 | ||||
-rw-r--r-- | java/jni/JNIMem.cxx | 3 | ||||
-rw-r--r-- | src/direct_bt/BasicTypes.cpp | 12 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 12 | ||||
-rw-r--r-- | src/direct_bt/UUID.cpp | 12 | ||||
-rw-r--r-- | src/direct_bt/dbt_debug.cpp | 11 |
7 files changed, 31 insertions, 29 deletions
diff --git a/api/direct_bt/LFRingbuffer.hpp b/api/direct_bt/LFRingbuffer.hpp index e2af5d4d..01ac3c00 100644 --- a/api/direct_bt/LFRingbuffer.hpp +++ b/api/direct_bt/LFRingbuffer.hpp @@ -135,9 +135,7 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb } if( writePos != localReadPos ) { // Avoid exception, abort! - ERR_PRINT("Internal Error: copy segment error: this %s, readPos %d/%d; writePos %d", - toString().c_str(), readPos.load(), localReadPos, writePos.load()); - abort(); + ABORT("copy segment error: this %s, readPos %d/%d; writePos %d", toString().c_str(), readPos.load(), localReadPos, writePos.load()); } readPos = localReadPos; size = 0; diff --git a/api/direct_bt/dbt_debug.hpp b/api/direct_bt/dbt_debug.hpp index 34b5d9e4..107a28e6 100644 --- a/api/direct_bt/dbt_debug.hpp +++ b/api/direct_bt/dbt_debug.hpp @@ -64,6 +64,12 @@ namespace direct_bt { #define PERF_TS_TD(m) #endif + /** Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ file:line: '. Function also appends last errno and strerror(errno). */ + void ABORT_impl(const char *file, const int line, const char * format, ...) noexcept; + + /** Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ FILE:LINE: '. Function also appends last errno and strerror(errno). */ + #define ABORT(...) { direct_bt::ABORT_impl(__FILE__, __LINE__, __VA_ARGS__); } + /** Use for unconditional error messages, prefix '[elapsed_time] Error @ file:line: '. Function also appends last errno and strerror(errno). */ void ERR_PRINTv(const char *file, const int line, const char * format, va_list args) noexcept; diff --git a/java/jni/JNIMem.cxx b/java/jni/JNIMem.cxx index 5ca11baa..19a63bdb 100644 --- a/java/jni/JNIMem.cxx +++ b/java/jni/JNIMem.cxx @@ -148,8 +148,7 @@ JNIGlobalRef::~JNIGlobalRef() noexcept { try { JNIEnv * env = *jni_env; if( nullptr == env ) { - ERR_PRINT("JNIGlobalRef dtor null JNIEnv"); - abort(); + ABORT("JNIGlobalRef dtor null JNIEnv"); } DBG_PRINT("JNIGlobalRef::dtor %p", object); if( nullptr != object ) { diff --git a/src/direct_bt/BasicTypes.cpp b/src/direct_bt/BasicTypes.cpp index 759e9055..fa3b5782 100644 --- a/src/direct_bt/BasicTypes.cpp +++ b/src/direct_bt/BasicTypes.cpp @@ -165,8 +165,7 @@ std::string direct_bt::uint8HexString(const uint8_t v, const bool leading0X) noe const int count = snprintf(&str[0], str.capacity(), ( leading0X ? "0x%.2X" : "%.2X" ), v); if( length != count ) { - ERR_PRINT("Internal-Error: uint8_t string not of length %d but %d", length, count); - abort(); + ABORT("uint8_t string not of length %d but %d", length, count); } return str; } @@ -179,8 +178,7 @@ std::string direct_bt::uint16HexString(const uint16_t v, const bool leading0X) n const int count = snprintf(&str[0], str.capacity(), ( leading0X ? "0x%.4X" : "%.4X" ), v); if( length != count ) { - ERR_PRINT("Internal-Error: uint16_t string not of length %d but %d", length, count); - abort(); + ABORT("uint16_t string not of length %d but %d", length, count); } return str; } @@ -193,8 +191,7 @@ std::string direct_bt::uint32HexString(const uint32_t v, const bool leading0X) n const int count = snprintf(&str[0], str.capacity(), ( leading0X ? "0x%.8X" : "%.8X" ), v); if( length != count ) { - ERR_PRINT("Internal-Error: uint32_t string not of length %d but %d", length, count); - abort(); + ABORT("uint32_t string not of length %d but %d", length, count); } return str; } @@ -207,8 +204,7 @@ std::string direct_bt::uint64HexString(const uint64_t v, const bool leading0X) n const int count = snprintf(&str[0], str.capacity(), ( leading0X ? "0x%.16" PRIX64 : "%.16" PRIX64 ), v); if( length != count ) { - ERR_PRINT("Internal-Error: uint64_t string not of length %d but %d", length, count); - abort(); + ABORT("uint64_t string not of length %d but %d", length, count); } return str; } diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index 544efd25..685bfdae 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -237,8 +237,7 @@ std::shared_ptr<AdapterInfo> DBTManager::initAdapter(const uint16_t dev_id, cons const MgmtEvtAdapterInfo * res1 = static_cast<MgmtEvtAdapterInfo*>(res.get()); adapterInfo = res1->toAdapterInfo(); if( dev_id != adapterInfo->dev_id ) { - ERR_PRINT("Internal-Error: AdapterInfo dev_id=%d != dev_id=%d: %s", adapterInfo->dev_id, dev_id, adapterInfo->toString().c_str()); - abort(); + ABORT("AdapterInfo dev_id=%d != dev_id=%d: %s", adapterInfo->dev_id, dev_id, adapterInfo->toString().c_str()); } } DBG_PRINT("initAdapter[%d]: Start: %s", dev_id, adapterInfo->toString().c_str()); @@ -282,8 +281,7 @@ std::shared_ptr<AdapterInfo> DBTManager::initAdapter(const uint16_t dev_id, cons const MgmtEvtAdapterInfo * res1 = static_cast<MgmtEvtAdapterInfo*>(res.get()); adapterInfo = res1->toAdapterInfo(); if( dev_id != adapterInfo->dev_id ) { - ERR_PRINT("Internal-Error: AdapterInfo dev_id=%d != dev_id=%d: %s", adapterInfo->dev_id, dev_id, adapterInfo->toString().c_str()); - abort(); + ABORT("AdapterInfo dev_id=%d != dev_id=%d: %s", adapterInfo->dev_id, dev_id, adapterInfo->toString().c_str()); } } DBG_PRINT("initAdapter[%d]: End: %s", dev_id, adapterInfo->toString().c_str()); @@ -405,12 +403,10 @@ next1: for(int i=0; ok && i < num_adapter; i++) { const uint16_t dev_id = get_uint16(data, 2+i*2, true /* littleEndian */); if( dev_id >= num_adapter ) { - ERR_PRINT("Internal-Error: dev_id %d >= num_adapter %d", dev_id, num_adapter); - abort(); + ABORT("dev_id %d >= num_adapter %d", dev_id, num_adapter); } if( adapterInfos[dev_id] != nullptr ) { - ERR_PRINT("Internal-Error: adapters[dev_id=%d] != nullptr: %s", dev_id, adapterInfos[dev_id]->toString().c_str()); - abort(); + ABORT("adapters[dev_id=%d] != nullptr: %s", dev_id, adapterInfos[dev_id]->toString().c_str()); } std::shared_ptr<AdapterInfo> adapterInfo = initAdapter(dev_id, defaultBTMode); adapterInfos[dev_id] = adapterInfo; diff --git a/src/direct_bt/UUID.cpp b/src/direct_bt/UUID.cpp index 07641fcc..596871c8 100644 --- a/src/direct_bt/UUID.cpp +++ b/src/direct_bt/UUID.cpp @@ -60,8 +60,7 @@ uuid128_t uuid_t::toUUID128(uuid128_t const & base_uuid, int const uuid32_le_oct case TypeSize::UUID32_SZ: return uuid128_t(*((uuid32_t*)this), base_uuid, uuid32_le_octet_index); case TypeSize::UUID128_SZ: return uuid128_t(*((uuid128_t*)this)); } - ERR_PRINT("Unknown Type %d", static_cast<int>(type)); - abort(); + ABORT("Unknown Type %d", static_cast<int>(type)); } std::string uuid_t::toUUID128String(uuid128_t const & base_uuid, int const le_octet_index) const noexcept { @@ -84,8 +83,7 @@ std::string uuid16_t::toString() const noexcept { const int count = snprintf(&str[0], str.capacity(), "%.4x", value); if( length != count ) { - ERR_PRINT("UUID16 string not of length %d but %d", length, count); - abort(); + ABORT("UUID16 string not of length %d but %d", length, count); } return str; } @@ -104,8 +102,7 @@ std::string uuid32_t::toString() const noexcept { const int count = snprintf(&str[0], str.capacity(), "%.8x", value); if( length != count ) { - ERR_PRINT("UUID32 string not of length %d but %d", length, count); - abort(); + ABORT("UUID32 string not of length %d but %d", length, count); } return str; } @@ -154,8 +151,7 @@ std::string uuid128_t::toString() const noexcept { const int count = snprintf(&str[0], str.capacity(), "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", part0, part1, part2, part3, part4, part5); if( length != count ) { - ERR_PRINT("UUID128 string not of length %d but %d", length, count); - abort(); + ABORT("UUID128 string not of length %d but %d", length, count); } return str; } diff --git a/src/direct_bt/dbt_debug.cpp b/src/direct_bt/dbt_debug.cpp index fbffcc02..753aebb2 100644 --- a/src/direct_bt/dbt_debug.cpp +++ b/src/direct_bt/dbt_debug.cpp @@ -53,6 +53,17 @@ void direct_bt::WORDY_PRINT(const char * format, ...) noexcept { } } +void direct_bt::ABORT_impl(const char *file, const int line, const char * format, ...) noexcept { + fprintf(stderr, "[%'9" PRIu64 "] ABORT @ %s:%d: ", DBTEnv::getElapsedMillisecond(), file, line); + va_list args; + va_start (args, format); + vfprintf(stderr, format, args); + va_end (args); + fprintf(stderr, "; last errno %d %s\n", errno, strerror(errno)); + fflush(stderr); + abort(); +} + void direct_bt::ERR_PRINTv(const char *file, const int line, const char * format, va_list args) noexcept { fprintf(stderr, "[%'9" PRIu64 "] Error @ %s:%d: ", DBTEnv::getElapsedMillisecond(), file, line); vfprintf(stderr, format, args); |