VirtualBox

Changeset 3376 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jul 3, 2007 8:21:03 AM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
22574
Message:

Some code for dumping iokit registry objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/darwin/iokit.cpp

    r2981 r3376  
    2828*   Header Files                                                               *
    2929*******************************************************************************/
     30#define LOG_GROUP LOG_GROUP_MAIN
     31
    3032#include <mach/mach.h>
    3133#include <Carbon/Carbon.h>
     
    3941#endif
    4042
     43#include <VBox/log.h>
    4144#include <iprt/mem.h>
    4245#include <iprt/string.h>
     
    186189    return false;
    187190}
     191
     192
     193#if 1 /* dumping disabled */
     194# define DARWIN_IOKIT_LOG(a)         Log(a)
     195# define DARWIN_IOKIT_LOG_FLUSH()    do {} while (0)
     196# define DARWIN_IOKIT_DUMP_OBJ(o)    do {} while (0)
     197#else
     198# if 0
     199#  include <iprt/stream.h>
     200#  define DARWIN_IOKIT_LOG(a) RTPrintf a
     201#  define DARWIN_IOKIT_LOG_FLUSH() RTStrmFlush(g_pStdOut)
     202# else
     203#  define DARWIN_IOKIT_LOG(a) RTLogPrintf a
     204#  define DARWIN_IOKIT_LOG(a) RTLogFlush()
     205# endif
     206# define DARWIN_IOKIT_DUMP_OBJ(o)    darwinDumpObj(o)
     207
     208/**
     209 * Callback for dumping a dictionary key.
     210 *
     211 * @param   pvKey       The key name.
     212 * @param   pvValue     The key value
     213 * @param   pvUser      The recursion depth.
     214 */
     215static void darwinDumpDictCallback(const void *pvKey, const void *pvValue, void *pvUser)
     216{
     217    /* display the key name. */
     218    char *pszKey = (char *)RTMemTmpAlloc(1024);
     219    if (!CFStringGetCString((CFStringRef)pvKey, pszKey, 1024, kCFStringEncodingUTF8))
     220        strcpy(pszKey, "CFStringGetCString failure");
     221    DARWIN_IOKIT_LOG(("%+*s%s", (int)(uintptr_t)pvUser, "", pszKey));
     222    RTMemTmpFree(pszKey);
     223
     224    /* display the value type */
     225    CFTypeID Type = CFGetTypeID(pvValue);
     226    DARWIN_IOKIT_LOG((" [%d-", Type));
     227
     228    /* display the value */
     229    if (Type == CFDictionaryGetTypeID())
     230    {
     231        DARWIN_IOKIT_LOG(("dictionary] =\n"
     232                     "%-*s{\n", (int)(uintptr_t)pvUser, ""));
     233        CFDictionaryApplyFunction((CFDictionaryRef)pvValue, darwinDumpDictCallback, (void *)((uintptr_t)pvUser + 4));
     234        DARWIN_IOKIT_LOG(("%-*s}\n", (int)(uintptr_t)pvUser, ""));
     235    }
     236    else if (Type == CFNumberGetTypeID())
     237    {
     238        union
     239        {
     240            SInt8 s8;
     241            SInt16 s16;
     242            SInt32 s32;
     243            SInt64 s64;
     244            Float32 rf32;
     245            Float64 rd64;
     246            char ch;
     247            short s;
     248            int i;
     249            long l;
     250            long long ll;
     251            float rf;
     252            double rd;
     253            CFIndex iCF;
     254        } u;
     255        memset(&u, 0, sizeof(u));
     256        CFNumberType NumType = CFNumberGetType((CFNumberRef)pvValue);
     257        if (CFNumberGetValue((CFNumberRef)pvValue, NumType, &u))
     258        {
     259            switch (CFNumberGetType((CFNumberRef)pvValue))
     260            {
     261                case kCFNumberSInt8Type:    DARWIN_IOKIT_LOG(("SInt8] = %RI8 (%#RX8)\n", NumType, u.s8, u.s8)); break;
     262                case kCFNumberSInt16Type:   DARWIN_IOKIT_LOG(("SInt16] = %RI16 (%#RX16)\n", NumType, u.s16, u.s16)); break;
     263                case kCFNumberSInt32Type:   DARWIN_IOKIT_LOG(("SInt32] = %RI32 (%#RX32)\n", NumType, u.s32, u.s32)); break;
     264                case kCFNumberSInt64Type:   DARWIN_IOKIT_LOG(("SInt64] = %RI64 (%#RX64)\n", NumType, u.s64, u.s64)); break;
     265                case kCFNumberFloat32Type:  DARWIN_IOKIT_LOG(("float32] = %#lx\n", NumType, u.l)); break;
     266                case kCFNumberFloat64Type:  DARWIN_IOKIT_LOG(("float64] = %#llx\n", NumType, u.ll)); break;
     267                case kCFNumberFloatType:    DARWIN_IOKIT_LOG(("float] = %#lx\n", NumType, u.l)); break;
     268                case kCFNumberDoubleType:   DARWIN_IOKIT_LOG(("double] = %#llx\n", NumType, u.ll)); break;
     269                case kCFNumberCharType:     DARWIN_IOKIT_LOG(("char] = %hhd (%hhx)\n", NumType, u.ch, u.ch)); break;
     270                case kCFNumberShortType:    DARWIN_IOKIT_LOG(("short] = %hd (%hx)\n", NumType, u.s, u.s)); break;
     271                case kCFNumberIntType:      DARWIN_IOKIT_LOG(("int] = %d (%#x)\n", NumType, u.i, u.i)); break;
     272                case kCFNumberLongType:     DARWIN_IOKIT_LOG(("long] = %ld (%#lx)\n", NumType, u.l, u.l)); break;
     273                case kCFNumberLongLongType: DARWIN_IOKIT_LOG(("long long] = %lld (%#llx)\n", NumType, u.ll, u.ll)); break;
     274                case kCFNumberCFIndexType:  DARWIN_IOKIT_LOG(("CFIndex] = %lld (%#llx)\n", NumType, (long long)u.iCF, (long long)u.iCF)); break;
     275                    break;
     276                default:                    DARWIN_IOKIT_LOG(("%d?] = %lld (%llx)\n", NumType, u.ll, u.ll)); break;
     277            }
     278        }
     279        else
     280            DARWIN_IOKIT_LOG(("number] = CFNumberGetValue failed\n"));
     281    }
     282    else if (Type == CFBooleanGetTypeID())
     283        DARWIN_IOKIT_LOG(("boolean] = %RTbool\n", CFBooleanGetValue((CFBooleanRef)pvValue)));
     284    else if (Type == CFStringGetTypeID())
     285    {
     286        DARWIN_IOKIT_LOG(("string] = "));
     287        char *pszValue = (char *)RTMemTmpAlloc(16*_1K);
     288        if (!CFStringGetCString((CFStringRef)pvValue, pszValue, 16*_1K, kCFStringEncodingUTF8))
     289            strcpy(pszValue, "CFStringGetCString failure");
     290        DARWIN_IOKIT_LOG(("\"%s\"\n", pszValue));
     291        RTMemTmpFree(pszValue);
     292    }
     293    else
     294        DARWIN_IOKIT_LOG(("??] = %p\n", pvValue));
     295}
     296
     297
     298/**
     299 * Dumps a dictionary to the log.
     300 *
     301 * @param   DictRef     The dictionary to dump.
     302 */
     303static void darwinDumpDict(CFMutableDictionaryRef DictRef, unsigned cIndents)
     304{
     305    CFDictionaryApplyFunction(DictRef, darwinDumpDictCallback, (void *)(uintptr_t)cIndents);
     306    DARWIN_IOKIT_LOG_FLUSH();
     307}
     308
     309
     310/**
     311 * Dumps an I/O kit registry object and all it children.
     312 * @param   Object      The object to dump.
     313 * @param   cIndents    The number of indents to use.
     314 */
     315static void darwinDumpObjInt(io_object_t Object, unsigned cIndents)
     316{
     317    static io_string_t s_szPath;
     318    kern_return_t krc = IORegistryEntryGetPath(Object, kIOServicePlane, s_szPath);
     319    if (krc != KERN_SUCCESS)
     320        strcpy(s_szPath, "IORegistryEntryGetPath failed");
     321    DARWIN_IOKIT_LOG(("Dumping %p - %s:\n", (const void *)Object, s_szPath));
     322
     323    CFMutableDictionaryRef PropsRef = 0;
     324    krc = IORegistryEntryCreateCFProperties(Object, &PropsRef, kCFAllocatorDefault, kNilOptions);
     325    if (krc == KERN_SUCCESS)
     326    {
     327        darwinDumpDict(PropsRef, cIndents + 4);
     328        CFRelease(PropsRef);
     329    }
     330
     331    /*
     332     * Children.
     333     */
     334    io_iterator_t Children;
     335    krc = IORegistryEntryGetChildIterator(Object, kIOServicePlane, &Children);
     336    if (krc == KERN_SUCCESS)
     337    {
     338        io_object_t Child;
     339        while ((Child = IOIteratorNext(Children)))
     340        {
     341            darwinDumpObjInt(Child, cIndents + 4);
     342            IOObjectRelease(Child);
     343        }
     344        IOObjectRelease(Children);
     345    }
     346    else
     347        DARWIN_IOKIT_LOG(("IORegistryEntryGetChildIterator -> %#x\n", krc));
     348}
     349
     350/**
     351 * Dumps an I/O kit registry object and all it children.
     352 * @param   Object      The object to dump.
     353 */
     354static void darwinDumpObj(io_object_t Object)
     355{
     356    darwinDumpObjInt(Object, 0);
     357}
     358
     359#endif
    188360
    189361
     
    221393    io_object_t Object;
    222394    while ((Object = IOIteratorNext(pIterator)))
     395    {
     396        DARWIN_IOKIT_DUMP_OBJ(Object);
    223397        IOObjectRelease(Object);
    224 }
    225 
    226 
    227 /**
    228  * Callback for the two attach notifications.
     398    }
     399}
     400
     401
     402/**
     403 * Callback for the 1st attach notification.
    229404 *
    230405 * @param   pvNotify        Our data.
    231406 * @param   NotifyIterator  The notification iterator.
    232407 */
    233 static void darwinUSBAttachNotification(void *pvNotify, io_iterator_t NotifyIterator)
    234 {
     408static void darwinUSBAttachNotification1(void *pvNotify, io_iterator_t NotifyIterator)
     409{
     410    DARWIN_IOKIT_LOG(("USB Attach Notification1\n"));
    235411    NOREF(pvNotify); //PDARWINUSBNOTIFY pNotify = (PDARWINUSBNOTIFY)pvNotify;
    236412    darwinDrainIterator(NotifyIterator);
     
    239415
    240416/**
    241  * Callback for the detach notifications.
     417 * Callback for the 2nd attach notification.
    242418 *
    243419 * @param   pvNotify        Our data.
    244420 * @param   NotifyIterator  The notification iterator.
    245421 */
     422static void darwinUSBAttachNotification2(void *pvNotify, io_iterator_t NotifyIterator)
     423{
     424    DARWIN_IOKIT_LOG(("USB Attach Notification2\n"));
     425    NOREF(pvNotify); //PDARWINUSBNOTIFY pNotify = (PDARWINUSBNOTIFY)pvNotify;
     426    darwinDrainIterator(NotifyIterator);
     427}
     428
     429
     430/**
     431 * Callback for the detach notifications.
     432 *
     433 * @param   pvNotify        Our data.
     434 * @param   NotifyIterator  The notification iterator.
     435 */
    246436static void darwinUSBDetachNotification(void *pvNotify, io_iterator_t NotifyIterator)
    247437{
     438    DARWIN_IOKIT_LOG(("USB Detach Notification\n"));
    248439    NOREF(pvNotify); //PDARWINUSBNOTIFY pNotify = (PDARWINUSBNOTIFY)pvNotify;
    249440    darwinDrainIterator(NotifyIterator);
     
    289480                                                                kIOPublishNotification,
    290481                                                                IOServiceMatching(kIOUSBDeviceClassName),
    291                                                                 darwinUSBAttachNotification,
     482                                                                darwinUSBAttachNotification1,
    292483                                                                pNotify,
    293484                                                                &pNotify->AttachIterator);
     
    298489                                                      kIOMatchedNotification,
    299490                                                      IOServiceMatching(kIOUSBDeviceClassName),
    300                                                       darwinUSBAttachNotification,
     491                                                      darwinUSBAttachNotification2,
    301492                                                      pNotify,
    302493                                                      &pNotify->AttachIterator2);
     
    365556{
    366557    AssertReturn(darwinOpenMasterPort(), NULL);
     558    //DARWIN_IOKIT_LOG(("DarwinGetUSBDevices\n"));
    367559
    368560    /*
     
    389581    while ((USBDevice = IOIteratorNext(USBDevices)) != 0)
    390582    {
     583        //DARWIN_IOKIT_DUMP_OBJ(USBDevice);
     584
    391585        /*
    392586         * Query the device properties from the registry.
     
    501695
    502696    IOObjectRelease(USBDevices);
     697    //DARWIN_IOKIT_LOG_FLUSH();
    503698
    504699    /*
Note: See TracChangeset for help on using the changeset viewer.

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