diff options
author | Andreas Nilsson <andreas.nilsson@mongodb.com> | 2016-07-08 16:13:15 -0400 |
---|---|---|
committer | Andreas Nilsson <andreas.nilsson@mongodb.com> | 2016-07-11 13:16:34 -0400 |
commit | c73a719b1c43e0b6b9c26e4e686ad5b1f940c67b (patch) | |
tree | 5bab18c0d07ae5bddd8acc9e0a733b0a7854bce0 /src/mongo/util/assert_util.cpp | |
parent | 4d9e3e4cb09805dfb5e181536a8830f4f878275c (diff) | |
download | mongo-c73a719b1c43e0b6b9c26e4e686ad5b1f940c67b.tar.gz |
SERVER-24523 Include file and line numbers in assertions
Diffstat (limited to 'src/mongo/util/assert_util.cpp')
-rw-r--r-- | src/mongo/util/assert_util.cpp | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp index 99b4ec6f5a0..c6ef9c7273c 100644 --- a/src/mongo/util/assert_util.cpp +++ b/src/mongo/util/assert_util.cpp @@ -165,39 +165,42 @@ NOINLINE_DECL void invariantOKFailed(const char* expr, std::abort(); } -NOINLINE_DECL void fassertFailed(int msgid) noexcept { - log() << "Fatal Assertion " << msgid << endl; +NOINLINE_DECL void fassertFailedWithLocation(int msgid, const char* file, unsigned line) noexcept { + log() << "Fatal Assertion " << msgid << " at " << file << " " << dec << line; breakpoint(); log() << "\n\n***aborting after fassert() failure\n\n" << endl; std::abort(); } -NOINLINE_DECL void fassertFailedNoTrace(int msgid) noexcept { - log() << "Fatal Assertion " << msgid << endl; +NOINLINE_DECL void fassertFailedNoTraceWithLocation(int msgid, + const char* file, + unsigned line) noexcept { + log() << "Fatal Assertion " << msgid << " at " << file << " " << dec << line; breakpoint(); log() << "\n\n***aborting after fassert() failure\n\n" << endl; quickExit(EXIT_ABRUPT); } -MONGO_COMPILER_NORETURN void fassertFailedWithStatus(int msgid, const Status& status) noexcept { - log() << "Fatal assertion " << msgid << " " << status; +MONGO_COMPILER_NORETURN void fassertFailedWithStatusWithLocation(int msgid, + const Status& status, + const char* file, + unsigned line) noexcept { + log() << "Fatal assertion " << msgid << " " << status << " at " << file << " " << dec << line; breakpoint(); log() << "\n\n***aborting after fassert() failure\n\n" << endl; std::abort(); } -MONGO_COMPILER_NORETURN void fassertFailedWithStatusNoTrace(int msgid, - const Status& status) noexcept { - log() << "Fatal assertion " << msgid << " " << status; +MONGO_COMPILER_NORETURN void fassertFailedWithStatusNoTraceWithLocation(int msgid, + const Status& status, + const char* file, + unsigned line) noexcept { + log() << "Fatal assertion " << msgid << " " << status << " at " << file << " " << dec << line; breakpoint(); log() << "\n\n***aborting after fassert() failure\n\n" << endl; quickExit(EXIT_ABRUPT); } -void uasserted(int msgid, const string& msg) { - uasserted(msgid, msg.c_str()); -} - void UserException::appendPrefix(stringstream& ss) const { ss << "userassert:"; } @@ -205,35 +208,54 @@ void MsgAssertionException::appendPrefix(stringstream& ss) const { ss << "massert:"; } -NOINLINE_DECL void uasserted(int msgid, const char* msg) { +void uassertedWithLocation(int msgid, const string& msg, const char* file, unsigned line) { + uassertedWithLocation(msgid, msg.c_str(), file, line); +} + +NOINLINE_DECL void uassertedWithLocation(int msgid, + const char* msg, + const char* file, + unsigned line) { assertionCount.condrollover(++assertionCount.user); - LOG(1) << "User Assertion: " << msgid << ":" << msg << endl; + log() << "User Assertion: " << msgid << ":" << msg << ' ' << file << ' ' << dec << line << endl; throw UserException(msgid, msg); } -void msgasserted(int msgid, const string& msg) { - msgasserted(msgid, msg.c_str()); +void msgassertedWithLocation(int msgid, const string& msg, const char* file, unsigned line) { + msgassertedWithLocation(msgid, msg.c_str(), file, line); } -NOINLINE_DECL void msgasserted(int msgid, const char* msg) { +NOINLINE_DECL void msgassertedWithLocation(int msgid, + const char* msg, + const char* file, + unsigned line) { assertionCount.condrollover(++assertionCount.warning); - log() << "Assertion: " << msgid << ":" << msg << endl; + log() << "Assertion: " << msgid << ":" << msg << ' ' << file << ' ' << dec << line << endl; logContext(); throw MsgAssertionException(msgid, msg); } -NOINLINE_DECL void msgassertedNoTrace(int msgid, const char* msg) { +NOINLINE_DECL void msgassertedNoTraceWithLocation(int msgid, + const char* msg, + const char* file, + unsigned line) { assertionCount.condrollover(++assertionCount.warning); - log() << "Assertion: " << msgid << ":" << msg << endl; + log() << "Assertion: " << msgid << ":" << msg << ' ' << file << ' ' << dec << line << endl; throw MsgAssertionException(msgid, msg); } -void msgassertedNoTrace(int msgid, const std::string& msg) { - msgassertedNoTrace(msgid, msg.c_str()); +void msgassertedNoTraceWithLocation(int msgid, + const std::string& msg, + const char* file, + unsigned line) { + msgassertedNoTraceWithLocation(msgid, msg.c_str(), file, line); } -void msgassertedNoTraceWithStatus(int msgid, const Status& status) { - msgassertedNoTrace(msgid, status.toString()); +void msgassertedNoTraceWithStatusWithLocation(int msgid, + const Status& status, + const char* file, + unsigned line) { + msgassertedNoTraceWithLocation(msgid, status.toString(), file, line); } std::string causedBy(const char* e) { |