VirtualBox

Changeset 51116 in vbox for trunk


Ignore:
Timestamp:
Apr 22, 2014 11:33:47 AM (11 years ago)
Author:
vboxsync
Message:

Mac OS X host: VBoxUSB.kext: added extra logging in order track VBoxUSBClient instance reference count dynamics.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/darwin/VBoxUSB.cpp

    r51107 r51116  
    6666RT_C_DECLS_END
    6767
     68/* Temporary: Extra logging */
     69#ifdef Log
     70# undef Log
     71#endif
     72#define Log LogRel
     73#ifdef Log2
     74# undef Log2
     75#endif
     76#define Log2 LogRel
     77/* Temporary: needed for extra debug info */
     78#define VBOX_PROC_SELFNAME_LEN  (20)
     79
    6880
    6981/*******************************************************************************
     
    133145    virtual void stop(IOService *pProvider);
    134146    virtual void free();
     147    virtual void retain() const;
     148    virtual void release(int freeWhen) const;
     149    virtual void taggedRetain(const void *pTag=0) const;
     150    virtual void taggedRelease(const void *pTag, const int freeWhen) const;
    135151    virtual IOExternalMethod *getTargetAndMethodForIndex(IOService **ppService, UInt32 iMethod);
    136152    /** @} */
     
    446462{
    447463    uint32_t cInstances = ASMAtomicIncU32(&g_cInstances);
    448     Log(("VBoxUSB::init([%p], %p) new g_cInstances=%d\n", this, pDictionary, cInstances));
     464    Log(("VBoxUSB::init([%p], %p) new g_cInstances=%d [retain count: %d]\n", this, pDictionary, cInstances, getRetainCount()));
    449465    if (IOService::init(pDictionary))
    450466    {
    451467        /* init members. */
     468        Log(("VBoxUSB::init([%p], %p) returns true [retain count: %d]\n", this, pDictionary, getRetainCount()));
    452469        return true;
    453470    }
    454471    ASMAtomicDecU32(&g_cInstances);
     472    Log(("VBoxUSB::init([%p], %p) returns false [retain count: %d]\n", this, pDictionary, getRetainCount()));
    455473    return false;
    456474}
     
    465483{
    466484    uint32_t cInstances = ASMAtomicDecU32(&g_cInstances); NOREF(cInstances);
    467     Log(("VBoxUSB::free([%p]) new g_cInstances=%d\n", this, cInstances));
     485    Log(("VBoxUSB::free([%p]) new g_cInstances=%d [retain count: %d]\n", this, cInstances, getRetainCount()));
    468486    IOService::free();
    469487}
     
    476494org_virtualbox_VBoxUSB::start(IOService *pProvider)
    477495{
    478     Log(("VBoxUSB::start([%p], %p {%s})\n", this, pProvider, pProvider->getName()));
     496    Log(("VBoxUSB::start([%p], %p {%s}) [retain count: %d]\n", this, pProvider, pProvider->getName(), getRetainCount()));
    479497
    480498    if (IOService::start(pProvider))
     
    482500        /* register the service. */
    483501        registerService();
     502        Log(("VBoxUSB::start([%p], %p {%s}) returns true [retain count: %d]\n", this, pProvider, pProvider->getName(), getRetainCount()));
    484503        return true;
    485504    }
     505
     506    Log(("VBoxUSB::start([%p], %p {%s}) returns false [retain count: %d]\n", this, pProvider, pProvider->getName(), getRetainCount()));
    486507    return false;
    487508}
     
    495516org_virtualbox_VBoxUSB::stop(IOService *pProvider)
    496517{
    497     Log(("VBoxUSB::stop([%p], %p (%s))\n", this, pProvider, pProvider->getName()));
     518    Log(("VBoxUSB::stop([%p], %p (%s)) (1) [retain count: %d]\n", this, pProvider, pProvider->getName(), getRetainCount()));
    498519    IOService::stop(pProvider);
     520    Log(("VBoxUSB::stop([%p], %p (%s)) (2) [retain count: %d]\n", this, pProvider, pProvider->getName(), getRetainCount()));
    499521}
    500522
     
    507529org_virtualbox_VBoxUSB::open(IOService *pForClient, IOOptionBits fOptions/* = 0*/, void *pvArg/* = 0*/)
    508530{
    509     Log(("VBoxUSB::open([%p], %p, %#x, %p)\n", this, pForClient, fOptions, pvArg));
     531    Log(("VBoxUSB::open([%p], %p, %#x, %p) [retain count: %d]\n", this, pForClient, fOptions, pvArg, getRetainCount()));
    510532    bool fRc = IOService::open(pForClient, fOptions, pvArg);
    511     Log(("VBoxUSB::open([%p], %p, %#x, %p) -> %d\n", this, pForClient, fOptions, pvArg, fRc));
     533    Log(("VBoxUSB::open([%p], %p, %#x, %p) -> %d [retain count: %d]\n", this, pForClient, fOptions, pvArg, fRc, getRetainCount()));
    512534    return fRc;
    513535}
     
    521543org_virtualbox_VBoxUSB::close(IOService *pForClient, IOOptionBits fOptions/* = 0*/)
    522544{
    523     Log(("VBoxUSB::close([%p], %p, %#x)\n", this, pForClient, fOptions));
    524545    IOService::close(pForClient, fOptions);
     546    Log(("VBoxUSB::close([%p], %p, %#x) [retain count: %d]\n", this, pForClient, fOptions, getRetainCount()));
    525547}
    526548
     
    533555org_virtualbox_VBoxUSB::terminate(IOOptionBits fOptions)
    534556{
    535     Log(("VBoxUSB::terminate([%p], %#x): g_cInstances=%d\n", this, fOptions, g_cInstances));
     557    Log(("VBoxUSB::terminate([%p], %#x): g_cInstances=%d [retain count: %d]\n", this, fOptions, g_cInstances, getRetainCount()));
    536558    bool fRc = IOService::terminate(fOptions);
    537     Log(("VBoxUSB::terminate([%p], %#x): returns %d\n", this, fOptions, fRc));
     559    Log(("VBoxUSB::terminate([%p], %#x): returns %d [retain count: %d]\n", this, fOptions, fRc, getRetainCount()));
    538560    return fRc;
    539561}
     
    564586    if (!OwningTask)
    565587    {
    566         Log(("VBoxUSBClient::initWithTask([%p], %p, %p, %#x) -> false (no task)\n", this, OwningTask, pvSecurityId, u32Type));
     588        Log(("VBoxUSBClient::initWithTask([%p], %p, %p, %#x) -> false (no task) [retain count: %d]\n", this, OwningTask, pvSecurityId, u32Type, getRetainCount()));
    567589        return false;
    568590    }
     591
     592    char pszProcName[VBOX_PROC_SELFNAME_LEN];
     593    proc_selfname(pszProcName, VBOX_PROC_SELFNAME_LEN);
     594
    569595    proc_t pProc = (proc_t)get_bsdtask_info(OwningTask); /* we need the pid */
    570     Log(("VBoxUSBClient::initWithTask([%p], %p(->%p:{.pid=%d}, %p, %#x)\n",
    571              this, OwningTask, pProc, pProc ? proc_pid(pProc) : -1, pvSecurityId, u32Type));
     596    Log(("VBoxUSBClient::initWithTask([%p], %p(->%p:{.pid=%d (%s)}, %p, %#x) [retain count: %d]\n",
     597             this, OwningTask, pProc, pProc ? proc_pid(pProc) : -1, pszProcName, pvSecurityId, u32Type, getRetainCount()));
    572598
    573599    if (IOUserClient::initWithTask(OwningTask, pvSecurityId , u32Type))
     
    579605
    580606        uint32_t cInstances = ASMAtomicIncU32(&g_cInstances);
    581         Log(("VBoxUSBClient::initWithTask([%p], %p(->%p:{.pid=%d}, %p, %#x) -> true; new g_cInstances=%d\n",
    582                  this, OwningTask, pProc, pProc ? proc_pid(pProc) : -1, pvSecurityId, u32Type, cInstances));
     607        Log(("VBoxUSBClient::initWithTask([%p], %p(->%p:{.pid=%d (%s)}, %p, %#x) -> true; new g_cInstances=%d [retain count: %d]\n",
     608                 this, OwningTask, pProc, pProc ? proc_pid(pProc) : -1, pszProcName, pvSecurityId, u32Type, cInstances, getRetainCount()));
    583609        return true;
    584610    }
    585611
    586     Log(("VBoxUSBClient::initWithTask([%p], %p(->%p:{.pid=%d}, %p, %#x) -> false\n",
    587              this, OwningTask, pProc, pProc ? proc_pid(pProc) : -1, pvSecurityId, u32Type));
     612    Log(("VBoxUSBClient::initWithTask([%p], %p(->%p:{.pid=%d (%s)}, %p, %#x) -> false [retain count: %d]\n",
     613             this, OwningTask, pProc, pProc ? proc_pid(pProc) : -1, pszProcName, pvSecurityId, u32Type, getRetainCount()));
    588614    return false;
    589615}
     
    598624{
    599625    uint32_t cInstances = ASMAtomicDecU32(&g_cInstances); NOREF(cInstances);
    600     Log(("VBoxUSBClient::free([%p]) new g_cInstances=%d\n", this, cInstances));
     626    Log(("VBoxUSBClient::free([%p]) new g_cInstances=%d [retain count: %d]\n", this, cInstances, getRetainCount()));
    601627    IOUserClient::free();
     628}
     629
     630
     631/**
     632 * Retain the object.
     633 * @remark  Only for logging.
     634 */
     635void
     636org_virtualbox_VBoxUSBClient::retain() const
     637{
     638    char pszProcName[VBOX_PROC_SELFNAME_LEN];
     639    proc_selfname(pszProcName, VBOX_PROC_SELFNAME_LEN);
     640
     641    Log(("VBoxUSBClient::retain([%p]) (1) pszProcName=[%s] [retain count: %d]\n", this, pszProcName, getRetainCount()));
     642    IOUserClient::retain();
     643    Log(("VBoxUSBClient::retain([%p]) (2) pszProcName=[%s] [retain count: %d]\n", this, pszProcName, getRetainCount()));
     644}
     645
     646
     647/**
     648 * Release the object.
     649 * @remark  Only for logging.
     650 */
     651void
     652org_virtualbox_VBoxUSBClient::release(int freeWhen) const
     653{
     654    char pszProcName[VBOX_PROC_SELFNAME_LEN];
     655    proc_selfname(pszProcName, VBOX_PROC_SELFNAME_LEN);
     656
     657    Log(("VBoxUSBClient::release([%p], freeWhen=%d) pszProcName=[%s] [retain count: %d]\n", this, freeWhen, pszProcName, getRetainCount()));
     658    IOUserClient::release(freeWhen);
     659}
     660
     661
     662/**
     663 * Tagged retain the object.
     664 * @remark  Only for logging.
     665 */
     666void
     667org_virtualbox_VBoxUSBClient::taggedRetain(const void *pTag) const
     668{
     669    char pszProcName[VBOX_PROC_SELFNAME_LEN];
     670    proc_selfname(pszProcName, VBOX_PROC_SELFNAME_LEN);
     671
     672    Log(("VBoxUSBClient::taggedRetain([%p], [pTag=%p]) (1) pszProcName=[%s] [retain count: %d]\n", this, pTag, pszProcName, getRetainCount()));
     673    IOUserClient::taggedRetain(pTag);
     674    Log(("VBoxUSBClient::taggedRetain([%p], [pTag=%p]) (2) pszProcName=[%s] [retain count: %d]\n", this, pTag, pszProcName, getRetainCount()));
     675}
     676
     677
     678/**
     679 * Tagged release the object.
     680 * @remark  Only for logging.
     681 */
     682void
     683org_virtualbox_VBoxUSBClient::taggedRelease(const void *pTag, const int freeWhen) const
     684{
     685    char pszProcName[VBOX_PROC_SELFNAME_LEN];
     686    proc_selfname(pszProcName, VBOX_PROC_SELFNAME_LEN);
     687
     688    Log(("VBoxUSBClient::taggedRelease([%p], [pTag=%p], [freeWhen=%d]) pszProcName=[%s] [retain count: %d]\n", this, pTag, freeWhen, pszProcName, getRetainCount()));
     689    IOUserClient::taggedRelease(pTag, freeWhen);
    602690}
    603691
     
    609697org_virtualbox_VBoxUSBClient::start(IOService *pProvider)
    610698{
    611     Log(("VBoxUSBClient::start([%p], %p)\n", this, pProvider));
     699    Log(("VBoxUSBClient::start([%p], %p) [retain count: %d]\n", this, pProvider, getRetainCount()));
    612700    if (IOUserClient::start(pProvider))
    613701    {
     
    625713            VBOXUSB_UNLOCK();
    626714
     715            Log(("VBoxUSBClient::start([%p]): returns true [retain count: %d]\n", this, getRetainCount()));
    627716            return true;
    628717        }
    629         Log(("VBoxUSBClient::start: %p isn't org_virtualbox_VBoxUSB\n", pProvider));
    630     }
     718        Log(("VBoxUSBClient::start: %p isn't org_virtualbox_VBoxUSB [retain count: %d]\n", pProvider, getRetainCount()));
     719    }
     720
     721    Log(("VBoxUSBClient::start([%p]): returns false [retain count: %d]\n", this, getRetainCount()));
    631722    return false;
    632723}
     
    639730org_virtualbox_VBoxUSBClient::clientClose(void)
    640731{
    641     Log(("VBoxUSBClient::clientClose([%p:{.m_Process=%d}])\n", this, (int)m_Process));
     732    Log(("VBoxUSBClient::clientClose([%p:{.m_Process=%d}]) [retain count: %d]\n", this, (int)m_Process, getRetainCount()));
    642733
    643734    /*
     
    682773    terminate();
    683774
     775    Log(("VBoxUSBClient::clientClose([%p:{.m_Process=%d}]) return kIOReturnSuccess [retain count: %d]\n", this, (int)m_Process, getRetainCount()));
     776
    684777    return kIOReturnSuccess;
    685778}
     
    693786org_virtualbox_VBoxUSBClient::clientDied(void)
    694787{
    695     Log(("VBoxUSBClient::clientDied([%p]) m_Task=%p R0Process=%p Process=%d\n",
    696              this, m_Task, RTR0ProcHandleSelf(), RTProcSelf()));
    697 
     788    Log(("VBoxUSBClient::clientDied([%p]) m_Task=%p R0Process=%p Process=%d\n [retain count: %d]",
     789             this, m_Task, RTR0ProcHandleSelf(), RTProcSelf(), getRetainCount()));
    698790    /* IOUserClient::clientDied() calls clientClose... */
    699     return IOUserClient::clientDied();
     791    bool fRc = IOUserClient::clientDied();
     792    Log(("VBoxUSBClient::clientDied([%p]): returns %d [retain count: %d]\n", this, fRc, getRetainCount()));
     793    return fRc;
    700794}
    701795
     
    709803{
    710804    /* kIOServiceRecursing, kIOServiceRequired, kIOServiceTerminate, kIOServiceSynchronous - interesting option bits */
    711     Log(("VBoxUSBClient::terminate([%p], %#x)\n", this, fOptions));
    712     return IOUserClient::terminate(fOptions);
     805    Log(("VBoxUSBClient::terminate([%p], %#x) [retain count: %d]\n", this, fOptions, getRetainCount()));
     806    bool fRc = IOUserClient::terminate(fOptions);
     807    Log(("VBoxUSBClient::terminate([%p]): returns %d [retain count: %d]\n", this, fRc, getRetainCount()));
     808    return fRc;
    713809}
    714810
     
    721817org_virtualbox_VBoxUSBClient::finalize(IOOptionBits fOptions)
    722818{
    723     Log(("VBoxUSBClient::finalize([%p], %#x)\n", this, fOptions));
    724     return IOUserClient::finalize(fOptions);
     819    Log(("VBoxUSBClient::finalize([%p], %#x) [retain count: %d]\n", this, fOptions, getRetainCount()));
     820    bool fRc = IOUserClient::finalize(fOptions);
     821    Log(("VBoxUSBClient::finalize([%p]): returns %d [retain count: %d]\n", this, fRc, getRetainCount()));
     822    return fRc;
    725823}
    726824
     
    732830org_virtualbox_VBoxUSBClient::stop(IOService *pProvider)
    733831{
    734     Log(("VBoxUSBClient::stop([%p])\n", this));
     832    Log(("VBoxUSBClient::stop([%p]) (1) [retain count: %d]\n", this, getRetainCount()));
    735833    IOUserClient::stop(pProvider);
     834    Log(("VBoxUSBClient::stop([%p]) (2) [retain count: %d]\n", this, getRetainCount()));
    736835
    737836    /*
     
    12951394        m_fBeingUnloaded = true;
    12961395
    1297     return IOUSBUserClientInit::terminate(fOptions);
     1396    bool fRc = IOUSBUserClientInit::terminate(fOptions);
     1397    Log(("VBoxUSBDevice::terminate([%p]): returns %d\n", this, fRc));
     1398    return fRc;
    12981399}
    12991400
     
    17431844    /* kIOServiceRecursing, kIOServiceRequired, kIOServiceTerminate, kIOServiceSynchronous - interesting option bits */
    17441845    Log(("VBoxUSBInterface::terminate([%p], %#x)\n", this, fOptions));
    1745     return IOUSBUserClientInit::terminate(fOptions);
     1846    bool fRc = IOUSBUserClientInit::terminate(fOptions);
     1847    Log(("VBoxUSBInterface::terminate([%p]): returns %d\n", this, fRc));
     1848    return fRc;
    17461849}
    17471850
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