GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/checkutils.cpp Lines: 19 19 100.0 %
Date: 2018-09-20 Branches: 2 2 100.0 %

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