1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2012-2019 The ManaPlus Developers |
4 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
5 |
|
|
* |
6 |
|
|
* This file is part of The ManaPlus Client. |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#ifdef ENABLE_ASSERTS |
23 |
|
|
|
24 |
|
|
#include "utils/checkutils.h" |
25 |
|
|
|
26 |
|
|
#include "logger.h" |
27 |
|
|
|
28 |
|
|
#ifdef HAVE_EXECINFO |
29 |
|
|
#include <execinfo.h> |
30 |
|
|
#endif // HAVE_EXECINFO |
31 |
|
|
|
32 |
|
|
#include "debug.h" |
33 |
|
|
|
34 |
|
12 |
void reportAssertStack(const char *const file, |
35 |
|
|
const unsigned int line, |
36 |
|
|
const char *const func, |
37 |
|
|
const char *const name, |
38 |
|
|
const char *const text) |
39 |
|
|
{ |
40 |
|
12 |
logger->log("--- Assert: %s --------------------------------------------", |
41 |
|
12 |
name); |
42 |
|
12 |
logger->assertLog("%s:%u: '%s' in function `%s'", |
43 |
|
|
file, |
44 |
|
|
line, |
45 |
|
|
text, |
46 |
|
12 |
func); |
47 |
|
|
#ifdef HAVE_EXECINFO |
48 |
|
12 |
reportStack(); |
49 |
|
|
#endif // HAVE_EXECINFO |
50 |
|
12 |
} |
51 |
|
|
|
52 |
|
28 |
void reportLogStack(const char *const file, |
53 |
|
|
const unsigned int line, |
54 |
|
|
const char *const func) |
55 |
|
|
{ |
56 |
|
28 |
logger->assertLog("%s:%u: in function `%s'", |
57 |
|
|
file, |
58 |
|
|
line, |
59 |
|
28 |
func); |
60 |
|
|
#ifdef HAVE_EXECINFO |
61 |
|
28 |
reportStack(); |
62 |
|
|
#endif // HAVE_EXECINFO |
63 |
|
28 |
} |
64 |
|
|
|
65 |
|
40 |
void reportStack() |
66 |
|
|
{ |
67 |
|
|
#ifdef HAVE_EXECINFO |
68 |
|
|
void *array[15]; |
69 |
|
40 |
const int size = static_cast<int>(backtrace(array, 15)); |
70 |
|
40 |
char **strings = backtrace_symbols(array, size); |
71 |
✓✓ |
385 |
for (int i = 0; i < size; i++) |
72 |
|
345 |
logger->log1(strings[i]); |
73 |
|
40 |
free(strings); |
74 |
|
|
#endif // HAVE_EXECINFO |
75 |
|
40 |
} |
76 |
|
|
|
77 |
|
|
#endif // ENABLE_ASSERTS |