VirtualBox

Changeset 73491 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 3, 2018 2:51:55 PM (6 years ago)
Author:
vboxsync
Message:

DBGF,DBGPluInWinNt: Produce more useful module names (e.g. stuff that works in DBGC).

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/DBGCCommands.cpp

    r73150 r73491  
    13971397    RTDBGMOD hDbgMod;
    13981398    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));
    14001401    if (RT_FAILURE(rc))
    14011402    {
  • trunk/src/VBox/Debugger/DBGPlugInWinNt.cpp

    r73486 r73491  
    2727#include <VBox/err.h>
    2828#include <VBox/param.h>
     29#include <iprt/ctype.h>
    2930#include <iprt/ldr.h>
    3031#include <iprt/mem.h>
     32#include <iprt/path.h>
    3133#include <iprt/stream.h>
    3234#include <iprt/string.h>
     
    300302 * @param   pThis           The instance data.
    301303 * @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.
    303306 * @param   pImageAddr      The image address.
    304307 * @param   cbImage         The size of the image.
    305308 */
    306 static void dbgDiggerWinNtProcessImage(PDBGDIGGERWINNT pThis, PUVM pUVM, const char *pszName,
     309static void dbgDiggerWinNtProcessImage(PDBGDIGGERWINNT pThis, PUVM pUVM, const char *pszName, const char *pszFilename,
    307310                                       PCDBGFADDRESS pImageAddr, uint32_t cbImage)
    308311{
     
    324327    RTERRINFOSTATIC ErrInfo;
    325328    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,
    327330                            pThis->f32Bit ? RTLDRARCH_X86_32 : RTLDRARCH_AMD64, cbImage,
    328331                            &hDbgMod, RTErrInfoInitStatic(&ErrInfo));
     
    350353    else
    351354        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 */
     365static 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;
    352399}
    353400
     
    690737            u.wsz[cbName / 2] = '\0';
    691738
    692             char *pszName;
    693             rc = RTUtf16ToUtf8(u.wsz, &pszName);
     739            char *pszFilename;
     740            rc = RTUtf16ToUtf8(u.wsz, &pszFilename);
    694741            if (RT_SUCCESS(rc))
    695742            {
     743                char        szModName[128];
     744                const char *pszModName = dbgDiggerWintNtFilenameToModuleName(pszFilename, szModName, sizeof(szModName));
     745
    696746                /* Read the start of the PE image and pass it along to a worker. */
    697747                DBGFADDRESS ImageAddr;
    698748                DBGFR3AddrFromFlat(pUVM, &ImageAddr, WINNT_UNION(pThis, &Mte, DllBase));
    699                 dbgDiggerWinNtProcessImage(pThis, pUVM, pszName, &ImageAddr, cbImageMte);
    700                 RTStrFree(pszName);
     749                dbgDiggerWinNtProcessImage(pThis, pUVM, pszModName, pszFilename, &ImageAddr, cbImageMte);
     750                RTStrFree(pszFilename);
    701751            }
    702752        }
  • trunk/src/VBox/Debugger/testcase/tstDBGCStubs.cpp

    r73445 r73491  
    198198    return VERR_INTERNAL_ERROR;
    199199}
    200 VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName,
     200VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, const char *pszFilename,
    201201                              RTLDRARCH enmArch, uint32_t cbImage, PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo)
    202202{
  • trunk/src/VBox/VMM/VMMR3/DBGFR3ModInMem.cpp

    r73150 r73491  
    2424
    2525#include <VBox/err.h>
     26#include <iprt/ctype.h>
    2627#include <iprt/ldr.h>
    2728#include <iprt/mem.h>
     29#include <iprt/path.h>
    2830#include <iprt/string.h>
    2931#include <iprt/formats/pecoff.h>
     
    8587
    8688/**
     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 */
     96const 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/**
    87136 * Handles in-memory ELF images.
    88137 *
     
    91140 * @param   pImageAddr      The image address.
    92141 * @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.
    94144 * @param   enmArch         The image arch if we force it, pass
    95145 *                          RTLDRARCH_WHATEVER if you don't care.
     
    99149 * @param   pErrInfo        Where to return extended error info on failure.
    100150 */
    101 static int dbgfR3ModInMemElf(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName,
     151static int dbgfR3ModInMemElf(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, const char *pszFilename,
    102152                             RTLDRARCH enmArch, uint32_t cbImage, PDBGFMODINMEMBUF puBuf,
    103153                             PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo)
    104154{
    105     RT_NOREF(pUVM, fFlags, pszName, enmArch, cbImage, puBuf, phDbgMod);
     155    RT_NOREF(pUVM, fFlags, pszName, pszFilename, enmArch, cbImage, puBuf, phDbgMod);
    106156    return RTERRINFO_LOG_SET_F(pErrInfo, VERR_INVALID_EXE_SIGNATURE, "Found ELF magic at %RGv", pImageAddr->FlatPtr);
    107157}
     
    422472 * @param   pImageAddr      The image address.
    423473 * @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.
    425476 * @param   enmArch         The image arch if we force it, pass
    426477 *                          RTLDRARCH_WHATEVER if you don't care.
     
    432483 * @param   pErrInfo        Where to return extended error info on failure.
    433484 */
    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                             PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo)
     485static 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)
    437488{
    438489    /*
     
    533584
    534585    /*
    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     */
    538588    if (!pszName)
    539589    {
     590        if (pszFilename)
     591            pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS);
    540592        /** @todo */
    541593    }
     594
     595    char szNormalized[128];
     596    pszName = dbgfR3ModNormalizeName(pszName, szNormalized, sizeof(szNormalized));
    542597
    543598    /*
     
    552607
    553608    RTDBGMOD hMod;
    554     rc = RTDbgModCreateFromPeImage(&hMod, pszName, NULL, &hLdrMod, cbImageFromHdr,
     609    rc = RTDbgModCreateFromPeImage(&hMod, pszFilename, pszName, &hLdrMod, cbImageFromHdr,
    555610                                   puBuf->Nt32.FileHeader.TimeDateStamp, DBGFR3AsGetConfig(pUVM));
    556611    if (RT_SUCCESS(rc))
     
    579634 * @param   pImageAddr      The image address.
    580635 * @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.
    582638 * @param   enmArch         The image arch if we force it, pass
    583639 *                          RTLDRARCH_WHATEVER if you don't care.
     
    586642 * @param   pErrInfo        Where to return extended error info on failure.
    587643 */
    588 VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName,
     644VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName, const char *pszFilename,
    589645                              RTLDRARCH enmArch, uint32_t cbImage, PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo)
    590646{
     
    612668
    613669    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);
    615671
    616672    uint32_t offNewHdrs;
     
    642698
    643699    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);
    646702
    647703    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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette