1 #ifndef _GLIBMM_DEBUG_H
2 #define _GLIBMM_DEBUG_H
3 
4 /* Copyright 2002 The gtkmm Development Team
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <glibmmconfig.h>
21 #include <glib.h>
22 
23 // Some stuff that's useful when debugging gtkmm internals:
24 
25 #ifdef GLIBMM_DEBUG_REFCOUNTING
26 
27 /* We can't use the equivalent GLib macro because it's always disabled in C++,
28  * even though __PRETTY_FUNCTION__ works fine in C++ as well if you use it
29  * right (i.e. concatenation with string literals isn't allowed).
30  */
31 #ifdef __GNUC__
32 #define GLIBMM_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
33 #else
34 #define GLIBMM_GNUC_PRETTY_FUNCTION ""
35 #endif
36 
37 #define GLIBMM_DEBUG_REFERENCE(cppInstance, cInstance)                             \
38   G_STMT_START                                                                     \
39   {                                                                                \
40     void* const cppInstance__ = (void*)(cppInstance);                              \
41     void* const cInstance__ = (void*)(cInstance);                                  \
42     g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                                         \
43       "file %s: line %d (%s):\n"                                                   \
44       "ref: C++ instance: %p; C instance: %p, ref_count = %u, type = %s\n",        \
45       __FILE__, __LINE__, GLIBMM_GNUC_PRETTY_FUNCTION, cppInstance__, cInstance__, \
46       G_OBJECT(cInstance__)->ref_count, G_OBJECT_TYPE_NAME(cInstance__));          \
47   }                                                                                \
48   G_STMT_END
49 
50 #define GLIBMM_DEBUG_UNREFERENCE(cppInstance, cInstance)                           \
51   G_STMT_START                                                                     \
52   {                                                                                \
53     void* const cppInstance__ = (void*)(cppInstance);                              \
54     void* const cInstance__ = (void*)(cInstance);                                  \
55     g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                                         \
56       "file %s: line %d (%s):\n"                                                   \
57       "unref: C++ instance: %p; C instance: %p, ref_count = %u, type = %s\n",      \
58       __FILE__, __LINE__, GLIBMM_GNUC_PRETTY_FUNCTION, cppInstance__, cInstance__, \
59       G_OBJECT(cInstance__)->ref_count, G_OBJECT_TYPE_NAME(cInstance__));          \
60   }                                                                                \
61   G_STMT_END
62 
63 #else
64 
65 #define GLIBMM_DEBUG_REFERENCE(cppInstance, cInstance) \
66   G_STMT_START { (void)0; }                            \
67   G_STMT_END
68 #define GLIBMM_DEBUG_UNREFERENCE(cppInstance, cInstance) \
69   G_STMT_START { (void)0; }                              \
70   G_STMT_END
71 
72 #endif /* GLIBMM_DEBUG_REFCOUNTING */
73 
74 #endif /* _GLIBMM_DEBUG_H */
75