Changeset 3534 for trunk/kDbg/kDbgModule.cpp
- Timestamp:
- Aug 23, 2007, 2:28:15 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.