GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/checkutils.cpp Lines: 16 16 100.0 %
Date: 2017-11-29 Branches: 2 2 100.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  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
24
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
24
    logger->log("--- Assert: %s --------------------------------------------",
40
        name);
41
24
    logger->assertLog("%s:%u: '%s' in function `%s'",
42
        file,
43
        line,
44
        text,
45
        func);
46
#ifdef HAVE_EXECINFO
47
24
    reportStack();
48
#endif  // HAVE_EXECINFO
49
24
}
50
51
56
void reportLogStack(const char *const file,
52
                    const unsigned int line,
53
                    const char *const func)
54
{
55
56
    logger->assertLog("%s:%u: in function `%s'",
56
        file,
57
        line,
58
        func);
59
#ifdef HAVE_EXECINFO
60
56
    reportStack();
61
#endif  // HAVE_EXECINFO
62
56
}
63
64
80
void reportStack()
65
{
66
#ifdef HAVE_EXECINFO
67
    void *array[15];
68
80
    const int size = static_cast<int>(backtrace(array, 15));
69
80
    char **strings = backtrace_symbols(array, size);
70
690
    for (int i = 0; i < size; i++)
71
610
        logger->log1(strings[i]);
72
80
    free(strings);
73
#endif  // HAVE_EXECINFO
74
80
}
75
76
#endif  // ENABLE_ASSERTS