Changeset 3529


Ignore:
Timestamp:
Aug 20, 2007, 5:25:44 AM (18 years ago)
Author:
bird
Message:

it builds.

Location:
trunk/kDbg
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/kDbg/kDbg.h

    r3528 r3529  
    6868/** A specified address or an address found in the debug info is invalid. */
    6969#define KDBG_ERR_INVALID_ADDRESS                        (KDBG_ERR_BASE + 12)
     70/** The dbghelp.dll is too old or something like that. */
     71#define KDBG_ERR_DBGHLP_VERSION_MISMATCH                (KDBG_ERR_BASE + 13)
     72/** Invalid executable format. */
     73#define KDBG_ERR_BAD_EXE_FORMAT                         (KDBG_ERR_BASE + 14)
    7074
    7175/** @} */
  • trunk/kDbg/kDbgHlp.h

    r3528 r3529  
    119119
    120120/**
     121 * Gets the native file handle.
     122 *
     123 * @return  The native file handle.
     124 *          -1 on failure.
     125 * @param   pFile           The file handle.
     126 */
     127uintptr_t kDbgHlpNativeFileHandle(PKDBGHLPFILE pFile);
     128
     129/**
    121130 * Gets the size of an open file.
    122131 *
     
    206215#endif
    207216
     217/**
     218 * Helper function that displays the first part of the assertion message.
     219 *
     220 * @param   pszExpr         The expression.
     221 * @param   pszFile         The file name.
     222 * @param   iLine           The line number is the file.
     223 * @param   pszFunction     The function name.
     224 */
     225void kDbgAssertMsg1(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction);
     226
     227/**
     228 * Helper function that displays custom assert message.
     229 *
     230 * @param   pszFormat       Format string that get passed to vprintf.
     231 * @param   ...             Format arguments.
     232 */
     233void kDbgAssertMsg2(const char *pszFormat, ...);
     234
     235
    208236#ifdef KDBG_STRICT
     237
    209238# define kDbgAssert(expr) \
    210239    do { \
     
    246275        }
    247276    } while (0)
     277
    248278#else   /* !KDBG_STRICT */
    249279# define kDbgAssert(expr)                       do { } while (0)
    250 # define kDbgAssertReturn(expr, rcRet)          do { } while (0)
     280# define kDbgAssertReturn(expr, rcRet)          return (rcRet)
    251281# define kDbgAssertMsg(expr, msg)               do { } while (0)
    252 # define kDbgAssertMsgReturn(expr, msg, rcRet)  do { } while (0)
     282# define kDbgAssertMsgReturn(expr, msg, rcRet)  return (rcRet)
    253283#endif  /* !KDBG_STRICT */
    254284
     
    257287#define kDbgAssertRC(rc)                        kDbgAssertMsg((rc) == 0, ("%s = %d\n", #rc, (rc)))
    258288#define kDbgAssertRCReturn(rc, rcRet)           kDbgAssertMsgReturn((rc) == 0, ("%s = %d -> %d\n", #rc, (rc), (rcRet)), (rcRet))
     289#define kDbgAssertFailed()                      kDbgAssert(0)
     290#define kDbgAssertFailedReturn(rcRet)           kDbgAssertReturn(0, (rcRet))
     291#define kDbgAssertMsgFailed(msg)                kDbgAssertMsg(0, msg)
     292#define kDbgAssertMsgFailedReturn(msg, rcRet)   kDbgAssertMsgReturn(0, msg, (rcRet))
    259293
    260294/** @} */
  • trunk/kDbg/kDbgHlpCrt.cpp

    r3528 r3529  
    3333#include <string.h>
    3434#include <errno.h>
     35#ifdef _MSC_VER
     36# include <io.h>
     37#endif
    3538
    3639
     
    126129
    127130
     131uintptr_t kDbgHlpNativeFileHandle(PKDBGHLPFILE pFile)
     132{
     133    int fd = fileno(pFile->pStrm);
     134#ifdef _MSC_VER
     135    return _get_osfhandle(fd);
     136#else
     137    return fd;
     138#endif
     139}
     140
     141
    128142int64_t kDbgHlpFileSize(PKDBGHLPFILE pFile)
    129143{
  • trunk/kDbg/kDbgModPE-generic.cpp

    r3528 r3529  
    6363 * @param   puRVA       Where to store the RVA on success.
    6464 */
    65 static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
     65static int kDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
    6666{
    6767    if (iSegment >= 0)
     
    8383        return 0;
    8484    }
    85     AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
     85    kDbgAssertMsgFailedReturn(("iSegment=%d\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
    8686}
    8787
     
    9797 * @param   poff        Where to store the segment offset.
    9898 */
    99 static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
     99static int kDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
    100100{
    101101    kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage),
     
    112112        }
    113113    }
    114     AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
     114    kDbgAssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
    115115}
    116116
     
    119119 * @copydoc KDBGMODOPS::pfnQueryLine
    120120 */
    121 static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
     121static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
    122122{
    123123    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     
    127127     */
    128128    uint32_t uRVA;
    129     int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     129    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    130130    if (!rc)
    131131    {
     
    137137        {
    138138            pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase);
    139             rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
     139            rc = kDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
    140140            pLine->iLine = Line.LineNumber;
    141141            pLine->cchFile = strlen(Line.FileName);
     
    147147        {
    148148            DWORD Err = GetLastError();
    149             rc = RTErrConvertFromWin32(Err);
     149            rc = kDbgModPeConvWinError(Err);
    150150        }
    151151#endif
     
    159159 * @copydoc KDBGMODOPS::pfnQuerySymbol
    160160 */
    161 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
     161static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
    162162{
    163163    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     
    167167     */
    168168    uint32_t uRVA;
    169     int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     169    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    170170    if (!rc)
    171171    {
     
    200200            {
    201201                pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase);
    202                 rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
     202                rc = kDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
    203203            }
    204204            pSym->cchName = (uint16_t)Buf.Sym.NameLen;
     
    211211        {
    212212            DWORD Err = GetLastError();
    213             rc = RTErrConvertFromWin32(Err);
     213            rc = kDbgModPeConvWinError(Err);
    214214        }
    215215#endif
     
    223223 * @copydoc KDBGMODOPS::pfnClose
    224224 */
    225 static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod)
     225static int rtDbgModPEClose(PKDBGMOD pMod)
    226226{
    227227    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     
    231231    //
    232232    //DWORD Err = GetLastError();
    233     //int rc = RTErrConvertFromWin32(Err);
    234     //AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
     233    //int rc = kDbgModPeConvWinError(Err);
     234    //kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
    235235    //return rc;
    236236    return VERR_NOT_IMPLEMENTED;
     
    255255 * @returns IPRT status code.
    256256 *
    257  * @param   File                The handle to the module.
     257 * @param   pFile               The handle to the module.
    258258 * @param   offHdr              The offset of the PE header.
    259259 * @param   pszModulePath       The path to the module.
     
    261261 *
    262262 */
    263 int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
     263int kdbgModPEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
    264264{
    265265    /*
     
    356356
    357357            DWORD Err = GetLastError();
    358             rc = RTErrConvertFromWin32(Err);
    359             AssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
     358            rc = kDbgModPeConvWinError(Err);
     359            kDbgAssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
    360360            g_pfnSymCleanup(hSymInst);
    361361        }
     
    363363        {
    364364            DWORD Err = GetLastError();
    365             rc = RTErrConvertFromWin32(Err);
    366             AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
     365            rc = kDbgModPeConvWinError(Err);
     366            kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
    367367        }
    368368#endif
  • trunk/kDbg/kDbgModPE-win.cpp

    r3528 r3529  
    3232#define _IMAGEHLP64
    3333#include <DbgHelp.h>
     34#include <malloc.h> /* alloca */
    3435
    3536#include "kDbgInternal.h"
     
    8182
    8283/**
     84 * Convers a Windows error to kDbg error code.
     85 *
     86 * @returns kDbg status code.
     87 * @param   rc          The Windows error.
     88 */
     89static int kDbgModPeConvWinError(DWORD rc)
     90{
     91    switch (rc)
     92    {
     93        case 0:                     return 0;
     94        default:                    return KDBG_ERR_GENERAL_FAILURE;
     95    }
     96}
     97
     98
     99/**
    83100 * Calcs the RVA for a segment:offset address.
    84101 *
     
    90107 * @param   puRVA       Where to store the RVA on success.
    91108 */
    92 static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
     109static int kDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
    93110{
    94111    if (iSegment >= 0)
     
    99116                            ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModPe->aSections[iSegment].Misc.VirtualSize),
    100117                            KDBG_ERR_INVALID_ADDRESS);
    101         *puRVA = pModPe->aSections[iSegment].VirtualAddress + off;
     118        *puRVA = pModPe->aSections[iSegment].VirtualAddress + (uint32_t)off;
    102119        return 0;
    103120    }
     
    107124        kDbgAssertMsgReturn(off < pModPe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage),
    108125                            KDBG_ERR_INVALID_ADDRESS);
    109         *puRVA = off;
     126        *puRVA = (uint32_t)off;
    110127        return 0;
    111128    }
    112     AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
     129    kDbgAssertMsgFailedReturn(("iSegment=%d\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
    113130}
    114131
     
    124141 * @param   poff        Where to store the segment offset.
    125142 */
    126 static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
     143static int kDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
    127144{
    128145    kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage),
     
    139156        }
    140157    }
    141     AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
     158    kDbgAssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
    142159}
    143160
     
    146163 * @copydoc KDBGMODOPS::pfnQueryLine
    147164 */
    148 static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
     165static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
    149166{
    150167    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     
    154171     */
    155172    uint32_t uRVA;
    156     int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     173    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    157174    if (!rc)
    158175    {
     
    163180        {
    164181            pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase);
    165             rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
     182            rc = kDbgModPeRVAToSegOff(pModPe, (uint32_t)pLine->RVA, &pLine->iSegment, &pLine->offSegment);
    166183            pLine->iLine = Line.LineNumber;
    167             pLine->cchFile = strlen(Line.FileName);
    168             if (pLine->cchFile >= sizeof(pLine->szFile))
    169                 pLine->cchFile = sizeof(pLine->szFile) - 1;
    170             memcpy(pLine->szFile, Line.FileName, pLine->cchFile + 1);
     184            size_t cchFile = strlen(Line.FileName);
     185            pLine->cchFile = cchFile < sizeof(pLine->szFile)
     186                           ? (uint16_t)cchFile
     187                           : (uint16_t)sizeof(pLine->szFile) - 1;
     188            memcpy(pLine->szFile, Line.FileName, pLine->cchFile);
     189            pLine->szFile[pLine->cchFile] = '\0';
    171190        }
    172191        else
    173192        {
    174193            DWORD Err = GetLastError();
    175             rc = RTErrConvertFromWin32(Err);
     194            rc = kDbgModPeConvWinError(Err);
    176195        }
    177196    }
     
    183202 * @copydoc KDBGMODOPS::pfnQuerySymbol
    184203 */
    185 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
     204static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
    186205{
    187206    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     
    191210     */
    192211    uint32_t uRVA;
    193     int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     212    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    194213    if (!rc)
    195214    {
     
    223242            {
    224243                pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase);
    225                 rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
     244                rc = kDbgModPeRVAToSegOff(pModPe, (uint32_t)pSym->RVA, &pSym->iSegment, &pSym->offSegment);
    226245            }
    227246            pSym->cchName = (uint16_t)Buf.Sym.NameLen;
     
    234253        {
    235254            DWORD Err = GetLastError();
    236             rc = RTErrConvertFromWin32(Err);
     255            rc = kDbgModPeConvWinError(Err);
    237256        }
    238257    }
     
    244263 * @copydoc KDBGMODOPS::pfnClose
    245264 */
    246 static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod)
     265static int rtDbgModPEClose(PKDBGMOD pMod)
    247266{
    248267    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     
    252271
    253272    DWORD Err = GetLastError();
    254     int rc = RTErrConvertFromWin32(Err);
    255     AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
     273    int rc = kDbgModPeConvWinError(Err);
     274    kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
    256275    return rc;
    257276}
     
    301320                    rc = 0;
    302321                else
    303                     rc = VERR_VERSION_MISMATCH;
     322                    rc = KDBG_ERR_DBGHLP_VERSION_MISMATCH;
    304323            }
    305324            else
    306                 rc = VERR_GENERAL_FAILURE;
     325                rc = KDBG_ERR_GENERAL_FAILURE;
    307326        }
    308327        else
    309             rc = RTErrConvertFromWin32(GetLastError());
     328            rc = kDbgModPeConvWinError(GetLastError());
    310329    }
    311330    else
    312         rc = RTErrConvertFromWin32(GetLastError());
     331        rc = kDbgModPeConvWinError(GetLastError());
    313332    return rc;
    314333}
     
    325344    uint32_t FileVersionMS = 0;
    326345    uint32_t FileVersionLS = 0;
    327     int rc = VERR_GENERAL_FAILURE;
     346    int rc = KDBG_ERR_GENERAL_FAILURE;
    328347    static char s_szDbgHelp[] = "\\dbghelp.dll";
    329     if (GetCurrentDirectory(cchPath - sizeof(s_szDbgHelp) + 1, pszPath))
     348    if (GetCurrentDirectory((DWORD)(cchPath - sizeof(s_szDbgHelp) + 1), pszPath))
    330349    {
    331350        strcat(pszPath, s_szDbgHelp);
    332351        int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    333         if (RT_SUCCESS(rc2))
     352        if (!rc2)
    334353            return rc2;
    335         if (rc != VERR_VERSION_MISMATCH)
     354        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
    336355            rc = rc2;
    337356    }
     
    340359     * Try the application directory.
    341360     */
    342     if (GetModuleFileName(NULL, pszPath, cchPath - sizeof(s_szDbgHelp) + 1))
     361    if (GetModuleFileName(NULL, pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1)))
    343362    {
    344363        strcat(strrchr(pszPath, '\\'), s_szDbgHelp);
     
    346365        if (!rc)
    347366            return rc2;
    348         if (rc != VERR_VERSION_MISMATCH)
     367        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
    349368            rc = rc2;
    350369    }
     
    353372     * Try the windows directory.
    354373     */
    355     if (GetSystemDirectory(pszPath, cchPath - sizeof(s_szDbgHelp) + 1))
     374    if (GetSystemDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1)))
    356375    {
    357376        strcat(pszPath, s_szDbgHelp);
    358377        int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    359         if (RT_SUCCESS(rc2))
     378        if (!rc2)
    360379            return rc2;
    361         if (rc != VERR_VERSION_MISMATCH)
     380        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
    362381            rc = rc2;
    363382    }
     
    366385     * Try the windows directory.
    367386     */
    368     if (GetWindowsDirectory(pszPath, cchPath - sizeof(s_szDbgHelp) + 1))
     387    if (GetWindowsDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1)))
    369388    {
    370389        strcat(pszPath, s_szDbgHelp);
    371390        int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    372         if (RT_SUCCESS(rc2))
     391        if (!rc2)
    373392            return rc2;
    374         if (rc != VERR_VERSION_MISMATCH)
     393        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
    375394            rc = rc2;
    376395    }
     
    397416                memcpy(&pszPath[pszEnd - psz], s_szDbgHelp, sizeof(s_szDbgHelp));
    398417                int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    399                 if (RT_SUCCESS(rc2))
     418                if (!rc2)
    400419                    return rc2;
    401                 if (rc != VERR_VERSION_MISMATCH)
     420                if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
    402421                    rc = rc2;
    403422            }
     
    410429    }
    411430
    412     if (rc == VERR_VERSION_MISMATCH)
    413         AssertMsgFailed(("dbghelp.dll found, but it was ancient! The highest file version found was 0x%08x'%08x.\n"
     431    if (rc == KDBG_ERR_DBGHLP_VERSION_MISMATCH)
     432        kDbgAssertMsgFailed(("dbghelp.dll found, but it was ancient! The highest file version found was 0x%08x'%08x.\n"
    414433                         "This program require a file version of at least 0x00060004'00000000. Please download\n"
    415434                         "the latest windbg and use the dbghelp.dll from that package. Just put it somewhere in\n"
    416435                         "the PATH and we'll find it.\n", FileVersionMS, FileVersionLS));
    417436    else
    418         AssertMsgFailed(("dbghelp.dll was not found! Download the latest windbg and use the dbghelp.dll\n"
     437        kDbgAssertMsgFailed(("dbghelp.dll was not found! Download the latest windbg and use the dbghelp.dll\n"
    419438                         "from that package - just put it somewhere in the PATH and we'll find it.\n"));
    420439    return rc;
     
    435454    /* primitive locking - make some useful API for this kind of spinning! */
    436455    static volatile uint32_t s_u32Lock = 0;
    437     while (!ASMAtomicCmpXchgU32(&s_u32Lock, 1, 0))
     456    while (!InterlockedCompareExchange((long volatile *)&s_u32Lock, 1, 0))
    438457        while (s_u32Lock)
    439             RTThreadYield();
     458            Sleep(1);
    440459    if (g_hDbgHelp)
    441460    {
    442         ASMAtomicXchgU32(&s_u32Lock, 0);
     461        InterlockedExchange((long volatile *)&s_u32Lock, 0);
    443462        return 0;
    444463    }
     
    451470    if (rc)
    452471    {
    453         ASMAtomicXchgU32(&s_u32Lock, 0);
     472        InterlockedExchange((volatile long *)&s_u32Lock, 0);
    454473        return rc;
    455474    }
     
    459478    {
    460479        DWORD Err = GetLastError();
    461         int rc = RTErrConvertFromWin32(Err);
    462         AssertMsgFailedReturn(("Failed to load '%s', Err=%d rc=%Rrc\n", szPath, Err, rc), rc);
     480        int rc = kDbgModPeConvWinError(Err);
     481        kDbgAssertMsgFailedReturn(("Failed to load '%s', Err=%d rc=%Rrc\n", szPath, Err, rc), rc);
    463482    }
    464483
     
    496515                { "SymGetLineFromAddr64", (FARPROC *)&g_pfnSymGetLineFromAddr64 },
    497516            };
    498             for (unsigned i = 0; i < ELEMENTS(s_aFunctions); i++)
     517            for (unsigned i = 0; i < KDBG_ELEMENTS(s_aFunctions); i++)
    499518            {
    500519                FARPROC pfn = GetProcAddress(hmod, s_aFunctions[i].pszName);
     
    502521                {
    503522                    DWORD Err = GetLastError();
    504                     rc = RTErrConvertFromWin32(Err);
    505                     AssertMsgFailed(("Failed to resolve %s in dbghelp, Err=%d rc=%Rrc\n",
     523                    rc = kDbgModPeConvWinError(Err);
     524                    kDbgAssertMsgFailed(("Failed to resolve %s in dbghelp, Err=%d rc=%Rrc\n",
    506525                                     s_aFunctions[i].pszName, Err, rc));
    507526                    break;
     
    511530            if (!rc)
    512531            {
    513                 ASMAtomicXchgSize(&g_hDbgHelp, hmod);
    514                 ASMAtomicXchgU32(&s_u32Lock, 0);
     532                //InterlockedExchange(&g_hDbgHelp, hmod);
     533                g_hDbgHelp = hmod;
     534                Sleep(1);
     535                InterlockedExchange((volatile long *)&s_u32Lock, 0);
    515536                return 0;
    516537            }
     
    518539        else
    519540        {
    520             rc = VERR_VERSION_MISMATCH;
    521             AssertMsgFailed(("ImagehlpApiVersion -> %p and MajorVersion=%d.\n", pVersion, pVersion ? pVersion->MajorVersion : 0));
     541            rc = KDBG_ERR_DBGHLP_VERSION_MISMATCH;
     542            kDbgAssertMsgFailed(("ImagehlpApiVersion -> %p and MajorVersion=%d.\n", pVersion, pVersion ? pVersion->MajorVersion : 0));
    522543        }
    523544    }
     
    525546    {
    526547        DWORD Err = GetLastError();
    527         rc = RTErrConvertFromWin32(Err);
    528         AssertMsgFailed(("Failed to resolve ImagehlpApiVersionEx in dbghelp, Err=%d rc=%Rrc\n", Err, rc));
     548        rc = kDbgModPeConvWinError(Err);
     549        kDbgAssertMsgFailed(("Failed to resolve ImagehlpApiVersionEx in dbghelp, Err=%d rc=%Rrc\n", Err, rc));
    529550    }
    530551    FreeLibrary(hmod);
    531     ASMAtomicXchgU32(&s_u32Lock, 0);
     552    InterlockedExchange((long volatile *)&s_u32Lock, 0);
    532553    return rc;
    533554}
     
    539560 * @returns IPRT status code.
    540561 *
    541  * @param   File                The handle to the module.
     562 * @param   pFile               The handle to the module.
    542563 * @param   offHdr              The offset of the PE header.
    543564 * @param   pszModulePath       The path to the module.
     
    545566 *
    546567 */
    547 int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
     568int kdbgModPEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
    548569{
    549570    /*
     
    551572     */
    552573    IMAGE_FILE_HEADER FHdr;
    553     int rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr), NULL);
    554     AssertRCReturn(rc, rc);
     574    int rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr));
     575    kDbgAssertRCReturn(rc, rc);
    555576
    556577    uint32_t cbImage;
    557578    if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER32))
    558         rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),
    559                           &cbImage, sizeof(cbImage), NULL);
     579        rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),
     580                           &cbImage, sizeof(cbImage));
    560581    else if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER64))
    561         rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),
    562                           &cbImage, sizeof(cbImage), NULL);
     582        rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),
     583                           &cbImage, sizeof(cbImage));
    563584    else
    564         AssertFailedReturn(VERR_BAD_EXE_FORMAT);
    565     AssertRCReturn(rc, rc);
     585        kDbgAssertFailedReturn(KDBG_ERR_BAD_EXE_FORMAT);
     586    kDbgAssertRCReturn(rc, rc);
    566587
    567588    /*
     
    575596     * Allocate the module and read/construct the section headers.
    576597     */
    577     PKDBGMODPE pModPe = (PKDBGMODPE)RTMemAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2]));
    578     AssertReturn(pModPe, KDBG_ERR_NO_MEMORY);
     598    PKDBGMODPE pModPe = (PKDBGMODPE)kDbgHlpAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2]));
     599    kDbgAssertReturn(pModPe, KDBG_ERR_NO_MEMORY);
    579600    pModPe->Core.u32Magic   = KDBGMOD_MAGIC;
    580601    pModPe->Core.pOps       = &g_rtDbgModPEOps;
    581     pModPe->Core.File       = File;
     602    pModPe->Core.pFile      = pFile;
    582603    pModPe->cbImage         = cbImage;
    583604    pModPe->cSections       = 1 + FHdr.NumberOfSections;
    584     rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,
    585                       &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections, NULL);
     605    rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,
     606                       &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections);
    586607    if (!rc)
    587608    {
     
    622643         */
    623644        static volatile uint32_t s_u32LastHandle = 1;
    624         HANDLE hSymInst = (HANDLE)ASMAtomicIncU32(&s_u32LastHandle);
     645        HANDLE hSymInst = (HANDLE)InterlockedIncrement((long *)&s_u32LastHandle);
    625646        while (     hSymInst == INVALID_HANDLE_VALUE
    626647               ||   hSymInst == (HANDLE)0
    627648               ||   hSymInst == GetCurrentProcess())
    628             hSymInst = (HANDLE)ASMAtomicIncU32(&s_u32LastHandle);
     649            hSymInst = (HANDLE)InterlockedIncrement((long *)&s_u32LastHandle);
    629650
    630651        /*
     
    635656            g_pfnSymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS);
    636657
    637             RTFileSeek(File, 0, RTFILE_SEEK_BEGIN, NULL); /* don't know if this is required or not... */
    638             DWORD64 ImageBase = g_pfnSymLoadModule64(hSymInst, (HANDLE)File, pszModulePath, NULL, 0x00400000, 0);
     658            kDbgHlpSeek(pFile, 0); /* don't know if this is required or not... */
     659            DWORD64 ImageBase = g_pfnSymLoadModule64(hSymInst, (HANDLE)kDbgHlpNativeFileHandle(pFile),
     660                                                     pszModulePath, NULL, 0x00400000, 0);
    639661            if (ImageBase)
    640662            {
     
    646668
    647669            DWORD Err = GetLastError();
    648             rc = RTErrConvertFromWin32(Err);
    649             AssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
     670            rc = kDbgModPeConvWinError(Err);
     671            kDbgAssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
    650672            g_pfnSymCleanup(hSymInst);
    651673        }
     
    653675        {
    654676            DWORD Err = GetLastError();
    655             rc = RTErrConvertFromWin32(Err);
    656             AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
     677            rc = kDbgModPeConvWinError(Err);
     678            kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
    657679        }
    658680    }
    659681    else
    660         AssertRC(rc);
     682        kDbgAssertRC(rc);
    661683
    662684    kDbgHlpFree(pModPe);
Note: See TracChangeset for help on using the changeset viewer.