-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathdebug.cpp
More file actions
87 lines (68 loc) · 1.72 KB
/
Copy pathdebug.cpp
File metadata and controls
87 lines (68 loc) · 1.72 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// LAF Base Library
// Copyright (c) 2021-2025 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "base/debug.h"
#include "base/convert_to.h"
#include "base/replace_string.h"
#include "base/string.h"
#include <cstdarg>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#if LAF_WINDOWS
#include <windows.h>
#endif
#ifdef _DEBUG
int base_assert(const char* condition, const char* file, int lineNum)
{
#if LAF_WINDOWS
std::vector<wchar_t> buf(MAX_PATH);
GetModuleFileNameW(nullptr, &buf[0], MAX_PATH);
int ret = _CrtDbgReportW(_CRT_ASSERT,
base::from_utf8(file).c_str(),
lineNum,
&buf[0],
base::from_utf8(condition).c_str());
return (ret == 1 ? 1 : 0);
#else
std::string text = file;
text += ":";
text += base::convert_to<std::string>(lineNum);
text += ": Assertion failed: ";
text += condition;
std::cerr << text << std::endl;
std::abort();
return 1;
#endif
}
#endif // _DEBUG
void base_trace(const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
char buf[4096];
vsnprintf(buf, sizeof(buf), msg, ap);
va_end(ap);
#if LAF_WINDOWS && _DEBUG
_CrtDbgReport(_CRT_WARN, nullptr, 0, nullptr, buf);
#endif
std::cerr << buf << std::flush;
}
void base_trace_raw(const char* str)
{
#if LAF_WINDOWS && _DEBUG
{
std::string output(str);
base::replace_string(output, "%", "%%");
_CrtDbgReport(_CRT_WARN, nullptr, 0, nullptr, output.c_str());
}
#endif
std::cerr << str << std::flush;
}