1/*
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
28#include <signal.h>
29#include <stdlib.h>
30#include <stdio.h>
31#include <memory.h>
32
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();
55#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);
60#endif
61  // If a debugger wasn't attached, we will have crashed by this point. If a
62  // debugger is attached, we'll continue from here.
63}
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
82