Changeset 3534
- Timestamp:
- Aug 23, 2007, 2:28:15 AM (18 years ago)
- Location:
- trunk/kDbg
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kDbg/Makefile.kmk
r3530 r3534 61 61 ## kDbgDump - Test program which dumps whatever is thrown at it. 62 62 ## 63 #PROGRAMS += kDbgDump63 PROGRAMS += kDbgDump 64 64 kDbgDump_TEMPLATE = kStuffEXE 65 65 kDbgDump_SOURCES = kDbgDump.cpp 66 kDbgDump_LIBS = $(TARGET_kDbgStatic) 66 kDbgDump_LIBS = \ 67 $(TARGET_kDbgStatic) \ 68 $(TARGET_kDbgStatic:kDbgStatic=kLdrStatic) 67 69 68 70 # Generate the rules -
trunk/kDbg/kDbgHlp.h
r3529 r3534 278 278 #else /* !KDBG_STRICT */ 279 279 # define kDbgAssert(expr) do { } while (0) 280 # define kDbgAssertReturn(expr, rcRet) return (rcRet)280 # define kDbgAssertReturn(expr, rcRet) do { if (!(expr)) return (rcRet); } while (0) 281 281 # define kDbgAssertMsg(expr, msg) do { } while (0) 282 # define kDbgAssertMsgReturn(expr, msg, rcRet) return (rcRet)282 # define kDbgAssertMsgReturn(expr, msg, rcRet) do { if (!(expr)) return (rcRet); } while (0) 283 283 #endif /* !KDBG_STRICT */ 284 284 285 #define kDbgAssertPtr(ptr) kDbgAssertMsg( VALID_PTR(expr), ("%s = %p\n", #ptr, (ptr)))286 #define kDbgAssertPtrReturn(ptr, rcRet) kDbgAssertMsgReturn( VALID_PTR(expr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet))285 #define kDbgAssertPtr(ptr) kDbgAssertMsg(KDBG_VALID_PTR(ptr), ("%s = %p\n", #ptr, (ptr))) 286 #define kDbgAssertPtrReturn(ptr, rcRet) kDbgAssertMsgReturn(KDBG_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet)) 287 287 #define kDbgAssertRC(rc) kDbgAssertMsg((rc) == 0, ("%s = %d\n", #rc, (rc))) 288 288 #define kDbgAssertRCReturn(rc, rcRet) kDbgAssertMsgReturn((rc) == 0, ("%s = %d -> %d\n", #rc, (rc), (rcRet)), (rcRet)) -
trunk/kDbg/kDbgInternal.h
r3530 r3534 43 43 const char *pszName; 44 44 45 /** Pointer to the next debug module readers. 46 * This is only used for dynamically registered readers. */ 47 struct KDBGMODOPS *pNext; 48 49 /** 50 * Tries to open the module. 51 * 52 * @returns 0 on success, KDBG_ERR on failure. 53 * @param pFile The file 54 * @param off The file offset of the debug info. This is 0 if there isn't 55 * any specfic debug info section and the reader should start 56 * looking for debug info at the start of the file. 57 * @param cb The size of the debug info in the file. INT64_MAX if we don't 58 * know or there isn't any particular debug info section in the file. 59 * @param pLdrMod The associated loader module. This can be NULL. 60 * @param ppMod Where to store the module that's been opened. 61 * 62 * @remark This is NULL for the builtin readers. 63 */ 64 int (*pfnOpen)(PKDBGHLPFILE pFile, int64_t off, int64_t cb, PKLDRMOD pLdrMod, PKDBGMOD pMod); 65 45 66 /** 46 67 * Closes the module. … … 58 79 * This will be approximated to the nearest symbol if there is no exact match. 59 80 * 60 * @returns IPRT status code.81 * @returns 0 on success. KLDR_ERR_* on failure. 61 82 * @param pMod The module. 62 83 * @param iSegment The segment this offset is relative to. … … 73 94 * This will be approximated to the nearest line number there is no exact match. 74 95 * 75 * @returns IPRT status code.96 * @returns 0 on success. KLDR_ERR_* on failure. 76 97 * @param pMod The module. 77 98 * @param iSegment The segment this offset is relative to. … … 112 133 113 134 int kdbgModPEOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod); 114 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr,const char *pszModulePath, PKDBGMOD *ppDbgMod);135 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, const char *pszModulePath, PKDBGMOD *ppDbgMod); 115 136 116 137 #ifdef __cplusplus -
trunk/kDbg/kDbgModPE.cpp
r3530 r3534 101 101 { 102 102 kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage), 103 KDBG_ERR_INVALID_ADDRESS);103 KDBG_ERR_INVALID_ADDRESS); 104 104 for (int32_t iSegment = 0; iSegment < pModPe->cSections; iSegment++) 105 105 { -
trunk/kDbg/kDbgModWinDbgHelp.cpp
r3531 r3534 431 431 if (rc == KDBG_ERR_DBGHLP_VERSION_MISMATCH) 432 432 kDbgAssertMsgFailed(("dbghelp.dll found, but it was ancient! The highest file version found was 0x%08x'%08x.\n" 433 "This program require a file version of at least 0x00060004'00000000. Please download\n"434 "the latest windbg and use the dbghelp.dll from that package. Just put it somewhere in\n"435 "the PATH and we'll find it.\n", FileVersionMS, FileVersionLS));433 "This program require a file version of at least 0x00060004'00000000. Please download\n" 434 "the latest windbg and use the dbghelp.dll from that package. Just put it somewhere in\n" 435 "the PATH and we'll find it.\n", FileVersionMS, FileVersionLS)); 436 436 else 437 437 kDbgAssertMsgFailed(("dbghelp.dll was not found! Download the latest windbg and use the dbghelp.dll\n" 438 "from that package - just put it somewhere in the PATH and we'll find it.\n"));438 "from that package - just put it somewhere in the PATH and we'll find it.\n")); 439 439 return rc; 440 440 } … … 566 566 * 567 567 */ 568 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath,PKDBGMOD *ppDbgMod)568 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, PKDBGMOD *ppDbgMod) 569 569 { 570 570 /* -
trunk/kDbg/kDbgModule.cpp
r3530 r3534 30 30 *******************************************************************************/ 31 31 #include "kDbg.h" 32 #include "kLdr.h" 32 33 #include "kDbgInternal.h" 33 34 … … 35 36 #include <kLdrModPE.h> 36 37 38 39 /******************************************************************************* 40 * Global Variables * 41 *******************************************************************************/ 42 43 44 45 KDBG_DECL(int) kDbgModuleOpenFilePart(PKDBGHLPFILE pFile, int64_t off, int64_t cb, PKDBGMOD *ppDbgMod) 46 { 47 #if KOS_WINDOWS 48 /* 49 * If we're on Windows, let DbgHelp have a go first. 50 */ 51 if (!off) 52 { 53 int rc = kdbgModWinDbgHelpOpen(pFile, ppDbgMod); 54 if (!rc) 55 return 0; 56 } 57 #endif 58 59 /* 60 * Probe the file for signatures we recognize. 61 */ 62 int64_t offHdr = 0; 63 union 64 { 65 uint32_t au32[4]; 66 uint16_t au16[8]; 67 uint8_t ab[16]; 68 char 69 } Buf; 70 rc = kDbgHlpReadAt(pFile, &Buf, sizeof(Buf), off); 71 72 } 73 74 75 KDBG_DECL(int) kDbgModuleOpenFile(PKDBGHLPFILE pFile, PKDBGMOD *ppDbgMod) 76 { 77 return kDbgModuleOpenFilePart(pFile, 0, INT64_MAX, ppDbgMod); 78 } 79 80 81 KDBG_DECL(int) kDbgModuleOpenkLdrMod(PKLDRMOD pLdrMod, PKDBGMOD *ppDbgMod) 82 { 83 /* 84 * Enumerate the debug info, if nothing found check for a matching .pdb, 85 * .dbg, .sym or .map file. 86 */ 87 88 } 37 89 38 90 … … 55 107 56 108 /* 57 * The file and try figure out the format.109 * Open the file and see if we can read it. 58 110 */ 59 111 PKDBGHLPFILE pFile; … … 61 113 if (rc) 62 114 return rc; 63 64 int64_t offHdr = 0; 65 union 66 { 67 uint32_t au32[4]; 68 uint16_t au16[8]; 69 uint8_t ab[16]; 70 } Buf; 71 rc = kDbgHlpRead(pFile, &Buf, sizeof(Buf)); 72 if ( !rc 73 && Buf.au16[0] == IMAGE_DOS_SIGNATURE) 74 { 75 /* new header? */ 76 uint32_t offNewHeader; 77 rc = kDbgHlpReadAt(pFile, KDBG_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew), &offNewHeader, sizeof(offNewHeader)); 78 if (!rc && offNewHeader) 115 rc = kDbgModuleOpenFile(pFile, ppDbgMod); 116 if (rc) 117 { 118 kDbgHlpClose(pFile); 119 120 /* 121 * Let kLdr have a shot at it, if it's a binary it may contain 122 * some debug sections or a link to an external debug file. 123 */ 124 PKLDRMOD pLdrMod; 125 int rc2 = kLdrModOpen(pszModulePath, *pLdrMod); 126 if (!rc2) 79 127 { 80 offHdr = offNewHeader; 81 rc = kDbgHlpReadAt(pFile, offNewHeader, &Buf, sizeof(Buf)); 128 rc = kDbgModuleOpenkLdrMod(pLdrMod, ppDbgMod); 129 if (rc) 130 kLdrModClose(pLdrMod); 82 131 } 83 132 } 84 if (!rc) 85 { 86 if (Buf.au16[0] == IMAGE_DOS_SIGNATURE) 87 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 88 #ifdef IMAGE_NE_SIGNATURE 89 else if (Buf.au16[0] == IMAGE_NE_SIGNATURE) 90 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 91 #endif 92 #ifdef IMAGE_LX_SIGNATURE 93 else if (Buf.au16[0] == IMAGE_LX_SIGNATURE) 94 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 95 #endif 96 #ifdef IMAGE_LE_SIGNATURE 97 else if (Buf.au16[0] == IMAGE_LE_SIGNATURE) 98 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 99 #endif 100 #ifdef IMAGE_ELF_SIGNATURE 101 else if (Buf.au32[0] == IMAGE_ELF_SIGNATURE) 102 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 103 #endif 104 #ifdef IMAGE_NT_SIGNATURE 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 113 rc = kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod); 114 } 115 #endif 116 /** @todo there are a number of text file formats too which I want to support. */ 117 else 118 rc = KDBG_ERR_UNKOWN_FORMAT; 119 } 120 121 if (rc) 122 kDbgHlpClose(pFile); 133 123 134 return rc; 124 135 }
Note:
See TracChangeset
for help on using the changeset viewer.