• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <signal.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 
16 #if WEBRTC_WIN
17 #define WIN32_LEAN_AND_MEAN
18 #include <windows.h>
19 #endif  // WEBRTC_WIN
20 
21 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
22 #include <CoreServices/CoreServices.h>
23 #endif  // WEBRTC_MAC && !defined(WEBRTC_IOS)
24 
25 #include <algorithm>
26 #include "webrtc/base/common.h"
27 #include "webrtc/base/logging.h"
28 
29 //////////////////////////////////////////////////////////////////////
30 // Assertions
31 //////////////////////////////////////////////////////////////////////
32 
33 namespace rtc {
34 
Break()35 void Break() {
36 #if WEBRTC_WIN
37   ::DebugBreak();
38 #else  // !WEBRTC_WIN
39   // On POSIX systems, SIGTRAP signals debuggers to break without killing the
40   // process. If a debugger isn't attached, the uncaught SIGTRAP will crash the
41   // app.
42   raise(SIGTRAP);
43 #endif
44   // If a debugger wasn't attached, we will have crashed by this point. If a
45   // debugger is attached, we'll continue from here.
46 }
47 
48 static AssertLogger custom_assert_logger_ = NULL;
49 
SetCustomAssertLogger(AssertLogger logger)50 void SetCustomAssertLogger(AssertLogger logger) {
51   custom_assert_logger_ = logger;
52 }
53 
LogAssert(const char * function,const char * file,int line,const char * expression)54 void LogAssert(const char* function, const char* file, int line,
55                const char* expression) {
56   if (custom_assert_logger_) {
57     custom_assert_logger_(function, file, line, expression);
58   } else {
59     LOG(LS_ERROR) << file << "(" << line << ")" << ": ASSERT FAILED: "
60                   << expression << " @ " << function;
61   }
62 }
63 
64 } // namespace rtc
65