Changeset 73491 in vbox for trunk/src/VBox
- Timestamp:
- Aug 3, 2018 2:51:55 PM (6 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGCCommands.cpp
r73150 r73491 1397 1397 RTDBGMOD hDbgMod; 1398 1398 RTERRINFOSTATIC ErrInfo; 1399 rc = DBGFR3ModInMem(pUVM, &ModAddress, fFlags, pszModName, enmArch, 0 /*cbImage*/, &hDbgMod, RTErrInfoInitStatic(&ErrInfo)); 1399 rc = DBGFR3ModInMem(pUVM, &ModAddress, fFlags, pszModName, pszModName, enmArch, 0 /*cbImage*/, 1400 &hDbgMod, RTErrInfoInitStatic(&ErrInfo)); 1400 1401 if (RT_FAILURE(rc)) 1401 1402 { -
trunk/src/VBox/Debugger/DBGPlugInWinNt.cpp
r73486 r73491 27 27 #include <VBox/err.h> 28 28 #include <VBox/param.h> 29 #include <iprt/ctype.h> 29 30 #include <iprt/ldr.h> 30 31 #include <iprt/mem.h> 32 #include <iprt/path.h> 31 33 #include <iprt/stream.h> 32 34 #include <iprt/string.h> … … 300 302 * @param pThis The instance data. 301 303 * @param pUVM The user mode VM handle. 302 * @param pszName The image name. 304 * @param pszName The module name. 305 * @param pszFilename The image filename. 303 306 * @param pImageAddr The image address. 304 307 * @param cbImage The size of the image. 305 308 */ 306 static void dbgDiggerWinNtProcessImage(PDBGDIGGERWINNT pThis, PUVM pUVM, const char *pszName, 309 static void dbgDiggerWinNtProcessImage(PDBGDIGGERWINNT pThis, PUVM pUVM, const char *pszName, const char *pszFilename, 307 310 PCDBGFADDRESS pImageAddr, uint32_t cbImage) 308 311 { … … 324 327 RTERRINFOSTATIC ErrInfo; 325 328 RTDBGMOD hDbgMod = NIL_RTDBGMOD; 326 int rc = DBGFR3ModInMem(pUVM, pImageAddr, pThis->fNt31 ? DBGFMODINMEM_F_PE_NT31 : 0, pszName, 329 int rc = DBGFR3ModInMem(pUVM, pImageAddr, pThis->fNt31 ? DBGFMODINMEM_F_PE_NT31 : 0, pszName, pszFilename, 327 330 pThis->f32Bit ? RTLDRARCH_X86_32 : RTLDRARCH_AMD64, cbImage, 328 331 &hDbgMod, RTErrInfoInitStatic(&ErrInfo)); … … 350 353 else 351 354 Log(("DigWinNt: %s: DBGFR3ModInMem failed: %Rrc\n", pszName, rc)); 355 } 356 357 358 /** 359 * Adjust the module name into something that's compatible with the debugger. 360 * 361 * @param pUVM The user mode VM handle. 362 * @param ppszName Pointer to the image name pointer. 363 * @param pImageAddr The image load address. 364 */ 365 static const char *dbgDiggerWintNtFilenameToModuleName(const char *pszFilename, char *pszName, size_t cbName) 366 { 367 /* Skip to the filename part of the filename. :-) */ 368 pszFilename = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS); 369 370 /* We try use 'nt' for the kernel. */ 371 if ( RTStrICmpAscii(pszFilename, "ntoskrnl.exe") == 0 372 || RTStrICmpAscii(pszFilename, "ntkrnlmp.exe") == 0) 373 return "nt"; 374 375 376 /* Drop the extension if .dll or .sys. */ 377 size_t cchFilename = strlen(pszFilename); 378 if ( cchFilename > 4 379 && pszFilename[cchFilename - 4] == '.') 380 { 381 if ( RTStrICmpAscii(&pszFilename[cchFilename - 4], ".sys") == 0 382 || RTStrICmpAscii(&pszFilename[cchFilename - 4], ".dll") == 0) 383 cchFilename -= 4; 384 } 385 386 /* Copy and do replacements. */ 387 if (cchFilename >= cbName) 388 cchFilename = cbName - 1; 389 size_t off; 390 for (off = 0; off < cchFilename; off++) 391 { 392 char ch = pszFilename[off]; 393 if (!RT_C_IS_ALNUM(ch)) 394 ch = '_'; 395 pszName[off] = ch; 396 } 397 pszName[off] = '\0'; 398 return pszName; 352 399 } 353 400 … … 690 737 u.wsz[cbName / 2] = '\0'; 691 738 692 char *psz Name;693 rc = RTUtf16ToUtf8(u.wsz, &psz Name);739 char *pszFilename; 740 rc = RTUtf16ToUtf8(u.wsz, &pszFilename); 694 741 if (RT_SUCCESS(rc)) 695 742 { 743 char szModName[128]; 744 const char *pszModName = dbgDiggerWintNtFilenameToModuleName(pszFilename, szModName, sizeof(szModName)); 745 696 746 /* Read the start of the PE image and pass it along to a worker. */ 697 747 DBGFADDRESS ImageAddr; 698 748 DBGFR3AddrFromFlat(pUVM, &ImageAddr, WINNT_UNION(pThis, &Mte, DllBase)); 699 dbgDiggerWinNtProcessImage(pThis, pUVM, psz Name, &ImageAddr, cbImageMte);700 RTStrFree(psz Name);749 dbgDiggerWinNtProcessImage(pThis, pUVM, pszModName, pszFilename, &ImageAddr, cbImageMte); 750 RTStrFree(pszFilename); 701 751 } 702 752 } -
trunk/src/VBox/Debugger/testcase/tstDBGCStubs.cpp
r73445 r73491 198 198 return VERR_INTERNAL_ERROR; 199 199 } 200 VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, 200 VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, const char *pszFilename, 201 201 RTLDRARCH enmArch, uint32_t cbImage, PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo) 202 202 { -
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.