OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 3 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
4 * Copyright (C) 2011 University of Szeged. All rights reserved. | 4 * Copyright (C) 2011 University of Szeged. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 #endif | 224 #endif |
225 } | 225 } |
226 | 226 |
227 FrameToNameScope::~FrameToNameScope() | 227 FrameToNameScope::~FrameToNameScope() |
228 { | 228 { |
229 free(m_cxaDemangled); | 229 free(m_cxaDemangled); |
230 } | 230 } |
231 | 231 |
232 } // anonymous namespace | 232 } // anonymous namespace |
233 | 233 |
| 234 #if !LOG_DISABLED |
| 235 namespace WTF { |
| 236 |
| 237 ScopedLogger::ScopedLogger(bool condition, const char* format, ...) |
| 238 : m_parent(condition ? current() : 0) |
| 239 , m_multiline(false) |
| 240 { |
| 241 if (!condition) |
| 242 return; |
| 243 |
| 244 va_list args; |
| 245 va_start(args, format); |
| 246 init(format, args); |
| 247 va_end(args); |
| 248 } |
| 249 |
| 250 ScopedLogger::~ScopedLogger() |
| 251 { |
| 252 if (current() == this) { |
| 253 if (m_multiline) |
| 254 indent(); |
| 255 else |
| 256 print(" "); |
| 257 print(")\n"); |
| 258 current() = m_parent; |
| 259 } |
| 260 } |
| 261 |
| 262 void ScopedLogger::init(const char* format, va_list args) |
| 263 { |
| 264 current() = this; |
| 265 if (m_parent) |
| 266 m_parent->writeNewlineIfNeeded(); |
| 267 indent(); |
| 268 print("( "); |
| 269 m_printFunc(format, args); |
| 270 } |
| 271 |
| 272 void ScopedLogger::writeNewlineIfNeeded() |
| 273 { |
| 274 if (!m_multiline) { |
| 275 print("\n"); |
| 276 m_multiline = true; |
| 277 } |
| 278 } |
| 279 |
| 280 void ScopedLogger::indent() |
| 281 { |
| 282 if (m_parent) { |
| 283 m_parent->indent(); |
| 284 printIndent(); |
| 285 } |
| 286 } |
| 287 |
| 288 void ScopedLogger::log(const char* format, ...) |
| 289 { |
| 290 if (current() != this) |
| 291 return; |
| 292 |
| 293 va_list args; |
| 294 va_start(args, format); |
| 295 |
| 296 writeNewlineIfNeeded(); |
| 297 indent(); |
| 298 printIndent(); |
| 299 m_printFunc(format, args); |
| 300 print("\n"); |
| 301 |
| 302 va_end(args); |
| 303 } |
| 304 |
| 305 void ScopedLogger::print(const char* format, ...) |
| 306 { |
| 307 va_list args; |
| 308 va_start(args, format); |
| 309 m_printFunc(format, args); |
| 310 va_end(args); |
| 311 } |
| 312 |
| 313 void ScopedLogger::printIndent() |
| 314 { |
| 315 print(" "); |
| 316 } |
| 317 |
| 318 ScopedLogger*& ScopedLogger::current() |
| 319 { |
| 320 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ScopedLogger*>, ref, new Thre
adSpecific<ScopedLogger*>); |
| 321 return *ref; |
| 322 } |
| 323 |
| 324 ScopedLogger::PrintFunctionPtr ScopedLogger::m_printFunc = vprintf_stderr_common
; |
| 325 |
| 326 } // namespace WTF |
| 327 #endif // !LOG_DISABLED |
| 328 |
234 void WTFPrintBacktrace(void** stack, int size) | 329 void WTFPrintBacktrace(void** stack, int size) |
235 { | 330 { |
236 for (int i = 0; i < size; ++i) { | 331 for (int i = 0; i < size; ++i) { |
237 FrameToNameScope frameToName(stack[i]); | 332 FrameToNameScope frameToName(stack[i]); |
238 const int frameNumber = i + 1; | 333 const int frameNumber = i + 1; |
239 if (frameToName.nullableName()) | 334 if (frameToName.nullableName()) |
240 printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i], frameToN
ame.nullableName()); | 335 printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i], frameToN
ame.nullableName()); |
241 else | 336 else |
242 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); | 337 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); |
243 } | 338 } |
(...skipping 23 matching lines...) Expand all Loading... |
267 printCallSite(file, line, function); | 362 printCallSite(file, line, function); |
268 } | 363 } |
269 | 364 |
270 void WTFLogAlways(const char* format, ...) | 365 void WTFLogAlways(const char* format, ...) |
271 { | 366 { |
272 va_list args; | 367 va_list args; |
273 va_start(args, format); | 368 va_start(args, format); |
274 vprintf_stderr_with_trailing_newline(format, args); | 369 vprintf_stderr_with_trailing_newline(format, args); |
275 va_end(args); | 370 va_end(args); |
276 } | 371 } |
OLD | NEW |