Changeset 101985 in vbox for trunk/src/libs/xpcom18a4
- Timestamp:
- Nov 8, 2023 4:32:10 PM (16 months ago)
- svn:sync-xref-src-repo-rev:
- 160082
- Location:
- trunk/src/libs/xpcom18a4/xpcom
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/base/nsDebugImpl.cpp
r3372 r101985 42 42 #include "nsDebug.h" 43 43 #include "prprf.h" 44 #include "prlog.h"45 44 #include "prinit.h" 46 45 #include "plstr.h" 47 46 #include "nsError.h" 48 #include "prerror.h"49 #include "prerr.h"50 51 #if defined(XP_BEOS)52 /* For DEBUGGER macros */53 #include <Debug.h>54 #endif55 56 #if defined(XP_UNIX) || defined(_WIN32) || defined(XP_OS2) || defined(XP_BEOS)57 /* for abort() and getenv() */58 #include <stdlib.h>59 #endif60 47 61 48 #if defined(XP_UNIX) && !defined(UNIX_CRASH_ON_ASSERT) … … 64 51 #include "nsISupportsUtils.h" 65 52 #include "nsTraceRefcntImpl.h" 66 67 #if defined(__GNUC__) && defined(__i386)68 # define DebugBreak() { asm("int $3"); }69 #elif defined(__APPLE__) && defined(TARGET_CARBON)70 # include "MacTypes.h"71 # define DebugBreak() { Debugger(); }72 #else73 # define DebugBreak()74 #endif75 53 #endif 76 54 77 #if defined(XP_OS2) 78 /* Added definitions for DebugBreak() for 2 different OS/2 compilers. Doing 79 * the int3 on purpose so that a developer can step over the 80 * instruction if so desired. Not always possible if trapping due to exception 81 * handling IBM-AKR 82 */ 83 #define INCL_WINDIALOGS // need for WinMessageBox 84 #include <os2.h> 85 #include <string.h> 86 87 #if defined(DEBUG) 88 #define DebugBreak() { asm("int $3"); } 89 #else 90 #define DebugBreak() 91 #endif /* DEBUG */ 92 #endif /* XP_OS2 */ 93 94 #if defined(_WIN32) 95 #include <windows.h> 96 #include <signal.h> 97 #elif defined(XP_MAC) 98 #define TEMP_MAC_HACK 99 100 //------------------------ 101 #ifdef TEMP_MAC_HACK 102 #include <MacTypes.h> 103 #include <Processes.h> 104 #include <string.h> 105 106 // TEMPORARY UNTIL WE HAVE MACINTOSH ENVIRONMENT VARIABLES THAT CAN TURN ON 107 // LOGGING ON MACINTOSH 108 // At this moment, NSPR's logging is a no-op on Macintosh. 109 110 #include <stdarg.h> 111 #include <stdio.h> 112 113 #undef PR_LOG 114 #undef PR_LogFlush 115 #define PR_LOG(module,level,args) dprintf args 116 #define PR_LogFlush() 117 static void dprintf(const char *format, ...) 118 { 119 va_list ap; 120 Str255 buffer; 121 122 va_start(ap, format); 123 buffer[0] = std::vsnprintf((char *)buffer + 1, sizeof(buffer) - 1, format, ap); 124 va_end(ap); 125 if (PL_strcasestr((char *)&buffer[1], "warning")) 126 printf("¥¥¥%s\n", (char*)buffer + 1); 127 else 128 DebugStr(buffer); 129 } 130 #endif // TEMP_MAC_HACK 131 //------------------------ 132 #elif defined(XP_UNIX) 133 #include<stdlib.h> 134 #endif 135 136 /* 137 * Determine if debugger is present in windows. 138 */ 139 #if defined (_WIN32) 140 141 typedef WINBASEAPI BOOL (WINAPI* LPFNISDEBUGGERPRESENT)(); 142 PRBool InDebugger() 143 { 144 PRBool fReturn = PR_FALSE; 145 LPFNISDEBUGGERPRESENT lpfnIsDebuggerPresent = NULL; 146 HINSTANCE hKernel = LoadLibrary("Kernel32.dll"); 147 148 if(hKernel) 149 { 150 lpfnIsDebuggerPresent = 151 (LPFNISDEBUGGERPRESENT)GetProcAddress(hKernel, "IsDebuggerPresent"); 152 if(lpfnIsDebuggerPresent) 153 { 154 fReturn = (*lpfnIsDebuggerPresent)(); 155 } 156 FreeLibrary(hKernel); 157 } 158 159 return fReturn; 160 } 161 162 #endif /* WIN32*/ 55 #include <iprt/cdefs.h> 56 #include <iprt/env.h> 57 #include <VBox/log.h> 163 58 164 59 NS_IMPL_THREADSAFE_ISUPPORTS1(nsDebugImpl, nsIDebug) … … 173 68 * compiled with debugging even if this library is not. 174 69 */ 175 static PRLogModuleInfo* gDebugLog;176 177 static void InitLog(void)178 {179 if (0 == gDebugLog) {180 gDebugLog = PR_NewLogModule("nsDebug");181 gDebugLog->level = PR_LOG_DEBUG;182 }183 }184 185 186 70 187 71 NS_IMETHODIMP 188 72 nsDebugImpl::Assertion(const char *aStr, const char *aExpr, const char *aFile, PRInt32 aLine) 189 73 { 190 InitLog(); 191 192 char buf[1000]; 193 PR_snprintf(buf, sizeof(buf), 194 "###!!! ASSERTION: %s: '%s', file %s, line %d", 195 aStr, aExpr, aFile, aLine); 196 197 // Write out the assertion message to the debug log 198 PR_LOG(gDebugLog, PR_LOG_ERROR, ("%s", buf)); 199 PR_LogFlush(); 200 201 // And write it out to the stderr 202 fprintf(stderr, "%s\n", buf); 203 fflush(stderr); 204 205 #if defined(_WIN32) 206 char* assertBehavior = getenv("XPCOM_DEBUG_BREAK"); 207 if (assertBehavior && strcmp(assertBehavior, "warn") == 0) 208 return NS_OK; 209 210 if(!InDebugger()) 211 { 212 DWORD code = IDRETRY; 213 214 /* Create the debug dialog out of process to avoid the crashes caused by 215 * Windows events leaking into our event loop from an in process dialog. 216 * We do this by launching windbgdlg.exe (built in xpcom/windbgdlg). 217 * See http://bugzilla.mozilla.org/show_bug.cgi?id=54792 218 */ 219 PROCESS_INFORMATION pi; 220 STARTUPINFO si; 221 char executable[MAX_PATH]; 222 char* pName; 223 224 memset(&pi, 0, sizeof(pi)); 225 226 memset(&si, 0, sizeof(si)); 227 si.cb = sizeof(si); 228 si.wShowWindow = SW_SHOW; 229 230 if(GetModuleFileName(GetModuleHandle(XPCOM_DLL), executable, MAX_PATH) && 231 NULL != (pName = strrchr(executable, '\\')) && 232 NULL != strcpy(pName+1, "windbgdlg.exe") && 233 #ifdef DEBUG_jband 234 (printf("Launching %s\n", executable), PR_TRUE) && 235 #endif 236 CreateProcess(executable, buf, NULL, NULL, PR_FALSE, 237 DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, 238 NULL, NULL, &si, &pi) && 239 WAIT_OBJECT_0 == WaitForSingleObject(pi.hProcess, INFINITE) && 240 GetExitCodeProcess(pi.hProcess, &code)) 241 { 242 CloseHandle(pi.hProcess); 243 } 244 245 switch(code) 246 { 247 case IDABORT: 248 //This should exit us 249 raise(SIGABRT); 250 //If we are ignored exit this way.. 251 _exit(3); 252 break; 253 254 case IDIGNORE: 255 return NS_OK; 256 // Fall Through 257 } 258 } 259 #endif 260 261 #if defined(XP_OS2) 262 char* assertBehavior = getenv("XPCOM_DEBUG_BREAK"); 263 if (assertBehavior && strcmp(assertBehavior, "warn") == 0) 264 return NS_OK; 265 266 char msg[1200]; 267 PR_snprintf(msg, sizeof(msg), 268 "%s\n\nClick Cancel to Debug Application.\n" 269 "Click Enter to continue running the Application.", buf); 270 ULONG code = MBID_ERROR; 271 code = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, msg, 272 "nsDebug::Assertion", 0, 273 MB_ERROR | MB_ENTERCANCEL); 274 275 /* It is possible that we are executing on a thread that doesn't have a 276 * message queue. In that case, the message won't appear, and code will 277 * be 0xFFFF. We'll give the user a chance to debug it by calling 278 * Break() 279 * Actually, that's a really bad idea since this happens a lot with threadsafe 280 * assertions and since it means that you can't actually run the debug build 281 * outside a debugger without it crashing constantly. 282 */ 283 if(( code == MBID_ENTER ) || (code == MBID_ERROR)) 284 { 285 return NS_OK; 286 // If Retry, Fall Through 287 } 288 #endif 289 290 Break(aFile, aLine); 291 return NS_OK; 74 RTAssertMsg1(aExpr, aLine, aFile, NULL); 75 RTAssertMsg2("%s\n", aStr); 76 return NS_OK; 292 77 } 293 78 … … 295 80 nsDebugImpl::Break(const char *aFile, PRInt32 aLine) 296 81 { 297 #ifndef TEMP_MAC_HACK 298 // Write out the assertion message to the debug log 299 InitLog(); 300 301 PR_LOG(gDebugLog, PR_LOG_ERROR, 302 ("###!!! Break: at file %s, line %d", aFile, aLine)); 303 PR_LogFlush(); 304 305 fprintf(stderr, "Break: at file %s, line %d\n",aFile, aLine); fflush(stderr); 306 fflush(stderr); 307 308 #if defined(_WIN32) 309 #ifdef _M_IX86 310 ::DebugBreak(); 311 #endif 312 #elif defined(XP_UNIX) && !defined(UNIX_CRASH_ON_ASSERT) 82 #if defined(XP_UNIX) && !defined(UNIX_CRASH_ON_ASSERT) 313 83 fprintf(stderr, "\07"); 314 84 315 c har *assertBehavior = getenv("XPCOM_DEBUG_BREAK");85 const char *assertBehavior = RTEnvGet("XPCOM_DEBUG_BREAK"); 316 86 317 87 if (!assertBehavior) { … … 350 120 351 121 } else if ( strcmp(assertBehavior,"trap")==0 ) { 352 353 DebugBreak(); 354 122 RT_BREAKPOINT(); 355 123 } else { 356 124 … … 360 128 fflush(stderr); // this shouldn't really be necessary, i don't think, 361 129 // but maybe there's some lame stdio that buffers stderr 362 363 #elif defined(XP_BEOS)364 {365 #ifdef UNIX_CRASH_ON_ASSERT366 char buf[2000];367 sprintf(buf, "Break: at file %s, line %d", aFile, aLine);368 DEBUGGER(buf);369 #endif370 }371 130 #else 372 131 Abort(aFile, aLine); 373 132 #endif 374 #endif // TEMP_MAC_HACK375 133 return NS_OK; 376 134 } … … 379 137 nsDebugImpl::Abort(const char *aFile, PRInt32 aLine) 380 138 { 381 InitLog(); 382 383 PR_LOG(gDebugLog, PR_LOG_ERROR, 384 ("###!!! Abort: at file %s, line %d", aFile, aLine)); 385 PR_LogFlush(); 386 fprintf(stderr, "\07 Abort\n"); fflush(stderr); 387 fflush(stderr); 388 389 #if defined(_WIN32) 390 #ifdef _M_IX86 391 long* __p = (long*) 0x7; 392 *__p = 0x7; 393 #else /* _M_ALPHA */ 394 PR_Abort(); 395 #endif 396 #elif defined(XP_MAC) 397 ExitToShell(); 398 #elif defined(XP_UNIX) 399 PR_Abort(); 400 #elif defined(XP_OS2) 401 DebugBreak(); 402 return NS_OK; 403 #elif defined(XP_BEOS) 404 { 405 #ifndef DEBUG_cls 406 char buf[2000]; 407 sprintf(buf, "Abort: at file %s, line %d", aFile, aLine); 408 DEBUGGER(buf); 409 #endif 410 } 411 #endif 412 return NS_OK; 139 AssertReleaseMsgFailed(("###!!! Abort: at file %s, line %d", aFile, aLine)); 140 return NS_OK; 413 141 } 414 142 … … 417 145 const char* aFile, PRIntn aLine) 418 146 { 419 InitLog(); 147 /* Debug log. */ 148 Log(("WARNING: %s, file %s, line %d", aMessage, aFile, aLine)); 420 149 421 char buf[1000]; 422 PR_snprintf(buf, sizeof(buf), 423 "WARNING: %s, file %s, line %d", 424 aMessage, aFile, aLine); 425 426 // Write out the warning message to the debug log 427 PR_LOG(gDebugLog, PR_LOG_ERROR, ("%s", buf)); 428 429 // And write it out to the stdout 430 fprintf(stderr, "%s\n", buf); 431 fflush(stderr); 432 return NS_OK; 150 // And write it out to the stdout 151 fprintf(stderr, "WARNING: %s, file %s, line %d", aMessage, aFile, aLine); 152 fflush(stderr); 153 return NS_OK; 433 154 } 434 155 … … 449 170 } 450 171 451 ////////////////////////////////////////////////////////////////////////////////452 453 NS_COM nsresult454 NS_ErrorAccordingToNSPR()455 {456 PRErrorCode err = PR_GetError();457 switch (err) {458 case PR_OUT_OF_MEMORY_ERROR: return NS_ERROR_OUT_OF_MEMORY;459 case PR_WOULD_BLOCK_ERROR: return NS_BASE_STREAM_WOULD_BLOCK;460 case PR_FILE_NOT_FOUND_ERROR: return NS_ERROR_FILE_NOT_FOUND;461 case PR_READ_ONLY_FILESYSTEM_ERROR: return NS_ERROR_FILE_READ_ONLY;462 case PR_NOT_DIRECTORY_ERROR: return NS_ERROR_FILE_NOT_DIRECTORY;463 case PR_IS_DIRECTORY_ERROR: return NS_ERROR_FILE_IS_DIRECTORY;464 case PR_LOOP_ERROR: return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK;465 case PR_FILE_EXISTS_ERROR: return NS_ERROR_FILE_ALREADY_EXISTS;466 case PR_FILE_IS_LOCKED_ERROR: return NS_ERROR_FILE_IS_LOCKED;467 case PR_FILE_TOO_BIG_ERROR: return NS_ERROR_FILE_TOO_BIG;468 case PR_NO_DEVICE_SPACE_ERROR: return NS_ERROR_FILE_NO_DEVICE_SPACE;469 case PR_NAME_TOO_LONG_ERROR: return NS_ERROR_FILE_NAME_TOO_LONG;470 case PR_DIRECTORY_NOT_EMPTY_ERROR: return NS_ERROR_FILE_DIR_NOT_EMPTY;471 case PR_NO_ACCESS_RIGHTS_ERROR: return NS_ERROR_FILE_ACCESS_DENIED;472 default: return NS_ERROR_FAILURE;473 }474 }475 476 ////////////////////////////////////////////////////////////////////////////////477 -
trunk/src/libs/xpcom18a4/xpcom/base/nsError.h
r64428 r101985 296 296 #define NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 1) 297 297 298 299 /*300 * This will return the nsresult corresponding to the most recent NSPR failure301 * returned by PR_GetError.302 *303 ***********************************************************************304 * Do not depend on this function. It will be going away!305 ***********************************************************************306 */307 extern NS_COM nsresult308 NS_ErrorAccordingToNSPR();309 310 311 #ifdef _MSC_VER312 #pragma warning(disable: 4251) /* 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream' */313 #pragma warning(disable: 4275) /* non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode' */314 298 #endif 315 299 316 #endif317 -
trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileUnix.cpp
r101944 r101985 74 74 #include "nsNativeCharsetUtils.h" 75 75 76 #include "prerror.h" 77 #include "prerr.h" 78 76 79 #include <iprt/errcore.h> 77 80 … … 93 96 return NS_ERROR_NOT_INITIALIZED; \ 94 97 PR_END_MACRO 98 99 NS_COM nsresult 100 NS_ErrorAccordingToNSPR() 101 { 102 PRErrorCode err = PR_GetError(); 103 switch (err) { 104 case PR_OUT_OF_MEMORY_ERROR: return NS_ERROR_OUT_OF_MEMORY; 105 case PR_WOULD_BLOCK_ERROR: return NS_BASE_STREAM_WOULD_BLOCK; 106 case PR_FILE_NOT_FOUND_ERROR: return NS_ERROR_FILE_NOT_FOUND; 107 case PR_READ_ONLY_FILESYSTEM_ERROR: return NS_ERROR_FILE_READ_ONLY; 108 case PR_NOT_DIRECTORY_ERROR: return NS_ERROR_FILE_NOT_DIRECTORY; 109 case PR_IS_DIRECTORY_ERROR: return NS_ERROR_FILE_IS_DIRECTORY; 110 case PR_LOOP_ERROR: return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; 111 case PR_FILE_EXISTS_ERROR: return NS_ERROR_FILE_ALREADY_EXISTS; 112 case PR_FILE_IS_LOCKED_ERROR: return NS_ERROR_FILE_IS_LOCKED; 113 case PR_FILE_TOO_BIG_ERROR: return NS_ERROR_FILE_TOO_BIG; 114 case PR_NO_DEVICE_SPACE_ERROR: return NS_ERROR_FILE_NO_DEVICE_SPACE; 115 case PR_NAME_TOO_LONG_ERROR: return NS_ERROR_FILE_NAME_TOO_LONG; 116 case PR_DIRECTORY_NOT_EMPTY_ERROR: return NS_ERROR_FILE_DIR_NOT_EMPTY; 117 case PR_NO_ACCESS_RIGHTS_ERROR: return NS_ERROR_FILE_ACCESS_DENIED; 118 default: return NS_ERROR_FAILURE; 119 } 120 } 121 95 122 96 123 /* directory enumerator */
Note:
See TracChangeset
for help on using the changeset viewer.