ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

debughlp.cpp
Go to the documentation of this file.
00001 /*
00002  * Helper functions for debugging
00003  *
00004  * Copyright 1998, 2002 Juergen Schmied
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <precomp.h>
00022 
00023 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
00024 
00025 static
00026 LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
00027 {
00028     WORD len;
00029 
00030     if(pidl)
00031     {
00032       len =  pidl->mkid.cb;
00033       if (len)
00034       {
00035         return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
00036       }
00037     }
00038     return NULL;
00039 }
00040 
00041 static
00042 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
00043 {
00044     return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
00045 }
00046 
00047 static
00048 LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
00049 {
00050     if(pidl && pidl->mkid.cb != 0x00)
00051       return (LPPIDLDATA) &(pidl->mkid.abID);
00052     return NULL;
00053 }
00054 
00055 static
00056 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
00057 {
00058     LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
00059 
00060     if (pdata)
00061     {
00062       switch (pdata->type)
00063       {
00064         case PT_GUID:
00065         case PT_SHELLEXT:
00066         case PT_YAGUID:
00067           return NULL;
00068 
00069         case PT_DRIVE:
00070         case PT_DRIVE1:
00071         case PT_DRIVE2:
00072         case PT_DRIVE3:
00073           return (LPSTR)&(pdata->u.drive.szDriveName);
00074 
00075         case PT_FOLDER:
00076         case PT_FOLDER1:
00077         case PT_VALUE:
00078         case PT_IESPECIAL1:
00079         case PT_IESPECIAL2:
00080           return (LPSTR)&(pdata->u.file.szNames);
00081 
00082         case PT_WORKGRP:
00083         case PT_COMP:
00084         case PT_NETWORK:
00085         case PT_NETPROVIDER:
00086         case PT_SHARE:
00087           return (LPSTR)&(pdata->u.network.szNames);
00088       }
00089     }
00090     return NULL;
00091 }
00092 
00093 static
00094 LPWSTR _dbg_ILGetTextPointerW(LPCITEMIDLIST pidl)
00095 {
00096     LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
00097 
00098     if (pdata)
00099     {
00100       switch (pdata->type)
00101       {
00102         case PT_GUID:
00103         case PT_SHELLEXT:
00104         case PT_YAGUID:
00105           return NULL;
00106 
00107         case PT_DRIVE:
00108         case PT_DRIVE1:
00109         case PT_DRIVE2:
00110         case PT_DRIVE3:
00111           /* return (LPSTR)&(pdata->u.drive.szDriveName);*/
00112           return NULL;
00113 
00114         case PT_FOLDER:
00115         case PT_FOLDER1:
00116         case PT_VALUE:
00117         case PT_IESPECIAL1:
00118         case PT_IESPECIAL2:
00119           /* return (LPSTR)&(pdata->u.file.szNames); */
00120           return NULL;
00121 
00122         case PT_WORKGRP:
00123         case PT_COMP:
00124         case PT_NETWORK:
00125         case PT_NETPROVIDER:
00126         case PT_SHARE:
00127           /* return (LPSTR)&(pdata->u.network.szNames); */
00128           return NULL;
00129 
00130         case PT_VALUEW:
00131           return (LPWSTR)&(pdata->u.file.szNames);
00132       }
00133     }
00134     return NULL;
00135 }
00136 
00137 
00138 static
00139 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
00140 {
00141     LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
00142 
00143     if (pdata)
00144     {
00145       switch (pdata->type)
00146       {
00147         case PT_FOLDER:
00148         case PT_VALUE:
00149         case PT_IESPECIAL1:
00150         case PT_IESPECIAL2:
00151           return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
00152 
00153         case PT_WORKGRP:
00154           return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
00155       }
00156     }
00157     return NULL;
00158 }
00159 
00160 static
00161 LPWSTR _dbg_ILGetSTextPointerW(LPCITEMIDLIST pidl)
00162 {
00163     LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
00164 
00165     if (pdata)
00166     {
00167       switch (pdata->type)
00168       {
00169         case PT_FOLDER:
00170         case PT_VALUE:
00171         case PT_IESPECIAL1:
00172         case PT_IESPECIAL2:
00173           /*return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1); */
00174           return NULL;
00175 
00176         case PT_WORKGRP:
00177           /* return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1); */
00178           return NULL;
00179 
00180         case PT_VALUEW:
00181           return (LPWSTR)(pdata->u.file.szNames + wcslen ((LPWSTR)pdata->u.file.szNames) + 1);
00182       }
00183     }
00184     return NULL;
00185 }
00186 
00187 
00188 static
00189 IID* _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
00190 {
00191     LPPIDLDATA pdata =_ILGetDataPointer(pidl);
00192 
00193     if (pdata)
00194     {
00195       switch (pdata->type)
00196       {
00197         case PT_SHELLEXT:
00198         case PT_GUID:
00199             case PT_YAGUID:
00200           return &(pdata->u.guid.guid);
00201       }
00202     }
00203     return NULL;
00204 }
00205 
00206 static
00207 void _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
00208 {
00209     LPSTR        szSrc;
00210     LPWSTR        szSrcW;
00211     GUID const *     riid;
00212 
00213     if (!pidl) return;
00214 
00215     if (szOut)
00216       *szOut = 0;
00217 
00218     if (_dbg_ILIsDesktop(pidl))
00219     {
00220      /* desktop */
00221       if (szOut) lstrcpynA(szOut, "Desktop", uOutSize);
00222     }
00223     else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
00224     {
00225       /* filesystem */
00226       if (szOut) lstrcpynA(szOut, szSrc, uOutSize);
00227     }
00228     else if (( szSrcW = _dbg_ILGetTextPointerW(pidl) ))
00229     {
00230       CHAR tmp[MAX_PATH];
00231       /* unicode filesystem */
00232       WideCharToMultiByte(CP_ACP,0,szSrcW, -1, tmp, MAX_PATH, NULL, NULL);
00233       if (szOut) lstrcpynA(szOut, tmp, uOutSize);
00234     }
00235     else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
00236     {
00237       if (szOut)
00238             sprintf( szOut, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
00239                  riid->Data1, riid->Data2, riid->Data3,
00240                  riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
00241                  riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
00242     }
00243 }
00244 
00245 
00246 
00247 
00248 void pdump (LPCITEMIDLIST pidl)
00249 {
00250     LPCITEMIDLIST pidltemp = pidl;
00251 
00252     if (!TRACE_ON(pidl)) return;
00253 
00254     if (! pidltemp)
00255     {
00256       MESSAGE ("-------- pidl=NULL (Desktop)\n");
00257     }
00258     else
00259     {
00260       MESSAGE ("-------- pidl=%p\n", pidl);
00261       if (pidltemp->mkid.cb)
00262       {
00263         do
00264         {
00265           if (_ILIsUnicode(pidltemp))
00266           {
00267               DWORD dwAttrib = 0;
00268               LPPIDLDATA pData   = _dbg_ILGetDataPointer(pidltemp);
00269               DWORD type = pData ? pData->type : 0;
00270               LPWSTR szLongName   = _dbg_ILGetTextPointerW(pidltemp);
00271               LPWSTR szShortName  = _dbg_ILGetSTextPointerW(pidltemp);
00272               char szName[MAX_PATH];
00273 
00274               _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
00275               if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
00276                 dwAttrib = pData->u.file.uFileAttribs;
00277 
00278               MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n",
00279                        pidltemp, pidltemp->mkid.cb, type, dwAttrib,
00280                            debugstr_a(szName), debugstr_w(szLongName), debugstr_w(szShortName));
00281           }
00282           else
00283           {
00284               DWORD dwAttrib = 0;
00285               LPPIDLDATA pData   = _dbg_ILGetDataPointer(pidltemp);
00286               DWORD type = pData ? pData->type : 0;
00287               LPSTR szLongName   = _dbg_ILGetTextPointer(pidltemp);
00288               LPSTR szShortName  = _dbg_ILGetSTextPointer(pidltemp);
00289               char szName[MAX_PATH];
00290 
00291               _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
00292               if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
00293                 dwAttrib = pData->u.file.uFileAttribs;
00294 
00295               MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n",
00296                        pidltemp, pidltemp->mkid.cb, type, dwAttrib,
00297                            debugstr_a(szName), debugstr_a(szLongName), debugstr_a(szShortName));
00298           }
00299 
00300           pidltemp = _dbg_ILGetNext(pidltemp);
00301 
00302         } while (pidltemp && pidltemp->mkid.cb);
00303       }
00304       else
00305       {
00306         MESSAGE ("empty pidl (Desktop)\n");
00307       }
00308       pcheck(pidl);
00309     }
00310 }
00311 
00312 static void dump_pidl_hex( LPCITEMIDLIST pidl )
00313 {
00314     const unsigned char *p = (const unsigned char *)pidl;
00315     const int max_bytes = 0x80;
00316 #define max_line 0x10
00317     char szHex[max_line*3+1], szAscii[max_line+1];
00318     int i, n;
00319 
00320     n = pidl->mkid.cb;
00321     if( n>max_bytes )
00322         n = max_bytes;
00323     for( i=0; i<n; i++ )
00324     {
00325         sprintf( &szHex[ (i%max_line)*3 ], "%02X ", p[i] );
00326         szAscii[ (i%max_line) ] = isprint( p[i] ) ? p[i] : '.';
00327 
00328         /* print out at the end of each line and when we're finished */
00329         if( i!=(n-1) && (i%max_line) != (max_line-1) )
00330             continue;
00331         szAscii[ (i%max_line)+1 ] = 0;
00332         ERR("%-*s   %s\n", max_line*3, szHex, szAscii );
00333     }
00334 }
00335 
00336 BOOL pcheck( LPCITEMIDLIST pidl )
00337 {
00338     DWORD type;
00339     LPCITEMIDLIST pidltemp = pidl;
00340 
00341     while( pidltemp && pidltemp->mkid.cb )
00342     {
00343         LPPIDLDATA pidlData = _dbg_ILGetDataPointer(pidltemp);
00344 
00345         if (pidlData)
00346         {
00347             type = pidlData->type;
00348             switch( type )
00349             {
00350                 case PT_CPLAPPLET:
00351                 case PT_GUID:
00352                 case PT_SHELLEXT:
00353                 case PT_DRIVE:
00354                 case PT_DRIVE1:
00355                 case PT_DRIVE2:
00356                 case PT_DRIVE3:
00357                 case PT_FOLDER:
00358                 case PT_VALUE:
00359                 case PT_VALUEW:
00360                 case PT_FOLDER1:
00361                 case PT_WORKGRP:
00362                 case PT_COMP:
00363                 case PT_NETPROVIDER:
00364                 case PT_NETWORK:
00365                 case PT_IESPECIAL1:
00366                 case PT_YAGUID:
00367                 case PT_IESPECIAL2:
00368                 case PT_SHARE:
00369                     break;
00370                 default:
00371                     ERR("unknown IDLIST %p [%p] size=%u type=%x\n",
00372                         pidl, pidltemp, pidltemp->mkid.cb,type );
00373                     dump_pidl_hex( pidltemp );
00374                     return FALSE;
00375             }
00376             pidltemp = _dbg_ILGetNext(pidltemp);
00377         }
00378         else
00379         {
00380             return FALSE;
00381         }
00382     }
00383     return TRUE;
00384 }
00385 
00386 static const struct {
00387     REFIID riid;
00388     const char *name;
00389 } InterfaceDesc[] = {
00390     {IID_IUnknown,            "IID_IUnknown"},
00391     {IID_IClassFactory,        "IID_IClassFactory"},
00392     {IID_IShellView,        "IID_IShellView"},
00393     {IID_IOleCommandTarget,    "IID_IOleCommandTarget"},
00394     {IID_IDropTarget,        "IID_IDropTarget"},
00395     {IID_IDropSource,        "IID_IDropSource"},
00396     {IID_IViewObject,        "IID_IViewObject"},
00397     {IID_IContextMenu,        "IID_IContextMenu"},
00398     {IID_IShellExtInit,        "IID_IShellExtInit"},
00399     {IID_IShellFolder,        "IID_IShellFolder"},
00400     {IID_IShellFolder2,        "IID_IShellFolder2"},
00401     {IID_IPersist,            "IID_IPersist"},
00402     {IID_IPersistFolder,        "IID_IPersistFolder"},
00403     {IID_IPersistFolder2,        "IID_IPersistFolder2"},
00404     {IID_IPersistFolder3,        "IID_IPersistFolder3"},
00405     {IID_IExtractIconA,        "IID_IExtractIconA"},
00406     {IID_IExtractIconW,        "IID_IExtractIconW"},
00407     {IID_IDataObject,        "IID_IDataObject"},
00408     {IID_IAutoComplete,            "IID_IAutoComplete"},
00409     {IID_IAutoComplete2,           "IID_IAutoComplete2"},
00410         {IID_IShellLinkA,              "IID_IShellLinkA"},
00411         {IID_IShellLinkW,              "IID_IShellLinkW"},
00412     };
00413 
00414 const char * shdebugstr_guid( const struct _GUID *id )
00415 {
00416     unsigned int i;
00417     const char* name = NULL;
00418     char clsidbuf[100];
00419 
00420     if (!id) return "(null)";
00421 
00422         for (i=0; i < sizeof(InterfaceDesc) / sizeof(InterfaceDesc[0]); i++) {
00423             if (IsEqualIID(InterfaceDesc[i].riid, *id)) name = InterfaceDesc[i].name;
00424         }
00425         if (!name) {
00426         if (HCR_GetClassNameA(*id, clsidbuf, 100))
00427             name = clsidbuf;
00428         }
00429 
00430             return wine_dbg_sprintf( "\n\t{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
00431                  id->Data1, id->Data2, id->Data3,
00432                  id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
00433                  id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
00434 }

Generated on Sat May 26 2012 04:24:53 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.