summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-02-12 17:20:07 (UTC)
committer mickeyl <mickeyl>2005-02-12 17:20:07 (UTC)
commit5ad68456ddf0b1dc722f92d7f6c94b82677c637c (patch) (unidiff)
tree1f86710721e9ca624d3a2f59593b4f7be3ddbec6
parent292ce81455773c463a8d7ed9c1aef2d08b90514d (diff)
downloadopie-5ad68456ddf0b1dc722f92d7f6c94b82677c637c.zip
opie-5ad68456ddf0b1dc722f92d7f6c94b82677c637c.tar.gz
opie-5ad68456ddf0b1dc722f92d7f6c94b82677c637c.tar.bz2
disable backtracing if building against uclibc
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp
index d8dfe26..45709dc 100644
--- a/libopie2/opiecore/odebug.cpp
+++ b/libopie2/opiecore/odebug.cpp
@@ -1,645 +1,649 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) 3 (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de)
4 (C) 2002 Holger Freyther (freyther@kde.org) 4 (C) 2002 Holger Freyther (freyther@kde.org)
5 (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) 5 (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
6 =. 6 =.
7 .=l. 7 .=l.
8           .>+-= 8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can 9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under 10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software 12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License, 13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version. 14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_. 15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that 16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of 18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more 21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details. 22++=   -.     .`     .: details.
23 :     =  ...= . :.=- 23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU 24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with 25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB. 26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30*/ 30*/
31 31
32// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo 32// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo
33// functions inlined to noops (which would then conflict with their definition here). 33// functions inlined to noops (which would then conflict with their definition here).
34 34
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36 36
37#if defined(__UCLIBC__)
38#define OPIE_NO_BACKTRACE
39#endif
40
37#ifdef OPIE_NO_DEBUG 41#ifdef OPIE_NO_DEBUG
38#undef odDebug 42#undef odDebug
39#undef odBacktrace 43#undef odBacktrace
40#endif 44#endif
41 45
42/* OPIE */ 46/* OPIE */
43 47
44#include <opie2/oapplication.h> 48#include <opie2/oapplication.h>
45#include <opie2/oglobalsettings.h> 49#include <opie2/oglobalsettings.h>
46#include <opie2/oconfig.h> 50#include <opie2/oconfig.h>
47 51
48/* QT */ 52/* QT */
49 53
50#include <qfile.h> 54#include <qfile.h>
51#include <qmessagebox.h> 55#include <qmessagebox.h>
52#include <qsocketdevice.h> 56#include <qsocketdevice.h>
53 57
54/* UNIX */ 58/* UNIX */
55 59
56#include <stdlib.h> // abort 60#include <stdlib.h> // abort
57#include <unistd.h> // getpid 61#include <unistd.h> // getpid
58#include <stdarg.h> // vararg stuff 62#include <stdarg.h> // vararg stuff
59#include <ctype.h> // isprint 63#include <ctype.h> // isprint
60#include <syslog.h> 64#include <syslog.h>
61#include <errno.h> 65#include <errno.h>
62#include <string.h> 66#include <string.h>
63 67
64#ifndef OPIE_NO_BACKTRACE 68#ifndef OPIE_NO_BACKTRACE
65#include <execinfo.h> 69#include <execinfo.h>
66#endif 70#endif
67 71
68namespace Opie { 72namespace Opie {
69namespace Core { 73namespace Core {
70namespace Internal { 74namespace Internal {
71/*====================================================================================== 75/*======================================================================================
72 * debug levels 76 * debug levels
73 *======================================================================================*/ 77 *======================================================================================*/
74 78
75enum DebugLevels { 79enum DebugLevels {
76 ODEBUG_INFO = 0, 80 ODEBUG_INFO = 0,
77 ODEBUG_WARN = 1, 81 ODEBUG_WARN = 1,
78 ODEBUG_ERROR = 2, 82 ODEBUG_ERROR = 2,
79 ODEBUG_FATAL = 3 83 ODEBUG_FATAL = 3
80}; 84};
81 85
82/*====================================================================================== 86/*======================================================================================
83 * oDebug private data 87 * oDebug private data
84 *======================================================================================*/ 88 *======================================================================================*/
85 89
86/*====================================================================================== 90/*======================================================================================
87 * the main debug function 91 * the main debug function
88 *======================================================================================*/ 92 *======================================================================================*/
89 93
90 94
91 95
92struct DebugBackend { 96struct DebugBackend {
93 DebugBackend() : m_opened( false ), m_file( 0 ) ,m_port( -1 ),m_sock( 0 ) { 97 DebugBackend() : m_opened( false ), m_file( 0 ) ,m_port( -1 ),m_sock( 0 ) {
94 m_outp = OGlobalSettings::debugMode(); 98 m_outp = OGlobalSettings::debugMode();
95 } 99 }
96 ~DebugBackend() { 100 ~DebugBackend() {
97 delete m_file; 101 delete m_file;
98 delete m_sock; 102 delete m_sock;
99 } 103 }
100 void debug( unsigned short level, unsigned int, const QString& data ); 104 void debug( unsigned short level, unsigned int, const QString& data );
101 105
102private: 106private:
103 void debugFile( const QString&, const QString& data ); 107 void debugFile( const QString&, const QString& data );
104 void debugMsgB( const QString&, const QString& data ); 108 void debugMsgB( const QString&, const QString& data );
105 void debugShel( const QString&, const QString& data ); 109 void debugShel( const QString&, const QString& data );
106 void debugSysl( int, const QString& ); 110 void debugSysl( int, const QString& );
107 void debugSock( const QString&, const QString& data ); 111 void debugSock( const QString&, const QString& data );
108 QCString line( const QString&, const QString& data ); 112 QCString line( const QString&, const QString& data );
109 bool m_opened : 1; 113 bool m_opened : 1;
110 QFile *m_file; 114 QFile *m_file;
111 QHostAddress m_addr; 115 QHostAddress m_addr;
112 int m_port; 116 int m_port;
113 QSocketDevice *m_sock; 117 QSocketDevice *m_sock;
114 short m_outp; 118 short m_outp;
115}; 119};
116 120
117void DebugBackend::debug(unsigned short level, unsigned int, const QString& data) { 121void DebugBackend::debug(unsigned short level, unsigned int, const QString& data) {
118 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); 122 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data );
119 123
120 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an 124 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an
121 // ML: example use. I think it's not necessary to implement such a strategy here. 125 // ML: example use. I think it's not necessary to implement such a strategy here.
122 // ML: Comments? 126 // ML: Comments?
123 127
124 int priority = 0; 128 int priority = 0;
125 QString caption; 129 QString caption;
126 QString lev; 130 QString lev;
127 switch( level ) 131 switch( level )
128 { 132 {
129 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; 133 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break;
130 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; 134 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break;
131 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; 135 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break;
132 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); 136 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." );
133 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; 137 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break;
134 } 138 }
135 139
136 if (!oApp && (m_outp == 1)) { 140 if (!oApp && (m_outp == 1)) {
137 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); 141 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" );
138 m_outp = 2; // need an application object to use MsgBox 142 m_outp = 2; // need an application object to use MsgBox
139 } 143 }
140 144
141 // gcc 2.9x is dumb and sucks... can you hear it? 145 // gcc 2.9x is dumb and sucks... can you hear it?
142 //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; 146 //QString areaName = (oApp) ? oApp->appName() : "<unknown>";
143 QString areaName; 147 QString areaName;
144 if ( oApp ) areaName = oApp->appName(); 148 if ( oApp ) areaName = oApp->appName();
145 else areaName = "<unknown>"; 149 else areaName = "<unknown>";
146 150
147 switch( m_outp ) { 151 switch( m_outp ) {
148 case ODEBUG_IGNORE: 152 case ODEBUG_IGNORE:
149 return; 153 return;
150 case ODEBUG_FILE: 154 case ODEBUG_FILE:
151 return debugFile( areaName, data ); 155 return debugFile( areaName, data );
152 case ODEBUG_MSGBOX: 156 case ODEBUG_MSGBOX:
153 return debugMsgB( areaName, data ); 157 return debugMsgB( areaName, data );
154 case ODEBUG_STDERR: 158 case ODEBUG_STDERR:
155 return debugShel( areaName,data ); 159 return debugShel( areaName,data );
156 case ODEBUG_SYSLOG: 160 case ODEBUG_SYSLOG:
157 return debugSysl( priority, data ); 161 return debugSysl( priority, data );
158 case ODEBUG_SOCKET: 162 case ODEBUG_SOCKET:
159 return debugSock( areaName, data ); 163 return debugSock( areaName, data );
160 } 164 }
161} 165}
162 166
163inline void DebugBackend::debugFile(const QString& area, const QString& data) { 167inline void DebugBackend::debugFile(const QString& area, const QString& data) {
164 /* something went wrong with the file don't bother.. */ 168 /* something went wrong with the file don't bother.. */
165 if ( m_opened && !m_file ) 169 if ( m_opened && !m_file )
166 return; 170 return;
167 else if ( !m_opened ) { 171 else if ( !m_opened ) {
168 m_opened = true; 172 m_opened = true;
169 m_file = new QFile( OGlobalSettings::debugOutput() ); 173 m_file = new QFile( OGlobalSettings::debugOutput() );
170 if (!m_file->open( IO_WriteOnly | IO_Append ) ) { 174 if (!m_file->open( IO_WriteOnly | IO_Append ) ) {
171 delete m_file; m_file = 0; 175 delete m_file; m_file = 0;
172 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*)OGlobalSettings::debugOutput(), 176 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*)OGlobalSettings::debugOutput(),
173 strerror(errno) ); 177 strerror(errno) );
174 return; 178 return;
175 } 179 }
176 } 180 }
177 181
178 /* go to end of file */ 182 /* go to end of file */
179 m_file->at( m_file->size() ); 183 m_file->at( m_file->size() );
180 QCString li = line( area, data ); 184 QCString li = line( area, data );
181 m_file->writeBlock(li.data(), li.length() ); 185 m_file->writeBlock(li.data(), li.length() );
182} 186}
183 187
184void DebugBackend::debugMsgB( const QString& area, const QString& data ) { 188void DebugBackend::debugMsgB( const QString& area, const QString& data ) {
185 QMessageBox::warning( 0l, "("+area+")", data, ("Ok") ); 189 QMessageBox::warning( 0l, "("+area+")", data, ("Ok") );
186} 190}
187 191
188void DebugBackend::debugShel( const QString& are, const QString& data ) { 192void DebugBackend::debugShel( const QString& are, const QString& data ) {
189 FILE *output = stderr; 193 FILE *output = stderr;
190 fprintf( output, "%s: %s", are.local8Bit().data(), 194 fprintf( output, "%s: %s", are.local8Bit().data(),
191 data.local8Bit().data() ); 195 data.local8Bit().data() );
192} 196}
193 197
194void DebugBackend::debugSysl( int prio, const QString& data ) { 198void DebugBackend::debugSysl( int prio, const QString& data ) {
195 ::syslog( prio, "%s", data.local8Bit().data() ); 199 ::syslog( prio, "%s", data.local8Bit().data() );
196} 200}
197 201
198void DebugBackend::debugSock( const QString& are, const QString& data ) { 202void DebugBackend::debugSock( const QString& are, const QString& data ) {
199 if ( m_opened && !m_sock ) 203 if ( m_opened && !m_sock )
200 return; 204 return;
201 else if ( !m_opened ){ 205 else if ( !m_opened ){
202 m_opened = true; 206 m_opened = true;
203 QString destination = OGlobalSettings::debugOutput(); 207 QString destination = OGlobalSettings::debugOutput();
204 if ( destination && destination.find(":") != -1 ) { 208 if ( destination && destination.find(":") != -1 ) {
205 QString host = destination.left( destination.find(":") ); 209 QString host = destination.left( destination.find(":") );
206 m_port = destination.right( destination.length()-host.length()-1 ).toInt(); 210 m_port = destination.right( destination.length()-host.length()-1 ).toInt();
207 m_addr.setAddress( host ); 211 m_addr.setAddress( host );
208 m_sock = new QSocketDevice( QSocketDevice::Datagram ); 212 m_sock = new QSocketDevice( QSocketDevice::Datagram );
209 }else{ 213 }else{
210 m_sock = 0; 214 m_sock = 0;
211 return; 215 return;
212 } 216 }
213 } 217 }
214 218
215 QCString li = line( are, data ); 219 QCString li = line( are, data );
216 int result = m_sock->writeBlock(li.data(), li.length(), m_addr, m_port ); 220 int result = m_sock->writeBlock(li.data(), li.length(), m_addr, m_port );
217 if ( result == -1 ) { 221 if ( result == -1 ) {
218 qDebug( "ODebug: can't send to address '"+ m_addr.toString() +":%d' (%s)", 222 qDebug( "ODebug: can't send to address '"+ m_addr.toString() +":%d' (%s)",
219 m_port, strerror(errno) ); 223 m_port, strerror(errno) );
220 } 224 }
221} 225}
222 226
223QCString DebugBackend::line( const QString& area, const QString& data ) { 227QCString DebugBackend::line( const QString& area, const QString& data ) {
224 QString str = area +":"+data; 228 QString str = area +":"+data;
225 return str.local8Bit(); 229 return str.local8Bit();
226} 230}
227 231
228static DebugBackend *backEnd = 0; 232static DebugBackend *backEnd = 0;
229} 233}
230static void clean_up_routine() { 234static void clean_up_routine() {
231 qWarning( "Clean up Debug" ); 235 qWarning( "Clean up Debug" );
232 delete Internal::backEnd; 236 delete Internal::backEnd;
233 Internal::backEnd = 0; 237 Internal::backEnd = 0;
234} 238}
235/*====================================================================================== 239/*======================================================================================
236 * odbgstream 240 * odbgstream
237 *======================================================================================*/ 241 *======================================================================================*/
238 242
239odbgstream& perror( odbgstream &s) 243odbgstream& perror( odbgstream &s)
240{ 244{
241 return s << QString::fromLocal8Bit(strerror(errno)); 245 return s << QString::fromLocal8Bit(strerror(errno));
242} 246}
243 247
244odbgstream odDebug(int area) 248odbgstream odDebug(int area)
245{ 249{
246 return odbgstream(area, Internal::ODEBUG_INFO); 250 return odbgstream(area, Internal::ODEBUG_INFO);
247} 251}
248odbgstream odDebug(bool cond, int area) 252odbgstream odDebug(bool cond, int area)
249{ 253{
250 if (cond) return odbgstream(area, Internal::ODEBUG_INFO); 254 if (cond) return odbgstream(area, Internal::ODEBUG_INFO);
251 else return odbgstream(0, 0, false); 255 else return odbgstream(0, 0, false);
252} 256}
253 257
254odbgstream odError(int area) 258odbgstream odError(int area)
255{ 259{
256 return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR); 260 return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR);
257} 261}
258 262
259odbgstream odError(bool cond, int area) 263odbgstream odError(bool cond, int area)
260{ 264{
261 if (cond) return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR); else return odbgstream(0,0,false); 265 if (cond) return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR); else return odbgstream(0,0,false);
262} 266}
263 267
264odbgstream odWarning(int area) 268odbgstream odWarning(int area)
265{ 269{
266 return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN); 270 return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN);
267} 271}
268 272
269odbgstream odWarning(bool cond, int area) 273odbgstream odWarning(bool cond, int area)
270{ 274{
271 if (cond) return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN); else return odbgstream(0,0,false); 275 if (cond) return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN); else return odbgstream(0,0,false);
272} 276}
273 277
274odbgstream odFatal(int area) 278odbgstream odFatal(int area)
275{ 279{
276 return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL); 280 return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL);
277} 281}
278 282
279odbgstream odFatal(bool cond, int area) 283odbgstream odFatal(bool cond, int area)
280{ 284{
281 if (cond) return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL); else return odbgstream(0,0,false); 285 if (cond) return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL); else return odbgstream(0,0,false);
282} 286}
283 287
284odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) 288odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print)
285 :area(_area), level(_level), print(_print) 289 :area(_area), level(_level), print(_print)
286{ 290{
287} 291}
288 292
289 293
290odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print) 294odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print)
291 :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) 295 :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print)
292{ 296{
293} 297}
294 298
295 299
296odbgstream::odbgstream(odbgstream &str) 300odbgstream::odbgstream(odbgstream &str)
297 :output(str.output), area(str.area), level(str.level), print(str.print) 301 :output(str.output), area(str.area), level(str.level), print(str.print)
298{ 302{
299 str.output.truncate(0); 303 str.output.truncate(0);
300} 304}
301 305
302 306
303odbgstream::odbgstream(const odbgstream &str) 307odbgstream::odbgstream(const odbgstream &str)
304 :output(str.output), area(str.area), level(str.level), print(str.print) 308 :output(str.output), area(str.area), level(str.level), print(str.print)
305{ 309{
306} 310}
307 311
308odbgstream& odbgstream::operator<<(bool i) 312odbgstream& odbgstream::operator<<(bool i)
309{ 313{
310 if (!print) return *this; 314 if (!print) return *this;
311 output += QString::fromLatin1(i ? "true" : "false"); 315 output += QString::fromLatin1(i ? "true" : "false");
312 return *this; 316 return *this;
313} 317}
314 318
315 319
316odbgstream& odbgstream::operator<<(short i) 320odbgstream& odbgstream::operator<<(short i)
317{ 321{
318 if (!print) return *this; 322 if (!print) return *this;
319 QString tmp; tmp.setNum(i); output += tmp; 323 QString tmp; tmp.setNum(i); output += tmp;
320 return *this; 324 return *this;
321} 325}
322 326
323 327
324odbgstream& odbgstream::operator<<(unsigned short i) 328odbgstream& odbgstream::operator<<(unsigned short i)
325{ 329{
326 if (!print) return *this; 330 if (!print) return *this;
327 QString tmp; tmp.setNum(i); output += tmp; 331 QString tmp; tmp.setNum(i); output += tmp;
328 return *this; 332 return *this;
329} 333}
330 334
331 335
332odbgstream& odbgstream::operator<<(unsigned char i) 336odbgstream& odbgstream::operator<<(unsigned char i)
333{ 337{
334 return operator<<( static_cast<char>( i ) ); 338 return operator<<( static_cast<char>( i ) );
335} 339}
336 340
337 341
338odbgstream& odbgstream::operator<<(int i) 342odbgstream& odbgstream::operator<<(int i)
339{ 343{
340 if (!print) return *this; 344 if (!print) return *this;
341 QString tmp; tmp.setNum(i); output += tmp; 345 QString tmp; tmp.setNum(i); output += tmp;
342 return *this; 346 return *this;
343} 347}
344 348
345 349
346odbgstream& odbgstream::operator<<(unsigned int i) 350odbgstream& odbgstream::operator<<(unsigned int i)
347{ 351{
348 if (!print) return *this; 352 if (!print) return *this;
349 QString tmp; tmp.setNum(i); output += tmp; 353 QString tmp; tmp.setNum(i); output += tmp;
350 return *this; 354 return *this;
351} 355}
352 356
353 357
354odbgstream& odbgstream::operator<<(long i) 358odbgstream& odbgstream::operator<<(long i)
355{ 359{
356 if (!print) return *this; 360 if (!print) return *this;
357 QString tmp; tmp.setNum(i); output += tmp; 361 QString tmp; tmp.setNum(i); output += tmp;
358 return *this; 362 return *this;
359} 363}
360 364
361 365
362odbgstream& odbgstream::operator<<(unsigned long i) 366odbgstream& odbgstream::operator<<(unsigned long i)
363{ 367{
364 if (!print) return *this; 368 if (!print) return *this;
365 QString tmp; tmp.setNum(i); output += tmp; 369 QString tmp; tmp.setNum(i); output += tmp;
366 return *this; 370 return *this;
367} 371}
368 372
369 373
370odbgstream& odbgstream::operator<<(const QString& string) 374odbgstream& odbgstream::operator<<(const QString& string)
371{ 375{
372 if (!print) return *this; 376 if (!print) return *this;
373 output += string; 377 output += string;
374 if (output.at(output.length() -1 ) == '\n') 378 if (output.at(output.length() -1 ) == '\n')
375 flush(); 379 flush();
376 return *this; 380 return *this;
377} 381}
378 382
379 383
380odbgstream& odbgstream::operator<<(const char *string) 384odbgstream& odbgstream::operator<<(const char *string)
381{ 385{
382 if (!print) return *this; 386 if (!print) return *this;
383 output += QString::fromUtf8(string); 387 output += QString::fromUtf8(string);
384 if (output.at(output.length() - 1) == '\n') 388 if (output.at(output.length() - 1) == '\n')
385 flush(); 389 flush();
386 return *this; 390 return *this;
387} 391}
388 392
389 393
390odbgstream& odbgstream::operator<<(const QCString& string) 394odbgstream& odbgstream::operator<<(const QCString& string)
391{ 395{
392 *this << string.data(); 396 *this << string.data();
393 return *this; 397 return *this;
394} 398}
395 399
396 400
397odbgstream& odbgstream::operator<<(const void * p) 401odbgstream& odbgstream::operator<<(const void * p)
398{ 402{
399 form("%p", p); 403 form("%p", p);
400 return *this; 404 return *this;
401} 405}
402 406
403odbgstream& odbgstream::operator<<(double d) 407odbgstream& odbgstream::operator<<(double d)
404{ 408{
405 QString tmp; tmp.setNum(d); output += tmp; 409 QString tmp; tmp.setNum(d); output += tmp;
406 return *this; 410 return *this;
407} 411}
408 412
409/* 413/*
410odbgstream::odbgstream &form(const char *format, ...) 414odbgstream::odbgstream &form(const char *format, ...)
411#ifdef __GNUC__ 415#ifdef __GNUC__
412 __attribute__ ( ( format ( printf, 2, 3 ) ) ) 416 __attribute__ ( ( format ( printf, 2, 3 ) ) )
413#endif 417#endif
414 ; 418 ;
415*/ 419*/
416 420
417void odbgstream::flush() 421void odbgstream::flush()
418{ 422{
419 if ( output.isEmpty() || !print ) 423 if ( output.isEmpty() || !print )
420 { 424 {
421 return; 425 return;
422 } 426 }
423 else 427 else
424 { 428 {
425 if ( !Internal::backEnd ) { 429 if ( !Internal::backEnd ) {
426 Internal::backEnd = new Internal::DebugBackend; 430 Internal::backEnd = new Internal::DebugBackend;
427 qAddPostRoutine( clean_up_routine ); 431 qAddPostRoutine( clean_up_routine );
428 } 432 }
429 Internal::backEnd->debug( level, area, output ); 433 Internal::backEnd->debug( level, area, output );
430 output = QString::null; 434 output = QString::null;
431 } 435 }
432} 436}
433 437
434odbgstream& odbgstream::form(const char *format, ...) 438odbgstream& odbgstream::form(const char *format, ...)
435{ 439{
436 char buf[4096]; 440 char buf[4096];
437 va_list arguments; 441 va_list arguments;
438 va_start( arguments, format ); 442 va_start( arguments, format );
439 buf[sizeof(buf)-1] = '\0'; 443 buf[sizeof(buf)-1] = '\0';
440 vsnprintf( buf, sizeof(buf)-1, format, arguments ); 444 vsnprintf( buf, sizeof(buf)-1, format, arguments );
441 va_end(arguments); 445 va_end(arguments);
442 *this << buf; 446 *this << buf;
443 return *this; 447 return *this;
444} 448}
445 449
446odbgstream::~odbgstream() 450odbgstream::~odbgstream()
447{ 451{
448 if (!output.isEmpty()) 452 if (!output.isEmpty())
449 { 453 {
450 fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); 454 fprintf(stderr, "ASSERT: debug output not ended with \\n\n");
451 *this << "\n"; 455 *this << "\n";
452 } 456 }
453} 457}
454 458
455odbgstream& odbgstream::operator<<(char ch) 459odbgstream& odbgstream::operator<<(char ch)
456{ 460{
457 if (!print) return *this; 461 if (!print) return *this;
458 if (!isprint(ch)) 462 if (!isprint(ch))
459 { 463 {
460 output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); 464 output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2);
461 } 465 }
462 else 466 else
463 { 467 {
464 output += ch; 468 output += ch;
465 if (ch == '\n') flush(); 469 if (ch == '\n') flush();
466 } 470 }
467 return *this; 471 return *this;
468} 472}
469 473
470odbgstream& odbgstream::operator<<( QWidget* widget ) 474odbgstream& odbgstream::operator<<( QWidget* widget )
471{ 475{
472 QString string, temp; 476 QString string, temp;
473 // ----- 477 // -----
474 if(widget==0) 478 if(widget==0)
475 { 479 {
476 string=(QString)"[Null pointer]"; 480 string=(QString)"[Null pointer]";
477 } else 481 } else
478 { 482 {
479 temp.setNum((ulong)widget, 16); 483 temp.setNum((ulong)widget, 16);
480 string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; 484 string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")";
481 if(widget->name(0)==0) 485 if(widget->name(0)==0)
482 { 486 {
483 string += " to unnamed widget, "; 487 string += " to unnamed widget, ";
484 } else 488 } else
485 { 489 {
486 string += (QString)" to widget " + widget->name() + ", "; 490 string += (QString)" to widget " + widget->name() + ", ";
487 } 491 }
488 string += "geometry=" 492 string += "geometry="
489 + QString().setNum(widget->width()) 493 + QString().setNum(widget->width())
490 + "x"+QString().setNum(widget->height()) 494 + "x"+QString().setNum(widget->height())
491 + "+"+QString().setNum(widget->x()) 495 + "+"+QString().setNum(widget->x())
492 + "+"+QString().setNum(widget->y()) 496 + "+"+QString().setNum(widget->y())
493 + "]"; 497 + "]";
494 } 498 }
495 if (!print) return *this; 499 if (!print) return *this;
496 500
497 output += string; 501 output += string;
498 if (output.at(output.length()-1) == '\n') 502 if (output.at(output.length()-1) == '\n')
499 { 503 {
500 flush(); 504 flush();
501 } 505 }
502 return *this; 506 return *this;
503} 507}
504 508
505/* 509/*
506 * either use 'output' directly and do the flush if needed 510 * either use 'output' directly and do the flush if needed
507 * or use the QString operator which calls the char* operator 511 * or use the QString operator which calls the char* operator
508 * 512 *
509 */ 513 */
510odbgstream& odbgstream::operator<<( const QDateTime& time) 514odbgstream& odbgstream::operator<<( const QDateTime& time)
511{ 515{
512 *this << time.toString(); 516 *this << time.toString();
513 return *this; 517 return *this;
514} 518}
515 519
516 520
517odbgstream& odbgstream::operator<<( const QDate& date) 521odbgstream& odbgstream::operator<<( const QDate& date)
518{ 522{
519 *this << date.toString(); 523 *this << date.toString();
520 524
521 return *this; 525 return *this;
522} 526}
523 527
524 528
525odbgstream& odbgstream::operator<<( const QTime& time ) 529odbgstream& odbgstream::operator<<( const QTime& time )
526{ 530{
527 *this << time.toString(); 531 *this << time.toString();
528 return *this; 532 return *this;
529} 533}
530 534
531 535
532odbgstream& odbgstream::operator<<( const QPoint& p ) 536odbgstream& odbgstream::operator<<( const QPoint& p )
533{ 537{
534 *this << "(" << p.x() << ", " << p.y() << ")"; 538 *this << "(" << p.x() << ", " << p.y() << ")";
535 return *this; 539 return *this;
536} 540}
537 541
538 542
539odbgstream& odbgstream::operator<<( const QSize& s ) 543odbgstream& odbgstream::operator<<( const QSize& s )
540{ 544{
541 *this << "[" << s.width() << "x" << s.height() << "]"; 545 *this << "[" << s.width() << "x" << s.height() << "]";
542 return *this; 546 return *this;
543} 547}
544 548
545 549
546odbgstream& odbgstream::operator<<( const QRect& r ) 550odbgstream& odbgstream::operator<<( const QRect& r )
547{ 551{
548 *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]"; 552 *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]";
549 return *this; 553 return *this;
550} 554}
551 555
552 556
553odbgstream& odbgstream::operator<<( const QRegion& reg ) 557odbgstream& odbgstream::operator<<( const QRegion& reg )
554{ 558{
555 *this << "[ "; 559 *this << "[ ";
556 QArray<QRect>rs=reg.rects(); 560 QArray<QRect>rs=reg.rects();
557 for (uint i=0;i<rs.size();++i) 561 for (uint i=0;i<rs.size();++i)
558 *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; 562 *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ;
559 *this <<"]"; 563 *this <<"]";
560 return *this; 564 return *this;
561} 565}
562 566
563 567
564odbgstream& odbgstream::operator<<( const QStringList& l ) 568odbgstream& odbgstream::operator<<( const QStringList& l )
565{ 569{
566 *this << "("; 570 *this << "(";
567 *this << l.join(","); 571 *this << l.join(",");
568 *this << ")"; 572 *this << ")";
569 573
570 return *this; 574 return *this;
571} 575}
572 576
573 577
574odbgstream& odbgstream::operator<<( const QColor& c ) 578odbgstream& odbgstream::operator<<( const QColor& c )
575{ 579{
576 if ( c.isValid() ) 580 if ( c.isValid() )
577 *this << c.name(); 581 *this << c.name();
578 else 582 else
579 *this << "(invalid/default)"; 583 *this << "(invalid/default)";
580 return *this; 584 return *this;
581} 585}
582 586
583 587
584odbgstream& odbgstream::operator<<( const QBrush& b) 588odbgstream& odbgstream::operator<<( const QBrush& b)
585{ 589{
586 static const char* const s_brushStyles[] = { 590 static const char* const s_brushStyles[] = {
587 "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern", 591 "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern",
588 "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern", 592 "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern",
589 "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern", 593 "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern",
590 "DiagCrossPattern" }; 594 "DiagCrossPattern" };
591 595
592 *this <<"[ style: "; 596 *this <<"[ style: ";
593 *this <<s_brushStyles[ b.style() ]; 597 *this <<s_brushStyles[ b.style() ];
594 *this <<" color: "; 598 *this <<" color: ";
595 // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes) 599 // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes)
596 if ( b.color().isValid() ) 600 if ( b.color().isValid() )
597 *this <<b.color().name() ; 601 *this <<b.color().name() ;
598 else 602 else
599 *this <<"(invalid/default)"; 603 *this <<"(invalid/default)";
600 if ( b.pixmap() ) 604 if ( b.pixmap() )
601 *this <<" has a pixmap"; 605 *this <<" has a pixmap";
602 *this <<" ]"; 606 *this <<" ]";
603 return *this; 607 return *this;
604} 608}
605 609
606 610
607 611
608QString odBacktrace( int levels ) 612QString odBacktrace( int levels )
609{ 613{
610 QString s; 614 QString s;
611#ifndef OPIE_NO_BACKTRACE 615#ifndef OPIE_NO_BACKTRACE
612 void* trace[256]; 616 void* trace[256];
613 int n = backtrace(trace, 256); 617 int n = backtrace(trace, 256);
614 char** strings = backtrace_symbols (trace, n); 618 char** strings = backtrace_symbols (trace, n);
615 619
616 if ( levels != -1 ) 620 if ( levels != -1 )
617 n = QMIN( n, levels ); 621 n = QMIN( n, levels );
618 s = "[\n"; 622 s = "[\n";
619 623
620 for (int i = 0; i < n; ++i) 624 for (int i = 0; i < n; ++i)
621 s += QString::number(i) + 625 s += QString::number(i) +
622 QString::fromLatin1(": ") + 626 QString::fromLatin1(": ") +
623 QString::fromLatin1(strings[i]) + QString::fromLatin1("\n"); 627 QString::fromLatin1(strings[i]) + QString::fromLatin1("\n");
624 s += "]\n"; 628 s += "]\n";
625 free (strings); 629 free (strings);
626#endif 630#endif
627 return s; 631 return s;
628} 632}
629 633
630void odClearDebugConfig() 634void odClearDebugConfig()
631{ 635{
632 /* 636 /*
633 delete oDebug_data->config; 637 delete oDebug_data->config;
634 oDebug_data->config = 0; 638 oDebug_data->config = 0;
635 */ 639 */
636} 640}
637 641
638 642
639#ifdef OPIE_NO_DEBUG 643#ifdef OPIE_NO_DEBUG
640#define odDebug ondDebug 644#define odDebug ondDebug
641#define odBacktrace ondBacktrace 645#define odBacktrace ondBacktrace
642#endif 646#endif
643 647
644} 648}
645} 649}