Index: /trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp
===================================================================
--- /trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp	(revision 86888)
+++ /trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp	(revision 86889)
@@ -388,4 +388,7 @@
             }
         }
+
+        if (RT_FAILURE(rc))
+            LogRel2(("Shared Clipboard: Waiting for even %RU32 failed, rc=%Rrc\n", uID, rc));
     }
     else
Index: /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp
===================================================================
--- /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp	(revision 86888)
+++ /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp	(revision 86889)
@@ -261,4 +261,6 @@
 
     int rc = readFromPasteboard(pClient->State.pCtx->hPasteboard, fFormat, pvData, cbData, pcbActual);
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Error reading host clipboard data from macOS, rc=%Rrc\n", rc));
 
     ShClSvcUnlock();
Index: /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp
===================================================================
--- /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp	(revision 86888)
+++ /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp	(revision 86889)
@@ -67,7 +67,13 @@
 
 /** @todo Someone please explain the protocol wrt overflows...  */
-static void vboxClipboardSvcWinGetData(uint32_t u32Format, const void *pvSrc, uint32_t cbSrc,
-                                       void *pvDst, uint32_t cbDst, uint32_t *pcbActualDst)
-{
+static int vboxClipboardSvcWinDataGet(uint32_t u32Format, const void *pvSrc, uint32_t cbSrc,
+                                      void *pvDst, uint32_t cbDst, uint32_t *pcbActualDst)
+{
+    AssertPtrReturn(pvSrc,        VERR_INVALID_POINTER);
+    AssertReturn   (cbSrc,        VERR_INVALID_PARAMETER);
+    AssertPtrReturn(pvDst,        VERR_INVALID_POINTER);
+    AssertReturn   (cbDst,        VERR_INVALID_PARAMETER);
+    AssertPtrReturn(pcbActualDst, VERR_INVALID_POINTER);
+
     LogFlowFunc(("cbSrc = %d, cbDst = %d\n", cbSrc, cbDst));
 
@@ -96,11 +102,8 @@
     else
     {
-        *pcbActualDst = cbSrc;
+        *pcbActualDst = cbSrc; /* Tell the caller how much space we need. */
 
         if (cbSrc > cbDst)
-        {
-            /* Do not copy data. The dst buffer is not enough. */
-            return;
-        }
+            return VERR_BUFFER_OVERFLOW;
 
         memcpy(pvDst, pvSrc, cbSrc);
@@ -111,7 +114,17 @@
 #endif
 
-    return;
-}
-
+    return VINF_SUCCESS;
+}
+
+/**
+ * Sets (places) clipboard data into the Windows clipboard.
+ *
+ * @returns VBox status code.
+ * @param   pCtx                Shared Clipboard context to use.
+ * @param   cfFormat            Windows clipboard format to set data for.
+ * @param   pvData              Pointer to actual clipboard data to set.
+ * @param   cbData              Size (in bytes) of actual clipboard data to set.
+ * @note
+ */
 static int vboxClipboardSvcWinDataSet(PSHCLCONTEXT pCtx, UINT cfFormat, void *pvData, uint32_t cbData)
 {
@@ -163,4 +176,7 @@
         rc = RTErrConvertFromWin32(GetLastError());
 
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Setting clipboard data for Windows host failed with %Rrc\n", rc));
+
     LogFlowFuncLeaveRC(rc);
     return rc;
@@ -174,5 +190,5 @@
     if (fFormat == VBOX_SHCL_FMT_NONE)
     {
-        LogRel2(("Shared Clipbaord: Windows format %u not supported, ingoring\n", uFormat));
+        LogRel2(("Shared Clipboard: Windows format %u not supported, ignoring\n", uFormat));
         return VERR_NOT_SUPPORTED;
     }
@@ -193,4 +209,7 @@
         ShClEventUnregister(&pCtx->pClient->EventSrc, idEvent);
     }
+
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Reading guest clipboard data for Windows host failed with %Rrc\n", rc));
 
     LogFlowFuncLeaveRC(rc);
@@ -340,5 +359,5 @@
             /* Announce available formats. Do not insert data -- will be inserted in WM_RENDERFORMAT (or via IDataObject). */
             SHCLFORMATS fFormats = (uint32_t)lParam;
-            LogFunc(("SHCL_WIN_WM_REPORT_FORMATS: fFormats=0x%x\n", fFormats));
+            LogFunc(("SHCL_WIN_WM_REPORT_FORMATS: fFormats=%#xn", fFormats));
 
 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
@@ -373,4 +392,8 @@
                     SharedClipboardWinClose();
                 }
