summaryrefslogtreecommitdiffstats
path: root/src/crimson/common/assert.cc
blob: 07610c33f891bec56f4d79f90ec1571181703bb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <cstdarg>
#include <iostream>

#include <seastar/util/backtrace.hh>
#include <seastar/core/reactor.hh>

#include "include/ceph_assert.h"

#include "crimson/common/log.h"

namespace ceph {
  [[gnu::cold]] void __ceph_assert_fail(const ceph::assert_data &ctx)
  {
    __ceph_assert_fail(ctx.assertion, ctx.file, ctx.line, ctx.function);
  }

  [[gnu::cold]] void __ceph_assert_fail(const char* assertion,
                                        const char* file, int line,
                                        const char* func)
  {
    seastar::logger& logger = crimson::get_logger(0);
    logger.error("{}:{} : In function '{}', ceph_assert(%s)\n"
                 "{}",
                 file, line, func, assertion,
                 seastar::current_backtrace());
    std::cout << std::flush;
    abort();
  }
  [[gnu::cold]] void __ceph_assertf_fail(const char *assertion,
                                         const char *file, int line,
                                         const char *func, const char* msg,
                                         ...)
  {
    char buf[8096];
    va_list args;
    va_start(args, msg);
    std::vsnprintf(buf, sizeof(buf), msg, args);
    va_end(args);

    seastar::logger& logger = crimson::get_logger(0);
    logger.error("{}:{} : In function '{}', ceph_assert(%s)\n"
                 "{}\n{}\n",
                 file, line, func, assertion,
                 buf,
                 seastar::current_backtrace());
    std::cout << std::flush;
    abort();
  }

  [[gnu::cold]] void __ceph_abort(const char* file, int line,
                                  const char* func, const std::string& msg)
  {
    seastar::logger& logger = crimson::get_logger(0);
    logger.error("{}:{} : In function '{}', abort(%s)\n"
                 "{}",
                 file, line, func, msg,
                 seastar::current_backtrace());
    std::cout << std::flush;
    abort();
  }

  [[gnu::cold]] void __ceph_abortf(const char* file, int line,
                                   const char* func, const char* fmt,
                                   ...)
  {
    char buf[8096];
    va_list args;
    va_start(args, fmt);
    std::vsnprintf(buf, sizeof(buf), fmt, args);
    va_end(args);

    seastar::logger& logger = crimson::get_logger(0);
    logger.error("{}:{} : In function '{}', abort()\n"
                 "{}\n{}\n",
                 file, line, func,
                 buf,
                 seastar::current_backtrace());
    std::cout << std::flush;
    abort();
  }
}