Changeset 19757 in vbox for trunk/src/VBox/Runtime/common/dbg
- Timestamp:
- May 15, 2009 11:37:31 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47378
- Location:
- trunk/src/VBox/Runtime/common/dbg
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgas.cpp
r19566 r19757 35 35 #include <iprt/asm.h> 36 36 #include <iprt/avl.h> 37 #include <iprt/assert.h> 38 #include <iprt/err.h> 39 #include <iprt/mem.h> 40 #include <iprt/param.h> 37 41 #include <iprt/string.h> 38 39 #include <iprt/mem.h> 40 #include <iprt/err.h> 41 #include <iprt/assert.h> 42 #include <iprt/param.h> 43 //#include "internal/dbg.h" 42 #include <iprt/semaphore.h> 44 43 #include "internal/magics.h" 45 44 … … 102 101 /** Magic value (RTDBGAS_MAGIC). */ 103 102 uint32_t u32Magic; 103 /** The number of reference to this address space. */ 104 uint32_t volatile cRefs; 105 /** Handle of the read-write lock. */ 106 RTSEMRW hLock; 104 107 /** Number of modules in the module address space. */ 105 108 uint32_t cModules; … … 132 135 AssertPtrReturn((pDbgAs), (rc)); \ 133 136 AssertReturn((pDbgAs)->u32Magic == RTDBGAS_MAGIC, (rc)); \ 137 AssertReturn((pDbgAs)->cRefs > 0, (rc)); \ 138 } while (0) 139 140 /** Locks the address space for reading. */ 141 #define RTDBGAS_LOCK_READ(pDbgAs) \ 142 do { \ 143 int rcLock = RTSemRWRequestRead((pDbgAs)->hLock, RT_INDEFINITE_WAIT); \ 144 AssertRC(rcLock); \ 145 } while (0) 146 147 /** Unlocks the address space after reading. */ 148 #define RTDBGAS_UNLOCK_READ(pDbgAs) \ 149 do { \ 150 int rcLock = RTSemRWReleaseRead((pDbgAs)->hLock); \ 151 AssertRC(rcLock); \ 152 } while (0) 153 154 /** Locks the address space for writing. */ 155 #define RTDBGAS_LOCK_WRITE(pDbgAs) \ 156 do { \ 157 int rcLock = RTSemRWRequestWrite((pDbgAs)->hLock, RT_INDEFINITE_WAIT); \ 158 AssertRC(rcLock); \ 159 } while (0) 160 161 /** Unlocks the address space after writing. */ 162 #define RTDBGAS_UNLOCK_WRITE(pDbgAs) \ 163 do { \ 164 int rcLock = RTSemRWReleaseWrite((pDbgAs)->hLock); \ 165 AssertRC(rcLock); \ 134 166 } while (0) 135 167 … … 139 171 *******************************************************************************/ 140 172 static void rtDbgAsModuleUnlinkMod(PRTDBGASINT pDbgAs, PRTDBGASMOD pMod); 173 static void rtDbgAsModuleUnlinkByMap(PRTDBGASINT pDbgAs, PRTDBGASMAP pMap); 141 174 142 175 … … 170 203 /* initalize it. */ 171 204 pDbgAs->u32Magic = RTDBGAS_MAGIC; 205 pDbgAs->cRefs = 1; 206 pDbgAs->hLock = NIL_RTSEMRW; 172 207 pDbgAs->cModules = 0; 173 208 pDbgAs->paModules = NULL; … … 178 213 pDbgAs->LastAddr = LastAddr; 179 214 memcpy(pDbgAs->szName, pszName, cchName + 1); 180 181 *phDbgAs = pDbgAs; 182 return VINF_SUCCESS; 215 int rc = RTSemRWCreate(&pDbgAs->hLock); 216 if (RT_SUCCESS(rc)) 217 { 218 *phDbgAs = pDbgAs; 219 return VINF_SUCCESS; 220 } 221 222 pDbgAs->u32Magic = 0; 223 RTMemFree(pDbgAs); 224 return rc; 183 225 } 184 226 … … 269 311 * reference counting. 270 312 * 271 * @returns IPRT status code. 272 * 273 * @param hDbgAs The address space handle. A NIL handle will 274 * be quietly ignored. 275 */ 276 RTDECL(int) RTDbgAsDestroy(RTDBGAS hDbgAs) 277 { 278 /* 279 * Validate input. 280 */ 281 if (hDbgAs == NIL_RTDBGAS) 282 return VINF_SUCCESS; 283 PRTDBGASINT pDbgAs = hDbgAs; 284 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 285 313 * @param pDbgAs The address space instance to be destroyed. 314 */ 315 static void rtDbgAsDestroy(PRTDBGASINT pDbgAs) 316 { 286 317 /* 287 318 * Mark the address space invalid and release all the modules. … … 302 333 303 334 RTMemFree(pDbgAs); 304 305 return VINF_SUCCESS; 335 } 336 337 338 /** 339 * Retains a reference to the address space. 340 * 341 * @returns New reference count, UINT32_MAX on invalid handle (asserted). 342 * 343 * @param hDbgAs The address space handle. 344 * 345 * @remarks Will not take any locks. 346 */ 347 RTDECL(uint32_t) RTDbgAsRetain(RTDBGAS hDbgAs) 348 { 349 PRTDBGASINT pDbgAs = hDbgAs; 350 RTDBGAS_VALID_RETURN_RC(pDbgAs, UINT32_MAX); 351 return ASMAtomicIncU32(&pDbgAs->cRefs); 352 } 353 354 355 /** 356 * Release a reference to the address space. 357 * 358 * When the reference count reaches zero, the address space is destroyed. 359 * That means unlinking all the modules it currently contains, potentially 360 * causing some or all of them to be destroyed as they are managed by 361 * reference counting. 362 * 363 * @returns New reference count, UINT32_MAX on invalid handle (asserted). 364 * 365 * @param hDbgAs The address space handle. The NIL handle is quietly 366 * ignored and 0 is returned. 367 * 368 * @remarks Will not take any locks. 369 */ 370 RTDECL(uint32_t) RTDbgAsRelease(RTDBGAS hDbgAs) 371 { 372 if (hDbgAs == NIL_RTDBGAS) 373 return 0; 374 PRTDBGASINT pDbgAs = hDbgAs; 375 RTDBGAS_VALID_RETURN_RC(pDbgAs, UINT32_MAX); 376 377 uint32_t cRefs = ASMAtomicDecU32(&pDbgAs->cRefs); 378 if (!cRefs) 379 rtDbgAsDestroy(pDbgAs); 380 return cRefs; 306 381 } 307 382 … … 314 389 * 315 390 * @param hDbgAs The address space handle. 391 * 392 * @remarks Will not take any locks. 316 393 */ 317 394 RTDECL(const char *) RTDbgAsName(RTDBGAS hDbgAs) … … 330 407 * 331 408 * @param hDbgAs The address space handle. 409 * 410 * @remarks Will not take any locks. 332 411 */ 333 412 RTDECL(RTUINTPTR) RTDbgAsFirstAddr(RTDBGAS hDbgAs) … … 346 425 * 347 426 * @param hDbgAs The address space handle. 427 * 428 * @remarks Will not take any locks. 348 429 */ 349 430 RTDECL(RTUINTPTR) RTDbgAsLastAddr(RTDBGAS hDbgAs) … … 363 444 * 364 445 * @param hDbgAs The address space handle. 365 */ 366 RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs) 446 * 447 * @remarks Will not take any locks. 448 */ 449 RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs) 367 450 { 368 451 PRTDBGASINT pDbgAs = hDbgAs; … … 382 465 * @param cb The size of what we're linking. 383 466 * @param pszName The name of the module. 467 * @param fFlags See RTDBGASLINK_FLAGS_*. 468 * 469 * @remarks The caller must have locked the address space for writing. 384 470 */ 385 471 int rtDbgAsModuleLinkCommon(PRTDBGASINT pDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, 386 RTUINTPTR Addr, RTUINTPTR cb, const char *pszName )472 RTUINTPTR Addr, RTUINTPTR cb, const char *pszName, uint32_t fFlags) 387 473 { 388 474 /* 389 475 * Check that the requested space is undisputed. 390 476 */ 391 PRTDBGASMAP pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, false /* fAbove */); 392 if ( pAdjMod 393 && pAdjMod->Core.KeyLast >= Addr) 394 return VERR_ADDRESS_CONFLICT; 395 pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, true /* fAbove */); 396 if ( pAdjMod 397 && pAdjMod->Core.Key >= Addr + cb - 1) 398 return VERR_ADDRESS_CONFLICT; 477 for (;;) 478 { 479 PRTDBGASMAP pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, false /* fAbove */); 480 if ( pAdjMod 481 && pAdjMod->Core.KeyLast >= Addr) 482 { 483 if (!(fFlags & RTDBGASLINK_FLAGS_REPLACE)) 484 return VERR_ADDRESS_CONFLICT; 485 rtDbgAsModuleUnlinkByMap(pDbgAs, pAdjMod); 486 continue; 487 } 488 pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, true /* fAbove */); 489 if ( pAdjMod 490 && pAdjMod->Core.Key >= Addr + cb - 1) 491 { 492 if (!(fFlags & RTDBGASLINK_FLAGS_REPLACE)) 493 return VERR_ADDRESS_CONFLICT; 494 rtDbgAsModuleUnlinkByMap(pDbgAs, pAdjMod); 495 continue; 496 } 497 break; 498 } 399 499 400 500 /* … … 491 591 492 592 493 494 495 593 /** 496 594 * Links a module into the address space at the give address. … … 506 604 * @param hDbgMod The module handle of the module to be linked in. 507 605 * @param ImageAddr The address to link the module at. 508 */ 509 RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr) 606 * @param fFlags See RTDBGASLINK_FLAGS_*. 607 */ 608 RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr, uint32_t fFlags) 510 609 { 511 610 /* … … 526 625 || ImageAddr + cb - 1 < ImageAddr) 527 626 return VERR_OUT_OF_RANGE; 627 AssertReturn(!(fFlags & ~RTDBGASLINK_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER); 528 628 529 629 /* 530 630 * Invoke worker common with RTDbgAsModuleLinkSeg. 531 631 */ 532 return rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, NIL_RTDBGSEGIDX, ImageAddr, cb, pszName); 632 RTDBGAS_LOCK_WRITE(pDbgAs); 633 int rc = rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, NIL_RTDBGSEGIDX, ImageAddr, cb, pszName, fFlags); 634 RTDBGAS_UNLOCK_WRITE(pDbgAs); 635 return rc; 533 636 } 534 637 … … 549 652 * linked in. 550 653 * @param SegAddr The address to link the segment at. 551 */ 552 RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr) 654 * @param fFlags See RTDBGASLINK_FLAGS_*. 655 */ 656 RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr, uint32_t fFlags) 553 657 { 554 658 /* … … 569 673 || SegAddr + cb - 1 < SegAddr) 570 674 return VERR_OUT_OF_RANGE; 675 AssertReturn(!(fFlags & ~RTDBGASLINK_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER); 571 676 572 677 /* 573 678 * Invoke worker common with RTDbgAsModuleLinkSeg. 574 679 */ 575 return rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, iSeg, SegAddr, cb, pszName); 680 RTDBGAS_LOCK_WRITE(pDbgAs); 681 int rc = rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, iSeg, SegAddr, cb, pszName, fFlags); 682 RTDBGAS_UNLOCK_WRITE(pDbgAs); 683 return rc; 576 684 } 577 685 … … 582 690 * @param pDbgAs Pointer to the address space instance data. 583 691 * @param pMod The module to unlink. 692 * 693 * @remarks The caller must have locked the address space for writing. 584 694 */ 585 695 static void rtDbgAsModuleUnlinkMod(PRTDBGASINT pDbgAs, PRTDBGASMOD pMod) … … 636 746 * @param pDbgAs Pointer to the address space instance data. 637 747 * @param pMap The map to unlink and free. 748 * 749 * @remarks The caller must have locked the address space for writing. 638 750 */ 639 751 static void rtDbgAsModuleUnlinkMap(PRTDBGASINT pDbgAs, PRTDBGASMAP pMap) … … 669 781 670 782 /** 671 * Unlinks all the mappings of a module from the address space. 672 * 673 * @returns IPRT status code. 674 * @retval VERR_NOT_FOUND if the module wasn't found. 675 * 676 * @param hDbgAs The address space handle. 677 * @param hDbgMod The module handle of the module to be unlinked. 678 */ 679 RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod) 680 { 681 /* 682 * Validate input. 683 */ 684 PRTDBGASINT pDbgAs = hDbgAs; 685 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 686 if (hDbgMod == NIL_RTDBGMOD) 687 return VINF_SUCCESS; 688 689 PRTDBGASMOD pMod = (PRTDBGASMOD)RTAvlPVGet(&pDbgAs->ModTree, hDbgMod); 690 if (!pMod) 691 return VERR_NOT_FOUND; 692 693 /* 694 * Unmap all but 695 */ 696 while (pMod->pMapHead) 697 rtDbgAsModuleUnlinkMap(pDbgAs, pMod->pMapHead); 698 rtDbgAsModuleUnlinkMod(pDbgAs, pMod); 699 return VINF_SUCCESS; 700 } 701 702 703 /** 704 * Unlinks the mapping at the specified address. 705 * 706 * @returns IPRT status code. 707 * @retval VERR_NOT_FOUND if no module or segment is mapped at that address. 708 * 709 * @param hDbgAs The address space handle. 710 * @param Addr The address within the mapping to be unlinked. 711 */ 712 RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr) 713 { 714 /* 715 * Validate input. 716 */ 717 PRTDBGASINT pDbgAs = hDbgAs; 718 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 719 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 720 if (pMap) 721 return VERR_NOT_FOUND; 722 783 * Worker for RTDbgAsModuleUnlinkByAddr and rtDbgAsModuleLinkCommon that 784 * unlinks a single mapping and releases the module if it's the last one. 785 * 786 * @param pDbgAs The address space instance. 787 * @param pMap The mapping to unlink. 788 * 789 * @remarks The caller must have locked the address space for writing. 790 */ 791 static void rtDbgAsModuleUnlinkByMap(PRTDBGASINT pDbgAs, PRTDBGASMAP pMap) 792 { 723 793 /* 724 794 * Unlink it from the address space. … … 729 799 if (!pMod->pMapHead) 730 800 rtDbgAsModuleUnlinkMod(pDbgAs, pMod); 801 } 802 803 804 /** 805 * Unlinks all the mappings of a module from the address space. 806 * 807 * @returns IPRT status code. 808 * @retval VERR_NOT_FOUND if the module wasn't found. 809 * 810 * @param hDbgAs The address space handle. 811 * @param hDbgMod The module handle of the module to be unlinked. 812 */ 813 RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod) 814 { 815 /* 816 * Validate input. 817 */ 818 PRTDBGASINT pDbgAs = hDbgAs; 819 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 820 if (hDbgMod == NIL_RTDBGMOD) 821 return VINF_SUCCESS; 822 823 RTDBGAS_LOCK_WRITE(pDbgAs); 824 PRTDBGASMOD pMod = (PRTDBGASMOD)RTAvlPVGet(&pDbgAs->ModTree, hDbgMod); 825 if (!pMod) 826 { 827 RTDBGAS_UNLOCK_WRITE(pDbgAs); 828 return VERR_NOT_FOUND; 829 } 830 831 /* 832 * Unmap all everything and release the module. 833 */ 834 while (pMod->pMapHead) 835 rtDbgAsModuleUnlinkMap(pDbgAs, pMod->pMapHead); 836 rtDbgAsModuleUnlinkMod(pDbgAs, pMod); 837 838 RTDBGAS_UNLOCK_WRITE(pDbgAs); 839 return VINF_SUCCESS; 840 } 841 842 843 /** 844 * Unlinks the mapping at the specified address. 845 * 846 * @returns IPRT status code. 847 * @retval VERR_NOT_FOUND if no module or segment is mapped at that address. 848 * 849 * @param hDbgAs The address space handle. 850 * @param Addr The address within the mapping to be unlinked. 851 */ 852 RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr) 853 { 854 /* 855 * Validate input. 856 */ 857 PRTDBGASINT pDbgAs = hDbgAs; 858 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 859 860 RTDBGAS_LOCK_WRITE(pDbgAs); 861 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 862 if (pMap) 863 { 864 RTDBGAS_UNLOCK_WRITE(pDbgAs); 865 return VERR_NOT_FOUND; 866 } 867 868 /* 869 * Hand it to 870 */ 871 rtDbgAsModuleUnlinkByMap(pDbgAs, pMap); 872 873 RTDBGAS_UNLOCK_WRITE(pDbgAs); 731 874 return VINF_SUCCESS; 732 875 } … … 754 897 PRTDBGASINT pDbgAs = hDbgAs; 755 898 RTDBGAS_VALID_RETURN_RC(pDbgAs, NIL_RTDBGMOD); 899 900 RTDBGAS_LOCK_READ(pDbgAs); 756 901 if (iModule >= pDbgAs->cModules) 902 { 903 RTDBGAS_UNLOCK_READ(pDbgAs); 757 904 return NIL_RTDBGMOD; 905 } 758 906 759 907 /* … … 762 910 RTDBGMOD hMod = (RTDBGMOD)pDbgAs->paModules[iModule].Core.Key; 763 911 RTDbgModRetain(hMod); 912 913 RTDBGAS_UNLOCK_READ(pDbgAs); 764 914 return hMod; 765 915 } … … 789 939 PRTDBGASINT pDbgAs = hDbgAs; 790 940 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 941 942 RTDBGAS_LOCK_READ(pDbgAs); 791 943 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 792 944 if (pMap) 945 { 946 RTDBGAS_UNLOCK_READ(pDbgAs); 793 947 return VERR_NOT_FOUND; 948 } 794 949 795 950 /* … … 806 961 if (piSeg) 807 962 *piSeg = pMap->iSeg; 963 964 RTDBGAS_UNLOCK_READ(pDbgAs); 808 965 return VINF_SUCCESS; 809 966 } … … 832 989 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 833 990 AssertPtrReturn(phMod, VERR_INVALID_POINTER); 991 992 RTDBGAS_LOCK_READ(pDbgAs); 834 993 PRTDBGASNAME pName = (PRTDBGASNAME)RTStrSpaceGet(&pDbgAs->NameSpace, pszName); 835 994 if (!pName) 995 { 996 RTDBGAS_UNLOCK_READ(pDbgAs); 836 997 return VERR_NOT_FOUND; 998 } 837 999 838 1000 PRTDBGASMOD pMod = pName->pHead; … … 841 1003 pMod = pMod->pNextName; 842 1004 if (!pMod) 1005 { 1006 RTDBGAS_UNLOCK_READ(pDbgAs); 843 1007 return VERR_OUT_OF_RANGE; 1008 } 844 1009 } 845 1010 … … 850 1015 RTDbgModRetain(hMod); 851 1016 *phMod = hMod; 1017 1018 RTDBGAS_UNLOCK_READ(pDbgAs); 852 1019 return VINF_SUCCESS; 1020 } 1021 1022 1023 /** 1024 * Internal worker that looks up and retains a module. 1025 * 1026 * @returns Module handle, NIL_RTDBGMOD if not found. 1027 * @param pDbgAs The address space instance data. 1028 * @param Addr Address within the module. 1029 * @param piSeg where to return the segment index. 1030 * @param poffSeg Where to return the segment offset. 1031 */ 1032 DECLINLINE(RTDBGMOD) rtDbgAsModuleByAddr(PRTDBGASINT pDbgAs, RTUINTPTR Addr, PRTDBGSEGIDX piSeg, PRTUINTPTR poffSeg) 1033 { 1034 RTDBGMOD hMod = NIL_RTDBGMOD; 1035 1036 RTDBGAS_LOCK_READ(pDbgAs); 1037 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 1038 if (pMap) 1039 { 1040 hMod = (RTDBGMOD)pMap->pMod->Core.Key; 1041 RTDbgModRetain(hMod); 1042 *piSeg = pMap->iSeg; 1043 *poffSeg = Addr - pMap->Core.Key; 1044 } 1045 RTDBGAS_UNLOCK_READ(pDbgAs); 1046 1047 return hMod; 853 1048 } 854 1049 … … 869 1064 { 870 1065 /* 871 * Validate input.1066 * Validate input and resolve the address. 872 1067 */ 873 1068 PRTDBGASINT pDbgAs = hDbgAs; 874 1069 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 875 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 876 if (pMap) 1070 1071 RTDBGSEGIDX iSeg; 1072 RTUINTPTR offSeg; 1073 RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg); 1074 if (hMod == NIL_RTDBGMOD) 877 1075 return VERR_NOT_FOUND; 878 1076 … … 880 1078 * Forward the call. 881 1079 */ 882 RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key; 883 return RTDbgModSymbolAdd(hMod, pszSymbol, pMap->iSeg, Addr - pMap->Core.Key, cb); 1080 int rc = RTDbgModSymbolAdd(hMod, pszSymbol, iSeg, offSeg, cb); 1081 RTDbgModRelease(hMod); 1082 return rc; 884 1083 } 885 1084 … … 901 1100 { 902 1101 /* 903 * Validate input .1102 * Validate input and resolve the address. 904 1103 */ 905 1104 PRTDBGASINT pDbgAs = hDbgAs; 906 1105 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 907 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 908 if (pMap) 1106 1107 RTDBGSEGIDX iSeg; 1108 RTUINTPTR offSeg; 1109 RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg); 1110 if (hMod == NIL_RTDBGMOD) 909 1111 return VERR_NOT_FOUND; 910 1112 … … 912 1114 * Forward the call. 913 1115 */ 914 RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key; 915 return RTDbgModSymbolByAddr(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, pSymbol); 1116 int rc = RTDbgModSymbolByAddr(hMod, iSeg, offSeg, poffDisp, pSymbol); 1117 RTDbgModRelease(hMod); 1118 return rc; 916 1119 } 917 1120 … … 934 1137 { 935 1138 /* 936 * Validate input .1139 * Validate input and resolve the address. 937 1140 */ 938 1141 PRTDBGASINT pDbgAs = hDbgAs; 939 1142 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 940 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 941 if (pMap) 1143 1144 RTDBGSEGIDX iSeg; 1145 RTUINTPTR offSeg; 1146 RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg); 1147 if (hMod == NIL_RTDBGMOD) 942 1148 return VERR_NOT_FOUND; 943 1149 … … 945 1151 * Forward the call. 946 1152 */ 947 RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key; 948 return RTDbgModSymbolByAddrA(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, ppSymbol); 1153 int rc = RTDbgModSymbolByAddrA(hMod, iSeg, offSeg, poffDisp, ppSymbol); 1154 RTDbgModRelease(hMod); 1155 return rc; 1156 } 1157 1158 1159 /** 1160 * Creates a snapshot of the module table on the temporary heap. 1161 * 1162 * The caller must release all the module handles before freeing the table 1163 * using RTMemTmpFree. 1164 * 1165 * @returns Module table snaphot. 1166 * @param pDbgAs The address space instance data. 1167 * @param pcModules Where to return the number of modules. 1168 */ 1169 DECLINLINE(PRTDBGMOD) rtDbgAsSnapshotModuleTable(PRTDBGASINT pDbgAs, uint32_t *pcModules) 1170 { 1171 RTDBGAS_LOCK_READ(pDbgAs); 1172 1173 uint32_t iMod = *pcModules = pDbgAs->cModules; 1174 PRTDBGMOD paModules = (PRTDBGMOD)RTMemTmpAlloc(sizeof(paModules[0]) * RT_MAX(iMod, 1)); 1175 if (paModules) 1176 { 1177 while (iMod-- > 0) 1178 { 1179 RTDBGMOD hMod = paModules[iMod]; 1180 paModules[iMod] = hMod; 1181 RTDbgModRetain(hMod); 1182 } 1183 } 1184 1185 RTDBGAS_UNLOCK_READ(pDbgAs); 1186 return paModules; 949 1187 } 950 1188 … … 973 1211 * Iterate the modules, looking for the symbol. 974 1212 */ 975 for (uint32_t i = 0; i < pDbgAs->cModules; i++) 976 { 977 RTDBGMOD hMod = (RTDBGMOD)pDbgAs->paModules[i].Core.Key; 978 int rc = RTDbgModSymbolByName(hMod, pszSymbol, pSymbol); 1213 uint32_t cModules; 1214 PRTDBGMOD paModules = rtDbgAsSnapshotModuleTable(pDbgAs, &cModules); 1215 if (!paModules) 1216 return VERR_NO_TMP_MEMORY; 1217 1218 for (uint32_t i = 0; i < cModules; i++) 1219 { 1220 int rc = RTDbgModSymbolByName(paModules[i], pszSymbol, pSymbol); 1221 RTDbgModRelease(paModules[i]); 979 1222 if (RT_SUCCESS(rc)) 1223 { 1224 for (i = i + 1; i < cModules; i++) 1225 RTDbgModRelease(paModules[i]); 1226 RTMemTmpFree(paModules); 980 1227 return rc; 981 } 1228 } 1229 } 1230 1231 RTMemTmpFree(paModules); 982 1232 return VERR_SYMBOL_NOT_FOUND; 983 1233 } … … 1009 1259 * Iterate the modules, looking for the symbol. 1010 1260 */ 1011 for (uint32_t i = 0; i < pDbgAs->cModules; i++) 1012 { 1013 RTDBGMOD hMod = (RTDBGMOD)pDbgAs->paModules[i].Core.Key; 1014 int rc = RTDbgModSymbolByNameA(hMod, pszSymbol, ppSymbol); 1261 uint32_t cModules; 1262 PRTDBGMOD paModules = rtDbgAsSnapshotModuleTable(pDbgAs, &cModules); 1263 if (!paModules) 1264 return VERR_NO_TMP_MEMORY; 1265 1266 for (uint32_t i = 0; i < cModules; i++) 1267 { 1268 int rc = RTDbgModSymbolByNameA(paModules[i], pszSymbol, ppSymbol); 1269 RTDbgModRelease(paModules[i]); 1015 1270 if (RT_SUCCESS(rc)) 1271 { 1272 for (i = i + 1; i < cModules; i++) 1273 RTDbgModRelease(paModules[i]); 1274 RTMemTmpFree(paModules); 1016 1275 return rc; 1017 } 1276 } 1277 } 1278 1279 RTMemTmpFree(paModules); 1018 1280 return VERR_SYMBOL_NOT_FOUND; 1019 1281 } … … 1036 1298 { 1037 1299 /* 1038 * Validate input .1300 * Validate input and resolve the address. 1039 1301 */ 1040 1302 PRTDBGASINT pDbgAs = hDbgAs; 1041 1303 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 1042 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 1043 if (pMap) 1304 1305 RTDBGSEGIDX iSeg; 1306 RTUINTPTR offSeg; 1307 RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg); 1308 if (hMod == NIL_RTDBGMOD) 1044 1309 return VERR_NOT_FOUND; 1045 1310 … … 1047 1312 * Forward the call. 1048 1313 */ 1049 RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key; 1050 return RTDbgModLineByAddr(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, pLine); 1314 int rc = RTDbgModLineByAddr(hMod, iSeg, offSeg, poffDisp, pLine); 1315 RTDbgModRelease(hMod); 1316 return rc; 1051 1317 } 1052 1318 … … 1069 1335 { 1070 1336 /* 1071 * Validate input .1337 * Validate input and resolve the address. 1072 1338 */ 1073 1339 PRTDBGASINT pDbgAs = hDbgAs; 1074 1340 RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE); 1075 PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr); 1076 if (pMap) 1341 1342 RTDBGSEGIDX iSeg; 1343 RTUINTPTR offSeg; 1344 RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg); 1345 if (hMod == NIL_RTDBGMOD) 1077 1346 return VERR_NOT_FOUND; 1078 1347 … … 1080 1349 * Forward the call. 1081 1350 */ 1082 RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key; 1083 return RTDbgModLineByAddrA(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, ppLine); 1084 } 1085 1351 int rc = RTDbgModLineByAddrA(hMod, iSeg, offSeg, poffDisp, ppLine); 1352 RTDbgModRelease(hMod); 1353 return rc; 1354 } 1355 -
trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp
r19566 r19757 45 45 46 46 47 RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, const char *pszImgFile, const char *pszDbgFile) 47 RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags) 48 { 49 return VERR_NOT_IMPLEMENTED; 50 } 51 52 RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags) 53 { 54 return VERR_NOT_IMPLEMENTED; 55 } 56 57 RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend, uint32_t fFlags) 48 58 { 49 59 return VERR_NOT_IMPLEMENTED;
Note:
See TracChangeset
for help on using the changeset viewer.