From e9cefdef68eb42caf6f249ae5d99dfd0f5ebdaa0 Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" Date: Wed, 9 Jul 2014 08:04:12 +0000 Subject: [PATCH] Improve libjingle's ASSERT and VERIFY macros on Windows. This change has the effect that when using a debugger, a failing ASSERT/VERIFY will break exactly where the failing expression is and not two callstacks up. Minidumps (for debug builds) will also have the failing expression at the top of the call stack. R=xians@webrtc.org, xians Review URL: https://webrtc-codereview.appspot.com/12929004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6633 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/base/common.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/talk/base/common.h b/talk/base/common.h index ed7d59ed6..be0e89dec 100644 --- a/talk/base/common.h +++ b/talk/base/common.h @@ -131,9 +131,17 @@ inline bool Assert(bool result, const char* function, const char* file, if (!result) { LogAssert(function, file, line, expression); Break(); - return false; } - return true; + return result; +} + +// Same as Assert above, but does not call Break(). Used in assert macros +// that implement their own breaking. +inline bool AssertNoBreak(bool result, const char* function, const char* file, + int line, const char* expression) { + if (!result) + LogAssert(function, file, line, expression); + return result; } } // namespace talk_base @@ -143,13 +151,28 @@ inline bool Assert(bool result, const char* function, const char* file, #endif #ifndef ASSERT +#if defined(WIN32) +// Using debugbreak() inline on Windows directly in the ASSERT macro, has the +// benefit of breaking exactly where the failing expression is and not two +// calls up the stack. +#define ASSERT(x) \ + (talk_base::AssertNoBreak((x), __FUNCTION__, __FILE__, __LINE__, #x) ? \ + (void)(1) : __debugbreak()) +#else #define ASSERT(x) \ (void)talk_base::Assert((x), __FUNCTION__, __FILE__, __LINE__, #x) #endif +#endif #ifndef VERIFY +#if defined(WIN32) +#define VERIFY(x) \ + (talk_base::AssertNoBreak((x), __FUNCTION__, __FILE__, __LINE__, #x) ? \ + true : (__debugbreak(), false)) +#else #define VERIFY(x) talk_base::Assert((x), __FUNCTION__, __FILE__, __LINE__, #x) #endif +#endif #else // !ENABLE_DEBUG