VirtualBox

Changeset 104976 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jun 20, 2024 10:17:44 AM (7 months ago)
Author:
vboxsync
Message:

Devices/Trace: Support streaming the tracelog over the network, bugref:10701

Location:
trunk/src/VBox/Devices/Trace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Trace/DrvIfsTrace.cpp

    r104894 r104976  
    9292        pThis->hTraceLog = NIL_RTTRACELOGWR;
    9393    }
    94 
    95     if (pThis->pszTraceFilePath)
    96     {
    97         PDMDrvHlpMMHeapFree(pDrvIns, pThis->pszTraceFilePath);
    98         pThis->pszTraceFilePath = NULL;
    99     }
    10094}
    10195
     
    126120     * Validate and read config.
    127121     */
    128     PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "TraceFilePath|", "");
    129 
    130     int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceFilePath", &pThis->pszTraceFilePath);
    131     AssertLogRelRCReturn(rc, rc);
    132 
    133     /* Try to create a file based trace log. */
    134     rc = RTTraceLogWrCreateFile(&pThis->hTraceLog, RTBldCfgVersion(), pThis->pszTraceFilePath);
    135     AssertLogRelRCReturn(rc, rc);
     122    PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "TraceFilePath|TraceLocation", "");
     123
     124    char *pszLocation = NULL;
     125    int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceFilePath", &pszLocation);
     126    if (RT_SUCCESS(rc))
     127    {
     128        /* Try to create a file based trace log. */
     129        rc = RTTraceLogWrCreateFile(&pThis->hTraceLog, RTBldCfgVersion(), pszLocation);
     130        PDMDrvHlpMMHeapFree(pDrvIns, pszLocation);
     131
     132        AssertLogRelRCReturn(rc, rc);
     133    }
     134    else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     135    {
     136        /* Try to connect to an external server. */
     137        rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceLocation", &pszLocation);
     138        if (RT_FAILURE(rc))
     139            return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
     140                                       N_("Configuration error: querying \"TraceLocation\" resulted in %Rrc"), rc);
     141
     142        char *pszPort = strchr(pszLocation, ':');
     143        if (!pszPort)
     144            return PDMDrvHlpVMSetError(pDrvIns, VERR_NOT_FOUND, RT_SRC_POS,
     145                                       N_("IfTrace#%d: The location misses the port to connect to"),
     146                                       pDrvIns->iInstance);
     147
     148        *pszPort = '\0'; /* Overwrite temporarily to avoid copying the hostname into a temporary buffer. */
     149        uint32_t uPort = 0;
     150        rc = RTStrToUInt32Ex(pszPort + 1, NULL, 10, &uPort);
     151        if (RT_FAILURE(rc))
     152            return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
     153                                       N_("IfTrace#%d: The port part of the location is not a numerical value"),
     154                                       pDrvIns->iInstance);
     155
     156        rc = RTTraceLogWrCreateTcpClient(&pThis->hTraceLog, RTBldCfgVersion(), pszLocation, uPort);
     157        *pszPort = ':'; /* Restore delimiter before checking the status. */
     158        if (RT_FAILURE(rc))
     159            return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
     160                                       N_("IfTrace#%d: Failed to connect to socket %s"),
     161                                       pDrvIns->iInstance, pszLocation);
     162
     163        PDMDrvHlpMMHeapFree(pDrvIns, pszLocation);
     164    }
     165
    136166
    137167    /*
  • trunk/src/VBox/Devices/Trace/DrvIfsTraceInternal.h

    r104894 r104976  
    6969    /** The trace log writer handle. */
    7070    RTTRACELOGWR         hTraceLog;
    71     /** Path of the trace log file. */
    72     char                 *pszTraceFilePath;
    7371
    7472} DRVIFTRACE;
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