Changeset 3550 for trunk/kStuff/kDbg/kDbgModule.cpp
- Timestamp:
- Aug 26, 2007, 3:13:35 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/kDbg/kDbgModule.cpp
r3543 r3550 9 9 * This file is part of kStuff. 10 10 * 11 * kStuff is free software; you can redistribute it and/or modify12 * it under the terms of the GNU Lesser General Public License as published13 * by the Free Software Foundation; either version 2 of the License, or14 * (at your option) any later version.11 * kStuff is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 15 * 16 16 * kStuff is distributed in the hope that it will be useful, 17 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 26 27 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 */ 28 26 29 27 /******************************************************************************* 30 28 * Header Files * 31 29 *******************************************************************************/ 32 #include <k/kDbgAll.h>33 #include <k/kErrors.h>34 #include <string.h>35 30 #include "kDbgInternal.h" 31 #include <k/kHlpString.h> 32 #include <k/kHlpAlloc.h> 36 33 37 34 … … 47 44 &g_kDbgModWinDbgHelpOpen, 48 45 #endif 49 &g_kDbgModLdr,50 &g_kDbgModCv8,51 &g_kDbgModDwarf,52 &g_kDbgModHll,53 &g_kDbgModStabs,54 &g_kDbgModSym,55 &g_kDbgModMapILink,56 &g_kDbgModMapMSLink,57 &g_kDbgModMapNm,58 &g_kDbgModMapWLink46 // &g_kDbgModLdr, 47 // &g_kDbgModCv8, 48 // &g_kDbgModDwarf, 49 // &g_kDbgModHll, 50 // &g_kDbgModStabs, 51 // &g_kDbgModSym, 52 // &g_kDbgModMapILink, 53 // &g_kDbgModMapMSLink, 54 // &g_kDbgModMapNm, 55 // &g_kDbgModMapWLink 59 56 }; 60 57 … … 93 90 kDbgAssertPtrReturn(pOps->pfnQueryLine, KERR_INVALID_POINTER); 94 91 kDbgAssertPtrReturn(pOps->pszName2, KERR_INVALID_POINTER); 95 if ( strcmp(pOps->pszName, pOps->pszName2))92 if (kHlpStrComp(pOps->pszName, pOps->pszName2)) 96 93 return KERR_INVALID_PARAMETER; 97 94 kDbgAssertReturn(pOps->pNext == NULL, KERR_INVALID_PARAMETER); … … 153 150 154 151 152 153 /** 154 * Worker for the kDbgModuleOpen* APIs. 155 * 156 * This will make sure the reader is buffered. I will also take care of 157 * closing the reader opened by kDbgModuleOpen on failure. 158 * 159 * @returns 0 on success. An appropriate kErrors status code on failure. 160 * @param ppDbgMod Where to store the new debug module reader instance. 161 * @param pRdr The file provider. 162 * @param fCloseRdr Whether pRdr should be close or not. This applies both 163 * to the failure path and to the success path, where it'll 164 * be close when the module is closed by kDbgModuleClose(). 165 * @param off The offset into the file where the debug info is supposed 166 * to be found. 167 * This is 0 if the entire file is the subject. 168 * @param cb The size of the debug info part of the file. 169 * This is KFOFF_MAX if the entire file is the subject. 170 * @param pLdrMod An optional kLdrMod association. 171 */ 172 static int kdbgModuleOpenWorker(PPKDBGMOD ppDbgMod, PKRDR pRdr, KBOOL fCloseRdr, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod) 173 { 174 /* 175 * If the reader isn't buffered create a buffered wrapper for it. 176 */ 177 int rc; 178 PKRDR pRdrWrapped = NULL; 179 if (!kRdrBufIsBuffered(pRdr)) 180 { 181 rc = kRdrBufWrap(&pRdrWrapped, pRdr, fCloseRdr); 182 if (rc) 183 { 184 if (fCloseRdr) 185 kRdrClose(pRdr); 186 return rc; 187 } 188 pRdr = pRdrWrapped; 189 } 190 191 /* 192 * Walk the built-in table and the list of registered readers 193 * and let each of them have a go at the file. Stop and return 194 * on the first one returning successfully. 195 */ 196 rc = KDBG_ERR_UNKOWN_FORMAT; 197 for (KSIZE i = 0; i < K_ELEMENTS(g_aBuiltIns); i++) 198 if (g_aBuiltIns[i]->pfnOpen) 199 { 200 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pRdr, fCloseRdr, off, cb, pLdrMod); 201 if (!rc) 202 return 0; 203 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 204 rc = rc2; 205 } 206 207 for (PKDBGMODOPS pCur = g_pHead; pCur; pCur = pCur->pNext) 208 if (g_aBuiltIns[i]->pfnOpen) 209 { 210 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pRdr, fCloseRdr, off, cb, pLdrMod); 211 if (!rc) 212 return 0; 213 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 214 rc = rc2; 215 } 216 217 if (pRdrWrapped) 218 kRdrClose(pRdrWrapped); 219 else if (fCloseRdr) 220 kRdrClose(pRdr); 221 return rc; 222 } 223 224 155 225 /** 156 226 * Opens a debug module reader for the specified file or file section … … 158 228 * @returns kStuff status code. 159 229 * @param ppDbgMod Where to store the debug module reader handle. 160 * @param p FileThe file reader.230 * @param pRdr The file reader. 161 231 * @param off The offset of the file section. If the entire file, pass 0. 162 232 * @param cb The size of the file section. If the entire file, pass KFOFF_MAX. … … 167 237 * This is an optional parameter, pass NULL if no kLdr module at hand. 168 238 */ 169 KDBG_DECL(int) kDbgModuleOpenFilePart(P KDBGMOD *ppDbgMod, PKDBGHLPFILE pFile, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod)239 KDBG_DECL(int) kDbgModuleOpenFilePart(PPKDBGMOD ppDbgMod, PKRDR pRdr, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod) 170 240 { 171 241 /* … … 173 243 */ 174 244 kDbgAssertPtrReturn(ppDbgMod, KERR_INVALID_POINTER); 175 kDbgAssertPtrReturn(p File, KERR_INVALID_POINTER);245 kDbgAssertPtrReturn(pRdr, KERR_INVALID_POINTER); 176 246 kDbgAssertPtrNullReturn(pLdrMod, KERR_INVALID_POINTER); 177 247 kDbgAssertMsgReturn(off >= 0 && off < KFOFF_MAX, (KFOFF_PRI "\n", off), KERR_INVALID_OFFSET); … … 181 251 182 252 /* 183 * Walk the built-in table and the list of registered readers 184 * and let each of them have a go at the file. Stop and return 185 * on the first one returning successfully. 186 */ 187 int rc = KDBG_ERR_UNKOWN_FORMAT; 188 for (KSIZE i = 0; i < K_ELEMENTS(g_aBuiltIns); i++) 189 if (g_aBuiltIns[i]->pfnOpen) 190 { 191 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pFile, off, cb, pLdrMod); 192 if (!rc) 193 return 0; 194 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 195 rc = rc2; 196 } 197 198 for (PKDBGMODOPS pCur = g_pHead; pCur; pCur = pCur->pNext) 199 if (g_aBuiltIns[i]->pfnOpen) 200 { 201 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pFile, off, cb, pLdrMod); 202 if (!rc) 203 return 0; 204 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 205 rc = rc2; 206 } 207 return rc; 253 * Hand it over to the internal worker. 254 */ 255 return kdbgModuleOpenWorker(ppDbgMod, pRdr, K_FALSE /* fCloseRdr */, off, cb, pLdrMod); 208 256 } 209 257 … … 214 262 * @returns kStuff status code. 215 263 * @param ppDbgMod Where to store the debug module reader handle. 216 * @param p FileThe file reader.264 * @param pRdr The file reader. 217 265 * @param pLdrMod Associated kLdr module that the kDbg component can use to 218 266 * verify and suplement the debug info found in the file specified … … 221 269 * This is an optional parameter, pass NULL if no kLdr module at hand. 222 270 */ 223 KDBG_DECL(int) kDbgModuleOpenFile(P KDBGMOD *ppDbgMod, PKDBGHLPFILE pFile, struct KLDRMOD *pLdrMod)224 { 225 return kDbgModuleOpenFilePart(ppDbgMod, p File, 0, KFOFF_MAX, pLdrMod);271 KDBG_DECL(int) kDbgModuleOpenFile(PPKDBGMOD ppDbgMod, PKRDR pRdr, struct KLDRMOD *pLdrMod) 272 { 273 return kDbgModuleOpenFilePart(ppDbgMod, pRdr, 0, KFOFF_MAX, pLdrMod); 226 274 } 227 275 … … 240 288 * This is an optional parameter, pass NULL if no kLdr module at hand. 241 289 */ 242 KDBG_DECL(int) kDbgModuleOpen(P KDBGMOD *ppDbgMod, const char *pszFilename, struct KLDRMOD *pLdrMod)290 KDBG_DECL(int) kDbgModuleOpen(PPKDBGMOD ppDbgMod, const char *pszFilename, struct KLDRMOD *pLdrMod) 243 291 { 244 292 /* … … 254 302 * Open the file and see if we can read it. 255 303 */ 256 PK DBGHLPFILE pFile;257 int rc = k DbgHlpOpenRO(pszFilename, &pFile);304 PKRDR pRdr; 305 int rc = kRdrBufOpen(&pRdr, pszFilename); 258 306 if (rc) 259 307 return rc; 260 rc = kDbgModuleOpenFilePart(ppDbgMod, pFile, 0, KFOFF_MAX, pLdrMod); 261 if (rc) 262 kDbgHlpClose(pFile); 308 rc = kdbgModuleOpenWorker(ppDbgMod, pRdr, K_TRUE /* fCloseRdr */, 0, KFOFF_MAX, pLdrMod); 263 309 return rc; 264 }265 266 267 /**268 * Validates a debug module handle.269 * All necessary asserting will be taken care of here.270 *271 * @returns True / false.272 * @param pMod The debug module handle.273 */274 KDBG_INLINE(bool) kdbgModIsValid(PKDBGMOD pMod)275 {276 kDbgAssertPtrReturn(pMod, false);277 kDbgAssertMsgReturn(pMod->u32Magic == KDBGMOD_MAGIC, ("%#x", pMod->u32Magic), false);278 kDbgAssertPtrReturn(pMod->pOps, false);279 return true;280 310 } 281 311 … … 289 319 KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod) 290 320 { 291 if (!kdbgModIsValid(pMod)) 292 return KERR_INVALID_PARAMETER; 293 321 KDBGMOD_VALIDATE(pMod); 294 322 int rc = pMod->pOps->pfnClose(pMod); 295 323 if (!rc) 296 kDbgHlpFree(pMod); 324 { 325 pMod->u32Magic++; 326 kHlpFree(pMod); 327 } 297 328 return rc; 298 329 } … … 314 345 KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 315 346 { 316 if (!kdbgModIsValid(pMod)) 317 return KERR_INVALID_PARAMETER; 347 KDBGMOD_VALIDATE(pMod); 318 348 kDbgAssertPtrReturn(pSym, KERR_INVALID_POINTER); 319 320 349 return pMod->pOps->pfnQuerySymbol(pMod, iSegment, off, pSym); 321 350 } … … 369 398 KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 370 399 { 371 if (!kdbgModIsValid(pMod)) 372 return KERR_INVALID_PARAMETER; 400 KDBGMOD_VALIDATE(pMod); 373 401 kDbgAssertPtrReturn(pLine, KERR_INVALID_POINTER); 374 375 402 return pMod->pOps->pfnQueryLine(pMod, iSegment, off, pLine); 376 403 }
Note:
See TracChangeset
for help on using the changeset viewer.