VirtualBox

Changeset 101987 in vbox for trunk/src/libs/xpcom18a4


Ignore:
Timestamp:
Nov 8, 2023 4:58:53 PM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom: Cleanup nsNativeComponentLoader.cpp, convert from PR_LOG to IPRT's logging infrastructure, bugref:10545

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/components/nsNativeComponentLoader.cpp

    r101875 r101987  
    6060#include "nsIObserverService.h"
    6161
    62 #if defined(XP_MAC)  // sdagley dougt fix
    63 #include <Files.h>
    64 #include <Errors.h>
    65 #include "nsILocalFileMac.h"
    66 #endif
    67 
    68 #include "prlog.h"
    69 extern PRLogModuleInfo *nsComponentManagerLog;
     62#include <iprt/assert.h>
     63#include <VBox/log.h>
    7064
    7165static PRBool PR_CALLBACK
     
    112106
    113107    if (!dll->IsLoaded()) {
    114 #ifdef PR_LOGGING
     108#ifdef LOG_ENABLED
    115109        nsXPIDLCString displayPath;
    116110        dll->GetDisplayPath(displayPath);
    117111
    118         PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
    119                ("nsNativeComponentLoader: loading \"%s\"",
    120                 displayPath.get()));
     112        Log(("nsNativeComponentLoader: loading \"%s\"\n", displayPath.get()));
    121113#endif
    122114        if (!dll->Load()) {
    123115
    124             PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
    125                    ("nsNativeComponentLoader: load FAILED"));
     116            Log(("nsNativeComponentLoader: load FAILED\n"));
    126117
    127118            char errorMsg[1024] = "<unknown; can't get error from NSPR>";
     
    144135    rv = GetFactoryFromModule(dll, aCID, _retval);
    145136
    146     PR_LOG(nsComponentManagerLog, NS_SUCCEEDED(rv) ? PR_LOG_DEBUG : PR_LOG_ERROR,
    147            ("nsNativeComponentLoader: Factory creation %s for %s",
    148             (NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"),
    149             aLocation));
     137    Log(("nsNativeComponentLoader: Factory creation %s for %s",
     138         (NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"),
     139         aLocation));
    150140
    151141    // If the dll failed to get us a factory. But the dll registered that
     
    176166                                                nsIFile *aDirectory)
    177167{
    178 #ifdef DEBUG
    179     /* do we _really_ want to print this every time? */
    180     fprintf(stderr, "nsNativeComponentLoader: autoregistering begins.\n");
    181 #endif
     168    Log(("nsNativeComponentLoader: autoregistering begins.\n"));
    182169
    183170    nsresult rv = RegisterComponentsInDir(aWhen, aDirectory);
    184171
    185 #ifdef DEBUG
    186     fprintf(stderr, "nsNativeComponentLoader: autoregistering %s\n",
    187            NS_FAILED(rv) ? "FAILED" : "succeeded");
    188 #endif
    189 
     172    Log(("nsNativeComponentLoader: autoregistering %s\n",
     173         NS_FAILED(rv) ? "FAILED" : "succeeded"));
    190174    return rv;
    191175}
     
    197181    nsresult rv = NS_ERROR_FAILURE;
    198182    PRBool isDir = PR_FALSE;
    199 
    200 #if 0
    201     // Going to many of these checks is a performance hit on the mac.
    202     // Since these routines are called relatively infrequently and
    203     // we will fail anyway down the line if a directory aint there,
    204     // we are commenting this check out.
    205 
    206     // Make sure we are dealing with a directory
    207     rv = dir->IsDirectory(&isDir);
    208     if (NS_FAILED(rv)) return rv;
    209 
    210     if (!isDir)
    211         return NS_ERROR_INVALID_ARG;
    212 #endif /* 0 */
    213183
    214184    // Create a directory iterator
     
    259229}
    260230
     231DECLINLINE(void) nsLogDllMsg(nsDll *dll, const char *pszWhat)
     232{
     233#ifdef LOG_ENABLED
     234    nsXPIDLCString displayPath;
     235    dll->GetDisplayPath(displayPath);
     236
     237    Log(("nsNativeComponentLoader: %s \"%s\".\n", pszWhat, displayPath.get()));
     238#endif
     239}
     240
    261241static nsresult PR_CALLBACK
    262242nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when)
     
    299279    if (NS_FAILED(rv))
    300280    {
    301 #ifdef PR_LOGGING
    302         nsXPIDLCString displayPath;
    303         dll->GetDisplayPath(displayPath);
    304 
    305         PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
    306                ("nsNativeComponentLoader: nsIModule::CanUnload() returned error for %s.",
    307                 displayPath.get()));
    308 #endif
     281        nsLogDllMsg(dll, "nsIModule::CanUnload() returned error for");
    309282        return rv;
    310283    }
     
    314287        if (dllMarkedForUnload)
    315288        {
    316 #ifdef PR_LOGGING
    317             nsXPIDLCString displayPath;
    318             dll->GetDisplayPath(displayPath);
    319 
    320             PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
    321                    ("nsNativeComponentLoader: + Unloading \"%s\".", displayPath.get()));
    322 #endif
     289            nsLogDllMsg(dll, "+ Unloading");
    323290
    324291#ifdef DEBUG_dougt
     
    329296        }
    330297        else
    331         {
    332 #ifdef PR_LOGGING
    333             nsXPIDLCString displayPath;
    334             dll->GetDisplayPath(displayPath);
    335 
    336             PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
    337                    ("nsNativeComponentLoader: Ready for unload \"%s\".", displayPath.get()));
    338 #endif
    339         }
     298            nsLogDllMsg(dll, "Ready for unload");
    340299    }
    341300    else
    342301    {
    343 #ifdef PR_LOGGING
    344         nsXPIDLCString displayPath;
    345         dll->GetDisplayPath(displayPath);
    346 
    347         PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
    348                ("nsNativeComponentLoader: NOT ready for unload %s", displayPath.get()));
    349 #endif
     302        nsLogDllMsg(dll, "NOT ready for unload");
    350303        rv = NS_ERROR_FAILURE;
    351304    }
     
    383336{
    384337    // Precondition: dll is not loaded already, unless we're deferred
    385     PR_ASSERT(deferred || dll->IsLoaded() == PR_FALSE);
     338    Assert(deferred || dll->IsLoaded() == PR_FALSE);
    386339
    387340    nsresult res;
     
    402355    }
    403356
    404 #ifdef PR_LOGGING
    405     nsXPIDLCString displayPath;
    406     dll->GetDisplayPath(displayPath);
    407 
    408     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
    409            ("nsNativeComponentLoader: Loaded \"%s\".", displayPath.get()));
    410 #endif
     357    nsLogDllMsg(dll, "Loaded");
    411358
    412359    // Tell the module to self register
     
    436383        {
    437384            res = res2;         // don't take this out -- see warning, above
    438 
    439 #ifdef PR_LOGGING
    440             nsXPIDLCString displayPath;
    441             dll->GetDisplayPath(displayPath);
    442             PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
    443                    ("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.",
    444                     displayPath.get()));
    445 #endif
     385            nsLogDllMsg(dll, "dll->GetDllSpec() FAILED on");
    446386        }
    447387        mobj = NULL;    // Force a release of the Module object before unload()
     
    472412}
    473413
    474 //
    475 // MOZ_DEMANGLE_SYMBOLS is only a linux + MOZ_DEBUG thing.
    476 //
    477 
    478 #if defined(MOZ_DEMANGLE_SYMBOLS)
    479 #include "nsTraceRefcntImpl.h" // for nsTraceRefcntImpl::DemangleSymbol()
    480 #endif
    481 
    482414nsresult
    483415nsNativeComponentLoader::DumpLoadError(nsDll *dll,
     
    485417                                       const char *aNsprErrorMsg)
    486418{
    487     PR_ASSERT(aCallerName != NULL);
     419    Assert(aCallerName != NULL);
    488420
    489421    if (nsnull == dll || nsnull == aNsprErrorMsg)
     
    492424    nsCAutoString errorMsg(aNsprErrorMsg);
    493425
    494 #if defined(MOZ_DEMANGLE_SYMBOLS)
    495     // Demangle undefined symbols
    496     nsCAutoString undefinedMagicString("undefined symbol:");
    497 
    498     PRInt32 offset = errorMsg.Find(undefinedMagicString, PR_TRUE);
    499 
    500     if (offset != kNotFound)
    501     {
    502         nsCAutoString symbol(errorMsg);
    503         nsCAutoString demangledSymbol;
    504 
    505         symbol.Cut(0,offset);
    506 
    507         symbol.Cut(0,undefinedMagicString.Length());
    508 
    509         symbol.StripWhitespace();
    510 
    511         char demangled[4096] = "\0";
    512 
    513         nsTraceRefcntImpl::DemangleSymbol(symbol.get(),demangled,sizeof(demangled));
    514 
    515         if (demangled && *demangled != '\0')
    516             demangledSymbol = demangled;
    517 
    518         if (!demangledSymbol.IsEmpty())
    519         {
    520             nsCAutoString tmp(errorMsg);
    521 
    522 
    523             tmp.Cut(offset + undefinedMagicString.Length(),
    524                     tmp.Length() - offset - undefinedMagicString.Length());
    525 
    526             tmp += " \n";
    527 
    528             tmp += demangledSymbol;
    529 
    530             errorMsg = tmp;
    531         }
    532     }
    533 #endif // MOZ_DEMANGLE_SYMBOLS
    534426    nsXPIDLCString displayPath;
    535427    dll->GetDisplayPath(displayPath);
     
    543435#endif
    544436
    545     // Do NSPR log
    546 #ifdef PR_LOGGING
    547     PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
    548            ("nsNativeComponentLoader: %s(%s) Load FAILED with error: %s",
    549             aCallerName,
    550             displayPath.get(),
    551             errorMsg.get()));
    552 #endif
     437    Log(("nsNativeComponentLoader: %s(%s) Load FAILED with error: %s",
     438         aCallerName, displayPath.get(), errorMsg.get()));
    553439    return NS_OK;
    554440}
     
    573459    if (NS_SUCCEEDED(res))
    574460    {
    575 #ifdef PR_LOGGING
    576         nsXPIDLCString displayPath;
    577         dll->GetDisplayPath(displayPath);
    578 
    579         PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
    580                ("nsNativeComponentLoader: %s using nsIModule to unregister self.", displayPath.get()));
    581 #endif
     461        nsLogDllMsg(dll, "using nsIModule to unregister self on");
     462
    582463        nsCOMPtr<nsIFile> fs;
    583464        res = dll->GetDllSpec(getter_AddRefs(fs));
     
    638519    rv = SelfUnregisterDll(dll);
    639520
    640 #ifdef PR_LOGGING
    641     nsXPIDLCString displayPath;
    642     dll->GetDisplayPath(displayPath);
    643 
    644     PR_LOG(nsComponentManagerLog, NS_SUCCEEDED(rv) ? PR_LOG_DEBUG : PR_LOG_ERROR,
    645            ("nsNativeComponentLoader: AutoUnregistration for %s %s.",
    646             (NS_FAILED(rv) ? "FAILED" : "succeeded"), displayPath.get()));
    647 #endif
     521    if (NS_SUCCEEDED(rv))
     522        nsLogDllMsg(dll, "AutoUnregistration succeeded for");
     523    else
     524        nsLogDllMsg(dll, "AutoUnregistration FAILED for");
    648525
    649526    if (NS_FAILED(rv))
     
    674551    *registered = PR_FALSE;
    675552
    676 #ifndef VBOX
    677     /* this should be a pref or registry entry, or something */
    678     static const char *ValidDllExtensions[] = {
    679         ".dll",     /* Windows */
    680         ".so",      /* Unix */
    681         ".shlb",    /* Mac ? */
    682         ".dso",     /* Unix ? */
    683         ".dylib",   /* Unix: Mach */
    684         ".so.1.0",  /* Unix: BSD */
    685         ".sl",      /* Unix: HP-UX */
    686 #if defined(VMS)
    687         ".exe",     /* Open VMS */
    688 #endif
    689         ".dlm",     /* new for all platforms */
    690         NULL
    691     };
    692 
    693     *registered = PR_FALSE;
    694 
    695 #if 0
    696     // This is a performance hit on mac. Since we have already checked
    697     // this; plus is we dont, load will fail anyway later on, this
    698     // is being commented out.
    699 
    700     // Ensure we are dealing with a file as opposed to a dir
    701     PRBool b = PR_FALSE;
    702 
    703     rv = component->IsFile(&b);
    704     if (NS_FAILED(rv) || !b)
    705         return rv;
    706 #endif /* 0 */
    707 
    708     // deal only with files that have a valid extension
    709     PRBool validExtension = PR_FALSE;
    710 
    711 #if defined(XP_MAC)  // sdagley dougt fix
    712     // rjc - on Mac, check the file's type code (skip checking the creator code)
    713 
    714     nsCOMPtr<nsILocalFileMac> localFileMac = do_QueryInterface(component);
    715     if (localFileMac)
    716     {
    717       OSType    type;
    718       rv = localFileMac->GetFileType(&type);
    719       if (NS_SUCCEEDED(rv))
    720       {
    721         // on Mac, Mozilla shared libraries are of type 'shlb'
    722         // Note: we don't check the creator (which for Mozilla is 'MOZZ')
    723         // so that 3rd party shared libraries will be noticed!
    724         validExtension = ((type == 'shlb') || (type == 'NSPL'));
    725       }
    726     }
    727 
    728 #else
    729     nsCAutoString leafName;
    730     rv = component->GetNativeLeafName(leafName);
    731     if (NS_FAILED(rv)) return rv;
    732     int flen = leafName.Length();
    733     for (int i=0; ValidDllExtensions[i] != NULL; i++)
    734     {
    735         int extlen = PL_strlen(ValidDllExtensions[i]);
    736 
    737         // Does fullname end with this extension
    738         if (flen >= extlen &&
    739             !PL_strcasecmp(leafName.get() + (flen - extlen), ValidDllExtensions[i])
    740             )
    741         {
    742             validExtension = PR_TRUE;
    743             break;
    744         }
    745     }
    746 #endif
    747 
    748     if (validExtension == PR_FALSE)
    749         // Skip invalid extensions
    750         return NS_OK;
    751 
    752 #else /* VBOX */
    753553    /* VBox: Only one valid suffix exist, so dispense with the the list. */
    754 # ifdef RT_OS_DARWIN
    755 #  ifdef VBOX_IN_32_ON_64_MAIN_API
     554#ifdef RT_OS_DARWIN
     555# ifdef VBOX_IN_32_ON_64_MAIN_API
    756556    static const char s_szSuff[]        = "-x86.dylib";
    757 #  else
     557# else
    758558    static const char s_szSuff[]        = ".dylib";
    759559    static const char s_szSuffInvalid[] = "-x86.dylib";
    760 #  endif
    761 # elif defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
    762 #  ifdef VBOX_IN_32_ON_64_MAIN_API
     560# endif
     561#elif defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
     562# ifdef VBOX_IN_32_ON_64_MAIN_API
    763563    static const char s_szSuff[]        = "-x86.dll";
    764 #else
     564# else
    765565    static const char s_szSuff[]        = ".dll";
    766566    static const char s_szSuffInvalid[] = "-x86.dll";
    767 #  endif
     567# endif
     568#else
     569# ifdef VBOX_IN_32_ON_64_MAIN_API
     570    static const char s_szSuff[]        = "-x86.so";
    768571# else
    769 #  ifdef VBOX_IN_32_ON_64_MAIN_API
    770     static const char s_szSuff[]        = "-x86.so";
    771 #else
    772572    static const char s_szSuff[]        = ".so";
    773573    static const char s_szSuffInvalid[] = "-x86.so";
    774 #  endif
    775574# endif
     575#endif
    776576
    777577    nsCAutoString strLeafName;
     
    783583        || PL_strcasecmp(strLeafName.get() + cchLeafName - sizeof(s_szSuff) + 1, s_szSuff))
    784584    {
    785         PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("Skipping '%s'...", strLeafName.get()));
     585        Log(("Skipping '%s'...", strLeafName.get()));
    786586        return NS_OK; /* skip */
    787587    }
    788 # ifndef VBOX_IN_32_ON_64_MAIN_API
     588#ifndef VBOX_IN_32_ON_64_MAIN_API
    789589    if (   cchLeafName >= sizeof(s_szSuffInvalid)
    790590        && !PL_strcasecmp(strLeafName.get() + cchLeafName - sizeof(s_szSuffInvalid) + 1, s_szSuffInvalid))
    791591    {
    792         PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("Skipping '%s' (#2)...", strLeafName.get()));
     592        Log(("Skipping '%s' (#2)...", strLeafName.get()));
    793593        return NS_OK; /* skip */
    794594    }
    795 # endif
    796     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("... '%s'", strLeafName.get()));
    797 #endif /* VBOX */
     595#endif
     596    Log(("... '%s'", strLeafName.get()));
    798597
    799598    nsXPIDLCString persistentDescriptor;
     
    820619        if (!dll->HasChanged())
    821620        {
    822 #ifdef PR_LOGGING
    823             nsXPIDLCString displayPath;
    824             dll->GetDisplayPath(displayPath);
    825 
    826621            // Dll hasn't changed. Skip.
    827             PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
    828                    ("nsNativeComponentLoader: + nsDll not changed \"%s\". Skipping...",
    829                     displayPath.get()));
    830 #endif
     622            nsLogDllMsg(dll, "Skipping because nsDll has not changed");
    831623            *registered = PR_TRUE;
    832624            return NS_OK;
     
    880672                // Dll doesn't want to be unloaded. Cannot re-register
    881673                // this dll.
    882 #ifdef PR_LOGGING
    883                 nsXPIDLCString displayPath;
    884                 dll->GetDisplayPath(displayPath);
    885 
    886                 PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
    887                        ("nsNativeComponentLoader: *** Dll already loaded. "
    888                         "Cannot unload either. Hence cannot re-register "
    889                         "\"%s\". Skipping...", displayPath.get()));
    890 #endif
     674                nsLogDllMsg(dll, "Skipping because Dll already loaded. "
     675                                 "Cannot unload either. Hence cannot re-register");
    891676                return rv;
    892677            }
     
    895680                                // ok to unload it.
    896681                dll->Unload();
    897 #ifdef PR_LOGGING
    898                 nsXPIDLCString displayPath;
    899                 dll->GetDisplayPath(displayPath);
    900                 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
    901                        ("nsNativeComponentLoader: + Unloading \"%s\". (no CanUnloadProc).",
    902                         displayPath.get()));
    903 #endif
     682                nsLogDllMsg(dll, "+ Unloading (no canUnloadProc)");
    904683            }
    905684
     
    912691            // is unloaded. And here we are with the dll still
    913692            // loaded. Whoever taught dp programming...
    914 #ifdef PR_LOGGING
    915             nsXPIDLCString displayPath;
    916             dll->GetDisplayPath(displayPath);
    917             PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
    918                    ("nsNativeComponentLoader: Dll still loaded. Cannot re-register "
    919                     "\"%s\". Skipping...", displayPath.get()));
    920 #endif
     693            nsLogDllMsg(dll, "Skipping because Dll still loaded. Cannot re-register");
    921694            return NS_ERROR_FAILURE;
    922695        }
     
    947720            return NS_OK;
    948721        } else {
    949 #ifdef PR_LOGGING
    950             nsXPIDLCString displayPath;
    951             dll->GetDisplayPath(displayPath);
    952 
    953             PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
    954                    ("nsNativeComponentLoader: Autoregistration FAILED for "
    955                     "\"%s\". Skipping...", displayPath.get()));
    956 #endif
     722            nsLogDllMsg(dll, "Skipping because Autoregistration FAILED for");
    957723            return NS_ERROR_FACTORY_NOT_REGISTERED;
    958724        }
     
    960726    else
    961727    {
    962 #ifdef PR_LOGGING
    963         nsXPIDLCString displayPath;
    964         dll->GetDisplayPath(displayPath);
    965 
    966         PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
    967                ("nsNativeComponentLoader: Autoregistration Passed for "
    968                 "\"%s\".", displayPath.get()));
    969 #endif
     728        nsLogDllMsg(dll, "Autoregistration Passed for");
    970729        // Marking dll along with modified time and size in the
    971730        // registry happens at PlatformRegister(). No need to do it
     
    980739                                                    PRBool *aRegistered)
    981740{
    982 #ifdef DEBUG
    983     fprintf(stderr, "nNCL: registering deferred (%d)\n",
    984             mDeferredComponents.Count());
    985 #endif
     741    Log(("nNCL: registering deferred (%d)\n", mDeferredComponents.Count()));
     742
    986743    *aRegistered = PR_FALSE;
    987744    if (!mDeferredComponents.Count())
     
    999756        }
    1000757    }
    1001 #ifdef DEBUG
     758
    1002759    if (*aRegistered)
    1003         fprintf(stderr, "nNCL: registered deferred, %d left\n",
    1004                 mDeferredComponents.Count());
     760        Log(("nNCL: registered deferred, %d left\n", mDeferredComponents.Count()));
    1005761    else
    1006         fprintf(stderr, "nNCL: didn't register any components, %d left\n",
    1007                 mDeferredComponents.Count());
    1008 #endif
     762        Log(("nNCL: didn't register any components, %d left\n", mDeferredComponents.Count()));
     763
    1009764    /* are there any fatal errors? */
    1010765    return NS_OK;
     
    1025780nsNativeComponentLoader::UnloadAll(PRInt32 aWhen)
    1026781{
    1027     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsNativeComponentLoader: Unloading...."));
     782    Log(("nsNativeComponentLoader: Unloading...."));
    1028783
    1029784    struct freeLibrariesClosure callData;
Note: See TracChangeset for help on using the changeset viewer.

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