- Timestamp:
- Aug 20, 2007, 5:42:03 AM (18 years ago)
- Location:
- trunk/kDbg
- Files:
-
- 4 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/kDbg/Makefile.kmk
r3528 r3530 37 37 kDbg_SOURCES := \ 38 38 kDbgModule.cpp \ 39 kDbgModPE -$(if $(eq $(BUILD_TARGET),win),win,generic).cpp \39 kDbgModPE.cpp \ 40 40 \ 41 41 kDbgLine.cpp \ … … 44 44 \ 45 45 kDbgHlpCrt.cpp 46 47 kDbg_SOURCES += \ 48 kDbgModWinDbgHelp.cpp 49 46 50 47 51 # -
trunk/kDbg/kDbg.h
r3529 r3530 59 59 /** The specified file was not found. */ 60 60 #define KDBG_ERR_FILE_NOT_FOUND (KDBG_ERR_BASE + 5) 61 /** Hit some unimplemented functionality - feel free to implement it :-) . */ 62 #define KDBG_ERR_NOT_IMPLEMENTED (KDBG_ERR_BASE + 6) 61 63 /** Generic error. */ 62 64 #define KDBG_ERR_GENERAL_FAILURE (KDBG_ERR_BASE + 9) -
trunk/kDbg/kDbgInternal.h
r3528 r3530 112 112 113 113 int kdbgModPEOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod); 114 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod); 114 115 115 116 #ifdef __cplusplus -
trunk/kDbg/kDbgModPE.cpp
r3529 r3530 31 31 #include "kDbgInternal.h" 32 32 #include <kLdrModPE.h> 33 #include <string.h> 33 34 34 35 … … 72 73 ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModPe->aSections[iSegment].Misc.VirtualSize), 73 74 KDBG_ERR_INVALID_ADDRESS); 74 *puRVA = pModPe->aSections[iSegment].VirtualAddress + off;75 *puRVA = pModPe->aSections[iSegment].VirtualAddress + (uint32_t)off; 75 76 return 0; 76 77 } … … 80 81 kDbgAssertMsgReturn(off < pModPe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage), 81 82 KDBG_ERR_INVALID_ADDRESS); 82 *puRVA = off;83 *puRVA = (uint32_t)off; 83 84 return 0; 84 85 } … … 119 120 * @copydoc KDBGMODOPS::pfnQueryLine 120 121 */ 121 static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)122 static int kDbgModPeQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 122 123 { 123 124 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 150 151 } 151 152 #endif 152 rc = VERR_NOT_IMPLEMENTED;153 rc = KDBG_ERR_NOT_IMPLEMENTED; 153 154 } 154 155 return rc; … … 159 160 * @copydoc KDBGMODOPS::pfnQuerySymbol 160 161 */ 161 static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)162 static int kDbgModPeQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 162 163 { 163 164 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 175 176 { 176 177 SYMBOL_INFO Sym; 177 char achBuffer[sizeof(SYMBOL_INFO) + RTDBG_SYMBOL_MAX];178 char achBuffer[sizeof(SYMBOL_INFO) + KDBG_SYMBOL_MAX]; 178 179 } Buf; 179 180 Buf.Sym.SizeOfStruct = sizeof(SYMBOL_INFO); 180 Buf.Sym.MaxNameLen = RTDBG_SYMBOL_MAX;181 Buf.Sym.MaxNameLen = KDBG_SYMBOL_MAX; 181 182 if (g_pfnSymFromAddr(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Buf.Sym)) 182 183 { … … 193 194 if ((Buf.Sym.Flags & (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) == (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) 194 195 { 195 pSym->iSegment = RTDBGSEG_ABS;196 pSym->iSegment = KDBGSEG_ABS; 196 197 pSym->offSegment = (KDBGADDR)Buf.Sym.Value; 197 198 pSym->RVA = (KDBGADDR)Buf.Sym.Value; … … 214 215 } 215 216 #endif 216 rc = VERR_NOT_IMPLEMENTED;217 rc = KDBG_ERR_NOT_IMPLEMENTED; 217 218 } 218 219 return rc; … … 223 224 * @copydoc KDBGMODOPS::pfnClose 224 225 */ 225 static int rtDbgModPEClose(PKDBGMOD pMod)226 static int kDbgModPeClose(PKDBGMOD pMod) 226 227 { 227 228 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; … … 234 235 //kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc)); 235 236 //return rc; 236 return VERR_NOT_IMPLEMENTED;237 return KDBG_ERR_NOT_IMPLEMENTED; 237 238 } 238 239 … … 241 242 * Methods for a PE module. 242 243 */ 243 static const KDBGMODOPS g_ rtDbgModPEOps =244 { 245 "PE (dbghelp)",246 rtDbgModPEClose,247 rtDbgModPEQuerySymbol,248 rtDbgModPEQueryLine244 static const KDBGMODOPS g_kDbgModPeOps = 245 { 246 "PE", 247 kDbgModPeClose, 248 kDbgModPeQuerySymbol, 249 kDbgModPeQueryLine 249 250 }; 250 251 … … 267 268 */ 268 269 IMAGE_FILE_HEADER FHdr; 269 int rc = kDbgHlpReadAt( File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr), NULL);270 AssertRCReturn(rc, rc);270 int rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr)); 271 kDbgAssertRCReturn(rc, rc); 271 272 272 273 uint32_t cbImage; 273 274 if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER32)) 274 rc = kDbgHlpReadAt( File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),275 &cbImage, sizeof(cbImage), NULL);275 rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage), 276 &cbImage, sizeof(cbImage)); 276 277 else if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER64)) 277 rc = kDbgHlpReadAt( File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),278 &cbImage, sizeof(cbImage), NULL);278 rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage), 279 &cbImage, sizeof(cbImage)); 279 280 else 280 AssertFailedReturn(VERR_BAD_EXE_FORMAT);281 AssertRCReturn(rc, rc);281 kDbgAssertFailedReturn(KDBG_ERR_BAD_EXE_FORMAT); 282 kDbgAssertRCReturn(rc, rc); 282 283 283 284 /* 284 285 * Allocate the module and read/construct the section headers. 285 286 */ 286 PKDBGMODPE pModPe = (PKDBGMODPE) RTMemAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2]));287 AssertReturn(pModPe, KDBG_ERR_NO_MEMORY);287 PKDBGMODPE pModPe = (PKDBGMODPE)kDbgHlpAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2])); 288 kDbgAssertReturn(pModPe, KDBG_ERR_NO_MEMORY); 288 289 pModPe->Core.u32Magic = KDBGMOD_MAGIC; 289 pModPe->Core.pOps = &g_ rtDbgModPEOps;290 pModPe->Core. File =File;290 pModPe->Core.pOps = &g_kDbgModPeOps; 291 pModPe->Core.pFile = pFile; 291 292 pModPe->cbImage = cbImage; 292 293 pModPe->cSections = 1 + FHdr.NumberOfSections; 293 rc = kDbgHlpReadAt( File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,294 &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections, NULL);294 rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader, 295 &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections); 295 296 if (!rc) 296 297 { … … 345 346 g_pfnSymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS); 346 347 347 RTFileSeek(File, 0, RTFILE_SEEK_BEGIN, NULL); /* don't know if this is required or not... */348 kDbgHlpSeek(pFile, 0); /* don't know if this is required or not... */ 348 349 DWORD64 ImageBase = g_pfnSymLoadModule64(hSymInst, (HANDLE)File, pszModulePath, NULL, 0x00400000, 0); 349 350 if (ImageBase) … … 367 368 } 368 369 #endif 369 rc = VERR_NOT_IMPLEMENTED;370 rc = KDBG_ERR_NOT_IMPLEMENTED; 370 371 } 371 372 else 372 AssertRC(rc);373 kDbgAssertRC(rc); 373 374 374 375 kDbgHlpFree(pModPe); -
trunk/kDbg/kDbgModWinDbgHelp.cpp
r3529 r3530 63 63 * A dbghelp based PE debug reader. 64 64 */ 65 typedef struct KDBGMOD PE65 typedef struct KDBGMODDBGHELP 66 66 { 67 67 /** The common module core. */ 68 KDBGMOD Core;68 KDBGMOD Core; 69 69 /** The image base. */ 70 70 DWORD64 ImageBase; … … 78 78 * implicit header section.*/ 79 79 IMAGE_SECTION_HEADER aSections[1]; 80 } KDBGMOD PE, *PKDBGMODPE;80 } KDBGMODDBGHELP, *PKDBGMODDBGHELP; 81 81 82 82 … … 102 102 * @returns IPRT status code. 103 103 * 104 * @param pMod PeThe PE debug module instance.104 * @param pModDH The PE debug module instance. 105 105 * @param iSegment The segment number. Special segments are dealt with as well. 106 106 * @param off The segment offset. 107 107 * @param puRVA Where to store the RVA on success. 108 108 */ 109 static int kDbgModPeSegOffToRVA(PKDBGMOD PE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)109 static int kDbgModPeSegOffToRVA(PKDBGMODDBGHELP pModDH, int32_t iSegment, KDBGADDR off, uint32_t *puRVA) 110 110 { 111 111 if (iSegment >= 0) 112 112 { 113 kDbgAssertMsgReturn(iSegment < pMod Pe->cSections, ("iSegment=%x cSections=%x\n", iSegment, pModPe->cSections),113 kDbgAssertMsgReturn(iSegment < pModDH->cSections, ("iSegment=%x cSections=%x\n", iSegment, pModDH->cSections), 114 114 KDBG_ERR_INVALID_ADDRESS); 115 kDbgAssertMsgReturn(off < pMod Pe->aSections[iSegment].Misc.VirtualSize,116 ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pMod Pe->aSections[iSegment].Misc.VirtualSize),115 kDbgAssertMsgReturn(off < pModDH->aSections[iSegment].Misc.VirtualSize, 116 ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModDH->aSections[iSegment].Misc.VirtualSize), 117 117 KDBG_ERR_INVALID_ADDRESS); 118 *puRVA = pMod Pe->aSections[iSegment].VirtualAddress + (uint32_t)off;118 *puRVA = pModDH->aSections[iSegment].VirtualAddress + (uint32_t)off; 119 119 return 0; 120 120 } … … 122 122 if (iSegment == KDBGSEG_RVA) 123 123 { 124 kDbgAssertMsgReturn(off < pMod Pe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage),124 kDbgAssertMsgReturn(off < pModDH->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModDH->cbImage), 125 125 KDBG_ERR_INVALID_ADDRESS); 126 126 *puRVA = (uint32_t)off; … … 136 136 * @returns IPRT status code. 137 137 * 138 * @param pMod PeThe PE debug module instance.138 * @param pModDH The PE debug module instance. 139 139 * @param uRVA The RVA. 140 140 * @param piSegment Where to store the segment number. 141 141 * @param poff Where to store the segment offset. 142 142 */ 143 static int kDbgModPeRVAToSegOff(PKDBGMOD PE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)144 { 145 kDbgAssertMsgReturn(uRVA < pMod Pe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage),146 KDBG_ERR_INVALID_ADDRESS);147 for (int32_t iSegment = 0; iSegment < pMod Pe->cSections; iSegment++)143 static int kDbgModPeRVAToSegOff(PKDBGMODDBGHELP pModDH, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff) 144 { 145 kDbgAssertMsgReturn(uRVA < pModDH->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModDH->cbImage), 146 KDBG_ERR_INVALID_ADDRESS); 147 for (int32_t iSegment = 0; iSegment < pModDH->cSections; iSegment++) 148 148 { 149 149 /** @todo should probably be less strict about address in the alignment gaps. */ 150 uint32_t off = uRVA - pMod Pe->aSections[iSegment].VirtualAddress;151 if (off < pMod Pe->aSections[iSegment].Misc.VirtualSize)150 uint32_t off = uRVA - pModDH->aSections[iSegment].VirtualAddress; 151 if (off < pModDH->aSections[iSegment].Misc.VirtualSize) 152 152 { 153 153 *poff = off; … … 163 163 * @copydoc KDBGMODOPS::pfnQueryLine 164 164 */ 165 static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)166 { 167 PKDBGMOD PE pModPe = (PKDBGMODPE)pMod;165 static int kdbgModDHQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 166 { 167 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod; 168 168 169 169 /* … … 171 171 */ 172 172 uint32_t uRVA; 173 int rc = kDbgModPeSegOffToRVA(pMod Pe, iSegment, off, &uRVA);173 int rc = kDbgModPeSegOffToRVA(pModDH, iSegment, off, &uRVA); 174 174 if (!rc) 175 175 { … … 177 177 IMAGEHLP_LINE64 Line; 178 178 Line.SizeOfStruct = sizeof(Line); 179 if (g_pfnSymGetLineFromAddr64(pMod Pe->hSymInst, pModPe->ImageBase + uRVA, &off, &Line))180 { 181 pLine->RVA = (KDBGADDR)(Line.Address - pMod Pe->ImageBase);182 rc = kDbgModPeRVAToSegOff(pMod Pe, (uint32_t)pLine->RVA, &pLine->iSegment, &pLine->offSegment);179 if (g_pfnSymGetLineFromAddr64(pModDH->hSymInst, pModDH->ImageBase + uRVA, &off, &Line)) 180 { 181 pLine->RVA = (KDBGADDR)(Line.Address - pModDH->ImageBase); 182 rc = kDbgModPeRVAToSegOff(pModDH, (uint32_t)pLine->RVA, &pLine->iSegment, &pLine->offSegment); 183 183 pLine->iLine = Line.LineNumber; 184 184 size_t cchFile = strlen(Line.FileName); … … 202 202 * @copydoc KDBGMODOPS::pfnQuerySymbol 203 203 */ 204 static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)205 { 206 PKDBGMOD PE pModPe = (PKDBGMODPE)pMod;204 static int kdbgModDHQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 205 { 206 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod; 207 207 208 208 /* … … 210 210 */ 211 211 uint32_t uRVA; 212 int rc = kDbgModPeSegOffToRVA(pMod Pe, iSegment, off, &uRVA);212 int rc = kDbgModPeSegOffToRVA(pModDH, iSegment, off, &uRVA); 213 213 if (!rc) 214 214 { … … 221 221 Buf.Sym.SizeOfStruct = sizeof(SYMBOL_INFO); 222 222 Buf.Sym.MaxNameLen = KDBG_SYMBOL_MAX; 223 if (g_pfnSymFromAddr(pMod Pe->hSymInst, pModPe->ImageBase + uRVA, &off, &Buf.Sym))223 if (g_pfnSymFromAddr(pModDH->hSymInst, pModDH->ImageBase + uRVA, &off, &Buf.Sym)) 224 224 { 225 225 pSym->cb = Buf.Sym.Size; … … 241 241 else 242 242 { 243 pSym->RVA = (KDBGADDR)(Buf.Sym.Address - pMod Pe->ImageBase);244 rc = kDbgModPeRVAToSegOff(pMod Pe, (uint32_t)pSym->RVA, &pSym->iSegment, &pSym->offSegment);243 pSym->RVA = (KDBGADDR)(Buf.Sym.Address - pModDH->ImageBase); 244 rc = kDbgModPeRVAToSegOff(pModDH, (uint32_t)pSym->RVA, &pSym->iSegment, &pSym->offSegment); 245 245 } 246 246 pSym->cchName = (uint16_t)Buf.Sym.NameLen; … … 263 263 * @copydoc KDBGMODOPS::pfnClose 264 264 */ 265 static int rtDbgModPEClose(PKDBGMOD pMod)266 { 267 PKDBGMOD PE pModPe = (PKDBGMODPE)pMod;268 269 if (g_pfnSymCleanup(pMod Pe->hSymInst))265 static int kdbgModDHClose(PKDBGMOD pMod) 266 { 267 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod; 268 269 if (g_pfnSymCleanup(pModDH->hSymInst)) 270 270 return 0; 271 271 … … 280 280 * Methods for a PE module. 281 281 */ 282 static const KDBGMODOPS g_ rtDbgModPEOps =282 static const KDBGMODOPS g_kdbgModDHOps = 283 283 { 284 284 "PE (dbghelp)", 285 rtDbgModPEClose,286 rtDbgModPEQuerySymbol,287 rtDbgModPEQueryLine285 kdbgModDHClose, 286 kdbgModDHQuerySymbol, 287 kdbgModDHQueryLine 288 288 }; 289 289 … … 296 296 * @param pszPath the path to the dbghelp.dll. 297 297 */ 298 static int rtDbgModPETryDbgHelp(const char *pszPath, uint32_t *pu32FileVersionMS, uint32_t *pu32FileVersionLS)298 static int kdbgModDHTryDbgHelp(const char *pszPath, uint32_t *pu32FileVersionMS, uint32_t *pu32FileVersionLS) 299 299 { 300 300 int rc; … … 337 337 * Find the dbghelp.dll 338 338 */ 339 static int rtDbgModPEFindDbgHelp(char *pszPath, size_t cchPath)339 static int kdbgModDHFindDbgHelp(char *pszPath, size_t cchPath) 340 340 { 341 341 /* … … 349 349 { 350 350 strcat(pszPath, s_szDbgHelp); 351 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);351 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 352 352 if (!rc2) 353 353 return rc2; … … 362 362 { 363 363 strcat(strrchr(pszPath, '\\'), s_szDbgHelp); 364 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);364 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 365 365 if (!rc) 366 366 return rc2; … … 375 375 { 376 376 strcat(pszPath, s_szDbgHelp); 377 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);377 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 378 378 if (!rc2) 379 379 return rc2; … … 388 388 { 389 389 strcat(pszPath, s_szDbgHelp); 390 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);390 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 391 391 if (!rc2) 392 392 return rc2; … … 415 415 memcpy(pszPath, psz, pszEnd - psz); 416 416 memcpy(&pszPath[pszEnd - psz], s_szDbgHelp, sizeof(s_szDbgHelp)); 417 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);417 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 418 418 if (!rc2) 419 419 return rc2; … … 447 447 * @returns IPRT status code. 448 448 */ 449 static int rtDbgModPELoadDbgHelp(void)449 static int kdbgModDHLoadDbgHelp(void) 450 450 { 451 451 if (g_hDbgHelp) … … 467 467 */ 468 468 char szPath[260]; 469 int rc = rtDbgModPEFindDbgHelp(szPath, sizeof(szPath));469 int rc = kdbgModDHFindDbgHelp(szPath, sizeof(szPath)); 470 470 if (rc) 471 471 { … … 566 566 * 567 567 */ 568 int kdbgMod PEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)568 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod) 569 569 { 570 570 /* … … 589 589 * Load dbghelp.dll. 590 590 */ 591 rc = rtDbgModPELoadDbgHelp();591 rc = kdbgModDHLoadDbgHelp(); 592 592 if (rc) 593 593 return rc; … … 596 596 * Allocate the module and read/construct the section headers. 597 597 */ 598 PKDBGMOD PE pModPe = (PKDBGMODPE)kDbgHlpAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2]));599 kDbgAssertReturn(pMod Pe, KDBG_ERR_NO_MEMORY);600 pMod Pe->Core.u32Magic = KDBGMOD_MAGIC;601 pMod Pe->Core.pOps = &g_rtDbgModPEOps;602 pMod Pe->Core.pFile = pFile;603 pMod Pe->cbImage = cbImage;604 pMod Pe->cSections = 1 + FHdr.NumberOfSections;598 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)kDbgHlpAlloc(KDBG_OFFSETOF(KDBGMODDBGHELP, aSections[FHdr.NumberOfSections + 2])); 599 kDbgAssertReturn(pModDH, KDBG_ERR_NO_MEMORY); 600 pModDH->Core.u32Magic = KDBGMOD_MAGIC; 601 pModDH->Core.pOps = &g_kdbgModDHOps; 602 pModDH->Core.pFile = pFile; 603 pModDH->cbImage = cbImage; 604 pModDH->cSections = 1 + FHdr.NumberOfSections; 605 605 rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader, 606 &pMod Pe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections);606 &pModDH->aSections[1], sizeof(pModDH->aSections[0]) * FHdr.NumberOfSections); 607 607 if (!rc) 608 608 { 609 PIMAGE_SECTION_HEADER pSH = &pMod Pe->aSections[0];609 PIMAGE_SECTION_HEADER pSH = &pModDH->aSections[0]; 610 610 memcpy(pSH->Name, "headers", sizeof(pSH->Name)); 611 pSH->Misc.VirtualSize = pMod Pe->aSections[1].VirtualAddress;611 pSH->Misc.VirtualSize = pModDH->aSections[1].VirtualAddress; 612 612 pSH->VirtualAddress = 0; 613 613 pSH->SizeOfRawData = pSH->Misc.VirtualSize; … … 619 619 pSH->Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ; 620 620 621 uint32_t uTheEnd = pMod Pe->aSections[FHdr.NumberOfSections].VirtualAddress622 + pMod Pe->aSections[FHdr.NumberOfSections].Misc.VirtualSize;621 uint32_t uTheEnd = pModDH->aSections[FHdr.NumberOfSections].VirtualAddress 622 + pModDH->aSections[FHdr.NumberOfSections].Misc.VirtualSize; 623 623 if (uTheEnd < cbImage) 624 624 { 625 pSH = &pMod Pe->aSections[pModPe->cSections++];625 pSH = &pModDH->aSections[pModDH->cSections++]; 626 626 memcpy(pSH->Name, "tail\0\0\0", sizeof(pSH->Name)); 627 627 pSH->Misc.VirtualSize = cbImage - uTheEnd; … … 661 661 if (ImageBase) 662 662 { 663 pMod Pe->hSymInst = hSymInst;664 pMod Pe->ImageBase = ImageBase;665 *ppDbgMod = &pMod Pe->Core;663 pModDH->hSymInst = hSymInst; 664 pModDH->ImageBase = ImageBase; 665 *ppDbgMod = &pModDH->Core; 666 666 return rc; 667 667 } … … 682 682 kDbgAssertRC(rc); 683 683 684 kDbgHlpFree(pMod Pe);684 kDbgHlpFree(pModDH); 685 685 return rc; 686 686 } -
trunk/kDbg/kDbgModule.cpp
r3528 r3530 104 104 #ifdef IMAGE_NT_SIGNATURE 105 105 else if (Buf.au32[0] == IMAGE_NT_SIGNATURE) 106 { 107 # ifdef KS_OS_WINDOWS 108 rc = kdbgModWinDbgHelpOpen(pFile, offHdr, pszModulePath, ppDbgMod); 109 if ( rc 110 && !kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod)) 111 rc = 0; 112 # endif 106 113 rc = kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod); 114 } 107 115 #endif 108 116 /** @todo there are a number of text file formats too which I want to support. */
Note:
See TracChangeset
for help on using the changeset viewer.