VirtualBox

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

Last change on this file since 102212 was 102212, checked in by vboxsync, 17 months ago

libs/xpcom: Remove now unused code in nsprpub, bugref:10545 [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
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 "prprf.h"
44#include "plstr.h"
45#include "nsError.h"
46
47#if defined(XP_UNIX) && !defined(UNIX_CRASH_ON_ASSERT)
48#include <signal.h>
49/* for nsTraceRefcnt::WalkTheStack() */
50#include "nsISupportsUtils.h"
51#include "nsTraceRefcntImpl.h"
52#endif
53
54#include <iprt/cdefs.h>
55#include <iprt/env.h>
56#include <VBox/log.h>
57
58NS_IMPL_THREADSAFE_ISUPPORTS1(nsDebugImpl, nsIDebug)
59
60nsDebugImpl::nsDebugImpl()
61{
62}
63
64/**
65 * Implementation of the nsDebug methods. Note that this code is
66 * always compiled in, in case some other module that uses it is
67 * compiled with debugging even if this library is not.
68 */
69
70NS_IMETHODIMP
71nsDebugImpl::Assertion(const char *aStr, const char *aExpr, const char *aFile, PRInt32 aLine)
72{
73 RTAssertMsg1(aExpr, aLine, aFile, NULL);
74 RTAssertMsg2("%s\n", aStr);
75 return NS_OK;
76}
77
78NS_IMETHODIMP
79nsDebugImpl::Break(const char *aFile, PRInt32 aLine)
80{
81#if defined(XP_UNIX) && !defined(UNIX_CRASH_ON_ASSERT)
82 fprintf(stderr, "\07");
83
84 const char *assertBehavior = RTEnvGet("XPCOM_DEBUG_BREAK");
85
86 if (!assertBehavior) {
87
88 // the default; nothing else to do
89 ;
90
91 } else if ( strcmp(assertBehavior, "suspend")== 0 ) {
92
93 // the suspend case is first because we wanna send the signal before
94 // other threads have had a chance to get too far from the state that
95 // caused this assertion (in case they happen to have been involved).
96 //
97 fprintf(stderr, "Suspending process; attach with the debugger.\n");
98 kill(0, SIGSTOP);
99
100 } else if ( strcmp(assertBehavior, "warn")==0 ) {
101
102 // same as default; nothing else to do (see "suspend" case comment for
103 // why this compare isn't done as part of the default case)
104 //
105 ;
106
107 }
108 else if ( strcmp(assertBehavior,"stack")==0 ) {
109
110 // walk the stack
111 //
112 nsTraceRefcntImpl::WalkTheStack(stderr);
113 }
114 else if ( strcmp(assertBehavior,"abort")==0 ) {
115
116 // same as UNIX_CRASH_ON_ASSERT
117 //
118 Abort(aFile, aLine);
119
120 } else if ( strcmp(assertBehavior,"trap")==0 ) {
121 RT_BREAKPOINT();
122 } else {
123
124 fprintf(stderr, "unrecognized value of XPCOM_DEBUG_BREAK env var!\n");
125
126 }
127 fflush(stderr); // this shouldn't really be necessary, i don't think,
128 // but maybe there's some lame stdio that buffers stderr
129#else
130 Abort(aFile, aLine);
131#endif
132 return NS_OK;
133}
134
135NS_IMETHODIMP
136nsDebugImpl::Abort(const char *aFile, PRInt32 aLine)
137{
138 AssertReleaseMsgFailed(("###!!! Abort: at file %s, line %d", aFile, aLine));
139 return NS_OK;
140}
141
142NS_IMETHODIMP
143nsDebugImpl::Warning(const char* aMessage,
144 const char* aFile, PRIntn aLine)
145{
146 /* Debug log. */
147 Log(("WARNING: %s, file %s, line %d", aMessage, aFile, aLine));
148
149 // And write it out to the stdout
150 fprintf(stderr, "WARNING: %s, file %s, line %d", aMessage, aFile, aLine);
151 fflush(stderr);
152 return NS_OK;
153}
154
155NS_METHOD
156nsDebugImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
157{
158 *aInstancePtr = nsnull;
159 nsIDebug* debug = new nsDebugImpl();
160 if (!debug)
161 return NS_ERROR_OUT_OF_MEMORY;
162
163 nsresult rv = debug->QueryInterface(aIID, aInstancePtr);
164 if (NS_FAILED(rv)) {
165 delete debug;
166 }
167
168 return rv;
169}
170
Note: See TracBrowser for help on using the repository browser.

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