Changeset 3529
- Timestamp:
- Aug 20, 2007, 5:25:44 AM (18 years ago)
- Location:
- trunk/kDbg
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kDbg/kDbg.h
r3528 r3529 68 68 /** A specified address or an address found in the debug info is invalid. */ 69 69 #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) 70 74 71 75 /** @} */ -
trunk/kDbg/kDbgHlp.h
r3528 r3529 119 119 120 120 /** 121 * Gets the native file handle. 122 * 123 * @return The native file handle. 124 * -1 on failure. 125 * @param pFile The file handle. 126 */ 127 uintptr_t kDbgHlpNativeFileHandle(PKDBGHLPFILE pFile); 128 129 /** 121 130 * Gets the size of an open file. 122 131 * … … 206 215 #endif 207 216 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 */ 225 void 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 */ 233 void kDbgAssertMsg2(const char *pszFormat, ...); 234 235 208 236 #ifdef KDBG_STRICT 237 209 238 # define kDbgAssert(expr) \ 210 239 do { \ … … 246 275 } 247 276 } while (0) 277 248 278 #else /* !KDBG_STRICT */ 249 279 # define kDbgAssert(expr) do { } while (0) 250 # define kDbgAssertReturn(expr, rcRet) do { } while (0)280 # define kDbgAssertReturn(expr, rcRet) return (rcRet) 251 281 # define kDbgAssertMsg(expr, msg) do { } while (0) 252 # define kDbgAssertMsgReturn(expr, msg, rcRet) do { } while (0)282 # define kDbgAssertMsgReturn(expr, msg, rcRet) return (rcRet) 253 283 #endif /* !KDBG_STRICT */ 254 284 … … 257 287 #define kDbgAssertRC(rc) kDbgAssertMsg((rc) == 0, ("%s = %d\n", #rc, (rc))) 258 288 #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)) 259 293 260 294 /** @} */ -
trunk/kDbg/kDbgHlpCrt.cpp
r3528 r3529 33 33 #include <string.h> 34 34 #include <errno.h> 35 #ifdef _MSC_VER 36 # include <io.h> 37 #endif 35 38 36 39 … … 126 129 127 130 131 uintptr_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 128 142 int64_t kDbgHlpFileSize(PKDBGHLPFILE pFile) 129 143 { -
trunk/kDbg/kDbgModPE-generic.cpp
r3528 r3529 63 63 * @param puRVA Where to store the RVA on success. 64 64 */ 65 static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)65 static int kDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA) 66 66 { 67 67 if (iSegment >= 0) … … 83 83 return 0; 84 84 } 85 AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS);85 kDbgAssertMsgFailedReturn(("iSegment=%d\n", iSegment), KDBG_ERR_INVALID_ADDRESS); 86 86 } 87 87 … … 97 97 * @param poff Where to store the segment offset. 98 98 */ 99 static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)99 static int kDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff) 100 100 { 101 101 kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage), … … 112 112 } 113 113 } 114 AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);114 kDbgAssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS); 115 115 } 116 116 … … 119 119 * @copydoc KDBGMODOPS::pfnQueryLine 120 120 */ 121 static DECLCALLBACK(int)rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)121 static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 122 122 { 123 123 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 127 127 */ 128 128 uint32_t uRVA; 129 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);129 int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 130 130 if (!rc) 131 131 { … … 137 137 { 138 138 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); 140 140 pLine->iLine = Line.LineNumber; 141 141 pLine->cchFile = strlen(Line.FileName); … … 147 147 { 148 148 DWORD Err = GetLastError(); 149 rc = RTErrConvertFromWin32(Err);149 rc = kDbgModPeConvWinError(Err); 150 150 } 151 151 #endif … … 159 159 * @copydoc KDBGMODOPS::pfnQuerySymbol 160 160 */ 161 static DECLCALLBACK(int)rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)161 static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 162 162 { 163 163 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 167 167 */ 168 168 uint32_t uRVA; 169 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);169 int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 170 170 if (!rc) 171 171 { … … 200 200 { 201 201 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); 203 203 } 204 204 pSym->cchName = (uint16_t)Buf.Sym.NameLen; … … 211 211 { 212 212 DWORD Err = GetLastError(); 213 rc = RTErrConvertFromWin32(Err);213 rc = kDbgModPeConvWinError(Err); 214 214 } 215 215 #endif … … 223 223 * @copydoc KDBGMODOPS::pfnClose 224 224 */ 225 static DECLCALLBACK(int)rtDbgModPEClose(PKDBGMOD pMod)225 static int rtDbgModPEClose(PKDBGMOD pMod) 226 226 { 227 227 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 231 231 // 232 232 //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)); 235 235 //return rc; 236 236 return VERR_NOT_IMPLEMENTED; … … 255 255 * @returns IPRT status code. 256 256 * 257 * @param FileThe handle to the module.257 * @param pFile The handle to the module. 258 258 * @param offHdr The offset of the PE header. 259 259 * @param pszModulePath The path to the module. … … 261 261 * 262 262 */ 263 int kdbgModPEOpen( RTFILEFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)263 int kdbgModPEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod) 264 264 { 265 265 /* … … 356 356 357 357 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)); 360 360 g_pfnSymCleanup(hSymInst); 361 361 } … … 363 363 { 364 364 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)); 367 367 } 368 368 #endif -
trunk/kDbg/kDbgModPE-win.cpp
r3528 r3529 32 32 #define _IMAGEHLP64 33 33 #include <DbgHelp.h> 34 #include <malloc.h> /* alloca */ 34 35 35 36 #include "kDbgInternal.h" … … 81 82 82 83 /** 84 * Convers a Windows error to kDbg error code. 85 * 86 * @returns kDbg status code. 87 * @param rc The Windows error. 88 */ 89 static 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 /** 83 100 * Calcs the RVA for a segment:offset address. 84 101 * … … 90 107 * @param puRVA Where to store the RVA on success. 91 108 */ 92 static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)109 static int kDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA) 93 110 { 94 111 if (iSegment >= 0) … … 99 116 ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModPe->aSections[iSegment].Misc.VirtualSize), 100 117 KDBG_ERR_INVALID_ADDRESS); 101 *puRVA = pModPe->aSections[iSegment].VirtualAddress + off;118 *puRVA = pModPe->aSections[iSegment].VirtualAddress + (uint32_t)off; 102 119 return 0; 103 120 } … … 107 124 kDbgAssertMsgReturn(off < pModPe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage), 108 125 KDBG_ERR_INVALID_ADDRESS); 109 *puRVA = off;126 *puRVA = (uint32_t)off; 110 127 return 0; 111 128 } 112 AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS);129 kDbgAssertMsgFailedReturn(("iSegment=%d\n", iSegment), KDBG_ERR_INVALID_ADDRESS); 113 130 } 114 131 … … 124 141 * @param poff Where to store the segment offset. 125 142 */ 126 static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)143 static int kDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff) 127 144 { 128 145 kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage), … … 139 156 } 140 157 } 141 AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);158 kDbgAssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS); 142 159 } 143 160 … … 146 163 * @copydoc KDBGMODOPS::pfnQueryLine 147 164 */ 148 static DECLCALLBACK(int)rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)165 static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 149 166 { 150 167 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 154 171 */ 155 172 uint32_t uRVA; 156 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);173 int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 157 174 if (!rc) 158 175 { … … 163 180 { 164 181 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); 166 183 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'; 171 190 } 172 191 else 173 192 { 174 193 DWORD Err = GetLastError(); 175 rc = RTErrConvertFromWin32(Err);194 rc = kDbgModPeConvWinError(Err); 176 195 } 177 196 } … … 183 202 * @copydoc KDBGMODOPS::pfnQuerySymbol 184 203 */ 185 static DECLCALLBACK(int)rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)204 static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 186 205 { 187 206 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 191 210 */ 192 211 uint32_t uRVA; 193 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);212 int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 194 213 if (!rc) 195 214 { … … 223 242 { 224 243 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); 226 245 } 227 246 pSym->cchName = (uint16_t)Buf.Sym.NameLen; … … 234 253 { 235 254 DWORD Err = GetLastError(); 236 rc = RTErrConvertFromWin32(Err);255 rc = kDbgModPeConvWinError(Err); 237 256 } 238 257 } … … 244 263 * @copydoc KDBGMODOPS::pfnClose 245 264 */ 246 static DECLCALLBACK(int)rtDbgModPEClose(PKDBGMOD pMod)265 static int rtDbgModPEClose(PKDBGMOD pMod) 247 266 { 248 267 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 252 271 253 272 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)); 256 275 return rc; 257 276 } … … 301 320 rc = 0; 302 321 else 303 rc = VERR_VERSION_MISMATCH;322 rc = KDBG_ERR_DBGHLP_VERSION_MISMATCH; 304 323 } 305 324 else 306 rc = VERR_GENERAL_FAILURE;325 rc = KDBG_ERR_GENERAL_FAILURE; 307 326 } 308 327 else 309 rc = RTErrConvertFromWin32(GetLastError());328 rc = kDbgModPeConvWinError(GetLastError()); 310 329 } 311 330 else 312 rc = RTErrConvertFromWin32(GetLastError());331 rc = kDbgModPeConvWinError(GetLastError()); 313 332 return rc; 314 333 } … … 325 344 uint32_t FileVersionMS = 0; 326 345 uint32_t FileVersionLS = 0; 327 int rc = VERR_GENERAL_FAILURE;346 int rc = KDBG_ERR_GENERAL_FAILURE; 328 347 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)) 330 349 { 331 350 strcat(pszPath, s_szDbgHelp); 332 351 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 333 if ( RT_SUCCESS(rc2))352 if (!rc2) 334 353 return rc2; 335 if (rc != VERR_VERSION_MISMATCH)354 if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH) 336 355 rc = rc2; 337 356 } … … 340 359 * Try the application directory. 341 360 */ 342 if (GetModuleFileName(NULL, pszPath, cchPath - sizeof(s_szDbgHelp) + 1))361 if (GetModuleFileName(NULL, pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1))) 343 362 { 344 363 strcat(strrchr(pszPath, '\\'), s_szDbgHelp); … … 346 365 if (!rc) 347 366 return rc2; 348 if (rc != VERR_VERSION_MISMATCH)367 if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH) 349 368 rc = rc2; 350 369 } … … 353 372 * Try the windows directory. 354 373 */ 355 if (GetSystemDirectory(pszPath, cchPath - sizeof(s_szDbgHelp) + 1))374 if (GetSystemDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1))) 356 375 { 357 376 strcat(pszPath, s_szDbgHelp); 358 377 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 359 if ( RT_SUCCESS(rc2))378 if (!rc2) 360 379 return rc2; 361 if (rc != VERR_VERSION_MISMATCH)380 if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH) 362 381 rc = rc2; 363 382 } … … 366 385 * Try the windows directory. 367 386 */ 368 if (GetWindowsDirectory(pszPath, cchPath - sizeof(s_szDbgHelp) + 1))387 if (GetWindowsDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1))) 369 388 { 370 389 strcat(pszPath, s_szDbgHelp); 371 390 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 372 if ( RT_SUCCESS(rc2))391 if (!rc2) 373 392 return rc2; 374 if (rc != VERR_VERSION_MISMATCH)393 if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH) 375 394 rc = rc2; 376 395 } … … 397 416 memcpy(&pszPath[pszEnd - psz], s_szDbgHelp, sizeof(s_szDbgHelp)); 398 417 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 399 if ( RT_SUCCESS(rc2))418 if (!rc2) 400 419 return rc2; 401 if (rc != VERR_VERSION_MISMATCH)420 if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH) 402 421 rc = rc2; 403 422 } … … 410 429 } 411 430 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" 414 433 "This program require a file version of at least 0x00060004'00000000. Please download\n" 415 434 "the latest windbg and use the dbghelp.dll from that package. Just put it somewhere in\n" 416 435 "the PATH and we'll find it.\n", FileVersionMS, FileVersionLS)); 417 436 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" 419 438 "from that package - just put it somewhere in the PATH and we'll find it.\n")); 420 439 return rc; … … 435 454 /* primitive locking - make some useful API for this kind of spinning! */ 436 455 static volatile uint32_t s_u32Lock = 0; 437 while (! ASMAtomicCmpXchgU32(&s_u32Lock, 1, 0))456 while (!InterlockedCompareExchange((long volatile *)&s_u32Lock, 1, 0)) 438 457 while (s_u32Lock) 439 RTThreadYield();458 Sleep(1); 440 459 if (g_hDbgHelp) 441 460 { 442 ASMAtomicXchgU32(&s_u32Lock, 0);461 InterlockedExchange((long volatile *)&s_u32Lock, 0); 443 462 return 0; 444 463 } … … 451 470 if (rc) 452 471 { 453 ASMAtomicXchgU32(&s_u32Lock, 0);472 InterlockedExchange((volatile long *)&s_u32Lock, 0); 454 473 return rc; 455 474 } … … 459 478 { 460 479 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); 463 482 } 464 483 … … 496 515 { "SymGetLineFromAddr64", (FARPROC *)&g_pfnSymGetLineFromAddr64 }, 497 516 }; 498 for (unsigned i = 0; i < ELEMENTS(s_aFunctions); i++)517 for (unsigned i = 0; i < KDBG_ELEMENTS(s_aFunctions); i++) 499 518 { 500 519 FARPROC pfn = GetProcAddress(hmod, s_aFunctions[i].pszName); … … 502 521 { 503 522 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", 506 525 s_aFunctions[i].pszName, Err, rc)); 507 526 break; … … 511 530 if (!rc) 512 531 { 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); 515 536 return 0; 516 537 } … … 518 539 else 519 540 { 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)); 522 543 } 523 544 } … … 525 546 { 526 547 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)); 529 550 } 530 551 FreeLibrary(hmod); 531 ASMAtomicXchgU32(&s_u32Lock, 0);552 InterlockedExchange((long volatile *)&s_u32Lock, 0); 532 553 return rc; 533 554 } … … 539 560 * @returns IPRT status code. 540 561 * 541 * @param FileThe handle to the module.562 * @param pFile The handle to the module. 542 563 * @param offHdr The offset of the PE header. 543 564 * @param pszModulePath The path to the module. … … 545 566 * 546 567 */ 547 int kdbgModPEOpen( RTFILEFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)568 int kdbgModPEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod) 548 569 { 549 570 /* … … 551 572 */ 552 573 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); 555 576 556 577 uint32_t cbImage; 557 578 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)); 560 581 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)); 563 584 else 564 AssertFailedReturn(VERR_BAD_EXE_FORMAT);565 AssertRCReturn(rc, rc);585 kDbgAssertFailedReturn(KDBG_ERR_BAD_EXE_FORMAT); 586 kDbgAssertRCReturn(rc, rc); 566 587 567 588 /* … … 575 596 * Allocate the module and read/construct the section headers. 576 597 */ 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); 579 600 pModPe->Core.u32Magic = KDBGMOD_MAGIC; 580 601 pModPe->Core.pOps = &g_rtDbgModPEOps; 581 pModPe->Core. File =File;602 pModPe->Core.pFile = pFile; 582 603 pModPe->cbImage = cbImage; 583 604 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); 586 607 if (!rc) 587 608 { … … 622 643 */ 623 644 static volatile uint32_t s_u32LastHandle = 1; 624 HANDLE hSymInst = (HANDLE) ASMAtomicIncU32(&s_u32LastHandle);645 HANDLE hSymInst = (HANDLE)InterlockedIncrement((long *)&s_u32LastHandle); 625 646 while ( hSymInst == INVALID_HANDLE_VALUE 626 647 || hSymInst == (HANDLE)0 627 648 || hSymInst == GetCurrentProcess()) 628 hSymInst = (HANDLE) ASMAtomicIncU32(&s_u32LastHandle);649 hSymInst = (HANDLE)InterlockedIncrement((long *)&s_u32LastHandle); 629 650 630 651 /* … … 635 656 g_pfnSymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS); 636 657 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); 639 661 if (ImageBase) 640 662 { … … 646 668 647 669 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)); 650 672 g_pfnSymCleanup(hSymInst); 651 673 } … … 653 675 { 654 676 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)); 657 679 } 658 680 } 659 681 else 660 AssertRC(rc);682 kDbgAssertRC(rc); 661 683 662 684 kDbgHlpFree(pModPe);
Note:
See TracChangeset
for help on using the changeset viewer.