-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.hpp
More file actions
61 lines (50 loc) · 1.82 KB
/
Copy pathassert.hpp
File metadata and controls
61 lines (50 loc) · 1.82 KB
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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025-Present Datadog, Inc.
#pragma once
#include <cstdio>
#include <cstdlib>
#if defined(__unix__) || defined(__APPLE__)
#include <execinfo.h>
#endif
// Asserts within the Datadog SDK implementation are disabled by default: they're
// intended primarily for internal development and therefore must be explicitly enabled
// by setting DD_ENABLE_ASSERTS=ON as a CMake build option
#ifndef WITH_DATADOG_ASSERTS
#define WITH_DATADOG_ASSERTS 0
#endif
#if WITH_DATADOG_ASSERTS
namespace datadog::impl {
inline void print_stack_trace() {
#if defined(__unix__) || defined(__APPLE__)
// This POSIX API inevitably requires C-style array-as-pointer semantics
// NOLINTBEGIN(cppcoreguidelines-*)
// NOLINTBEGIN(bugprone-multi-level-implicit-pointer-conversion)
void* array[16];
size_t size = backtrace(array, 16);
char** strings = backtrace_symbols(array, static_cast<int>(size));
std::fprintf(stderr, "Stack trace:\n");
for (size_t i = 0; i < size; i++) {
std::fprintf(stderr, " [%zu] %s\n", i, strings[i]);
}
free(strings);
// NOLINTEND(bugprone-multi-level-implicit-pointer-conversion)
// NOLINTEND(cppcoreguidelines-*)
#endif
}
} // namespace datadog::impl
// clang-format off
#define DATADOG_ASSERT(Cond, Msg) \
do { /* NOLINT(cppcoreguidelines-avoid-do-while) */ \
if (!(Cond)) { \
std::fprintf(stderr, "Assertion failed: %s (%s:%d)\n", (Msg), __FILE__, __LINE__); /* NOLINT(cppcoreguidelines-pro-type-vararg) */ \
datadog::impl::print_stack_trace(); \
std::abort(); \
} \
} while (0)
// clang-format on
#else
#define DATADOG_ASSERT(Cond, Msg) ((void)(Cond), (void)(Msg))
#endif