The Pedigree Project 0.1
assert.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/machine/Machine.h"
22#include "pedigree/kernel/machine/Serial.h"
23#include "pedigree/kernel/panic.h"
24#include "pedigree/kernel/processor/Processor.h"
25#include "pedigree/kernel/utilities/StaticString.h"
26
27extern "C" void _assert(bool b, const char* file, int line, const char* func) {
28 if (b)
29 return;
30
32 // Ordinary log sinks may be disabled, and debugger entry may itself fail.
33 if (Machine::instance().getNumSerial()) {
34 Serial* serial = Machine::instance().getSerial(0);
35 if (serial) {
36 TinyStaticString location;
37 location.append(line, 10);
38 serial->write_str("\nASSERT: ");
39 serial->write_str(file);
40 serial->write_str(":");
41 serial->write_str(location);
42 serial->write_str(" in ");
43 serial->write_str(func);
44 serial->write_str("\n");
45 }
46 }
47 ERROR_NOLOCK("Assertion failed in file " << file);
48 ERROR_NOLOCK("In function '" << func << "'");
49 ERROR_NOLOCK("On line " << Dec << line << Hex << ".");
51
52 ERROR_NOLOCK("You may not resume after a failed assertion.");
53 }
54
55 // Best reason for a return is that the debugger isn't active. Either way,
56 // it's an error condition, panic.
57 panic("assertion failed");
58}
virtual Serial * getSerial(size_t n)=0
static void breakpoint()
static size_t m_Initialised
Definition Processor.h:483
void _assert(bool b, const char *file, int line, const char *func)
Definition assert.cc:27
void EXPORTED_PUBLIC panic(const char *msg) NORETURN
Definition panic.cc:118
@ Dec
Definition Log.h:126
@ Hex
Definition Log.h:124