Changeset 3528 for trunk/kDbg/kDbgModule.cpp
- Timestamp:
- Aug 20, 2007, 4:43:13 AM (18 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/kDbg/kDbgModule.cpp
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3526 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * 4 * kProfile Mark 2 - Debug Info Reader5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 * 3 * kDbg - The Debug Info Reader, Module API. 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This file is part of kLIBC. … … 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #ifdef KDBG_USE_IPRT 32 # include <iprt/file.h> 33 # include <iprt/string.h> 34 # include <iprt/err.h> 35 # include <iprt/assert.h> 36 # include <iprt/alloc.h> 37 #else 38 #endif 39 40 #include "kDbgBase.h" 41 #include "DBGInternal.h" 31 #include "kDbg.h" 32 #include "kDbgInternal.h" 33 42 34 #include <kLdrModMZ.h> 43 35 #include <kLdrModPE.h> … … 52 44 * @param ppDbgMod Where to store the debug module handle. 53 45 */ 54 RTDECL(int) RTDbgModuleOpen(const char *pszModulePath, PRTDBGMOD *ppDbgMod)46 KDBG_DECL(int) kDbgModuleOpen(const char *pszModulePath, PKDBGMOD *ppDbgMod) 55 47 { 56 48 /* 57 49 * Validate input. 58 50 */ 59 AssertMsgReturn(VALID_PTR(pszModulePath), ("%p\n", pszModulePath), VERR_INVALID_POINTER);60 AssertMsgReturn(*pszModulePath, ("%p\n", pszModulePath), VERR_INVALID_PARAMETER);61 AssertMsgReturn(VALID_PTR(ppDbgMod), ("%p\n", ppDbgMod), VERR_INVALID_POINTER);51 kDbgAssertPtrReturn(pszModulePath, KDBG_ERR_INVALID_POINTER); 52 kDbgAssertMsgReturn(*pszModulePath, ("%p\n", pszModulePath), KDBG_ERR_INVALID_PARAMETER); 53 kDbgAssertPtrReturn(ppDbgMod, KDBG_ERR_INVALID_POINTER); 62 54 *ppDbgMod = NULL; 63 55 … … 65 57 * The file and try figure out the format. 66 58 */ 67 RTFILEFile;68 int rc = RTFileOpen(&File, pszModulePath, RTFILE_O_READ | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN);69 if ( RT_FAILURE(rc))59 PKDBGHLPFILE pFile; 60 int rc = kDbgHlpOpenRO(pszModulePath, &pFile); 61 if (rc) 70 62 return rc; 71 63 72 RTFOFFoffHdr = 0;64 int64_t offHdr = 0; 73 65 union 74 66 { … … 77 69 uint8_t ab[16]; 78 70 } Buf; 79 rc = RTFileRead(File, &Buf, sizeof(Buf), NULL);80 if ( RT_SUCCESS(rc)71 rc = kDbgHlpRead(pFile, &Buf, sizeof(Buf)); 72 if ( !rc 81 73 && Buf.au16[0] == IMAGE_DOS_SIGNATURE) 82 74 { 83 75 /* new header? */ 84 76 uint32_t offNewHeader; 85 rc = RTFileReadAt(File, KDBG_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew), &offNewHeader, sizeof(offNewHeader), NULL);86 if ( RT_SUCCESS(rc)&& offNewHeader)77 rc = kDbgHlpReadAt(pFile, KDBG_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew), &offNewHeader, sizeof(offNewHeader)); 78 if (!rc && offNewHeader) 87 79 { 88 80 offHdr = offNewHeader; 89 rc = RTFileReadAt(File, offNewHeader, &Buf, sizeof(Buf), NULL);81 rc = kDbgHlpReadAt(pFile, offNewHeader, &Buf, sizeof(Buf)); 90 82 } 91 83 } 92 if ( RT_SUCCESS(rc))84 if (!rc) 93 85 { 94 86 if (Buf.au16[0] == IMAGE_DOS_SIGNATURE) 95 rc = VERR_NOT_SUPPORTED;87 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 96 88 #ifdef IMAGE_NE_SIGNATURE 97 89 else if (Buf.au16[0] == IMAGE_NE_SIGNATURE) 98 rc = VERR_NOT_SUPPORTED;90 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 99 91 #endif 100 92 #ifdef IMAGE_LX_SIGNATURE 101 93 else if (Buf.au16[0] == IMAGE_LX_SIGNATURE) 102 rc = VERR_NOT_SUPPORTED;94 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 103 95 #endif 104 96 #ifdef IMAGE_LE_SIGNATURE 105 97 else if (Buf.au16[0] == IMAGE_LE_SIGNATURE) 106 rc = VERR_NOT_SUPPORTED;98 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 107 99 #endif 108 100 #ifdef IMAGE_ELF_SIGNATURE 109 101 else if (Buf.au32[0] == IMAGE_ELF_SIGNATURE) 110 rc = VERR_NOT_SUPPORTED;102 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 111 103 #endif 112 104 #ifdef IMAGE_NT_SIGNATURE 113 105 else if (Buf.au32[0] == IMAGE_NT_SIGNATURE) 114 rc = rtDbgModPEOpen(File, offHdr, pszModulePath, ppDbgMod);106 rc = kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod); 115 107 #endif 116 108 /** @todo there are a number of text file formats too which I want to support. */ 117 109 else 118 rc = VERR_NOT_SUPPORTED; 119 120 } 121 122 if (RT_FAILURE(rc)) 123 RTFileClose(File); 110 rc = KDBG_ERR_UNKOWN_FORMAT; 111 } 112 113 if (rc) 114 kDbgHlpClose(pFile); 124 115 return rc; 125 116 } … … 133 124 * @param pMod The debug module handle. 134 125 */ 135 DECLINLINE(bool) rtDbgModIsValid(PRTDBGMOD pMod)136 { 137 AssertMsgReturn(VALID_PTR(pMod), ("%p", pMod), false);138 AssertMsgReturn(pMod->u32Magic == RTDBGMOD_MAGIC, ("%RX32", pMod->u32Magic), false);139 AssertMsgReturn(VALID_PTR(pMod->pOps), ("%p", pMod->pOps), false);126 KDBG_INLINE(bool) kdbgModIsValid(PKDBGMOD pMod) 127 { 128 kDbgAssertPtrReturn(pMod, false); 129 kDbgAssertMsgReturn(pMod->u32Magic == KDBGMOD_MAGIC, ("%#x", pMod->u32Magic), false); 130 kDbgAssertPtrReturn(pMod->pOps, false); 140 131 return true; 141 132 } … … 148 139 * @param pMod The module handle. 149 140 */ 150 RTDECL(int) RTDbgModuleClose(PRTDBGMOD pMod)151 { 152 if (! rtDbgModIsValid(pMod))153 return VERR_INVALID_PARAMETER;141 KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod) 142 { 143 if (!kdbgModIsValid(pMod)) 144 return KDBG_ERR_INVALID_PARAMETER; 154 145 155 146 int rc = pMod->pOps->pfnClose(pMod); 156 if ( RT_SUCCESS(rc))157 RTMemFree(pMod);147 if (!rc) 148 kDbgHlpFree(pMod); 158 149 return rc; 159 150 } … … 173 164 * @param pSym Where to store the symbol details. 174 165 */ 175 RTDECL(int) RTDbgModuleQuerySymbol(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym)176 { 177 if (! rtDbgModIsValid(pMod))178 return VERR_INVALID_PARAMETER;179 AssertMsgReturn(VALID_PTR(pSym), ("%p", pSym), VERR_INVALID_POINTER);166 KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 167 { 168 if (!kdbgModIsValid(pMod)) 169 return KDBG_ERR_INVALID_PARAMETER; 170 kDbgAssertPtrReturn(pSym, KDBG_ERR_INVALID_POINTER); 180 171 181 172 return pMod->pOps->pfnQuerySymbol(pMod, iSegment, off, pSym); … … 195 186 * @param off The offset into the segment. 196 187 * @param ppSym Where to store the pointer to the symbol info. 197 * Free the returned symbol using RTDbgSymbolFree().198 */ 199 RTDECL(int) RTDbgModuleQuerySymbolA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGSYMBOL ppSym)200 { 201 AssertMsgReturn(VALID_PTR(ppSym), ("%p\n", ppSym), VERR_INVALID_POINTER);202 203 RTDBGSYMBOL Sym;204 int rc = RTDbgModuleQuerySymbol(pMod, iSegment, off, &Sym);205 if ( RT_SUCCESS(rc))206 { 207 *ppSym = RTDbgSymbolDup(&Sym);188 * Free the returned symbol using kDbgSymbolFree(). 189 */ 190 KDBG_DECL(int) kDbgModuleQuerySymbolA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGSYMBOL ppSym) 191 { 192 kDbgAssertPtrReturn(ppSym, KDBG_ERR_INVALID_POINTER); 193 194 KDBGSYMBOL Sym; 195 int rc = kDbgModuleQuerySymbol(pMod, iSegment, off, &Sym); 196 if (!rc) 197 { 198 *ppSym = kDbgSymbolDup(&Sym); 208 199 if (!*ppSym) 209 rc = VERR_NO_MEMORY;200 rc = KDBG_ERR_NO_MEMORY; 210 201 } 211 202 else … … 228 219 * @param pLine Where to store the line number details. 229 220 */ 230 RTDECL(int) RTDbgModuleQueryLine(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine)231 { 232 if (! rtDbgModIsValid(pMod))233 return VERR_INVALID_PARAMETER;234 AssertMsgReturn(VALID_PTR(pLine), ("%p", pLine), VERR_INVALID_POINTER);221 KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 222 { 223 if (!kdbgModIsValid(pMod)) 224 return KDBG_ERR_INVALID_PARAMETER; 225 kDbgAssertPtrReturn(pLine, KDBG_ERR_INVALID_POINTER); 235 226 236 227 return pMod->pOps->pfnQueryLine(pMod, iSegment, off, pLine); … … 250 241 * @param off The offset into the segment. 251 242 * @param ppLine Where to store the pointer to the line number info. 252 * Free the returned line number using RTDbgLineFree().253 */ 254 RTDECL(int) RTDbgModuleQueryLineA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGLINE ppLine)255 { 256 AssertMsgReturn(VALID_PTR(ppLine), ("%p\n", ppLine), VERR_INVALID_POINTER);257 258 RTDBGLINE Line;259 int rc = RTDbgModuleQueryLine(pMod, iSegment, off, &Line);260 if ( RT_SUCCESS(rc))261 { 262 *ppLine = RTDbgLineDup(&Line);243 * Free the returned line number using kDbgLineFree(). 244 */ 245 KDBG_DECL(int) kDbgModuleQueryLineA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGLINE ppLine) 246 { 247 kDbgAssertPtrReturn(ppLine, KDBG_ERR_INVALID_POINTER); 248 249 KDBGLINE Line; 250 int rc = kDbgModuleQueryLine(pMod, iSegment, off, &Line); 251 if (!rc) 252 { 253 *ppLine = kDbgLineDup(&Line); 263 254 if (!*ppLine) 264 rc = VERR_NO_MEMORY;255 rc = KDBG_ERR_NO_MEMORY; 265 256 } 266 257 else -
Property svn:eol-style
set to
Note:
See TracChangeset
for help on using the changeset viewer.