VirtualBox

Changeset 8800 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 14, 2008 3:03:54 AM (17 years ago)
Author:
vboxsync
Message:

Started digging into the solaris guest kernel. Added DBGFR3MemRead.

Location:
trunk/src/VBox
Files:
2 added
6 edited

Legend:

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

    r8155 r8800  
    6767static DECLCALLBACK(int) dbgcCmdEcho(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
    6868static DECLCALLBACK(int) dbgcCmdRunScript(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
     69static DECLCALLBACK(int) dbgcCmdDetect(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
    6970
    7071
     
    167168    { "exit",       0,        0,        NULL,               0,                          NULL,               0,          dbgcCmdQuit,        "",                     "Exits the debugger." },
    168169    { "format",     1,        1,        &g_aArgAny[0],      ELEMENTS(g_aArgAny),        NULL,               0,          dbgcCmdFormat,      "",                     "Evaluates an expression and formats it." },
     170    { "detect",     0,        0,        NULL,               0,                          NULL,               0,          dbgcCmdDetect,      "",                     "Detects or re-detects the guest os and starts the OS specific digger." },
    169171    { "harakiri",   0,        0,        NULL,               0,                          NULL,               0,          dbgcCmdHarakiri,    "",                     "Kills debugger process." },
    170172    { "help",       0,        ~0,       &g_aArgHelp[0],     ELEMENTS(g_aArgHelp),       NULL,               0,          dbgcCmdHelp,        "[cmd/op [..]]",        "Display help. For help about info items try 'info help'." },
     
    716718
    717719    NOREF(pCmd); NOREF(pResult); NOREF(pVM);
     720    return rc;
     721}
     722
     723
     724/**
     725 * The 'detect' command.
     726 *
     727 * @returns VBox status.
     728 * @param   pCmd        Pointer to the command descriptor (as registered).
     729 * @param   pCmdHlp     Pointer to command helper functions.
     730 * @param   pVM         Pointer to the current VM (if any).
     731 * @param   paArgs      Pointer to (readonly) array of arguments.
     732 * @param   cArgs       Number of arguments in the array.
     733 */
     734static DECLCALLBACK(int) dbgcCmdDetect(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
     735{
     736    /* check that the parser did what it's supposed to do. */
     737    if (cArgs != 0)
     738        return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
     739
     740    /*
     741     * Perform the detection.
     742     */
     743    char szName[64];
     744    int rc = DBGFR3OSDetect(pVM, szName, sizeof(szName));
     745    if (RT_FAILURE(rc))
     746        return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Executing DBGFR3OSDetect().");
     747    if (rc == VINF_SUCCESS)
     748    {
     749        rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Guest OS: %s\n", szName);
     750        char szVersion[64];
     751        int rc2 = DBGFR3OSQueryNameAndVersion(pVM, NULL, 0, szVersion, sizeof(szVersion));
     752        if (RT_SUCCESS(rc2))
     753            rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Version : %s\n", szVersion);
     754    }
     755    else
     756        rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Unable to figure out which guest OS it is, sorry.\n");
     757    NOREF(pCmd); NOREF(pResult); NOREF(paArgs);
    718758    return rc;
    719759}
  • trunk/src/VBox/Debugger/DBGConsole.cpp

    r8155 r8800  
    158158
    159159#include "DBGCInternal.h"
     160#include "DBGPlugIns.h"
    160161
    161162
     
    20472048            rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
    20482049                                         "Current VM is %08x\n" /** @todo get and print the VM name! */
    2049                                          "VBoxDbg> ",
    2050                                          pDbgc->pVM);
     2050                                         , pDbgc->pVM);
    20512051        }
    20522052        else
    20532053            rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to attach to VM %p\n", pDbgc->pVM);
    20542054    }
    2055     else
     2055
     2056    /*
     2057     * Load plugins.
     2058     * This is currently hardcoded simplicity.
     2059     */
     2060    if (RT_SUCCESS(rc) && pVM)
     2061    {
     2062        static PCDBGFOSREG s_aPlugIns[] =
     2063        {
     2064            //&g_DBGDiggerFreeBSD,
     2065            //&g_DBGDiggerLinux,
     2066            //&g_DBGDiggerOS2,
     2067            &g_DBGDiggerSolaris,
     2068            //&g_DBGDiggerWinNt
     2069        };
     2070
     2071        pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "Loading Plugins:");
     2072        for (unsigned i = 0; i < RT_ELEMENTS(s_aPlugIns); i++)
     2073        {
     2074            pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, " %s", s_aPlugIns[i]->szName);
     2075            rc = DBGFR3OSRegister(pVM, s_aPlugIns[i]);
     2076            if (RT_FAILURE(rc) && rc != VERR_ALREADY_LOADED)
     2077                pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "->%Rrc", rc);
     2078        }
     2079        pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\n");
     2080    }
     2081
     2082    if (RT_SUCCESS(rc))
    20562083        rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
    20572084                                     "VBoxDbg> ");
    20582085
    20592086    /*
    2060      * Run the main loop.
     2087     * Run the debugger main loop.
    20612088     */
    20622089    if (RT_SUCCESS(rc))
  • trunk/src/VBox/Debugger/Makefile.kmk

    r8760 r8800  
    5656        DBGCEmulateCodeView.cpp \
    5757        DBGCOps.cpp \
    58         DBGCTcp.cpp
     58        DBGCTcp.cpp \
     59        DBGPlugInSolaris.cpp
    5960
    6061
  • trunk/src/VBox/Debugger/testcase/tstDBGCStubs.cpp

    r8160 r8800  
    282282    return VERR_INTERNAL_ERROR;
    283283}
     284DBGFR3DECL(int) DBGFR3MemRead(PVM pVM, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead)
     285{
     286    return VERR_INTERNAL_ERROR;
     287}
    284288DBGFR3DECL(void) DBGFR3AddrFromPhys(PVM pVM, PDBGFADDRESS pAddress, RTGCPHYS PhysAddr)
    285289{
    286290}
     291DBGFR3DECL(int) DBGFR3OSRegister(PVM pVM, PCDBGFOSREG pReg)
     292{
     293    return VERR_INTERNAL_ERROR;
     294}
     295DBGFR3DECL(int) DBGFR3OSDetect(PVM pVM, char *pszName, size_t cchName)
     296{
     297    return VERR_INTERNAL_ERROR;
     298}
     299DBGFR3DECL(int) DBGFR3OSQueryNameAndVersion(PVM pVM, char *pszName, size_t cchName, char *pszVersion, size_t cchVersion)
     300{
     301    return VERR_INTERNAL_ERROR;
     302}
  • trunk/src/VBox/VMM/DBGFMem.cpp

    r8155 r8800  
    116116
    117117
     118/**
     119 * Read guest memory.
     120 *
     121 * @returns VBox status code.
     122 * @param   pVM             Pointer to the shared VM structure.
     123 * @param   pAddress        Where to start reading.
     124 * @param   pvBuf           Where to store the data we've read.
     125 * @param   cbRead          The number of bytes to read.
     126 */
     127static DECLCALLBACK(int) dbgfR3MemRead(PVM pVM, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead)
     128{
     129    /*
     130     * Validate the input we use, PGM does the rest.
     131     */
     132    if (!DBGFR3AddrIsValid(pVM, pAddress))
     133        return VERR_INVALID_POINTER;
     134    if (!VALID_PTR(pvBuf))
     135        return VERR_INVALID_POINTER;
     136    if (DBGFADDRESS_IS_HMA(pAddress))
     137        return VERR_INVALID_POINTER;
     138
     139    /*
     140     * Select DBGF worker by addressing mode.
     141     */
     142    int rc;
     143    PGMMODE enmMode = PGMGetGuestMode(pVM);
     144    if (    enmMode == PGMMODE_REAL
     145        ||  enmMode == PGMMODE_PROTECTED
     146        ||  DBGFADDRESS_IS_PHYS(pAddress) )
     147        rc = PGMPhysReadGCPhys(pVM, pvBuf, pAddress->FlatPtr, cbRead);
     148    else
     149        rc = PGMPhysReadGCPtr(pVM, pvBuf, pAddress->FlatPtr, cbRead);
     150    return rc;
     151}
     152
     153
     154/**
     155 * Read guest memory.
     156 *
     157 * @returns VBox status code.
     158 * @param   pVM             Pointer to the shared VM structure.
     159 * @param   pAddress        Where to start reading.
     160 * @param   pvBuf           Where to store the data we've read.
     161 * @param   cbRead          The number of bytes to read.
     162 */
     163DBGFR3DECL(int) DBGFR3MemRead(PVM pVM, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead)
     164{
     165    PVMREQ pReq;
     166    int rc = VMR3ReqCallU(pVM->pUVM, &pReq, RT_INDEFINITE_WAIT, 0, (PFNRT)dbgfR3MemRead, 4,
     167                          pVM, pAddress, pvBuf, cbRead);
     168    if (VBOX_SUCCESS(rc))
     169        rc = pReq->iStatus;
     170    VMR3ReqFree(pReq);
     171
     172    return rc;
     173}
  • trunk/src/VBox/VMM/DBGFOS.cpp

    r8797 r8800  
    3838
    3939/**
     40 * EMT worker function for DBGFR3OSRegister.
     41 *
     42 * @returns VBox status code.
     43 * @param   pVM     Pointer to the shared VM structure.
     44 * @param   pReg    The registration structure.
     45 */
     46static DECLCALLBACK(int) dbgfR3OSRegister(PVM pVM, PDBGFOSREG pReg)
     47{
     48    /* more validations. */
     49    for (PDBGFOS pOS = pVM->dbgf.s.pOSHead; pOS; pOS = pOS->pNext)
     50        if (!strcmp(pOS->pReg->szName, pReg->szName))
     51        {
     52            Log(("dbgfR3OSRegister: %s -> VERR_ALREADY_LOADED\n", pReg->szName));
     53            return VERR_ALREADY_LOADED;
     54        }
     55
     56    /*
     57     * Allocate a new structure, call the constructor and link it into the list.
     58     */
     59    PDBGFOS pOS = (PDBGFOS)MMR3HeapAllocZ(pVM, MM_TAG_DBGF_OS, RT_OFFSETOF(DBGFOS, abData[pReg->cbData]));
     60    AssertReturn(pOS, VERR_NO_MEMORY);
     61    pOS->pReg = pReg;
     62
     63    int rc = pOS->pReg->pfnConstruct(pVM, pOS->abData);
     64    if (RT_SUCCESS(rc))
     65    {
     66        pOS->pNext = pVM->dbgf.s.pOSHead;
     67        pVM->dbgf.s.pOSHead = pOS;
     68    }
     69    else
     70    {
     71        if (pOS->pReg->pfnDestruct)
     72            pOS->pReg->pfnDestruct(pVM, pOS->abData);
     73        MMR3HeapFree(pOS);
     74    }
     75
     76    return VINF_SUCCESS;
     77}
     78
     79
     80/**
    4081 * Registers a guest OS digger.
    4182 *
     
    4687 * @param   pVM     Pointer to the shared VM structure.
    4788 * @param   pReg    The registration structure.
    48  */
    49 DBGFR3DECL(int) DBGFR3OSRegister(PVM pVM, PDBGFOSREG pReg)
     89 * @thread  Any.
     90 */
     91DBGFR3DECL(int) DBGFR3OSRegister(PVM pVM, PCDBGFOSREG pReg)
    5092{
    5193    /*
    5294     * Validate intput.
    5395     */
    54     VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
    5596    AssertPtrReturn(pReg, VERR_INVALID_POINTER);
    5697    AssertReturn(pReg->u32Magic == DBGFOSREG_MAGIC, VERR_INVALID_MAGIC);
     
    5899    AssertReturn(!pReg->fFlags, VERR_INVALID_PARAMETER);
    59100    AssertReturn(pReg->cbData < _2G, VERR_INVALID_PARAMETER);
    60     AssertReturn(!pReg->szName[0], VERR_INVALID_NAME);
     101    AssertReturn(pReg->szName[0], VERR_INVALID_NAME);
    61102    AssertReturn(memchr(&pReg->szName[0], '\0', sizeof(pReg->szName)), VERR_INVALID_NAME);
    62103    AssertPtrReturn(pReg->pfnConstruct, VERR_INVALID_POINTER);
     
    68109    AssertPtrReturn(pReg->pfnQueryVersion, VERR_INVALID_POINTER);
    69110    AssertPtrReturn(pReg->pfnQueryInterface, VERR_INVALID_POINTER);
    70     for (PDBGFOS pOS = pVM->dbgf.s.pOSHead; pOS; pOS = pOS->pNext)
    71         AssertMsgReturn(!strcmp(pOS->pReg->szName, pReg->szName), ("%s\n", pReg->szName), VERR_ALREADY_EXISTS);
    72 
    73     /*
    74      * Allocate a new structure, call the constructor and link it into the list.
    75      */
    76     PDBGFOS pOS = (PDBGFOS)MMR3HeapAllocZ(pVM, MM_TAG_DBGF_OS, RT_OFFSETOF(DBGFOS, abData[pReg->cbData]));
    77     AssertReturn(pOS, VERR_NO_MEMORY);
    78     pOS->pReg = pReg;
    79 
    80     int rc = pOS->pReg->pfnConstruct(pVM, pOS->abData);
     111
     112    /*
     113     * Pass it on to the EMT.
     114     */
     115    PVMREQ pReq;
     116    int rc = VMR3ReqCallU(pVM->pUVM, &pReq, RT_INDEFINITE_WAIT, 0, (PFNRT)dbgfR3OSRegister, 2, pVM, pReg);
    81117    if (RT_SUCCESS(rc))
    82     {
    83         pOS->pNext = pVM->dbgf.s.pOSHead;
    84         pVM->dbgf.s.pOSHead = pOS;
    85     }
    86     else
    87     {
    88         if (pOS->pReg->pfnDestruct)
    89             pOS->pReg->pfnDestruct(pVM, pOS->abData);
    90         MMR3HeapFree(pOS);
    91     }
    92 
    93     return VINF_SUCCESS;
     118        rc = pReq->iStatus;
     119    VMR3ReqFree(pReq);
     120
     121    return rc;
    94122}
    95123
     
    126154
    127155/**
    128  * Detectes the guest OS and try dig out symbols and useful stuff.
    129  *
    130  * When called the 2nd time, symbols will be updated that if the OS
    131  * is the same.
     156 * EMT worker function for DBGFR3OSDetect.
    132157 *
    133158 * @returns VBox status code.
     
    139164 * @param   cchName     Size of the buffer.
    140165 */
    141 DBGFR3DECL(int) DBGFR3OSDetect(PVM pVM, char *pszName, size_t cchName)
    142 {
    143     VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
    144     AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
    145 
     166static DECLCALLBACK(int) dbgfR3OSDetect(PVM pVM, char *pszName, size_t cchName)
     167{
    146168    /*
    147169     * Cycle thru the detection routines.
    148170     */
    149     if (pszName && cchName)
    150         *pszName = '\0';
    151171    PDBGFOS const pOldOS = pVM->dbgf.s.pCurOS;
    152172    pVM->dbgf.s.pCurOS = NULL;
     
    178198
    179199/**
    180  * Queries the name and/or version string for the guest OS.
    181  *
    182  * It goes without saying that this querying is done using the current
    183  * guest OS digger and not additions or user configuration.
     200 * Detectes the guest OS and try dig out symbols and useful stuff.
     201 *
     202 * When called the 2nd time, symbols will be updated that if the OS
     203 * is the same.
     204 *
     205 * @returns VBox status code.
     206 * @retval  VINF_SUCCESS if successfully detected.
     207 * @retval  VINF_DBGF_OS_NOT_DETCTED if we cannot figure it out.
     208 *
     209 * @param   pVM         Pointer to the shared VM structure.
     210 * @param   pszName     Where to store the OS name. Empty string if not detected.
     211 * @param   cchName     Size of the buffer.
     212 * @thread  Any.
     213 */
     214DBGFR3DECL(int) DBGFR3OSDetect(PVM pVM, char *pszName, size_t cchName)
     215{
     216    AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
     217    if (pszName && cchName)
     218        *pszName = '\0';
     219
     220    /*
     221     * Pass it on to the EMT.
     222     */
     223    PVMREQ pReq;
     224    int rc = VMR3ReqCallU(pVM->pUVM, &pReq, RT_INDEFINITE_WAIT, 0, (PFNRT)dbgfR3OSDetect, 3, pVM, pszName, cchName);
     225    if (RT_SUCCESS(rc))
     226        rc = pReq->iStatus;
     227    VMR3ReqFree(pReq);
     228
     229    return rc;
     230}
     231
     232
     233/**
     234 * EMT worker function for DBGFR3OSQueryNameAndVersion
    184235 *
    185236 * @returns VBox status code.
     
    190241 * @param   cchVersion      The size of the version buffer.
    191242 */
    192 DBGFR3DECL(int) DBGFR3OSNameAndVersion(PVM pVM, char *pszName, size_t cchName, char *pszVersion, size_t cchVersion)
    193 {
    194     VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
    195     AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
    196     AssertPtrNullReturn(pszVersion, VERR_INVALID_POINTER);
    197 
    198     /*
    199      * Initialize the output up front.
    200      */
    201     if (pszName && cchName)
    202         *pszName = '\0';
    203     if (pszVersion && cchVersion)
    204         *pszVersion = '\0';
    205 
     243static DECLCALLBACK(int) dbgfR3OSQueryNameAndVersion(PVM pVM, char *pszName, size_t cchName, char *pszVersion, size_t cchVersion)
     244{
    206245    /*
    207246     * Any known OS?
     
    237276
    238277/**
     278 * Queries the name and/or version string for the guest OS.
     279 *
     280 * It goes without saying that this querying is done using the current
     281 * guest OS digger and not additions or user configuration.
     282 *
     283 * @returns VBox status code.
     284 * @param   pVM             Pointer to the shared VM structure.
     285 * @param   pszName         Where to store the OS name. Optional.
     286 * @param   cchName         The size of the name buffer.
     287 * @param   pszVersion      Where to store the version string. Optional.
     288 * @param   cchVersion      The size of the version buffer.
     289 * @thread  Any.
     290 */
     291DBGFR3DECL(int) DBGFR3OSQueryNameAndVersion(PVM pVM, char *pszName, size_t cchName, char *pszVersion, size_t cchVersion)
     292{
     293    AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
     294    AssertPtrNullReturn(pszVersion, VERR_INVALID_POINTER);
     295
     296    /*
     297     * Initialize the output up front.
     298     */
     299    if (pszName && cchName)
     300        *pszName = '\0';
     301    if (pszVersion && cchVersion)
     302        *pszVersion = '\0';
     303
     304    /*
     305     * Pass it on to the EMT.
     306     */
     307    PVMREQ pReq;
     308    int rc = VMR3ReqCallU(pVM->pUVM, &pReq, RT_INDEFINITE_WAIT, 0, (PFNRT)dbgfR3OSQueryNameAndVersion,
     309                          5, pVM, pszName, cchName, pszVersion, cchVersion);
     310    if (RT_SUCCESS(rc))
     311        rc = pReq->iStatus;
     312    VMR3ReqFree(pReq);
     313
     314    return rc;
     315}
     316
     317
     318/**
     319 * EMT worker for DBGFR3OSQueryInterface.
     320 *
     321 * @param   pVM         Pointer to the shared VM structure.
     322 * @param   enmIf       The interface identifier.
     323 * @param   ppvIf       Where to store the interface pointer on success.
     324 */
     325static DECLCALLBACK(void) dbgfR3OSQueryInterface(PVM pVM, DBGFOSINTERFACE enmIf, void **ppvIf)
     326{
     327    if (pVM->dbgf.s.pCurOS)
     328    {
     329        *ppvIf = pVM->dbgf.s.pCurOS->pReg->pfnQueryInterface(pVM, pVM->dbgf.s.pCurOS->abData, enmIf);
     330        if (*ppvIf)
     331        {
     332            /** @todo Create EMT wrapper for the returned interface once we've defined one...
     333             * Just keep a list of wrapper together with the OS instance. */
     334        }
     335    }
     336    else
     337        *ppvIf = NULL;
     338}
     339
     340
     341/**
    239342 * Query an optional digger interface.
    240343 *
     
    243346 * @param   pVM         Pointer to the shared VM structure.
    244347 * @param   enmIf       The interface identifier.
     348 * @thread  Any.
    245349 */
    246350DBGFR3DECL(void *) DBGFR3OSQueryInterface(PVM pVM, DBGFOSINTERFACE enmIf)
    247351{
    248352    AssertMsgReturn(enmIf > DBGFOSINTERFACE_INVALID && enmIf < DBGFOSINTERFACE_END, ("%d\n", enmIf), NULL);
    249     if (pVM->dbgf.s.pCurOS)
    250         return pVM->dbgf.s.pCurOS->pReg->pfnQueryInterface(pVM, pVM->dbgf.s.pCurOS->abData, enmIf);
    251     return NULL;
    252 }
    253 
     353
     354    /*
     355     * Pass it on to the EMT.
     356     */
     357    void *pvIf = NULL;
     358    PVMREQ pReq;
     359    VMR3ReqCallVoidU(pVM->pUVM, &pReq, RT_INDEFINITE_WAIT, (PFNRT)dbgfR3OSQueryInterface, 3, pVM, enmIf, &pvIf);
     360    VMR3ReqFree(pReq);
     361
     362    return pvIf;
     363}
     364
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