- Timestamp:
- Nov 3, 2018 2:59:35 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 126340
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGPlugInOS2.cpp
r75166 r75242 89 89 uint32_t mte_modver; /**< added even later. */ 90 90 } LDRMTE; 91 /** @name LDRMTE::mte_flag2 values 92 * @{ */ 93 #define MTEFORMATMASK UINT16_C(0x0003) 94 #define MTEFORMATR1 UINT16_C(0x0000) 95 #define MTEFORMATNE UINT16_C(0x0001) 96 #define MTEFORMATLX UINT16_C(0x0002) 97 #define MTEFORMATR2 UINT16_C(0x0003) 98 #define MTESYSTEMDLL UINT16_C(0x0004) 99 #define MTELOADORATTACH UINT16_C(0x0008) 100 #define MTECIRCLEREF UINT16_C(0x0010) 101 #define MTEFREEFIXUPS UINT16_C(0x0020) /* had different meaning earlier */ 102 #define MTEPRELOADED UINT16_C(0x0040) 103 #define MTEGETMTEDONE UINT16_C(0x0080) 104 #define MTEPACKSEGDONE UINT16_C(0x0100) 105 #define MTE20LIELIST UINT16_C(0x0200) 106 #define MTESYSPROCESSED UINT16_C(0x0400) 107 #define MTEPSDMOD UINT16_C(0x0800) 108 #define MTEDLLONEXTLST UINT16_C(0x1000) 109 #define MTEPDUMPCIRCREF UINT16_C(0x2000) 110 /** @} */ 111 /** @name LDRMTE::mte_flag1 values 112 * @{ */ 113 #define MTE1_NOAUTODS UINT32_C(0x00000000) 114 #define MTE1_SOLO UINT32_C(0x00000001) 115 #define MTE1_INSTANCEDS UINT32_C(0x00000002) 116 #define MTE1_INSTLIBINIT UINT32_C(0x00000004) 117 #define MTE1_GINISETUP UINT32_C(0x00000008) 118 #define MTE1_NOINTERNFIXUPS UINT32_C(0x00000010) 119 #define MTE1_NOEXTERNFIXUPS UINT32_C(0x00000020) 120 #define MTE1_CLASS_ALL UINT32_C(0x00000000) 121 #define MTE1_CLASS_PROGRAM UINT32_C(0x00000040) 122 #define MTE1_CLASS_GLOBAL UINT32_C(0x00000080) 123 #define MTE1_CLASS_SPECIFIC UINT32_C(0x000000c0) 124 #define MTE1_CLASS_MASK UINT32_C(0x000000c0) 125 #define MTE1_MTEPROCESSED UINT32_C(0x00000100) 126 #define MTE1_USED UINT32_C(0x00000200) 127 #define MTE1_DOSLIB UINT32_C(0x00000400) 128 #define MTE1_DOSMOD UINT32_C(0x00000800) /**< The OS/2 kernel (DOSCALLS).*/ 129 #define MTE1_MEDIAFIXED UINT32_C(0x00001000) 130 #define MTE1_LDRINVALID UINT32_C(0x00002000) 131 #define MTE1_PROGRAMMOD UINT32_C(0x00000000) 132 #define MTE1_DEVDRVMOD UINT32_C(0x00004000) 133 #define MTE1_LIBRARYMOD UINT32_C(0x00008000) 134 #define MTE1_VDDMOD UINT32_C(0x00010000) 135 #define MTE1_MVDMMOD UINT32_C(0x00020000) 136 #define MTE1_INGRAPH UINT32_C(0x00040000) 137 #define MTE1_GINIDONE UINT32_C(0x00080000) 138 #define MTE1_ADDRALLOCED UINT32_C(0x00100000) 139 #define MTE1_FSDMOD UINT32_C(0x00200000) 140 #define MTE1_FSHMOD UINT32_C(0x00400000) 141 #define MTE1_LONGNAMES UINT32_C(0x00800000) 142 #define MTE1_MEDIACONTIG UINT32_C(0x01000000) 143 #define MTE1_MEDIA16M UINT32_C(0x02000000) 144 #define MTE1_SWAPONLOAD UINT32_C(0x04000000) 145 #define MTE1_PORTHOLE UINT32_C(0x08000000) 146 #define MTE1_MODPROT UINT32_C(0x10000000) 147 #define MTE1_NEWMOD UINT32_C(0x20000000) 148 #define MTE1_DLLTERM UINT32_C(0x40000000) 149 #define MTE1_SYMLOADED UINT32_C(0x80000000) 150 /** @} */ 151 91 152 92 153 /** … … 95 156 typedef struct LDRSMTE 96 157 { 97 uint32_t smte_mpages; /**< module page count. */98 uint32_t smte_startobj; /**< Entrypoint segment number. */99 uint32_t smte_eip; /**< Entrypoint offset value. */100 uint32_t smte_stackobj; /**< Stack segment number. */101 uint32_t smte_esp; /**< Stack offset value*/102 uint32_t smte_pageshift; /**< Page shift value. */103 uint32_t smte_fixupsize; /**< Size of the fixup section. */104 uint32_t smte_objtab; /**< Pointer to LDROTE array. */105 uint32_t smte_objcnt; /**< Number of segments. */106 uint32_t smte_objmap; /**< Address of the object page map. */107 uint32_t smte_itermap; /**< File offset of the iterated data map*/108 uint32_t smte_rsrctab; /**< Pointer to resource table? */109 uint32_t smte_rsrccnt; /**< Number of resource table entries. */110 uint32_t smte_restab; /**< Pointer to the resident name table. */111 uint32_t smte_enttab; /**< Possibly entry point table address, if not file offset. */112 uint32_t smte_fpagetab; /* Offset of Fixup Page Table*/113 uint32_t smte_frectab; /* Offset of Fixup Record Table*/114 uint32_t smte_impmod; 115 uint32_t smte_impproc; 116 uint32_t smte_datapage; 117 uint32_t smte_nrestab; 118 uint32_t smte_cbnrestab; 119 uint32_t smte_autods; 120 uint32_t smte_debuginfo; /* Offset of the debugging info*/121 uint32_t smte_debuglen; /* The len of the debug info in bytes*/122 uint32_t smte_heapsize; 123 uint32_t smte_path; /**< Address of full name string. */124 uint16_t smte_semcount; 125 uint16_t smte_semowner; 126 uint32_t smte_pfilecache; /** Address of cached data if replace-module is used. */127 uint32_t smte_stacksize; /**< Stack size for .exe thread 1. */128 uint16_t smte_alignshift; 129 uint16_t smte_NEexpver; 130 uint16_t smte_pathlen; /**< Length of smte_path */131 uint16_t smte_NEexetype; 132 uint16_t smte_csegpack; 133 uint8_t smte_major_os; /**< added later to lie about OS version */134 uint8_t smte_minor_os; /**< added later to lie about OS version */158 uint32_t smte_mpages; /**< 0x00: module page count. */ 159 uint32_t smte_startobj; /**< 0x04: Entrypoint segment number. */ 160 uint32_t smte_eip; /**< 0x08: Entrypoint offset value. */ 161 uint32_t smte_stackobj; /**< 0x0c: Stack segment number. */ 162 uint32_t smte_esp; /**< 0x10: Stack offset value*/ 163 uint32_t smte_pageshift; /**< 0x14: Page shift value. */ 164 uint32_t smte_fixupsize; /**< 0x18: Size of the fixup section. */ 165 uint32_t smte_objtab; /**< 0x1c: Pointer to LDROTE array. */ 166 uint32_t smte_objcnt; /**< 0x20: Number of segments. */ 167 uint32_t smte_objmap; /**< 0x20: Address of the object page map. */ 168 uint32_t smte_itermap; /**< 0x20: File offset of the iterated data map*/ 169 uint32_t smte_rsrctab; /**< 0x20: Pointer to resource table? */ 170 uint32_t smte_rsrccnt; /**< 0x30: Number of resource table entries. */ 171 uint32_t smte_restab; /**< 0x30: Pointer to the resident name table. */ 172 uint32_t smte_enttab; /**< 0x30: Possibly entry point table address, if not file offset. */ 173 uint32_t smte_fpagetab; /**< 0x30 */ 174 uint32_t smte_frectab; /**< 0x40 */ 175 uint32_t smte_impmod; /**< 0x44 */ 176 uint32_t smte_impproc; /**< 0x48 */ 177 uint32_t smte_datapage; /**< 0x4c */ 178 uint32_t smte_nrestab; /**< 0x50 */ 179 uint32_t smte_cbnrestab; /**< 0x54 */ 180 uint32_t smte_autods; /**< 0x58 */ 181 uint32_t smte_debuginfo; /**< 0x5c */ 182 uint32_t smte_debuglen; /**< 0x60 */ 183 uint32_t smte_heapsize; /**< 0x64 */ 184 uint32_t smte_path; /**< 0x68 Address of full name string. */ 185 uint16_t smte_semcount; /**< 0x6c */ 186 uint16_t smte_semowner; /**< 0x6e */ 187 uint32_t smte_pfilecache; /**< 0x70: Address of cached data if replace-module is used. */ 188 uint32_t smte_stacksize; /**< 0x74: Stack size for .exe thread 1. */ 189 uint16_t smte_alignshift; /**< 0x78: */ 190 uint16_t smte_NEexpver; /**< 0x7a: */ 191 uint16_t smte_pathlen; /**< 0x7c: Length of smte_path */ 192 uint16_t smte_NEexetype; /**< 0x7e: */ 193 uint16_t smte_csegpack; /**< 0x80: */ 194 uint8_t smte_major_os; /**< 0x82: added later to lie about OS version */ 195 uint8_t smte_minor_os; /**< 0x83: added later to lie about OS version */ 135 196 } LDRSMTE; 197 AssertCompileSize(LDRSMTE, 0x84); 136 198 137 199 typedef struct LDROTE … … 444 506 } DBGDIGGEROS2BUF; 445 507 446 447 static void dbgdiggerOS2ProcessModule(PUVM pUVM, PDBGDIGGEROS2 pThis, DBGDIGGEROS2BUF *pBuf) 508 /** Arguments dbgdiggerOS2ProcessModule passes to the module open callback. */ 509 typedef struct 510 { 511 const char *pszModPath; 512 const char *pszModName; 513 LDRMTE const *pMte; 514 LDRSMTE const *pSwapMte; 515 } DBGDIGGEROS2OPEN; 516 517 518 /** 519 * @callback_method_impl{FNRTDBGCFGOPEN, Debug image/image searching callback.} 520 */ 521 static DECLCALLBACK(int) dbgdiggerOs2OpenModule(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2) 522 { 523 DBGDIGGEROS2OPEN *pArgs = (DBGDIGGEROS2OPEN *)pvUser1; 524 525 RTDBGMOD hDbgMod = NIL_RTDBGMOD; 526 int rc = RTDbgModCreateFromImage(&hDbgMod, pszFilename, pArgs->pszModName, RTLDRARCH_WHATEVER, hDbgCfg); 527 if (RT_SUCCESS(rc)) 528 { 529 /** @todo Do some info matching before using it? */ 530 531 *(PRTDBGMOD)pvUser2 = hDbgMod; 532 return VINF_CALLBACK_RETURN; 533 } 534 LogRel(("DbgDiggerOs2: dbgdiggerOs2OpenModule: %Rrc - %s\n", rc, pszFilename)); 535 return rc; 536 } 537 538 539 static void dbgdiggerOS2ProcessModule(PUVM pUVM, PDBGDIGGEROS2 pThis, DBGDIGGEROS2BUF *pBuf, 540 const char *pszCacheSubDir, RTDBGAS hAs, RTDBGCFG hDbgCfg) 448 541 { 449 542 RT_NOREF(pThis); … … 452 545 * Save the MTE. 453 546 */ 547 static const char * const s_apszMteFmts[4] = { "Reserved1", "NE", "LX", "Reserved2" }; 454 548 LDRMTE const Mte = pBuf->mte; 549 if ((Mte.mte_flags2 & MTEFORMATMASK) != MTEFORMATLX) 550 { 551 LogRel(("DbgDiggerOs2: MTE format not implemented: %s (%d)\n", 552 s_apszMteFmts[(Mte.mte_flags2 & MTEFORMATMASK)], Mte.mte_flags2 & MTEFORMATMASK)); 553 return; 554 } 455 555 456 556 /* … … 473 573 } 474 574 475 #if 0476 575 /* 477 576 * Try read the path name, falling back on module name. 478 577 */ 479 rc = VERR_NOT_AVAILABLE; 578 char szModPath[260]; 579 rc = VERR_READ_ERROR; 480 580 if (SwapMte.smte_path != 0 && SwapMte.smte_pathlen > 0) 481 581 { 482 uint32_t cbToRead = RT_MIN(SwapMte.smte_path, sizeof( *pBuf) - 1);483 rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_path), pBuf->ach, cbToRead);484 pBuf->ach[cbToRead] = '\0';582 uint32_t cbToRead = RT_MIN(SwapMte.smte_path, sizeof(szModPath) - 1); 583 rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_path), szModPath, cbToRead); 584 szModPath[cbToRead] = '\0'; 485 585 } 486 586 if (RT_FAILURE(rc)) 487 587 { 488 memcpy(pBuf->ach, Mte.mte_modname, sizeof(Mte.mte_modname)); 489 pBuf->ach[sizeof(Mte.mte_modname)] = '\0'; 490 RTStrStripR(pBuf->ach); 491 } 492 #endif 493 494 /* 495 * Create a simple module. 496 */ 497 memcpy(pBuf->ach, Mte.mte_modname, sizeof(Mte.mte_modname)); 498 pBuf->ach[sizeof(Mte.mte_modname)] = '\0'; 499 RTStrStripR(pBuf->ach); 500 501 RTDBGMOD hDbgMod; 502 rc = RTDbgModCreate(&hDbgMod, pBuf->ach, 0 /*cbSeg*/, 0 /*fFlags*/); 588 memcpy(szModPath, Mte.mte_modname, sizeof(Mte.mte_modname)); 589 szModPath[sizeof(Mte.mte_modname)] = '\0'; 590 RTStrStripR(szModPath); 591 } 592 LogRel(("DbgDiggerOS2: szModPath='%s'\n", szModPath)); 593 594 /* 595 * Sanitize the module name. 596 */ 597 char szModName[16]; 598 memcpy(szModName, Mte.mte_modname, sizeof(Mte.mte_modname)); 599 szModName[sizeof(Mte.mte_modname)] = '\0'; 600 RTStrStripR(szModName); 601 602 /* 603 * Read the object table into the buffer. 604 */ 605 rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_objtab), 606 &pBuf->aOtes[0], sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt); 503 607 if (RT_FAILURE(rc)) 504 608 { 505 LogRel(("DbgDiggerOs2: RTDbgModCreate failed: %Rrc\n", rc)); 609 LogRel(("DbgDiggerOs2: Error reading object table @ %#RX32 LB %#zx: %Rrc\n", 610 SwapMte.smte_objtab, sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt, rc)); 506 611 return; 507 612 } 613 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++) 614 { 615 LogRel(("DbgDiggerOs2: seg%u: %RX32 LB %#x\n", i, pBuf->aOtes[i].ote_base, pBuf->aOtes[i].ote_size)); 616 /** @todo validate it. */ 617 } 618 619 /* No need to continue without an address space (shouldn't happen). */ 620 if (hAs == NIL_RTDBGAS) 621 return; 622 623 /* 624 * Try find a debug file for this module. 625 */ 626 RTDBGMOD hDbgMod = NIL_RTDBGMOD; 627 if (hDbgCfg != NIL_RTDBGCFG) 628 { 629 DBGDIGGEROS2OPEN Args = { szModPath, szModName, &Mte, &SwapMte }; 630 RTDbgCfgOpenEx(hDbgCfg, szModPath, pszCacheSubDir, NULL, 631 RT_OPSYS_OS2 | RTDBGCFG_O_CASE_INSENSITIVE | RTDBGCFG_O_EXECUTABLE_IMAGE 632 | RTDBGCFG_O_RECURSIVE | RTDBGCFG_O_NO_SYSTEM_PATHS, 633 dbgdiggerOs2OpenModule, &Args, &hDbgMod); 634 } 635 636 /* 637 * Fallback is a simple module into which we insert sections. 638 */ 639 uint32_t cSegments = SwapMte.smte_objcnt; 640 if (hDbgMod == NIL_RTDBGMOD) 641 { 642 rc = RTDbgModCreate(&hDbgMod, szModName, 0 /*cbSeg*/, 0 /*fFlags*/); 643 if (RT_SUCCESS(rc)) 644 { 645 uint32_t uRva = 0; 646 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++) 647 { 648 char szSegNm[16]; 649 RTStrPrintf(szSegNm, sizeof(szSegNm), "seg%u", i); 650 rc = RTDbgModSegmentAdd(hDbgMod, uRva, pBuf->aOtes[i].ote_size, szSegNm, 0 /*fFlags*/, NULL); 651 if (RT_FAILURE(rc)) 652 { 653 LogRel(("DbgDiggerOs2: RTDbgModSegmentAdd failed (i=%u, ote_size=%#x): %Rrc\n", 654 i, pBuf->aOtes[i].ote_size, rc)); 655 cSegments = i; 656 break; 657 } 658 uRva += RT_ALIGN_32(pBuf->aOtes[i].ote_size, _4K); 659 } 660 } 661 else 662 { 663 LogRel(("DbgDiggerOs2: RTDbgModCreate failed: %Rrc\n", rc)); 664 return; 665 } 666 } 667 668 /* 669 * Tag the module and link its segments. 670 */ 508 671 rc = RTDbgModSetTag(hDbgMod, DIG_OS2_MOD_TAG); 509 672 if (RT_SUCCESS(rc)) 510 673 { 511 RTDBGAS hAs = DBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL); 512 if (hAs != NIL_RTDBGAS) 513 { 514 /* 515 * Read the object table and do the linking of each of them. 516 */ 517 rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_objtab), 518 &pBuf->aOtes[0], sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt); 519 if (RT_SUCCESS(rc)) 520 { 521 uint32_t uRva = 0; 522 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++) 523 { 524 char szSegNm[16]; 525 RTStrPrintf(szSegNm, sizeof(szSegNm), "seg%u", i); 526 rc = RTDbgModSegmentAdd(hDbgMod, uRva, pBuf->aOtes[i].ote_size, szSegNm, 0 /*fFlags*/, NULL); 527 if (RT_FAILURE(rc)) 528 { 529 LogRel(("DbgDiggerOs2: RTDbgModSegmentAdd failed (i=%u, ote_size=%#x): %Rrc\n", 530 i, pBuf->aOtes[i].ote_size, rc)); 531 break; 532 } 533 rc = RTDbgAsModuleLinkSeg(hAs, hDbgMod, i, pBuf->aOtes[i].ote_base, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/); 534 if (RT_FAILURE(rc)) 535 LogRel(("DbgDiggerOs2: RTDbgAsModuleLinkSeg failed (i=%u, ote_base=%#x): %Rrc\n", 536 i, pBuf->aOtes[i].ote_base, rc)); 537 uRva += RT_ALIGN_32(pBuf->aOtes[i].ote_size, _4K); 538 } 539 } 540 else 541 LogRel(("DbgDiggerOs2: Error reading object table @ %#RX32 LB %#zx: %Rrc\n", 542 SwapMte.smte_objtab, sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt, rc)); 674 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++) 675 { 676 rc = RTDbgAsModuleLinkSeg(hAs, hDbgMod, i, pBuf->aOtes[i].ote_base, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/); 677 if (RT_FAILURE(rc)) 678 LogRel(("DbgDiggerOs2: RTDbgAsModuleLinkSeg failed (i=%u, ote_base=%#x): %Rrc\n", 679 i, pBuf->aOtes[i].ote_base, rc)); 543 680 } 544 else545 LogRel(("DbgDiggerOs2: DBGFR3AsResolveAndRetain failed\n"));546 RTDbgAsRelease(hAs);547 681 } 548 682 else 549 683 LogRel(("DbgDiggerOs2: RTDbgModSetTag failed: %Rrc\n", rc)); 550 684 RTDbgModRelease(hDbgMod); 551 552 685 } 553 686 … … 602 735 if (RT_SUCCESS(rc)) 603 736 { 737 uint32_t uOs2Krnl = UINT32_MAX; 738 RTDBGCFG hDbgCfg = DBGFR3AsGetConfig(pUVM); /* (don't release this) */ 739 RTDBGAS hAs = DBGFR3AsResolveAndRetain(pUVM, DBGF_AS_GLOBAL); 740 741 char szCacheSubDir[24]; 742 RTStrPrintf(szCacheSubDir, sizeof(szCacheSubDir), "os2-%u.%u", pThis->OS2MajorVersion, pThis->OS2MinorVersion); 743 604 744 DBGFR3AddrFromFlat(pUVM, &Addr, uBuf.au32[0]); 605 745 while (Addr.FlatPtr != 0 && Addr.FlatPtr != UINT32_MAX) … … 610 750 LogRel(("DbgDiggerOs2: Module @ %#010RX32: %.8s %#x %#x\n", (uint32_t)Addr.FlatPtr, 611 751 uBuf.mte.mte_modname, uBuf.mte.mte_flags1, uBuf.mte.mte_flags2)); 752 if (uBuf.mte.mte_flags1 & MTE1_DOSMOD) 753 uOs2Krnl = (uint32_t)Addr.FlatPtr; 612 754 613 755 DBGFR3AddrFromFlat(pUVM, &Addr, uBuf.mte.mte_link); 614 dbgdiggerOS2ProcessModule(pUVM, pThis, &uBuf );756 dbgdiggerOS2ProcessModule(pUVM, pThis, &uBuf, szCacheSubDir, hAs, hDbgCfg); 615 757 } 758 759 /* Load the kernel again. To make sure we didn't drop any segments due 760 to overlap/conflicts/whatever. */ 761 if (uOs2Krnl != UINT32_MAX) 762 { 763 rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, uOs2Krnl), 764 &uBuf.mte, sizeof(uBuf.mte)); 765 if (RT_SUCCESS(rc)) 766 { 767 LogRel(("DbgDiggerOs2: Module @ %#010RX32: %.8s %#x %#x [again]\n", (uint32_t)Addr.FlatPtr, 768 uBuf.mte.mte_modname, uBuf.mte.mte_flags1, uBuf.mte.mte_flags2)); 769 dbgdiggerOS2ProcessModule(pUVM, pThis, &uBuf, szCacheSubDir, hAs, hDbgCfg); 770 } 771 } 772 773 RTDbgAsRelease(hAs); 616 774 } 617 775 }
Note:
See TracChangeset
for help on using the changeset viewer.