+
+                if (RT_FAILURE(rc))
+                    LogRel(("Shared Clipboard: Reporting clipboard formats %#x to Windows host failed with %Rrc\n", fFormats, rc));
+
 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
             }
@@ -714,5 +737,5 @@
 
 int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx,
-                        SHCLFORMAT uFormat, void *pvData, uint32_t cbData, uint32_t *pcbActual)
+                        SHCLFORMAT uFmt, void *pvData, uint32_t cbData, uint32_t *pcbActual)
 {
     AssertPtrReturn(pClient,   VERR_INVALID_POINTER);
@@ -725,5 +748,5 @@
     AssertPtrReturn(pClient->State.pCtx, VERR_INVALID_POINTER);
 
-    LogFlowFunc(("uFormat=%02X\n", uFormat));
+    LogFlowFunc(("uFmt=%#x\n", uFmt));
 
     HANDLE hClip = NULL;
@@ -737,20 +760,15 @@
     if (RT_SUCCESS(rc))
     {
-        LogFunc(("Clipboard opened\n"));
-
-        if (uFormat & VBOX_SHCL_FMT_BITMAP)
-        {
+        if (uFmt & VBOX_SHCL_FMT_BITMAP)
+        {
+            LogFunc(("CF_DIB\n"));
             hClip = GetClipboardData(CF_DIB);
             if (hClip != NULL)
             {
                 LPVOID lp = GlobalLock(hClip);
-
                 if (lp != NULL)
                 {
-                    LogFunc(("CF_DIB\n"));
-
-                    vboxClipboardSvcWinGetData(VBOX_SHCL_FMT_BITMAP, lp, GlobalSize(hClip),
-                                               pvData, cbData, pcbActual);
-
+                    rc = vboxClipboardSvcWinDataGet(VBOX_SHCL_FMT_BITMAP, lp, GlobalSize(hClip),
+                                                    pvData, cbData, pcbActual);
                     GlobalUnlock(hClip);
                 }
@@ -761,18 +779,15 @@
             }
         }
-        else if (uFormat & VBOX_SHCL_FMT_UNICODETEXT)
-        {
+        else if (uFmt & VBOX_SHCL_FMT_UNICODETEXT)
+        {
+            LogFunc(("CF_UNICODETEXT\n"));
             hClip = GetClipboardData(CF_UNICODETEXT);
             if (hClip != NULL)
             {
                 LPWSTR uniString = (LPWSTR)GlobalLock(hClip);
-
                 if (uniString != NULL)
                 {
-                    LogFunc(("CF_UNICODETEXT\n"));
-
-                    vboxClipboardSvcWinGetData(VBOX_SHCL_FMT_UNICODETEXT, uniString, (lstrlenW(uniString) + 1) * 2,
-                                               pvData, cbData, pcbActual);
-
+                    rc = vboxClipboardSvcWinDataGet(VBOX_SHCL_FMT_UNICODETEXT, uniString, (lstrlenW(uniString) + 1) * 2,
+                                                    pvData, cbData, pcbActual);
                     GlobalUnlock(hClip);
                 }
@@ -783,10 +798,11 @@
             }
         }
-        else if (uFormat & VBOX_SHCL_FMT_HTML)
-        {
-            UINT format = RegisterClipboardFormat(SHCL_WIN_REGFMT_HTML);
-            if (format != 0)
-            {
-                hClip = GetClipboardData(format);
+        else if (uFmt & VBOX_SHCL_FMT_HTML)
+        {
+            LogFunc(("SHCL_WIN_REGFMT_HTML\n"));
+            UINT uRegFmt = RegisterClipboardFormat(SHCL_WIN_REGFMT_HTML);
+            if (uRegFmt != 0)
+            {
+                hClip = GetClipboardData(uRegFmt);
                 if (hClip != NULL)
                 {
@@ -794,10 +810,12 @@
                     if (lp != NULL)
                     {
-                        /** @todo r=andy Add data overflow handling. */
-                        vboxClipboardSvcWinGetData(VBOX_SHCL_FMT_HTML, lp, GlobalSize(hClip),
-                                                   pvData, cbData, pcbActual);
+                        rc = vboxClipboardSvcWinDataGet(VBOX_SHCL_FMT_HTML, lp, GlobalSize(hClip),
+                                                        pvData, cbData, pcbActual);
 #ifdef LOG_ENABLED
-                        LogFlowFunc(("Raw HTML clipboard data from host:"));
-                        ShClDbgDumpHtml((char *)pvData, cbData);
+                        if (RT_SUCCESS(rc))
+                        {
+                            LogFlowFunc(("Raw HTML clipboard data from host:\n"));
+                            ShClDbgDumpHtml((char *)pvData, cbData);
+                        }
 #endif
                         GlobalUnlock(hClip);
@@ -811,5 +829,5 @@
         }
 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
-        else if (uFormat & VBOX_SHCL_FMT_URI_LIST)
+        else if (uFmt & VBOX_SHCL_FMT_URI_LIST)
         {
             AssertFailed(); /** @todo */
@@ -819,9 +837,12 @@
     }
 
-    if (hClip == NULL)
+    if (hClip == NULL) /* Empty data is not fatal. */
     {
         /* Reply with empty data. */
-        vboxClipboardSvcWinGetData(0, NULL, 0, pvData, cbData, pcbActual);
-    }
+        vboxClipboardSvcWinDataGet(0, NULL, 0, pvData, cbData, pcbActual);
+    }
+
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Error reading host clipboard data in format %#x from Windows, rc=%Rrc\n", uFmt, rc));
 
     LogFlowFuncLeaveRC(rc);
Index: /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp
===================================================================
--- /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp	(revision 86888)
+++ /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp	(revision 86889)
@@ -230,4 +230,7 @@
         rc = VERR_NO_MEMORY;
 
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Error reading host clipboard data from X11, rc=%Rrc\n", rc));
+
     LogFlowFuncLeaveRC(rc);
     return rc;
@@ -287,5 +290,4 @@
 {
     AssertPtrReturnVoid(pCtx);
-    RT_NOREF(rcCompletion);
     AssertPtrReturnVoid(pReq);
 
@@ -316,4 +318,6 @@
     if (pReq)
         RTMemFree(pReq);
+
+    LogRel2(("Shared Clipboard: Request for clipboard data from X11 host completed with %Rrc\n", rcCompletion));
 }
 
@@ -376,4 +380,7 @@
     }
 
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Requesting data in format %#x for X11 host failed with %Rrc\n", fFormat, rc));
+
     LogFlowFuncLeaveRC(rc);
     return rc;
Index: /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp
===================================================================
--- /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp	(revision 86888)
+++ /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp	(revision 86889)
@@ -1332,4 +1332,7 @@
     }
 
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Requesting data in formats %#x from guest failed with %Rrc\n", fFormats, rc));
+
     LogFlowFuncLeaveRC(rc);
     return rc;
@@ -1337,5 +1340,5 @@
 
 /**
- * Signals that clipboard data from the guest has been received.
+ * Signals the host that clipboard data from the guest has been received.
  *
  * @returns VBox status code. Returns VERR_NOT_FOUND when related event ID was not found.
@@ -1389,4 +1392,7 @@
     }
 
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Signalling of guest clipboard data to the host failed with %Rrc\n", rc));
+
     LogFlowFuncLeaveRC(rc);
     return rc;
@@ -1403,6 +1409,7 @@
 int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats)
 {
+    AssertPtrReturn(pClient, VERR_INVALID_POINTER);
+
     LogFlowFunc(("fFormats=%#x\n", fFormats));
-    AssertPtrReturn(pClient, VERR_INVALID_POINTER);
 
 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
@@ -1453,4 +1460,7 @@
     else
         rc = VERR_NO_MEMORY;
+
+    if (RT_FAILURE(rc))
+        LogRel(("Shared Clipboard: Reporting formats %#x to guest failed with %Rrc\n", fFormats, rc));
 
     LogFlowFuncLeaveRC(rc);
@@ -1527,5 +1537,9 @@
             }
             else
+            {
                 rc = ShClBackendFormatAnnounce(pClient, fFormats);
+                if (RT_FAILURE(rc))
+                    LogRel(("Shared Clipboard: Reporting guest clipboard formats to the host failed with %Rrc\n", rc));
+            }
         }
     }
@@ -1535,5 +1549,12 @@
 
 /**
- * Handles the VBOX_SHCL_GUEST_FN_DATA_READ message from the guest.
+ * Called when the guest wants to read host clipboard data.
+ * Handles the VBOX_SHCL_GUEST_FN_DATA_READ message.
+ *
+ * @returns VBox status code.
+ * @retval  VINF_BUFFER_OVERFLOW if the guest supplied a smaller buffer than needed in order to read the host clipboard data.
+ * @param   pClient             Client that wants to read host clipboard data.
+ * @param   cParms              Number of HGCM parameters supplied in \a paParms.
+ * @param   paParms             Array of HGCM parameters.
  */
 static int shClSvcClientReadData(PSHCLCLIENT pClient, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
@@ -1637,6 +1658,7 @@
         /* Read clipboard data from the extension. */
         rc = g_ExtState.pfnExtension(g_ExtState.pvExtension, VBOX_CLIPBOARD_EXT_FN_DATA_READ, &parms, sizeof(parms));
-        LogRelFlowFunc(("Shared Clipboard: DATA/Ext: fDelayedAnnouncement=%RTbool fDelayedFormats=%#x cbData=%RU32->%RU32 rc=%Rrc\n",
-                        g_ExtState.fDelayedAnnouncement, g_ExtState.fDelayedFormats, cbData, parms.cbData, rc));
+
+        LogRel2(("Shared Clipboard: Read extension clipboard data (fDelayedAnnouncement=%RTbool, fDelayedFormats=%#x, max %RU32 bytes), got %RU32 bytes: rc=%Rrc\n",
+                 g_ExtState.fDelayedAnnouncement, g_ExtState.fDelayedFormats, cbData, parms.cbData, rc));
 
         /* Did the extension send the clipboard formats yet?
@@ -1659,5 +1681,10 @@
     {
         rc = ShClBackendReadData(pClient, &cmdCtx, uFormat, pvData, cbData, &cbActual);
-        LogRelFlowFunc(("Shared Clipboard: DATA/Host: cbData=%RU32->%RU32 rc=%Rrc\n", cbData, cbActual, rc));
+        if (RT_SUCCESS(rc))
+        {
+            LogRel2(("Shared Clipboard: Read host clipboard data (max %RU32 bytes), got %RU32 bytes\n", cbData, cbActual));
+        }
+        else
+            LogRel(("Shared Clipboard: Reading host clipboard data failed with %Rrc\n", rc));
     }
 
@@ -1679,4 +1706,13 @@
 }
 
+/**
+ * Called when the guest writes clipboard data to the host.
+ * Handles the VBOX_SHCL_GUEST_FN_DATA_WRITE message.
+ *
+ * @returns VBox status code.
+ * @param   pClient             Client that wants to read host clipboard data.
+ * @param   cParms              Number of HGCM parameters supplied in \a paParms.
+ * @param   paParms             Array of HGCM parameters.
+ */
 int shClSvcClientWriteData(PSHCLCLIENT pClient, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
 {
@@ -1811,7 +1847,11 @@
         /* Let the backend implementation know. */
         rc = ShClBackendWriteData(pClient, &cmdCtx, uFormat, pvData, cbData);
+        if (RT_FAILURE(rc))
+            LogRel(("Shared Clipboard: Writing guest clipboard data to the host failed with %Rrc\n", rc));
 
         int rc2; /* Don't return internals back to the guest. */
         rc2 = ShClSvcGuestDataSignal(pClient, &cmdCtx, uFormat, pvData, cbData); /* To complete pending events, if any. */
+        if (RT_FAILURE(rc2))
+            LogRel(("Shared Clipboard: Signalling host about guest clipboard data failed with %Rrc\n", rc2));
         AssertRC(rc2);
     }
