ManaPlus
checkutils.cpp
Go to the documentation of this file.
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 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  logger->log("--- Assert: %s --------------------------------------------",
41  name);
42  logger->assertLog("%s:%u: '%s' in function `%s'",
43  file,
44  line,
45  text,
46  func);
47 #ifdef HAVE_EXECINFO
48  reportStack();
49 #endif // HAVE_EXECINFO
50 }
51 
52 void reportLogStack(const char *const file,
53  const unsigned int line,
54  const char *const func)
55 {
56  logger->assertLog("%s:%u: in function `%s'",
57  file,
58  line,
59  func);
60 #ifdef HAVE_EXECINFO
61  reportStack();
62 #endif // HAVE_EXECINFO
63 }
64 
65 void reportStack()
66 {
67 #ifdef HAVE_EXECINFO
68  void *array[15];
69  const int size = static_cast<int>(backtrace(array, 15));
70  char **strings = backtrace_symbols(array, size);
71  for (int i = 0; i < size; i++)
72  logger->log1(strings[i]);
73  free(strings);
74 #endif // HAVE_EXECINFO
75 }
76 
77 #endif // ENABLE_ASSERTS
void log(const char *const log_text,...)
Definition: logger.cpp:269
void assertLog(const char *const log_text,...)
Definition: logger.cpp:316
void log1(const char *const log_text)
Definition: logger.cpp:238
Logger * logger
Definition: logger.cpp:89
int size()
Definition: emotedb.cpp:306