diff options
author | Andreas Nilsson <andreas.nilsson@mongodb.com> | 2016-07-07 09:02:09 -0400 |
---|---|---|
committer | Andreas Nilsson <andreas.nilsson@mongodb.com> | 2016-07-07 16:39:52 -0400 |
commit | 744750da3a7173def0c37025e6d21f2c358363b5 (patch) | |
tree | 5650b08801e2ad92ff197e265608c5e23e7ef041 /src/mongo/util/assert_util.cpp | |
parent | 5aa7c8a0b64bcd7e6781d335e6c786483fadee8e (diff) | |
download | mongo-744750da3a7173def0c37025e6d21f2c358363b5.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 | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp index 99b4ec6f5a0..0148969aaff 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,19 +208,29 @@ 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); } |