8000 TRI_ASSERT Log Stream by maierlars · Pull Request #14676 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

TRI_ASSERT Log Stream #14676

New issue

Have a questio 8000 n about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion arangod/Replication2/ReplicatedLog/LogLeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ auto replicated_log::LogLeader::GuardedLeaderData::updateCommitIndexLeader(
<< "updating commit index to " << newIndex << "with quorum " << quorum->quorum;
auto oldIndex = _commitIndex;

TRI_ASSERT(_commitIndex < newIndex);
TRI_ASSERT(_commitIndex < newIndex)
<< "_commitIndex == " << _commitIndex << ", newIndex == " << newIndex;
_commitIndex = newIndex;
_lastQuorum = quorum;

Expand Down
6 changes: 5 additions & 1 deletion lib/Basics/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ void CrashHandler::crash(char const* context) {
}

/// @brief logs an assertion failure and crashes the program
void CrashHandler::assertionFailure(char const* file, int line, char const* func, char const* context) {
void CrashHandler::assertionFailure(char const* file, int line, char const* func, char const* context, const char *message) {
// assemble an "assertion failured in file:line: message" string
char buffer[4096];
memset(&buffer[0], 0, sizeof(buffer));
Expand All @@ -601,6 +601,10 @@ void CrashHandler::assertionFailure(char const* file, int line, char const* func
}
appendNullTerminatedString(": ", p);
appendNullTerminatedString(context, 256, p);
if (message != nullptr) {
appendNullTerminatedString(" ; ", p);
appendNullTerminatedString(message, p);
}

crash(&buffer[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Basics/CrashHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CrashHandler {
[[noreturn]] static void crash(char const* context);

/// @brief logs an assertion failure and crashes the program
[[noreturn]] static void assertionFailure(char const* file, int line, char const* func, char const* context);
[[noreturn]] static void assertionFailure(char const* file, int line, char const* func, char const* context, const char* message);

/// @brief set flag to kill process hard using SIGKILL, in order to circumvent core
/// file generation etc.
Expand Down
58 changes: 44 additions & 14 deletions lib/Basics/debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <stdlib.h>
#include <ostream>
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -199,31 +200,60 @@ enable_if_t<is_container<T>::value, std::ostream&> operator<<(std::ostream& o, T
return o;
}

namespace debug {
struct NoOpStream {
template <typename T>
auto operator<<(T const&) noexcept -> NoOpStream& {
return *this;
}
};

struct AssertionLogger {
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
void operator&(std::ostringstream const& stream) const {
std::string message = stream.str();
arangodb::CrashHandler::assertionFailure(file, line, function, expr,
message.empty() ? nullptr : message.c_str());
}
// can be removed in C++20 because of LWG 1203
void operator&(std::ostream const& stream) const {
operator&(static_cast<std::ostringstream const&>(stream));
}

const char* file;
int line;
const char* function;
const char* expr;
#endif
void operator&(NoOpStream const&) const noexcept {}
static auto getOutputStream() -> std::ostringstream&& {
static thread_local std::ostringstream stream;
return std::move(stream);
}
};

} // namespace debug

} // namespace arangodb

/// @brief assert
#ifndef TRI_ASSERT

#ifdef ARANGODB_ENABLE_MAINTAINER_MODE

#define TRI_ASSERT(expr) /*GCOVR_EXCL_LINE*/ \
do { \
if (!(ADB_LIKELY(expr))) { \
arangodb::CrashHandler::assertionFailure(__FILE__, __LINE__, __FUNCTION__, #expr); \
} else { \
} \
} while (false)
#define TRI_ASSERT(expr) /*GCOVR_EXCL_LINE*/ \
(ADB_LIKELY(expr)) \
? (void)nullptr \
: ::arangodb::debug::AssertionLogger{__FILE__, __LINE__, \
ARANGODB_PRETTY_FUNCTION, #expr} & \
::arangodb::debug::AssertionLogger::getOutputStream()

#else

#define TRI_ASSERT(expr) /*GCOVR_EXCL_LINE*/ \
do { \
if (false) { \
(void)(expr); \
} \
} while (false)
#define TRI_ASSERT(expr) /*GCOVR_EXCL_LINE*/ \
(true) ? ((false) ? (void)(expr) : (void)nullptr) \
: ::arangodb::debug::AssertionLogger{} & ::arangodb::debug::NoOpStream {}

#endif // #ifdef ARANGODB_ENABLE_MAINTAINER_MODE

#endif // #ifndef TRI_ASSERT

8 changes: 8 additions & 0 deletions lib/Basics/system-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@
#endif
#endif

// pretty function name macro
#if defined(__clang__) || defined(__GNUC__)
#define ARANGODB_PRETTY_FUNCTION __PRETTY_FUNCTION__
#elif defined(_MSC_VER)
#define ARANGODB_PRETTY_FUNCTION __FUNCSIG__
#else
#define ARANGODB_PRETTY_FUNCTION __func__
#endif
0