VirtualBox

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

Last change on this file since 106580 was 102458, checked in by vboxsync, 12 months ago

libs/xpcom: Get rid of PL_strcasecmp/PL_strncasecmp and replace with IPRT equivalents, bugref:10545

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

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