VirtualBox

Changeset 73491 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Aug 3, 2018 2:51:55 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124118
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.

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