VirtualBox

Changeset 86889 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Nov 16, 2020 2:23:04 PM (4 years ago)
Author:
vboxsync
Message:

Shared Clipboard: More (optional) release logging for error diagnosis.

Location:
trunk/src/VBox/HostServices/SharedClipboard
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp

    r85989 r86889  
    261261
    262262    int rc = readFromPasteboard(pClient->State.pCtx->hPasteboard, fFormat, pvData, cbData, pcbActual);
     263    if (RT_FAILURE(rc))
     264        LogRel(("Shared Clipboard: Error reading host clipboard data from macOS, rc=%Rrc\n", rc));
    263265
    264266    ShClSvcUnlock();
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp

    r86247 r86889  
    6767
    6868/** @todo Someone please explain the protocol wrt overflows...  */
    69 static void vboxClipboardSvcWinGetData(uint32_t u32Format, const void *pvSrc, uint32_t cbSrc,
    70                                        void *pvDst, uint32_t cbDst, uint32_t *pcbActualDst)
    71 {
     69static int vboxClipboardSvcWinDataGet(uint32_t u32Format, const void *pvSrc, uint32_t cbSrc,
     70                                      void *pvDst, uint32_t cbDst, uint32_t *pcbActualDst)
     71{
     72    AssertPtrReturn(pvSrc,        VERR_INVALID_POINTER);
     73    AssertReturn   (cbSrc,        VERR_INVALID_PARAMETER);
     74    AssertPtrReturn(pvDst,        VERR_INVALID_POINTER);
     75    AssertReturn   (cbDst,        VERR_INVALID_PARAMETER);
     76    AssertPtrReturn(pcbActualDst, VERR_INVALID_POINTER);
     77
    7278    LogFlowFunc(("cbSrc = %d, cbDst = %d\n", cbSrc, cbDst));
    7379
     
    96102    else
    97103    {
    98         *pcbActualDst = cbSrc;
     104        *pcbActualDst = cbSrc; /* Tell the caller how much space we need. */
    99105
    100106        if (cbSrc > cbDst)
    101         {
    102             /* Do not copy data. The dst buffer is not enough. */
    103             return;
    104         }
     107            return VERR_BUFFER_OVERFLOW;
    105108
    106109        memcpy(pvDst, pvSrc, cbSrc);
     
    111114#endif
    112115
    113     return;
    114 }
    115 
     116    return VINF_SUCCESS;
     117}
     118
     119/**
     120 * Sets (places) clipboard data into the Windows clipboard.
     121 *
     122 * @returns VBox status code.
     123 * @param   pCtx                Shared Clipboard context to use.
     124 * @param   cfFormat            Windows clipboard format to set data for.
     125 * @param   pvData              Pointer to actual clipboard data to set.
     126 * @param   cbData              Size (in bytes) of actual clipboard data to set.
     127 * @note
     128 */
    116129static int vboxClipboardSvcWinDataSet(PSHCLCONTEXT pCtx, UINT cfFormat, void *pvData, uint32_t cbData)
    117130{
     
    163176        rc = RTErrConvertFromWin32(GetLastError());
    164177
     178    if (RT_FAILURE(rc))
     179        LogRel(("Shared Clipboard: Setting clipboard data for Windows host failed with %Rrc\n", rc));
     180
    165181    LogFlowFuncLeaveRC(rc);
    166182    return rc;
     
    174190    if (fFormat == VBOX_SHCL_FMT_NONE)
    175191    {
    176         LogRel2(("Shared Clipbaord: Windows format %u not supported, ingoring\n", uFormat));
     192        LogRel2(("Shared Clipboard: Windows format %u not supported, ignoring\n", uFormat));
    177193        return VERR_NOT_SUPPORTED;
    178194    }
     
    193209        ShClEventUnregister(&pCtx->pClient->EventSrc, idEvent);
    194210    }
     211
     212    if (RT_FAILURE(rc))
     213        LogRel(("Shared Clipboard: Reading guest clipboard data for Windows host failed with %Rrc\n", rc));
    195214
    196215    LogFlowFuncLeaveRC(rc);
     
    340359            /* Announce available formats. Do not insert data -- will be inserted in WM_RENDERFORMAT (or via IDataObject). */
    341360            SHCLFORMATS fFormats = (uint32_t)lParam;
    342             LogFunc(("SHCL_WIN_WM_REPORT_FORMATS: fFormats=0x%x\n", fFormats));
     361            LogFunc(("SHCL_WIN_WM_REPORT_FORMATS: fFormats=%#xn", fFormats));
    343362
    344363#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     
    373392                    SharedClipboardWinClose();
    374393                }
     394
     395                if (RT_FAILURE(rc))
     396                    LogRel(("Shared Clipboard: Reporting clipboard formats %#x to Windows host failed with %Rrc\n", fFormats, rc));
     397
    375398#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    376399            }
     
    714737
    715738int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx,
    716                         SHCLFORMAT uFormat, void *pvData, uint32_t cbData, uint32_t *pcbActual)
     739                        SHCLFORMAT uFmt, void *pvData, uint32_t cbData, uint32_t *pcbActual)
    717740{
    718741    AssertPtrReturn(pClient,   VERR_INVALID_POINTER);
     
    725748    AssertPtrReturn(pClient->State.pCtx, VERR_INVALID_POINTER);
    726749
    727     LogFlowFunc(("uFormat=%02X\n", uFormat));
     750    LogFlowFunc(("uFmt=%#x\n", uFmt));
    728751
    729752    HANDLE hClip = NULL;
     
    737760    if (RT_SUCCESS(rc))
    738761    {
    739         LogFunc(("Clipboard opened\n"));
    740 
    741         if (uFormat & VBOX_SHCL_FMT_BITMAP)
    742         {
     762        if (uFmt & VBOX_SHCL_FMT_BITMAP)
     763        {
     764            LogFunc(("CF_DIB\n"));
    743765            hClip = GetClipboardData(CF_DIB);
    744766            if (hClip != NULL)
    745767            {
    746768                LPVOID lp = GlobalLock(hClip);
    747 
    748769                if (lp != NULL)
    749770                {
    750                     LogFunc(("CF_DIB\n"));
    751 
    752                     vboxClipboardSvcWinGetData(VBOX_SHCL_FMT_BITMAP, lp, GlobalSize(hClip),
    753                                                pvData, cbData, pcbActual);
    754 
     771                    rc = vboxClipboardSvcWinDataGet(VBOX_SHCL_FMT_BITMAP, lp, GlobalSize(hClip),
     772                                                    pvData, cbData, pcbActual);
    755773                    GlobalUnlock(hClip);
    756774                }
     
    761779            }
    762780        }
    763         else if (uFormat & VBOX_SHCL_FMT_UNICODETEXT)
    764         {
     781        else if (uFmt & VBOX_SHCL_FMT_UNICODETEXT)
     782        {
     783            LogFunc(("CF_UNICODETEXT\n"));
    765784            hClip = GetClipboardData(CF_UNICODETEXT);
    766785            if (hClip != NULL)
    767786            {
    768787                LPWSTR uniString = (LPWSTR)GlobalLock(hClip);
    769 
    770788                if (uniString != NULL)
    771789                {
    772                     LogFunc(("CF_UNICODETEXT\n"));
    773 
    774                     vboxClipboardSvcWinGetData(VBOX_SHCL_FMT_UNICODETEXT, uniString, (lstrlenW(uniString) + 1) * 2,
    775                                                pvData, cbData, pcbActual);
    776 
     790                    rc = vboxClipboardSvcWinDataGet(VBOX_SHCL_FMT_UNICODETEXT, uniString, (lstrlenW(uniString) + 1) * 2,
     791                                                    pvData, cbData, pcbActual);
    777792                    GlobalUnlock(hClip);
    778793                }
     
    783798            }
    784799        }
    785         else if (uFormat & VBOX_SHCL_FMT_HTML)
    786         {
    787             UINT format = RegisterClipboardFormat(SHCL_WIN_REGFMT_HTML);
    788             if (format != 0)
    789             {
    790                 hClip = GetClipboardData(format);
     800        else if (uFmt & VBOX_SHCL_FMT_HTML)
     801        {
     802            LogFunc(("SHCL_WIN_REGFMT_HTML\n"));
     803            UINT uRegFmt = RegisterClipboardFormat(SHCL_WIN_REGFMT_HTML);
     804            if (uRegFmt != 0)
     805            {
     806                hClip = GetClipboardData(uRegFmt);
    791807                if (hClip != NULL)
    792808                {
     
    794810                    if (lp != NULL)
    795811                    {
    796                         /** @todo r=andy Add data overflow handling. */
    797                         vboxClipboardSvcWinGetData(VBOX_SHCL_FMT_HTML, lp, GlobalSize(hClip),
    798                                                    pvData, cbData, pcbActual);
     812                        rc = vboxClipboardSvcWinDataGet(VBOX_SHCL_FMT_HTML, lp, GlobalSize(hClip),
     813                                                        pvData, cbData, pcbActual);
    799814#ifdef LOG_ENABLED
    800                         LogFlowFunc(("Raw HTML clipboard data from host:"));
    801                         ShClDbgDumpHtml((char *)pvData, cbData);
     815                        if (RT_SUCCESS(rc))
     816                        {
     817                            LogFlowFunc(("Raw HTML clipboard data from host:\n"));
     818                            ShClDbgDumpHtml((char *)pvData, cbData);
     819                        }
    802820#endif
    803821                        GlobalUnlock(hClip);
     
    811829        }
    812830#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    813         else if (uFormat & VBOX_SHCL_FMT_URI_LIST)
     831        else if (uFmt & VBOX_SHCL_FMT_URI_LIST)
    814832        {
    815833            AssertFailed(); /** @todo */
     
    819837    }
    820838
    821     if (hClip == NULL)
     839    if (hClip == NULL) /* Empty data is not fatal. */
    822840    {
    823841        /* Reply with empty data. */
    824         vboxClipboardSvcWinGetData(0, NULL, 0, pvData, cbData, pcbActual);
    825     }
     842        vboxClipboardSvcWinDataGet(0, NULL, 0, pvData, cbData, pcbActual);
     843    }
     844
     845    if (RT_FAILURE(rc))
     846        LogRel(("Shared Clipboard: Error reading host clipboard data in format %#x from Windows, rc=%Rrc\n", uFmt, rc));
    826847
    827848    LogFlowFuncLeaveRC(rc);
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp

    r86691 r86889  
    230230        rc = VERR_NO_MEMORY;
    231231
     232    if (RT_FAILURE(rc))
     233        LogRel(("Shared Clipboard: Error reading host clipboard data from X11, rc=%Rrc\n", rc));
     234
    232235    LogFlowFuncLeaveRC(rc);
    233236    return rc;
     
    287290{
    288291    AssertPtrReturnVoid(pCtx);
    289     RT_NOREF(rcCompletion);
    290292    AssertPtrReturnVoid(pReq);
    291293
     
    316318    if (pReq)
    317319        RTMemFree(pReq);
     320
     321    LogRel2(("Shared Clipboard: Request for clipboard data from X11 host completed with %Rrc\n", rcCompletion));
    318322}
    319323
     
    376380    }
    377381
     382    if (RT_FAILURE(rc))
     383        LogRel(("Shared Clipboard: Requesting data in format %#x for X11 host failed with %Rrc\n", fFormat, rc));
     384
    378385    LogFlowFuncLeaveRC(rc);
    379386    return rc;
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp

    r86363 r86889  
    13321332    }
    13331333
     1334    if (RT_FAILURE(rc))
     1335        LogRel(("Shared Clipboard: Requesting data in formats %#x from guest failed with %Rrc\n", fFormats, rc));
     1336
    13341337    LogFlowFuncLeaveRC(rc);
    13351338    return rc;
     
    13371340
    13381341/**
    1339  * Signals that clipboard data from the guest has been received.
     1342 * Signals the host that clipboard data from the guest has been received.
    13401343 *
    13411344 * @returns VBox status code. Returns VERR_NOT_FOUND when related event ID was not found.
     
    13891392    }
    13901393
     1394    if (RT_FAILURE(rc))
     1395        LogRel(("Shared Clipboard: Signalling of guest clipboard data to the host failed with %Rrc\n", rc));
     1396
    13911397    LogFlowFuncLeaveRC(rc);
    13921398    return rc;
     
    14031409int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats)
    14041410{
     1411    AssertPtrReturn(pClient, VERR_INVALID_POINTER);
     1412
    14051413    LogFlowFunc(("fFormats=%#x\n", fFormats));
    1406     AssertPtrReturn(pClient, VERR_INVALID_POINTER);
    14071414
    14081415#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     
    14531460    else
    14541461        rc = VERR_NO_MEMORY;
     1462
     1463    if (RT_FAILURE(rc))
     1464        LogRel(("Shared Clipboard: Reporting formats %#x to guest failed with %Rrc\n", fFormats, rc));
    14551465
    14561466    LogFlowFuncLeaveRC(rc);
     
    15271537            }
    15281538            else
     1539            {
    15291540                rc = ShClBackendFormatAnnounce(pClient, fFormats);
     1541                if (RT_FAILURE(rc))
     1542                    LogRel(("Shared Clipboard: Reporting guest clipboard formats to the host failed with %Rrc\n", rc));
     1543            }
    15301544        }
    15311545    }
     
    15351549
    15361550/**
    1537  * Handles the VBOX_SHCL_GUEST_FN_DATA_READ message from the guest.
     1551 * Called when the guest wants to read host clipboard data.
     1552 * Handles the VBOX_SHCL_GUEST_FN_DATA_READ message.
     1553 *
     1554 * @returns VBox status code.
     1555 * @retval  VINF_BUFFER_OVERFLOW if the guest supplied a smaller buffer than needed in order to read the host clipboard data.
     1556 * @param   pClient             Client that wants to read host clipboard data.
     1557 * @param   cParms              Number of HGCM parameters supplied in \a paParms.
     1558 * @param   paParms             Array of HGCM parameters.
    15381559 */
    15391560static int shClSvcClientReadData(PSHCLCLIENT pClient, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     
    16371658        /* Read clipboard data from the extension. */
    16381659        rc = g_ExtState.pfnExtension(g_ExtState.pvExtension, VBOX_CLIPBOARD_EXT_FN_DATA_READ, &parms, sizeof(parms));
    1639         LogRelFlowFunc(("Shared Clipboard: DATA/Ext: fDelayedAnnouncement=%RTbool fDelayedFormats=%#x cbData=%RU32->%RU32 rc=%Rrc\n",
    1640                         g_ExtState.fDelayedAnnouncement, g_ExtState.fDelayedFormats, cbData, parms.cbData, rc));
     1660
     1661        LogRel2(("Shared Clipboard: Read extension clipboard data (fDelayedAnnouncement=%RTbool, fDelayedFormats=%#x, max %RU32 bytes), got %RU32 bytes: rc=%Rrc\n",
     1662                 g_ExtState.fDelayedAnnouncement, g_ExtState.fDelayedFormats, cbData, parms.cbData, rc));
    16411663
    16421664        /* Did the extension send the clipboard formats yet?
     
    16591681    {
    16601682        rc = ShClBackendReadData(pClient, &cmdCtx, uFormat, pvData, cbData, &cbActual);
    1661         LogRelFlowFunc(("Shared Clipboard: DATA/Host: cbData=%RU32->%RU32 rc=%Rrc\n", cbData, cbActual, rc));
     1683        if (RT_SUCCESS(rc))
     1684        {
     1685            LogRel2(("Shared Clipboard: Read host clipboard data (max %RU32 bytes), got %RU32 bytes\n", cbData, cbActual));
     1686        }
     1687        else
     1688            LogRel(("Shared Clipboard: Reading host clipboard data failed with %Rrc\n", rc));
    16621689    }
    16631690
     
    16791706}
    16801707
     1708/**
     1709 * Called when the guest writes clipboard data to the host.
     1710 * Handles the VBOX_SHCL_GUEST_FN_DATA_WRITE message.
     1711 *
     1712 * @returns VBox status code.
     1713 * @param   pClient             Client that wants to read host clipboard data.
     1714 * @param   cParms              Number of HGCM parameters supplied in \a paParms.
     1715 * @param   paParms             Array of HGCM parameters.
     1716 */
    16811717int shClSvcClientWriteData(PSHCLCLIENT pClient, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    16821718{
     
    18111847        /* Let the backend implementation know. */
    18121848        rc = ShClBackendWriteData(pClient, &cmdCtx, uFormat, pvData, cbData);
     1849        if (RT_FAILURE(rc))
     1850            LogRel(("Shared Clipboard: Writing guest clipboard data to the host failed with %Rrc\n", rc));
    18131851
    18141852        int rc2; /* Don't return internals back to the guest. */
    18151853        rc2 = ShClSvcGuestDataSignal(pClient, &cmdCtx, uFormat, pvData, cbData); /* To complete pending events, if any. */
     1854        if (RT_FAILURE(rc2))
     1855            LogRel(("Shared Clipboard: Signalling host about guest clipboard data failed with %Rrc\n", rc2));
    18161856        AssertRC(rc2);
    18171857    }
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