home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / xpcom / src / nsDebug.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.5 KB  |  115 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "nsDebug.h"
  20. #include "prlog.h"
  21.  
  22. /**
  23.  * Implementation of the nsDebug methods. Note that this code is
  24.  * always compiled in, in case some other module that uses it is
  25.  * compiled with debugging even if this library is not.
  26.  */
  27.  
  28. static PRLogModuleInfo* gDebugLog;
  29.  
  30. static void InitLog(void)
  31. {
  32.   if (0 == gDebugLog) {
  33.     gDebugLog = PR_NewLogModule("nsDebug");
  34.     gDebugLog->level = PR_LOG_DEBUG;
  35.   }
  36. }
  37.  
  38. NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
  39. {
  40.   InitLog();
  41.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  42.          ("Abort: at file %s, line %d", aFile, aLine));
  43.   PR_LogFlush();
  44. #if defined(_WIN32)
  45.   long* __p = (long*) 0x7;
  46.   *__p = 0x7;
  47. #endif
  48. }
  49.  
  50. NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
  51.                                   const char* aFile, PRIntn aLine)
  52. {
  53.   InitLog();
  54.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  55.          ("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
  56.           aFile, aLine));
  57.   Abort(aFile, aLine);
  58. }
  59.  
  60. NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
  61.                                    const char* aFile, PRIntn aLine)
  62. {
  63.   InitLog();
  64.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  65.          ("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
  66.           aFile, aLine));
  67.   Abort(aFile, aLine);
  68. }
  69.  
  70. NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
  71.                                const char* aFile, PRIntn aLine)
  72. {
  73.   InitLog();
  74.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  75.          ("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
  76.           aFile, aLine));
  77.   Abort(aFile, aLine);
  78. }
  79.  
  80. NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
  81.                                        const char* aFile, PRIntn aLine)
  82. {
  83.   InitLog();
  84.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  85.          ("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
  86.           aFile, aLine));
  87.   Abort(aFile, aLine);
  88. }
  89.  
  90. NS_COM void nsDebug::NotReached(const char* aMessage,
  91.                                 const char* aFile, PRIntn aLine)
  92. {
  93.   InitLog();
  94.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  95.          ("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
  96.   Abort(aFile, aLine);
  97. }
  98.  
  99. NS_COM void nsDebug::Error(const char* aMessage,
  100.                            const char* aFile, PRIntn aLine)
  101. {
  102.   InitLog();
  103.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  104.          ("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
  105.   Abort(aFile, aLine);
  106. }
  107.  
  108. NS_COM void nsDebug::Warning(const char* aMessage,
  109.                              const char* aFile, PRIntn aLine)
  110. {
  111.   InitLog();
  112.   PR_LOG(gDebugLog, PR_LOG_ERROR,
  113.          ("Warning: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
  114. }
  115.