blob: 40755ddbd73af019d5a6c368322d3901207323ab [file] [log] [blame]
henrike@webrtc.org0e118e72013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004--2005, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
henrike@webrtc.org1a04b882013-07-22 21:07:49 +000028#include <signal.h>
henrike@webrtc.org0e118e72013-07-10 00:45:36 +000029#include <stdlib.h>
30#include <stdio.h>
wu@webrtc.org2a81a382014-01-03 22:08:47 +000031#include <string.h>
henrike@webrtc.org0e118e72013-07-10 00:45:36 +000032
33#if WIN32
34#define WIN32_LEAN_AND_MEAN
35#include <windows.h>
36#endif // WIN32
37
38#if OSX
39#include <CoreServices/CoreServices.h>
40#endif // OSX
41
42#include <algorithm>
43#include "talk/base/common.h"
44#include "talk/base/logging.h"
45
46//////////////////////////////////////////////////////////////////////
47// Assertions
48//////////////////////////////////////////////////////////////////////
49
50namespace talk_base {
51
52void Break() {
53#if WIN32
54 ::DebugBreak();
henrike@webrtc.org1a04b882013-07-22 21:07:49 +000055#else // !WIN32
56 // On POSIX systems, SIGTRAP signals debuggers to break without killing the
57 // process. If a debugger isn't attached, the uncaught SIGTRAP will crash the
58 // app.
59 raise(SIGTRAP);
henrike@webrtc.org0e118e72013-07-10 00:45:36 +000060#endif
henrike@webrtc.org1a04b882013-07-22 21:07:49 +000061 // If a debugger wasn't attached, we will have crashed by this point. If a
62 // debugger is attached, we'll continue from here.
henrike@webrtc.org0e118e72013-07-10 00:45:36 +000063}
64
65static AssertLogger custom_assert_logger_ = NULL;
66
67void SetCustomAssertLogger(AssertLogger logger) {
68 custom_assert_logger_ = logger;
69}
70
71void LogAssert(const char* function, const char* file, int line,
72 const char* expression) {
73 if (custom_assert_logger_) {
74 custom_assert_logger_(function, file, line, expression);
75 } else {
76 LOG(LS_ERROR) << file << "(" << line << ")" << ": ASSERT FAILED: "
77 << expression << " @ " << function;
78 }
79}
80
81} // namespace talk_base