chromium/v8/src/base/logging.h

// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BASE_LOGGING_H_
#define V8_BASE_LOGGING_H_

#include <cstdint>
#include <cstring>
#include <iterator>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#include "src/base/abort-mode.h"
#include "src/base/base-export.h"
#include "src/base/build_config.h"
#include "src/base/compiler-specific.h"
#include "src/base/immediate-crash.h"
#include "src/base/template-utils.h"

V8_BASE_EXPORT V8_NOINLINE void V8_Dcheck(const char* file, int line,
                                          const char* message);

#ifdef DEBUG
// In debug, include file, line, and full error message for all
// FATAL() calls.
[[noreturn]] PRINTF_FORMAT(3, 4) V8_BASE_EXPORT V8_NOINLINE
    void V8_Fatal(const char* file, int line, const char* format, ...);
#define FATAL(...)

// The following can be used instead of FATAL() to prevent calling
// IMMEDIATE_CRASH in official mode. Please only use if needed for testing.
// See v8:13945
#define GRACEFUL_FATAL(...)

#else
[[noreturn]] PRINTF_FORMAT(1, 2) V8_BASE_EXPORT V8_NOINLINE
    void V8_Fatal(const char* format, ...);
#define GRACEFUL_FATAL

#if !defined(OFFICIAL_BUILD)
// In non-official release, include full error message, but drop file & line
// numbers. It saves binary size to drop the |file| & |line| as opposed to just
// passing in "", 0 for them.
#define FATAL
#else
// FATAL(msg) -> IMMEDIATE_CRASH()
// FATAL(msg, ...) -> V8_Fatal(msg, ...)
#define FATAL_HELPER
#define FATAL_DISCARD_ARG
#define FATAL
#endif  // !defined(OFFICIAL_BUILD)
#endif  // DEBUG

namespace v8::base {
// These string constants are pattern-matched by fuzzers.
constexpr const char* kUnimplementedCodeMessage =;
constexpr const char* kUnreachableCodeMessage =;
}  // namespace v8::base

#define UNIMPLEMENTED()
#define UNREACHABLE()
// g++ versions <= 8 cannot use UNREACHABLE() in a constexpr function.
// TODO(miladfarca): Remove once all compilers handle this properly.
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ <= 8)
#define CONSTEXPR_UNREACHABLE
#else
#define CONSTEXPR_UNREACHABLE()
#endif

namespace v8 {
base  // namespace base
}  // namespace v8


// The DCHECK macro is equivalent to CHECK except that it only
// generates code in debug builds.
#ifdef DEBUG
#define DCHECK_EQ(lhs, rhs)
#define DCHECK_NE(lhs, rhs)
#define DCHECK_GT(lhs, rhs)
#define DCHECK_GE(lhs, rhs)
#define DCHECK_LT(lhs, rhs)
#define DCHECK_LE(lhs, rhs)
#define DCHECK_NULL(val)
#define DCHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(lhs, rhs)
#define DCHECK_BOUNDS(index, limit)
#else
#define DCHECK
#define DCHECK_WITH_LOC
#define DCHECK_WITH_MSG_AND_LOC
#define DCHECK_EQ
#define DCHECK_NE
#define DCHECK_GT
#define DCHECK_GE
#define DCHECK_LT
#define DCHECK_LE
#define DCHECK_NULL
#define DCHECK_NOT_NULL
#define DCHECK_IMPLIES
#define DCHECK_BOUNDS
#endif

#endif  // V8_BASE_LOGGING_H_