VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/base/nsDebugImpl.cpp@ 102348

最後變更 在這個檔案從102348是 102348,由 vboxsync 提交於 16 月 前

libs/xpcom: Get rid of prprf.h and prprf.c, bugref:10545 [build fix]

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.0 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
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/
9 *
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
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * IBM Corp.
24 * Henry Sobotka
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40#include "nsXPCOMPrivate.h"
41#include "nsDebugImpl.h"
42#include "nsDebug.h"
43#include "plstr.h"
44#include "nsError.h"
45
46#if defined(XP_UNIX) && !defined(UNIX_CRASH_ON_ASSERT)
47#include <signal.h>
48/* for nsTraceRefcnt::WalkTheStack() */
49#include "nsISupportsUtils.h"
50#include "nsTraceRefcntImpl.h"
51#endif
52
53#include <iprt/cdefs.h>
54#include <iprt/env.h>
55#include <VBox/log.h>
56
57NS_IMPL_THREADSAFE_ISUPPORTS1(nsDebugImpl, nsIDebug)
58
59nsDebugImpl::nsDebugImpl()
60{
61}
62
63/**
64 * Implementation of the nsDebug methods. Note that this code is
65 * always compiled in, in case some other module that uses it is
66 * compiled with debugging even if this library is not.
67 */
68
69NS_IMETHODIMP
70nsDebugImpl::Assertion(const char *aStr, const char *aExpr, const char *aFile, PRInt32 aLine)
71{
72 RTAssertMsg1(aExpr, aLine, aFile, NULL);
73 RTAssertMsg2("%s\n", aStr);
74 return NS_OK;
75}
76
77NS_IMETHODIMP
78nsDebugImpl::Break(const char *aFile, PRInt32 aLine)
79{
80#if defined(XP_UNIX) && !defined(UNIX_CRASH_ON_ASSERT)
81 fprintf(stderr, "\07");
82
83 const char *assertBehavior = RTEnvGet("XPCOM_DEBUG_BREAK");
84
85 if (!assertBehavior) {
86
87 // the default; nothing else to do
88 ;
89
90 } else if ( strcmp(assertBehavior, "suspend")== 0 ) {
91
92 // the suspend case is first because we wanna send the signal before
93 // other threads have had a chance to get too far from the state that
94 // caused this assertion (in case they happen to have been involved).
95 //
96 fprintf(stderr, "Suspending process; attach with the debugger.\n");
97 kill(0, SIGSTOP);
98
99 } else if ( strcmp(assertBehavior, "warn")==0 ) {
100
101 // same as default; nothing else to do (see "suspend" case comment for
102 // why this compare isn't done as part of the default case)
103 //
104 ;
105
106 }
107 else if ( strcmp(assertBehavior,"stack")==0 ) {
108
109 // walk the stack
110 //
111 nsTraceRefcntImpl::WalkTheStack(stderr);
112 }
113 else if ( strcmp(assertBehavior,"abort")==0 ) {
114
115 // same as UNIX_CRASH_ON_ASSERT
116 //
117 Abort(aFile, aLine);
118
119 } else if ( strcmp(assertBehavior,"trap")==0 ) {
120 RT_BREAKPOINT();
121 } else {
122
123 fprintf(stderr, "unrecognized value of XPCOM_DEBUG_BREAK env var!\n");
124
125 }
126 fflush(stderr); // this shouldn't really be necessary, i don't think,
127 // but maybe there's some lame stdio that buffers stderr
128#else
129 Abort(aFile, aLine);
130#endif
131 return NS_OK;
132}
133
134NS_IMETHODIMP
135nsDebugImpl::Abort(const char *aFile, PRInt32 aLine)
136{
137 AssertReleaseMsgFailed(("###!!! Abort: at file %s, line %d", aFile, aLine));
138 return NS_OK;
139}
140
141NS_IMETHODIMP
142nsDebugImpl::Warning(const char* aMessage,
143 const char* aFile, PRIntn aLine)
144{
145 /* Debug log. */
146 Log(("WARNING: %s, file %s, line %d", aMessage, aFile, aLine));
147
148 // And write it out to the stdout
149 fprintf(stderr, "WARNING: %s, file %s, line %d", aMessage, aFile, aLine);
150 fflush(stderr);
151 return NS_OK;
152}
153
154NS_METHOD
155nsDebugImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
156{
157 *aInstancePtr = nsnull;
158 nsIDebug* debug = new nsDebugImpl();
159 if (!debug)
160 return NS_ERROR_OUT_OF_MEMORY;
161
162 nsresult rv = debug->QueryInterface(aIID, aInstancePtr);
163 if (NS_FAILED(rv)) {
164 delete debug;
165 }
166
167 return rv;
168}
169
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette