Changeset 73491 in vbox for trunk/src/VBox/VMM/VMMR3
- Timestamp:
- Aug 3, 2018 2:51:55 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 124118
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/DBGFR3ModInMem.cpp
r73150 r73491 24 24 25 25 #include <VBox/err.h> 26 #include <iprt/ctype.h> 26 27 #include <iprt/ldr.h> 27 28 #include <iprt/mem.h> 29 #include <iprt/path.h> 28 30 #include <iprt/string.h> 29 31 #include <iprt/formats/pecoff.h> … … 85 87 86 88 /** 89 * Normalizes a debug module name. 90 * 91 * @returns Normalized debug module name. 92 * @param pszName The name. 93 * @param pszBuf Buffer to use if work is needed. 94 * @param cbBuf Size of buffer. 95 */ 96 const char *dbgfR3ModNormalizeName(const char *pszName, char *pszBuf, size_t cbBuf) 97 { 98 /* 99 * Skip to the filename in case someone gave us a full filename path. 100 */ 101 pszName = RTPathFilenameEx(pszName, RTPATH_STR_F_STYLE_DOS); 102 103 /* 104 * Is it okay? 105 */ 106 size_t cchName = strlen(pszName); 107 size_t off = 0; 108 for (;; off++) 109 { 110 char ch = pszName[off]; 111 if (ch == '\0') 112 return pszName; 113 if (!RT_C_IS_ALNUM(ch) && ch != '_') 114 break; 115 } 116 117 /* 118 * It's no okay, so morph it. 119 */ 120 if (cchName >= cbBuf) 121 cchName = cbBuf - 1; 122 for (off = 0; off < cchName; off++) 123 { 124 char ch = pszName[off]; 125 if (!RT_C_IS_ALNUM(ch)) 126 ch = '_'; 127 pszBuf[off] = ch; 128 } 129 pszBuf[off] = '\0'; 130 131 return pszBuf; 132 } 133 134 135 /** 87 136 * Handles in-memory ELF images. 88 137 * … … 91 140 * @param pImageAddr The image address. 92 141 * @param fFlags Flags, DBGFMODINMEM_F_XXX. 93 * @param pszName The image name, optional. 142 * @param pszName The module name, optional. 143 * @param pszFilename The image filename, optional. 94 144 * @param enmArch The image arch if we force it, pass 95 145 * RTLDRARCH_WHATEVER if you don't care. … … 99 149 * @param pErrInfo Where to return extended error info on failure. 100 150 */ 101 static int dbgfR3ModInMemElf(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, 151 static int dbgfR3ModInMemElf(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, const char *pszFilename, 102 152 RTLDRARCH enmArch, uint32_t cbImage, PDBGFMODINMEMBUF puBuf, 103 153 PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo) 104 154 { 105 RT_NOREF(pUVM, fFlags, pszName, enmArch, cbImage, puBuf, phDbgMod);155 RT_NOREF(pUVM, fFlags, pszName, pszFilename, enmArch, cbImage, puBuf, phDbgMod); 106 156 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_INVALID_EXE_SIGNATURE, "Found ELF magic at %RGv", pImageAddr->FlatPtr); 107 157 } … … 422 472 * @param pImageAddr The image address. 423 473 * @param fFlags Flags, DBGFMODINMEM_F_XXX. 424 * @param pszName The image name, optional. 474 * @param pszName The module name, optional. 475 * @param pszFilename The image filename, optional. 425 476 * @param enmArch The image arch if we force it, pass 426 477 * RTLDRARCH_WHATEVER if you don't care. … … 432 483 * @param pErrInfo Where to return extended error info on failure. 433 484 */ 434 static int dbgfR3ModInMemPe(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, RTLDRARCH enmArch,435 uint32_t cbImage, uint32_t offPeHdrs, uint32_t cbPeHdrsPart1, PDBGFMODINMEMBUF puBuf,436 P RTDBGMOD phDbgMod, PRTERRINFO pErrInfo)485 static int dbgfR3ModInMemPe(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, const char *pszFilename, 486 RTLDRARCH enmArch, uint32_t cbImage, uint32_t offPeHdrs, uint32_t cbPeHdrsPart1, 487 PDBGFMODINMEMBUF puBuf, PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo) 437 488 { 438 489 /* … … 533 584 534 585 /* 535 * Guess the image name if not specified. 536 */ 537 //char szImageName[64]; 586 * Guess the module name if not specified and make sure it conforms to DBGC expectations. 587 */ 538 588 if (!pszName) 539 589 { 590 if (pszFilename) 591 pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS); 540 592 /** @todo */ 541 593 } 594 595 char szNormalized[128]; 596 pszName = dbgfR3ModNormalizeName(pszName, szNormalized, sizeof(szNormalized)); 542 597 543 598 /* … … 552 607 553 608 RTDBGMOD hMod; 554 rc = RTDbgModCreateFromPeImage(&hMod, psz Name, NULL, &hLdrMod, cbImageFromHdr,609 rc = RTDbgModCreateFromPeImage(&hMod, pszFilename, pszName, &hLdrMod, cbImageFromHdr, 555 610 puBuf->Nt32.FileHeader.TimeDateStamp, DBGFR3AsGetConfig(pUVM)); 556 611 if (RT_SUCCESS(rc)) … … 579 634 * @param pImageAddr The image address. 580 635 * @param fFlags Flags, DBGFMODINMEM_F_XXX. 581 * @param pszName The image name, optional. 636 * @param pszName The module name, optional. 637 * @param pszFilename The image filename, optional. 582 638 * @param enmArch The image arch if we force it, pass 583 639 * RTLDRARCH_WHATEVER if you don't care. … … 586 642 * @param pErrInfo Where to return extended error info on failure. 587 643 */ 588 VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, 644 VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, const char *pszFilename, 589 645 RTLDRARCH enmArch, uint32_t cbImage, PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo) 590 646 { … … 612 668 613 669 if (uBuf.ab[0] == ELFMAG0 && uBuf.ab[1] == ELFMAG1 && uBuf.ab[2] == ELFMAG2 && uBuf.ab[3] == ELFMAG3) 614 return dbgfR3ModInMemElf(pUVM, pImageAddr, fFlags, pszName, enmArch, cbImage, &uBuf, phDbgMod, pErrInfo);670 return dbgfR3ModInMemElf(pUVM, pImageAddr, fFlags, pszName, pszFilename, enmArch, cbImage, &uBuf, phDbgMod, pErrInfo); 615 671 616 672 uint32_t offNewHdrs; … … 642 698 643 699 if (uBuf.Nt32.Signature == IMAGE_NT_SIGNATURE) 644 return dbgfR3ModInMemPe(pUVM, pImageAddr, fFlags, pszName, enmArch, cbImage, offNewHdrs, cbPeHdrsPart1, &uBuf,645 phDbgMod, pErrInfo);700 return dbgfR3ModInMemPe(pUVM, pImageAddr, fFlags, pszName, pszFilename, enmArch, cbImage, offNewHdrs, cbPeHdrsPart1, 701 &uBuf, phDbgMod, pErrInfo); 646 702 647 703 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_INVALID_EXE_SIGNATURE, "No PE/LX/NE header at %RGv (off=%#RX32): %.8Rhxs",
Note:
See TracChangeset
for help on using the changeset viewer.