summaryrefslogtreecommitdiff
path: root/glib/glibmm/debug.h
blob: 0ece7f55a1640c8599771850b9047a598b8350ba (plain)
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
// -*- c++ -*-
#ifndef _GLIBMM_DEBUG_H
#define _GLIBMM_DEBUG_H

/* $Id$ */

/* Copyright 2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <glib/gmacros.h>
#include <glibmmconfig.h>

// Some stuff that's useful when debugging gtkmm internals:

#ifdef GTKMM_DEBUG_REFCOUNTING

#include <glib/gmessages.h>

/* We can't use G_GNUC_PRETTY_FUNCTION because it's always disabled in C++,
 * even though __PRETTY_FUNCTION__ works fine in C++ as well if you use it
 * right (i.e. concatenation with string literals isn't allowed).
 */
#ifdef __GNUC__
#define GTKMM_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
#else
#define GTKMM_GNUC_PRETTY_FUNCTION ""
#endif

#define GTKMM_DEBUG_REFERENCE(cppInstance, cInstance)                               \
    G_STMT_START{                                                                   \
      void *const cppInstance__ = (void*) (cppInstance);                            \
      void *const cInstance__   = (void*) (cInstance);                              \
      g_log(G_LOG_DOMAIN,                                                           \
            G_LOG_LEVEL_DEBUG,                                                      \
            "file %s: line %d (%s):\n"                                              \
            "ref: C++ instance: %p; C instance: %p, ref_count = %u, type = %s\n",   \
            __FILE__,                                                               \
            __LINE__,                                                               \
            GTKMM_GNUC_PRETTY_FUNCTION,                                             \
            cppInstance__,                                                          \
            cInstance__,                                                            \
            G_OBJECT(cInstance__)->ref_count,                                       \
            G_OBJECT_TYPE_NAME(cInstance__));                                       \
    }G_STMT_END

#define GTKMM_DEBUG_UNREFERENCE(cppInstance, cInstance)                             \
    G_STMT_START{                                                                   \
      void *const cppInstance__ = (void*) (cppInstance);                            \
      void *const cInstance__   = (void*) (cInstance);                              \
      g_log(G_LOG_DOMAIN,                                                           \
            G_LOG_LEVEL_DEBUG,                                                      \
            "file %s: line %d (%s):\n"                                              \
            "unref: C++ instance: %p; C instance: %p, ref_count = %u, type = %s\n", \
            __FILE__,                                                               \
            __LINE__,                                                               \
            GTKMM_GNUC_PRETTY_FUNCTION,                                             \
            cppInstance__,                                                          \
            cInstance__,                                                            \
            G_OBJECT(cInstance__)->ref_count,                                       \
            G_OBJECT_TYPE_NAME(cInstance__));                                       \
    }G_STMT_END

#else

#define GTKMM_DEBUG_REFERENCE(cppInstance,cInstance)    G_STMT_START{ (void)0; }G_STMT_END
#define GTKMM_DEBUG_UNREFERENCE(cppInstance,cInstance)  G_STMT_START{ (void)0; }G_STMT_END

#endif /* GTKMM_DEBUG_REFCOUNTING */

#endif /* _GLIBMM_DEBUG_H */