1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is globalmenu-extension.
17
* The Initial Developer of the Original Code is
19
* Portions created by the Initial Developer are Copyright (C) 2010
20
* the Initial Developer. All Rights Reserved.
23
* Chris Coulson <chris.coulson@canonical.com>
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the MPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the MPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
42
#include <nsStringAPI.h>
45
#if defined DEBUG_chrisccoulson && !defined DEBUG
47
#undef NS_WARN_IF_FALSE
50
#define NS_ASSERTION(expr, str) \
53
NS_DebugBreak(NS_DEBUG_ASSERTION, str, #expr, __FILE__, __LINE__); \
57
#define NS_WARN_IF_FALSE(_expr,_msg) \
60
NS_DebugBreak(NS_DEBUG_WARNING, _msg, #_expr, __FILE__, __LINE__); \
64
#define NS_WARNING(str) \
65
NS_DebugBreak(NS_DEBUG_WARNING, str, nsnull, __FILE__, __LINE__)
69
#define DEBUG_chrisccoulson
72
#ifdef DEBUG_chrisccoulson
76
FunctionTracer(const char *funcName, const char *extra): mFuncName(funcName), mExtra(extra)
78
if (getenv("GLOBAL_MENU_VERBOSE")) {
79
printf("%*s=== globalmenu-extension: Entering %s [%s] ===\n", sDepth, "", mFuncName.get(), mExtra.get());
84
FunctionTracer(const char *funcName): mFuncName(funcName)
86
if (getenv("GLOBAL_MENU_VERBOSE")) {
87
printf("%*s=== globalmenu-extension: Entering %s ===\n", sDepth, "", mFuncName.get());
95
if (getenv("GLOBAL_MENU_VERBOSE")) {
96
if (mExtra.Length() > 0) {
97
printf("%*s=== globalmenu-extension: Leaving %s [%s] ===\n", sDepth, "", mFuncName.get(), mExtra.get());
99
printf("%*s=== globalmenu-extension: Leaving %s ===\n", sDepth, "", mFuncName.get());
104
static PRUint32 sDepth;
110
#define DEBUG_WITH_THIS_MENUOBJECT(format...) \
111
DEBUG_WITH_MENUOBJECT(this, format)
113
#define DEBUG_WITH_MENUOBJECT(object, format...) \
114
if (getenv("GLOBAL_MENU_VERBOSE")) { \
115
nsCOMPtr<nsIContent> content; \
116
if (object) object->GetContent(getter_AddRefs(content)); \
119
if (content) content->GetAttr(kNameSpaceID_None, uWidgetAtoms::id, id); \
120
CopyUTF16toUTF8(id, cid); \
122
asprintf(&str, format); \
123
printf("%*s* globalmenu-extension %s: %s [menuobject: %p (id: %s)] [this: %p]\n", FunctionTracer::sDepth, "", __PRETTY_FUNCTION__, str, object, cid.get(), this); \
127
#define DEBUG_WITH_CONTENT(content, format...) \
128
if (getenv("GLOBAL_MENU_VERBOSE")) { \
131
if (content) content->GetAttr(kNameSpaceID_None, uWidgetAtoms::id, id); \
132
CopyUTF16toUTF8(id, cid); \
134
asprintf(&str, format); \
135
printf("%*s* globalmenu-extension %s: %s [content: %p (id: %s)] [this: %p]\n", FunctionTracer::sDepth, "", __PRETTY_FUNCTION__, str, content, cid.get(), this); \
139
#define DEBUG_CSTR_FROM_UTF16(str) __extension__({ \
140
nsCAutoString cstr; \
141
CopyUTF16toUTF8(str, cstr); \
145
#define TRACE_WITH_THIS_MENUOBJECT() \
146
TRACE_WITH_MENUOBJECT(this)
148
#define TRACE_WITH_MENUOBJECT(object) \
151
nsCOMPtr<nsIContent> content; \
152
if (object) object->GetContent(getter_AddRefs(content)); \
154
if (content) content->GetAttr(kNameSpaceID_None, uWidgetAtoms::id, _id); \
155
nsCAutoString _cid; \
156
CopyUTF16toUTF8(_id, _cid); \
157
asprintf(&_id_s, "menuobject: %p (id: %s)", object, _cid.get()); \
159
FunctionTracer _marker(__PRETTY_FUNCTION__, _id_s); \
162
#define TRACE_WITH_CONTENT(content) \
166
content->GetAttr(kNameSpaceID_None, uWidgetAtoms::id, _id); \
167
nsCAutoString _cid; \
168
CopyUTF16toUTF8(_id, _cid); \
169
asprintf(&_id_s, "id: %s", _cid.get()); \
171
FunctionTracer _marker(__PRETTY_FUNCTION__, _id_s); \
175
FunctionTracer _marker(__PRETTY_FUNCTION__);
177
#define DEBUG_WITH_THIS_MENUOBJECT(format...)
178
#define DEBUG_WITH_MENUOBJECT(object, format...)
179
#define DEBUG_WITH_CONTENT(content, format...)
180
#define DEBUG_CSTR_FROM_UTF16(str)
181
#define TRACE_WITH_THIS_MENUOBJECT()
182
#define TRACE_WITH_MENUOBJECT(object)
183
#define TRACE_WITH_CONTENT(content)