Changeset 38531 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Aug 25, 2011 2:30:23 PM (13 years ago)
- Location:
- trunk/src/VBox/Runtime/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgmoddwarf.cpp
r38515 r38531 44 44 *******************************************************************************/ 45 45 /** 46 * DWARF sections. 47 */ 48 typedef enum krtDbgModDwarfSect 49 { 50 krtDbgModDwarfSect_abbrev = 0, 51 krtDbgModDwarfSect_aranges, 52 krtDbgModDwarfSect_frame, 53 krtDbgModDwarfSect_info, 54 krtDbgModDwarfSect_inlined, 55 krtDbgModDwarfSect_line, 56 krtDbgModDwarfSect_loc, 57 krtDbgModDwarfSect_macinfo, 58 krtDbgModDwarfSect_pubnames, 59 krtDbgModDwarfSect_pubtypes, 60 krtDbgModDwarfSect_ranges, 61 krtDbgModDwarfSect_str, 62 krtDbgModDwarfSect_types, 63 /** End of valid parts (exclusive). */ 64 krtDbgModDwarfSect_End 65 } krtDbgModDwarfSect; 66 67 /** 46 68 * The instance data of the DWARF reader. 47 69 */ 48 70 typedef struct RTDBGMODDWARF 49 71 { 50 /** Pointer to back to the debug info module. */ 72 /** The debug container containing doing the real work. */ 73 RTDBGMOD hCnt; 74 /** Pointer to back to the debug info module (no reference ofc). */ 51 75 PRTDBGMODINT pMod; 52 /** The number of DWARF sections in the image. */53 uint32_t cSections;54 76 55 77 /** Total line number count. */ … … 57 79 /** Total symbol count. */ 58 80 uint32_t cSymbols; 81 82 /** DWARF debug info sections. */ 83 struct 84 { 85 /** The file offset of the part. */ 86 RTFOFF offFile; 87 /** The size of the part. */ 88 size_t cb; 89 /** The memory mapping of the part. */ 90 void const *pv; 91 /** Set if present. */ 92 bool fPresent; 93 } aSections[krtDbgModDwarfSect_End]; 59 94 } RTDBGMODDWARF; 60 95 /** Pointer to instance data of the DWARF reader. */ … … 63 98 64 99 100 /** 101 * Loads a DWARF section from the image file. 102 * 103 * @returns IPRT status code. 104 * @param pThis The DWARF instance. 105 * @param enmSect The section to load. 106 */ 107 static int rtDbgModDwarfLoadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect) 108 { 109 /* 110 * Don't load stuff twice. 111 */ 112 if (pThis->aSections[enmSect].pv) 113 return VINF_SUCCESS; 114 115 /* 116 * Sections that are not present cannot be loaded, treat them like they 117 * are empty 118 */ 119 if (!pThis->aSections[enmSect].fPresent) 120 { 121 Assert(pThis->aSections[enmSect].cb); 122 return VINF_SUCCESS; 123 } 124 if (!pThis->aSections[enmSect].cb) 125 return VINF_SUCCESS; 126 127 /* 128 * Sections must be readable with the current image interface. 129 */ 130 if (pThis->aSections[enmSect].offFile < 0) 131 return VERR_OUT_OF_RANGE; 132 133 /* 134 * Do the job. 135 */ 136 return pThis->pMod->pImgVt->pfnMapPart(pThis->pMod, pThis->aSections[enmSect].offFile, pThis->aSections[enmSect].cb, 137 &pThis->aSections[enmSect].pv); 138 } 139 140 141 /** 142 * Unloads a DWARF section previously mapped by rtDbgModDwarfLoadSection. 143 * 144 * @returns IPRT status code. 145 * @param pThis The DWARF instance. 146 * @param enmSect The section to unload. 147 */ 148 static int rtDbgModDwarfUnloadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect) 149 { 150 if (!pThis->aSections[enmSect].pv) 151 return VINF_SUCCESS; 152 153 return pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv); 154 } 155 156 157 65 158 /** @interface_method_impl{RTDBGMODVTDBG,pfnLineByAddr} */ 66 159 static DECLCALLBACK(int) rtDbgModDwarf_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off, … … 68 161 { 69 162 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv; 70 return VERR_DBG_NO_LINE_NUMBERS;163 return RTDbgModLineByAddr(pThis->hCnt, iSeg, off, poffDisp, pLineInfo); 71 164 } 72 165 … … 76 169 { 77 170 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv; 78 return VERR_DBG_NO_LINE_NUMBERS;171 return RTDbgModLineByOrdinal(pThis->hCnt, iOrdinal, pLineInfo); 79 172 } 80 173 … … 84 177 { 85 178 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv; 86 return pThis->cLines;179 return RTDbgModLineCount(pThis->hCnt); 87 180 } 88 181 … … 92 185 uint32_t iSeg, RTUINTPTR off, uint32_t *piOrdinal) 93 186 { 94 return VERR_NOT_SUPPORTED; 187 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv; 188 return RTDbgModLineAdd(pThis->hCnt, pszFile, uLineNo, iSeg, off, piOrdinal); 95 189 } 96 190 … … 185 279 { 186 280 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv; 281 282 for (unsigned iSect = 0; iSect < RT_ELEMENTS(pThis->aSections); iSect++) 283 if (pThis->aSections[iSect].pv) 284 pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[iSect].cb, &pThis->aSections[iSect].pv); 285 286 RTDbgModRelease(pThis->hCnt); 187 287 RTMemFree(pThis); 288 188 289 return VINF_SUCCESS; 189 290 } 190 291 191 292 293 static int rtDbgModDwarfExplodeLineNumbers(PRTDBGMODDWARF pThis) 294 { 295 if (!pThis->aSections[krtDbgModDwarfSect_line].fPresent) 296 return VINF_SUCCESS; 297 int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_line); 298 if (RT_FAILURE(rc)) 299 return rc; 300 301 302 int rc2 = rtDbgModDwarfUnloadSection(pThis, krtDbgModDwarfSect_line); 303 return RT_SUCCESS(rc2) || RT_FAILURE(rc) ? rc : rc2; 304 } 305 306 307 static int rtDbgModDwarfExtractSymbols(PRTDBGMODDWARF pThis) 308 { 309 int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_info); 310 if (RT_FAILURE(rc)) 311 return rc; 312 313 314 return VERR_NOT_IMPLEMENTED; 315 } 316 317 192 318 /** @callback_method_impl{FNRTLDRENUMDBG} */ 193 static DECLCALLBACK(int) rtDbgModDwarf _EnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType,194 195 196 319 static DECLCALLBACK(int) rtDbgModDwarfEnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType, 320 uint16_t iMajorVer, uint16_t iMinorVer, const char *pszPartNm, 321 RTFOFF offFile, RTUINTPTR LinkAddress, RTUINTPTR cb, 322 const char *pszExtFile, void *pvUser) 197 323 { 198 324 /* … … 204 330 return VINF_SUCCESS; 205 331 332 /* 333 * Must have a part name starting with debug_ and possibly prefixed by dots 334 * or underscores. 335 */ 336 if (!strncmp(pszPartNm, ".debug_", sizeof(".debug_") - 1)) 337 pszPartNm += sizeof(".debug_") - 1; 338 else if (!strncmp(pszPartNm, "__debug_", sizeof("__debug_") - 1)) 339 pszPartNm += sizeof("__debug_") - 1; 340 else 341 AssertMsgFailedReturn(("%s\n", pszPartNm), VINF_SUCCESS /*ignore*/); 342 343 /* 344 * Figure out which part we're talking about. 345 */ 346 krtDbgModDwarfSect enmSect; 347 if (0) { /* dummy */ } 348 #define ELSE_IF_STRCMP_SET(a_Name) else if (!strcmp(pszPartNm, #a_Name)) enmSect = krtDbgModDwarfSect_ ## a_Name 349 ELSE_IF_STRCMP_SET(abbrev); 350 ELSE_IF_STRCMP_SET(aranges); 351 ELSE_IF_STRCMP_SET(frame); 352 ELSE_IF_STRCMP_SET(info); 353 ELSE_IF_STRCMP_SET(inlined); 354 ELSE_IF_STRCMP_SET(line); 355 ELSE_IF_STRCMP_SET(loc); 356 ELSE_IF_STRCMP_SET(macinfo); 357 ELSE_IF_STRCMP_SET(pubnames); 358 ELSE_IF_STRCMP_SET(pubtypes); 359 ELSE_IF_STRCMP_SET(ranges); 360 ELSE_IF_STRCMP_SET(str); 361 ELSE_IF_STRCMP_SET(types); 362 #undef ELSE_IF_STRCMP_SET 363 else 364 { 365 AssertMsgFailed(("%s\n", pszPartNm)); 366 return VINF_SUCCESS; 367 } 368 369 /* 370 * Record the section. 371 */ 206 372 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pvUser; 207 pThis->cSections++; 208 /** @todo detect what and record it */ 373 AssertMsgReturn(!pThis->aSections[enmSect].fPresent, ("duplicate %s\n", pszPartNm), VINF_SUCCESS /*ignore*/); 374 375 pThis->aSections[enmSect].fPresent = true; 376 pThis->aSections[enmSect].offFile = offFile; 377 pThis->aSections[enmSect].pv = NULL; 378 pThis->aSections[enmSect].cb = (size_t)cb; 379 if (pThis->aSections[enmSect].cb != cb) 380 pThis->aSections[enmSect].cb = ~(size_t)0; 381 209 382 return VINF_SUCCESS; 210 383 } … … 221 394 222 395 /* 223 * Enume ate the debug info in the module, looking for DWARF bits.396 * Enumerate the debug info in the module, looking for DWARF bits. 224 397 */ 225 398 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)RTMemAllocZ(sizeof(*pThis)); … … 228 401 pThis->pMod = pMod; 229 402 230 int rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, rtDbgModDwarf _EnumCallback, pThis);403 int rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, rtDbgModDwarfEnumCallback, pThis); 231 404 if (RT_SUCCESS(rc)) 232 405 { 233 if (pThis-> cSections)406 if (pThis->aSections[krtDbgModDwarfSect_info].fPresent) 234 407 { 235 pMod->pvDbgPriv = pThis; 236 return VINF_SUCCESS; 408 /* 409 * Extract / explode the data we want (symbols and line numbers) 410 * storing them in a container module. 411 */ 412 rc = RTDbgModCreate(&pThis->hCnt, pMod->pszName, 0 /*cbSeg*/, 0 /*fFlags*/); 413 if (RT_SUCCESS(rc)) 414 { 415 rc = rtDbgModDwarfExtractSymbols(pThis); 416 if (RT_SUCCESS(rc)) 417 rc = rtDbgModDwarfExplodeLineNumbers(pThis); 418 if (RT_SUCCESS(rc)) 419 { 420 pMod->pvDbgPriv = pThis; 421 return VINF_SUCCESS; 422 } 423 424 /* bail out. */ 425 RTDbgModRelease(pThis->hCnt); 426 } 237 427 } 238 239 /* Didn't find any DWARF info, bail out. */ 240 rc = VERR_DBG_NO_MATCHING_INTERPRETER; 428 else 429 rc = VERR_DBG_NO_MATCHING_INTERPRETER; 241 430 } 242 431 RTMemFree(pThis); -
trunk/src/VBox/Runtime/common/dbg/dbgmodldr.cpp
r38516 r38531 110 110 /*.pfnClose = */ rtDbgModLdr_Close, 111 111 /*.pfnEnumDbgInfo = */ rtDbgModLdr_EnumDbgInfo, 112 /*.pfnMapPart = */ NULL /** @todo*/, 113 /*.pfnUnmapPart = */ NULL /** @todo*/, 112 114 113 115 /*.u32EndMagic = */ RTDBGMODVTIMG_MAGIC -
trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp
r38515 r38531 86 86 { 87 87 PFNRT pfn; 88 PFNRTLDRENUMDBG pfnEnumDbgInfo; 88 89 PFNRTLDRENUMSYMS pfnEnumSyms; 89 90 PFNRTLDRIMPORT pfnGetImport; … … 92 93 const void *pvBits; 93 94 PRTLDRMODKLDR pMod; 95 int rc; 94 96 } RTLDRMODKLDRARGS, *PRTLDRMODKLDRARGS; 95 96 97 /*******************************************************************************98 * Internal Functions *99 *******************************************************************************/100 static int rtkldrConvertError(int krc);101 static int rtkldrConvertErrorFromIPRT(int rc);102 103 104 static int rtkldrRdrCreate( PPKRDR ppRdr, const char *pszFilename);105 static int rtkldrRdrDestroy( PKRDR pRdr);106 static int rtkldrRdrRead( PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off);107 static int rtkldrRdrAllMap( PKRDR pRdr, const void **ppvBits);108 static int rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits);109 static KFOFF rtkldrRdrSize( PKRDR pRdr);110 static KFOFF rtkldrRdrTell( PKRDR pRdr);111 static const char * rtkldrRdrName(PKRDR pRdr);112 static KIPTR rtkldrRdrNativeFH(PKRDR pRdr);113 static KSIZE rtkldrRdrPageSize(PKRDR pRdr);114 static int rtkldrRdrMap( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed);115 static int rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);116 static int rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect);117 static int rtkldrRdrUnmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);118 static void rtkldrRdrDone( PKRDR pRdr);119 120 121 static DECLCALLBACK(int) rtkldrClose(PRTLDRMODINTERNAL pMod);122 static DECLCALLBACK(int) rtkldrDone(PRTLDRMODINTERNAL pMod);123 static DECLCALLBACK(int) rtkldrEnumSymbols(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits,124 RTUINTPTR BaseAddress,PFNRTLDRENUMSYMS pfnCallback, void *pvUser);125 static int rtkldrEnumSymbolsWrapper(PKLDRMOD pMod, uint32_t iSymbol,126 const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,127 KLDRADDR uValue, uint32_t fKind, void *pvUser);128 static DECLCALLBACK(size_t) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod);129 static DECLCALLBACK(int) rtkldrGetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress,130 PFNRTLDRIMPORT pfnGetImport, void *pvUser);131 static DECLCALLBACK(int) rtkldrRelocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress,132 RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);133 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, KSIZE cchSymbol,134 const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser);135 136 static DECLCALLBACK(int) rtkldrGetSymbolEx(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress,137 const char *pszSymbol, RTUINTPTR *pValue);138 static DECLCALLBACK(int) rtkldr_EnumDbgInfo(PRTLDRMODINTERNAL pMod, const void *pvBits,139 PFNRTLDRENUMDBG pfnCallback, void *pvUser);140 141 97 142 98 … … 271 227 272 228 229 230 /** @copydoc KLDRRDROPS::pfnCreate 231 * @remark This is a dummy which isn't used. */ 232 static int rtkldrRdr_Create( PPKRDR ppRdr, const char *pszFilename) 233 { 234 AssertReleaseFailed(); 235 return -1; 236 } 237 238 239 /** @copydoc KLDRRDROPS::pfnDestroy */ 240 static int rtkldrRdr_Destroy( PKRDR pRdr) 241 { 242 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 243 int rc = pReader->pfnDestroy(pReader); 244 return rtkldrConvertErrorFromIPRT(rc); 245 } 246 247 248 /** @copydoc KLDRRDROPS::pfnRead */ 249 static int rtkldrRdr_Read( PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off) 250 { 251 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 252 int rc = pReader->pfnRead(pReader, pvBuf, cb, off); 253 return rtkldrConvertErrorFromIPRT(rc); 254 } 255 256 257 /** @copydoc KLDRRDROPS::pfnAllMap */ 258 static int rtkldrRdr_AllMap( PKRDR pRdr, const void **ppvBits) 259 { 260 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 261 int rc = pReader->pfnMap(pReader, ppvBits); 262 return rtkldrConvertErrorFromIPRT(rc); 263 } 264 265 266 /** @copydoc KLDRRDROPS::pfnAllUnmap */ 267 static int rtkldrRdr_AllUnmap(PKRDR pRdr, const void *pvBits) 268 { 269 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 270 int rc = pReader->pfnUnmap(pReader, pvBits); 271 return rtkldrConvertErrorFromIPRT(rc); 272 } 273 274 275 /** @copydoc KLDRRDROPS::pfnSize */ 276 static KFOFF rtkldrRdr_Size( PKRDR pRdr) 277 { 278 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 279 return (KFOFF)pReader->pfnSize(pReader); 280 } 281 282 283 /** @copydoc KLDRRDROPS::pfnTell */ 284 static KFOFF rtkldrRdr_Tell( PKRDR pRdr) 285 { 286 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 287 return (KFOFF)pReader->pfnTell(pReader); 288 } 289 290 291 /** @copydoc KLDRRDROPS::pfnName */ 292 static const char * rtkldrRdr_Name(PKRDR pRdr) 293 { 294 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 295 return pReader->pfnLogName(pReader); 296 } 297 298 299 /** @copydoc KLDRRDROPS::pfnNativeFH */ 300 static KIPTR rtkldrRdr_NativeFH(PKRDR pRdr) 301 { 302 AssertFailed(); 303 return -1; 304 } 305 306 307 /** @copydoc KLDRRDROPS::pfnPageSize */ 308 static KSIZE rtkldrRdr_PageSize(PKRDR pRdr) 309 { 310 return PAGE_SIZE; 311 } 312 313 314 /** @copydoc KLDRRDROPS::pfnMap */ 315 static int rtkldrRdr_Map( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed) 316 { 317 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 318 AssertFailed(); 319 return -1; 320 } 321 322 323 /** @copydoc KLDRRDROPS::pfnRefresh */ 324 static int rtkldrRdr_Refresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 325 { 326 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 327 AssertFailed(); 328 return -1; 329 } 330 331 332 /** @copydoc KLDRRDROPS::pfnProtect */ 333 static int rtkldrRdr_Protect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect) 334 { 335 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 336 AssertFailed(); 337 return -1; 338 } 339 340 341 /** @copydoc KLDRRDROPS::pfnUnmap */ 342 static int rtkldrRdr_Unmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 343 { 344 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 345 AssertFailed(); 346 return -1; 347 } 348 349 /** @copydoc KLDRRDROPS::pfnDone */ 350 static void rtkldrRdr_Done( PKRDR pRdr) 351 { 352 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 353 } 354 355 273 356 /** 274 357 * The file reader operations. … … 280 363 /* .pszName = */ "IPRT", 281 364 /* .pNext = */ NULL, 282 /* .pfnCreate = */ rtkldrRdr Create,283 /* .pfnDestroy = */ rtkldrRdr Destroy,284 /* .pfnRead = */ rtkldrRdr Read,285 /* .pfnAllMap = */ rtkldrRdr AllMap,286 /* .pfnAllUnmap = */ rtkldrRdr AllUnmap,287 /* .pfnSize = */ rtkldrRdr Size,288 /* .pfnTell = */ rtkldrRdr Tell,289 /* .pfnName = */ rtkldrRdr Name,290 /* .pfnNativeFH = */ rtkldrRdr NativeFH,291 /* .pfnPageSize = */ rtkldrRdr PageSize,292 /* .pfnMap = */ rtkldrRdr Map,293 /* .pfnRefresh = */ rtkldrRdr Refresh,294 /* .pfnProtect = */ rtkldrRdr Protect,295 /* .pfnUnmap = */ rtkldrRdr Unmap,296 /* .pfnDone = */ rtkldrRdr Done,365 /* .pfnCreate = */ rtkldrRdr_Create, 366 /* .pfnDestroy = */ rtkldrRdr_Destroy, 367 /* .pfnRead = */ rtkldrRdr_Read, 368 /* .pfnAllMap = */ rtkldrRdr_AllMap, 369 /* .pfnAllUnmap = */ rtkldrRdr_AllUnmap, 370 /* .pfnSize = */ rtkldrRdr_Size, 371 /* .pfnTell = */ rtkldrRdr_Tell, 372 /* .pfnName = */ rtkldrRdr_Name, 373 /* .pfnNativeFH = */ rtkldrRdr_NativeFH, 374 /* .pfnPageSize = */ rtkldrRdr_PageSize, 375 /* .pfnMap = */ rtkldrRdr_Map, 376 /* .pfnRefresh = */ rtkldrRdr_Refresh, 377 /* .pfnProtect = */ rtkldrRdr_Protect, 378 /* .pfnUnmap = */ rtkldrRdr_Unmap, 379 /* .pfnDone = */ rtkldrRdr_Done, 297 380 /* .u32Dummy = */ 42 298 381 }; 299 382 300 383 301 /** @copydoc KLDRRDROPS::pfnCreate 302 * @remark This is a dummy which isn't used. */ 303 static int rtkldrRdrCreate( PPKRDR ppRdr, const char *pszFilename) 304 { 305 AssertReleaseFailed(); 306 return -1; 307 } 308 309 310 /** @copydoc KLDRRDROPS::pfnDestroy */ 311 static int rtkldrRdrDestroy( PKRDR pRdr) 312 { 313 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 314 int rc = pReader->pfnDestroy(pReader); 315 return rtkldrConvertErrorFromIPRT(rc); 316 } 317 318 319 /** @copydoc KLDRRDROPS::pfnRead */ 320 static int rtkldrRdrRead( PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off) 321 { 322 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 323 int rc = pReader->pfnRead(pReader, pvBuf, cb, off); 324 return rtkldrConvertErrorFromIPRT(rc); 325 } 326 327 328 /** @copydoc KLDRRDROPS::pfnAllMap */ 329 static int rtkldrRdrAllMap( PKRDR pRdr, const void **ppvBits) 330 { 331 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 332 int rc = pReader->pfnMap(pReader, ppvBits); 333 return rtkldrConvertErrorFromIPRT(rc); 334 } 335 336 337 /** @copydoc KLDRRDROPS::pfnAllUnmap */ 338 static int rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits) 339 { 340 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 341 int rc = pReader->pfnUnmap(pReader, pvBits); 342 return rtkldrConvertErrorFromIPRT(rc); 343 } 344 345 346 /** @copydoc KLDRRDROPS::pfnSize */ 347 static KFOFF rtkldrRdrSize( PKRDR pRdr) 348 { 349 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 350 return (KFOFF)pReader->pfnSize(pReader); 351 } 352 353 354 /** @copydoc KLDRRDROPS::pfnTell */ 355 static KFOFF rtkldrRdrTell( PKRDR pRdr) 356 { 357 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 358 return (KFOFF)pReader->pfnTell(pReader); 359 } 360 361 362 /** @copydoc KLDRRDROPS::pfnName */ 363 static const char * rtkldrRdrName(PKRDR pRdr) 364 { 365 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 366 return pReader->pfnLogName(pReader); 367 } 368 369 370 /** @copydoc KLDRRDROPS::pfnNativeFH */ 371 static KIPTR rtkldrRdrNativeFH(PKRDR pRdr) 372 { 373 AssertFailed(); 374 return -1; 375 } 376 377 378 /** @copydoc KLDRRDROPS::pfnPageSize */ 379 static KSIZE rtkldrRdrPageSize(PKRDR pRdr) 380 { 381 return PAGE_SIZE; 382 } 383 384 385 /** @copydoc KLDRRDROPS::pfnMap */ 386 static int rtkldrRdrMap( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed) 387 { 388 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 389 AssertFailed(); 390 return -1; 391 } 392 393 394 /** @copydoc KLDRRDROPS::pfnRefresh */ 395 static int rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 396 { 397 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 398 AssertFailed(); 399 return -1; 400 } 401 402 403 /** @copydoc KLDRRDROPS::pfnProtect */ 404 static int rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect) 405 { 406 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 407 AssertFailed(); 408 return -1; 409 } 410 411 412 /** @copydoc KLDRRDROPS::pfnUnmap */ 413 static int rtkldrRdrUnmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 414 { 415 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 416 AssertFailed(); 417 return -1; 418 } 419 420 /** @copydoc KLDRRDROPS::pfnDone */ 421 static void rtkldrRdrDone( PKRDR pRdr) 422 { 423 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 424 } 425 426 427 428 429 430 431 /** 432 * Operations for a kLdr module. 433 */ 434 static const RTLDROPS g_rtkldrOps = 435 { 436 "kLdr", 437 rtkldrClose, 438 NULL, 439 rtkldrDone, 440 rtkldrEnumSymbols, 441 /* ext */ 442 rtkldrGetImageSize, 443 rtkldrGetBits, 444 rtkldrRelocate, 445 rtkldrGetSymbolEx, 446 rtkldr_EnumDbgInfo, 447 42 448 }; 384 449 385 450 386 451 387 /** @copydoc RTLDROPS::pfnClose */ 452 static DECLCALLBACK(int) rtkldr Close(PRTLDRMODINTERNAL pMod)388 static DECLCALLBACK(int) rtkldr_Close(PRTLDRMODINTERNAL pMod) 453 389 { 454 390 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; … … 459 395 460 396 /** @copydoc RTLDROPS::pfnDone */ 461 static DECLCALLBACK(int) rtkldr Done(PRTLDRMODINTERNAL pMod)397 static DECLCALLBACK(int) rtkldr_Done(PRTLDRMODINTERNAL pMod) 462 398 { 463 399 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; 464 400 int rc = kLdrModMostlyDone(pModkLdr); 465 return rtkldrConvertError(rc);466 }467 468 469 /** @copydoc RTLDROPS::pfnEnumSymbols */470 static DECLCALLBACK(int) rtkldrEnumSymbols(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress,471 PFNRTLDRENUMSYMS pfnCallback, void *pvUser)472 {473 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;474 RTLDRMODKLDRARGS Args;475 Args.pvUser = pvUser;476 Args.u.pfnEnumSyms = pfnCallback;477 Args.pMod = (PRTLDRMODKLDR)pMod;478 Args.pvBits = pvBits;479 int rc = kLdrModEnumSymbols(pModkLdr, pvBits, BaseAddress,480 fFlags & RTLDR_ENUM_SYMBOL_FLAGS_ALL ? KLDRMOD_ENUM_SYMS_FLAGS_ALL : 0,481 rtkldrEnumSymbolsWrapper, &Args);482 401 return rtkldrConvertError(rc); 483 402 } … … 514 433 515 434 435 /** @copydoc RTLDROPS::pfnEnumSymbols */ 436 static DECLCALLBACK(int) rtkldr_EnumSymbols(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress, 437 PFNRTLDRENUMSYMS pfnCallback, void *pvUser) 438 { 439 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; 440 RTLDRMODKLDRARGS Args; 441 Args.pvUser = pvUser; 442 Args.u.pfnEnumSyms = pfnCallback; 443 Args.pMod = (PRTLDRMODKLDR)pMod; 444 Args.pvBits = pvBits; 445 Args.rc = VINF_SUCCESS; 446 int rc = kLdrModEnumSymbols(pModkLdr, pvBits, BaseAddress, 447 fFlags & RTLDR_ENUM_SYMBOL_FLAGS_ALL ? KLDRMOD_ENUM_SYMS_FLAGS_ALL : 0, 448 rtkldrEnumSymbolsWrapper, &Args); 449 if (Args.rc != VINF_SUCCESS) 450 rc = Args.rc; 451 else 452 rc = rtkldrConvertError(rc); 453 return rc; 454 } 455 456 516 457 /** @copydoc RTLDROPS::pfnGetImageSize */ 517 static DECLCALLBACK(size_t) rtkldr GetImageSize(PRTLDRMODINTERNAL pMod)458 static DECLCALLBACK(size_t) rtkldr_GetImageSize(PRTLDRMODINTERNAL pMod) 518 459 { 519 460 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; 520 461 return kLdrModSize(pModkLdr); 521 }522 523 524 /** @copydoc RTLDROPS::pfnGetBits */525 static DECLCALLBACK(int) rtkldrGetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress,526 PFNRTLDRIMPORT pfnGetImport, void *pvUser)527 {528 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;529 RTLDRMODKLDRARGS Args;530 Args.pvUser = pvUser;531 Args.u.pfnGetImport = pfnGetImport;532 Args.pMod = (PRTLDRMODKLDR)pMod;533 Args.pvBits = pvBits;534 int rc = kLdrModGetBits(pModkLdr, pvBits, BaseAddress, rtkldrGetImportWrapper, &Args);535 return rtkldrConvertError(rc);536 }537 538 539 /** @copydoc RTLDROPS::pfnRelocate */540 static DECLCALLBACK(int) rtkldrRelocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress,541 RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser)542 {543 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;544 RTLDRMODKLDRARGS Args;545 Args.pvUser = pvUser;546 Args.u.pfnGetImport = pfnGetImport;547 Args.pMod = (PRTLDRMODKLDR)pMod;548 Args.pvBits = pvBits;549 int rc = kLdrModRelocateBits(pModkLdr, pvBits, NewBaseAddress, OldBaseAddress, rtkldrGetImportWrapper, &Args);550 return rtkldrConvertError(rc);551 462 } 552 463 … … 597 508 598 509 510 /** @copydoc RTLDROPS::pfnGetBits */ 511 static DECLCALLBACK(int) rtkldr_GetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress, 512 PFNRTLDRIMPORT pfnGetImport, void *pvUser) 513 { 514 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; 515 RTLDRMODKLDRARGS Args; 516 Args.pvUser = pvUser; 517 Args.u.pfnGetImport = pfnGetImport; 518 Args.pMod = (PRTLDRMODKLDR)pMod; 519 Args.pvBits = pvBits; 520 Args.rc = VINF_SUCCESS; 521 int rc = kLdrModGetBits(pModkLdr, pvBits, BaseAddress, rtkldrGetImportWrapper, &Args); 522 if (Args.rc != VINF_SUCCESS) 523 rc = Args.rc; 524 else 525 rc = rtkldrConvertError(rc); 526 return rc; 527 } 528 529 530 /** @copydoc RTLDROPS::pfnRelocate */ 531 static DECLCALLBACK(int) rtkldr_Relocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress, 532 RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser) 533 { 534 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; 535 RTLDRMODKLDRARGS Args; 536 Args.pvUser = pvUser; 537 Args.u.pfnGetImport = pfnGetImport; 538 Args.pMod = (PRTLDRMODKLDR)pMod; 539 Args.pvBits = pvBits; 540 Args.rc = VINF_SUCCESS; 541 int rc = kLdrModRelocateBits(pModkLdr, pvBits, NewBaseAddress, OldBaseAddress, rtkldrGetImportWrapper, &Args); 542 if (Args.rc != VINF_SUCCESS) 543 rc = Args.rc; 544 else 545 rc = rtkldrConvertError(rc); 546 return rc; 547 } 548 599 549 600 550 /** @copydoc RTLDROPS::pfnGetSymbolEx */ 601 static DECLCALLBACK(int) rtkldr GetSymbolEx(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress,602 const char *pszSymbol, RTUINTPTR *pValue)551 static DECLCALLBACK(int) rtkldr_GetSymbolEx(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress, 552 const char *pszSymbol, RTUINTPTR *pValue) 603 553 { 604 554 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; … … 631 581 632 582 583 /** @copydoc FNKLDRENUMDBG */ 584 static int rtkldrEnumDbgInfoWrapper(PKLDRMOD pMod, KU32 iDbgInfo, KLDRDBGINFOTYPE enmType, KI16 iMajorVer, KI16 iMinorVer, 585 const char *pszPartNm, KLDRFOFF offFile, KLDRADDR LinkAddress, KLDRSIZE cb, 586 const char *pszExtFile, void *pvUser) 587 { 588 PRTLDRMODKLDRARGS pArgs = (PRTLDRMODKLDRARGS)pvUser; 589 590 RTLDRDBGINFOTYPE enmMyType; 591 switch (enmType) 592 { 593 case KLDRDBGINFOTYPE_UNKNOWN: enmMyType = RTLDRDBGINFOTYPE_UNKNOWN; break; 594 case KLDRDBGINFOTYPE_STABS: enmMyType = RTLDRDBGINFOTYPE_STABS; break; 595 case KLDRDBGINFOTYPE_DWARF: enmMyType = RTLDRDBGINFOTYPE_DWARF; break; 596 case KLDRDBGINFOTYPE_CODEVIEW: enmMyType = RTLDRDBGINFOTYPE_CODEVIEW; break; 597 case KLDRDBGINFOTYPE_WATCOM: enmMyType = RTLDRDBGINFOTYPE_WATCOM; break; 598 case KLDRDBGINFOTYPE_HLL: enmMyType = RTLDRDBGINFOTYPE_HLL; break; 599 default: 600 AssertFailed(); 601 enmMyType = RTLDRDBGINFOTYPE_UNKNOWN; 602 break; 603 } 604 605 int rc = pArgs->u.pfnEnumDbgInfo(&pArgs->pMod->Core, iDbgInfo, enmMyType, iMajorVer, iMinorVer, pszPartNm, 606 offFile, LinkAddress, cb, pszExtFile, pArgs->pvUser); 607 if (RT_FAILURE(rc)) 608 return rc; /* don't bother converting. */ 609 return 0; 610 } 611 612 633 613 /** @copydoc RTLDROPS::pfnEnumDbgInfo */ 634 614 static DECLCALLBACK(int) rtkldr_EnumDbgInfo(PRTLDRMODINTERNAL pMod, const void *pvBits, 635 615 PFNRTLDRENUMDBG pfnCallback, void *pvUser) 636 616 { 637 return VERR_NOT_SUPPORTED; 638 } 617 PRTLDRMODKLDR pThis = (PRTLDRMODKLDR)pMod; 618 RTLDRMODKLDRARGS Args; 619 Args.pvUser = pvUser; 620 Args.u.pfnEnumDbgInfo = pfnCallback; 621 Args.pvBits = pvBits; 622 Args.pMod = pThis; 623 Args.rc = VINF_SUCCESS; 624 int rc = kLdrModEnumDbgInfo(pThis->pMod, pvBits, rtkldrEnumDbgInfoWrapper, &Args); 625 if (Args.rc != VINF_SUCCESS) 626 rc = Args.rc; 627 return rc; 628 } 629 630 631 /** 632 * Operations for a kLdr module. 633 */ 634 static const RTLDROPS g_rtkldrOps = 635 { 636 "kLdr", 637 rtkldr_Close, 638 NULL, 639 rtkldr_Done, 640 rtkldr_EnumSymbols, 641 /* ext */ 642 rtkldr_GetImageSize, 643 rtkldr_GetBits, 644 rtkldr_Relocate, 645 rtkldr_GetSymbolEx, 646 rtkldr_EnumDbgInfo, 647 42 648 }; 639 649 640 650 … … 667 677 } 668 678 669 /* Create a rtkldrRdr instance. */679 /* Create a rtkldrRdr_ instance. */ 670 680 PRTKLDRRDR pRdr = (PRTKLDRRDR)RTMemAllocZ(sizeof(*pRdr)); 671 681 if (!pRdr)
Note:
See TracChangeset
for help on using the changeset viewer.