VirtualBox

Changeset 19193 in vbox


Ignore:
Timestamp:
Apr 27, 2009 2:39:31 AM (16 years ago)
Author:
vboxsync
Message:

DBGFSym.cpp: Quick implementation of a binary image search path in DBGFR3ModuleLoad, current using the env.var. VBOXDBG_IMAGE_PATH.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/DBGFSym.cpp

    r19190 r19193  
    2525*******************************************************************************/
    2626#define LOG_GROUP LOG_GROUP_DBGF
    27 #if defined(RT_OS_WINDOWS) && 0 //defined(DEBUG_bird) // enabled this is you want to debug win32 guests or the hypervisor.
     27#if defined(RT_OS_WINDOWS) && 0 //defined(DEBUG_bird) // enabled this is you want to debug win32 guests, the hypervisor of EFI.
    2828# include <Windows.h>
    2929# define _IMAGEHLP64
     
    4141#include <iprt/assert.h>
    4242
     43#include <iprt/path.h>
     44#include <iprt/ctype.h>
     45#include <iprt/env.h>
     46#include <iprt/param.h>
    4347#ifndef HAVE_DBGHELP
    4448# include <iprt/avl.h>
    4549# include <iprt/string.h>
    46 # include <iprt/ctype.h>
    4750#endif
    4851
     
    548551}
    549552
     553/**
     554 * Tries to open the file using the image search paths.
     555 *
     556 * This is currently a quick hack and the only way to specifying the path is by setting
     557 * VBOXDBG_IMAGE_PATH in the environment. It uses semicolon as separator everywhere.
     558 *
     559 * @returns VBox status code.
     560 * @param   pVM             The VM handle.
     561 * @param   pszFilename     The name of the file to locate and open.
     562 * @param   pszFound        Where to return the actual filename.
     563 * @param   cchFound        The buffer size.
     564 * @param   ppFile          Where to return the opened file.
     565 */
     566int dbgfR3ModuleLocateAndOpen(PVM pVM, const char *pszFilename, char *pszFound, size_t cchFound, FILE **ppFile)
     567{
     568    /* Check the filename length. */
     569    size_t const    cchFilename = strlen(pszFilename);
     570    if (cchFilename >= cchFound)
     571        return VERR_FILENAME_TOO_LONG;
     572    const char     *pszName = RTPathFilename(pszFilename);
     573    if (!pszName)
     574        return VERR_IS_A_DIRECTORY;
     575    size_t const    cchName = strlen(pszName);
     576
     577    /*
     578     * Try default location first.
     579     */
     580    memcpy(pszFound, pszFilename, cchFilename + 1);
     581    FILE *pFile = *ppFile = fopen(pszFound, "rb");
     582    if (pFile)
     583        return VINF_SUCCESS;
     584
     585    /*
     586     * Walk the search path.
     587     */
     588    const char *psz = RTEnvGet("VBOXDBG_IMAGE_PATH");
     589    if (!psz)
     590        psz = ".";                      /* default */
     591    while (*psz)
     592    {
     593        /* Skip leading blanks - no directories with leading spaces, thank you. */
     594        while (RT_C_IS_BLANK(*psz))
     595            psz++;
     596
     597        /* Fine the end of this element. */
     598        const char *pszNext;
     599        const char *pszEnd = strchr(psz, ';');
     600        if (!pszEnd)
     601            pszEnd = pszNext = strchr(psz, '\0');
     602        else
     603            pszNext = pszEnd + 1;
     604        if (pszEnd != psz)
     605        {
     606            size_t const cch = pszEnd - psz;
     607            if (cch + 1 + cchName < cchFound)
     608            {
     609                /** @todo RTPathCompose, RTPathComposeN(). This code isn't right
     610                 * for 'E:' on DOS systems. It may also create unwanted double slashes. */
     611                memcpy(pszFound, psz, cch);
     612                pszFound[cch] = '/';
     613                memcpy(pszFound + cch + 1, pszName, cchName + 1);
     614                *ppFile = pFile = fopen(pszFound, "rb");
     615                if (pFile)
     616                    return VINF_SUCCESS;
     617            }
     618
     619            /** @todo do a depth search using the specified path. */
     620        }
     621
     622        /* advance */
     623        psz = pszNext;
     624    }
     625
     626    /* not found */
     627    return VERR_OPEN_FAILED;
     628}
     629
    550630
    551631/**
     
    578658     * Open the load file.
    579659     */
    580     int rc = VINF_SUCCESS;
    581     FILE *pFile = fopen(pszFilename, "rb");
     660    FILE *pFile;
     661    char szFoundFile[RTPATH_MAX];
     662    int rc = dbgfR3ModuleLocateAndOpen(pVM, pszFilename, szFoundFile, sizeof(szFoundFile), &pFile);
    582663    if (pFile)
    583664    {
     
    595676                #ifdef HAVE_DBGHELP
    596677                /** @todo arg! checkout the inserting of modules and then loading them again.... Or just the module representation.... */
    597                 DWORD64 ImageBase = SymLoadModule64(pVM, NULL, (char *)(void *)pszFilename, (char *)(void *)pszName, ModuleAddress, cbImage);
     678                DWORD64 ImageBase = SymLoadModule64(pVM, NULL, (char *)(void *)szFoundFile, (char *)(void *)pszName, ModuleAddress, cbImage);
    598679                if (!ImageBase)
    599680                    ImageBase = SymLoadModule64(pVM, NULL, (char *)(void *)pszName, (char *)(void *)pszName, ModuleAddress, cbImage);
     
    652733        fclose(pFile);
    653734    }
    654     else
    655         rc = VERR_OPEN_FAILED;
    656735    return rc;
    657736}
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