Changeset 38515 in vbox for trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp
- Timestamp:
- Aug 24, 2011 2:33:32 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp
r33540 r38515 137 137 g_hDbgModStrCache = NIL_RTSTRCACHE; 138 138 139 PRTDBGMODREGDBG p Cur= g_pDbgHead;139 PRTDBGMODREGDBG pDbg = g_pDbgHead; 140 140 g_pDbgHead = NULL; 141 while (p Cur)141 while (pDbg) 142 142 { 143 PRTDBGMODREGDBG pNext = p Cur->pNext;144 AssertMsg(p Cur->cUsers == 0, ("%#x %s\n", pCur->cUsers, pCur->pVt->pszName));145 RTMemFree(p Cur);146 p Cur= pNext;143 PRTDBGMODREGDBG pNext = pDbg->pNext; 144 AssertMsg(pDbg->cUsers == 0, ("%#x %s\n", pDbg->cUsers, pDbg->pVt->pszName)); 145 RTMemFree(pDbg); 146 pDbg = pNext; 147 147 } 148 148 149 Assert(!g_pImgHead); 149 PRTDBGMODREGIMG pImg = g_pImgHead; 150 g_pImgHead = NULL; 151 while (pImg) 152 { 153 PRTDBGMODREGIMG pNext = pImg->pNext; 154 AssertMsg(pImg->cUsers == 0, ("%#x %s\n", pImg->cUsers, pImg->pVt->pszName)); 155 RTMemFree(pImg); 156 pImg = pNext; 157 } 150 158 } 151 159 } … … 197 205 198 206 /** 207 * Internal worker for register a image interpreter. 208 * 209 * Called while owning the write lock or when locking isn't required. 210 * 211 * @returns IPRT status code. 212 * @retval VERR_NO_MEMORY 213 * @retval VERR_ALREADY_EXISTS 214 * 215 * @param pVt The virtual function table of the image 216 * interpreter. 217 */ 218 static int rtDbgModImageInterpreterRegister(PCRTDBGMODVTIMG pVt) 219 { 220 /* 221 * Search or duplicate registration. 222 */ 223 PRTDBGMODREGIMG pPrev = NULL; 224 for (PRTDBGMODREGIMG pCur = g_pImgHead; pCur; pCur = pCur->pNext) 225 { 226 if (pCur->pVt == pVt) 227 return VERR_ALREADY_EXISTS; 228 if (!strcmp(pCur->pVt->pszName, pVt->pszName)) 229 return VERR_ALREADY_EXISTS; 230 pPrev = pCur; 231 } 232 233 /* 234 * Create a new record and add it to the end of the list. 235 */ 236 PRTDBGMODREGIMG pReg = (PRTDBGMODREGIMG)RTMemAlloc(sizeof(*pReg)); 237 if (!pReg) 238 return VERR_NO_MEMORY; 239 pReg->pVt = pVt; 240 pReg->cUsers = 0; 241 pReg->pNext = NULL; 242 if (pPrev) 243 pPrev->pNext = pReg; 244 else 245 g_pImgHead = pReg; 246 return VINF_SUCCESS; 247 } 248 249 250 /** 199 251 * Do-once callback that initializes the read/write semaphore and registers 200 252 * the built-in interpreters. … … 219 271 */ 220 272 rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgNm); 273 if (RT_SUCCESS(rc)) 274 rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgDwarf); 275 if (RT_SUCCESS(rc)) 276 rc = rtDbgModImageInterpreterRegister(&g_rtDbgModVtImgLdr); 221 277 if (RT_SUCCESS(rc)) 222 278 { … … 313 369 314 370 315 RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags) 316 { 317 318 return VERR_NOT_IMPLEMENTED; 371 RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags) 372 { 373 /* 374 * Input validation and lazy initialization. 375 */ 376 AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER); 377 *phDbgMod = NIL_RTDBGMOD; 378 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER); 379 AssertReturn(*pszFilename, VERR_INVALID_PARAMETER); 380 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER); 381 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); 382 383 int rc = rtDbgModLazyInit(); 384 if (RT_FAILURE(rc)) 385 return rc; 386 387 if (!pszName) 388 pszName = RTPathFilename(pszFilename); 389 390 /* 391 * Allocate a new module instance. 392 */ 393 PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod)); 394 if (!pDbgMod) 395 return VERR_NO_MEMORY; 396 pDbgMod->u32Magic = RTDBGMOD_MAGIC; 397 pDbgMod->cRefs = 1; 398 rc = RTCritSectInit(&pDbgMod->CritSect); 399 if (RT_SUCCESS(rc)) 400 { 401 pDbgMod->pszName = RTStrCacheEnter(g_hDbgModStrCache, pszName); 402 if (pDbgMod->pszName) 403 { 404 pDbgMod->pszImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename); 405 if (pDbgMod->pszImgFile) 406 { 407 /* 408 * Find an image reader which groks the file. 409 */ 410 rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT); 411 if (RT_SUCCESS(rc)) 412 { 413 rc = VERR_DBG_NO_MATCHING_INTERPRETER; 414 PRTDBGMODREGIMG pImg; 415 for (pImg = g_pImgHead; pImg; pImg = pImg->pNext) 416 { 417 pDbgMod->pImgVt = pImg->pVt; 418 pDbgMod->pvImgPriv = NULL; 419 rc = pImg->pVt->pfnTryOpen(pDbgMod); 420 if (RT_SUCCESS(rc)) 421 { 422 /* 423 * Find a debug info interpreter. 424 */ 425 rc = VERR_DBG_NO_MATCHING_INTERPRETER; 426 for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext) 427 { 428 pDbgMod->pDbgVt = pDbg->pVt; 429 pDbgMod->pvDbgPriv = NULL; 430 rc = pDbg->pVt->pfnTryOpen(pDbgMod); 431 if (RT_SUCCESS(rc)) 432 { 433 /* 434 * That's it! 435 */ 436 ASMAtomicIncU32(&pDbg->cUsers); 437 ASMAtomicIncU32(&pImg->cUsers); 438 RTSemRWReleaseRead(g_hDbgModRWSem); 439 440 *phDbgMod = pDbgMod; 441 return rc; 442 } 443 } 444 445 /* 446 * Image detected, but found no debug info we were 447 * able to understand. 448 */ 449 /** @todo Fall back on exported symbols! */ 450 pDbgMod->pImgVt->pfnClose(pDbgMod); 451 break; 452 } 453 } 454 455 /* 456 * Could it be a file containing raw debug info? 457 */ 458 if (!pImg) 459 { 460 pDbgMod->pImgVt = NULL; 461 pDbgMod->pvImgPriv = NULL; 462 pDbgMod->pszDbgFile = pDbgMod->pszImgFile; 463 pDbgMod->pszImgFile = NULL; 464 465 for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext) 466 { 467 pDbgMod->pDbgVt = pDbg->pVt; 468 pDbgMod->pvDbgPriv = NULL; 469 rc = pDbg->pVt->pfnTryOpen(pDbgMod); 470 if (RT_SUCCESS(rc)) 471 { 472 /* 473 * That's it! 474 */ 475 ASMAtomicIncU32(&pDbg->cUsers); 476 RTSemRWReleaseRead(g_hDbgModRWSem); 477 478 *phDbgMod = pDbgMod; 479 return rc; 480 } 481 } 482 483 pDbgMod->pszImgFile = pDbgMod->pszDbgFile; 484 pDbgMod->pszDbgFile = NULL; 485 } 486 487 /* bail out */ 488 RTSemRWReleaseRead(g_hDbgModRWSem); 489 } 490 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName); 491 } 492 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile); 493 } 494 RTCritSectDelete(&pDbgMod->CritSect); 495 } 496 497 RTMemFree(pDbgMod); 498 return rc; 319 499 } 320 500 RT_EXPORT_SYMBOL(RTDbgModCreateFromImage);
Note:
See TracChangeset
for help on using the changeset viewer.