Index: /trunk/include/VBox/cpum.h
===================================================================
--- /trunk/include/VBox/cpum.h	(revision 21251)
+++ /trunk/include/VBox/cpum.h	(revision 21252)
@@ -956,4 +956,6 @@
 VMMDECL(bool)           CPUMIsGuestDebugStateActive(PVMCPU pVCpu);
 VMMDECL(void)           CPUMDeactivateGuestDebugState(PVMCPU pVCpu);
+VMMDECL(bool)           CPUMIsHyperDebugStateActive(PVMCPU pVCpu);
+VMMDECL(void)           CPUMDeactivateHyperDebugState(PVMCPU pVCpu);
 VMMDECL(uint32_t)       CPUMGetGuestCPL(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore);
 VMMDECL(bool)           CPUMAreHiddenSelRegsValid(PVM pVM);
@@ -1038,4 +1040,7 @@
 VMMR0DECL(int)          CPUMR0SaveGuestDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, bool fDR6);
 VMMR0DECL(int)          CPUMR0LoadGuestDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, bool fDR6);
+VMMR0DECL(int)          CPUMR0LoadHostDebugState(PVM pVM, PVMCPU pVCpu);
+VMMR0DECL(int)          CPUMR0SaveHostDebugState(PVM pVM, PVMCPU pVCpu);
+VMMR0DECL(int)          CPUMR0LoadHyperDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, bool fDR6);
 
 /** @} */
Index: /trunk/src/VBox/VMM/CPUMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/CPUMInternal.h	(revision 21251)
+++ /trunk/src/VBox/VMM/CPUMInternal.h	(revision 21252)
@@ -76,4 +76,6 @@
 /** Sync the debug state on entry (32->64 switcher only). */
 #define CPUM_SYNC_DEBUG_STATE           RT_BIT(8)
+/** Enabled use of hypervisor debug registers in guest context. */
+#define CPUM_USE_DEBUG_REGS_HYPER       RT_BIT(9)
 /** @} */
 
Index: /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp	(revision 21251)
+++ /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp	(revision 21252)
@@ -1930,11 +1930,22 @@
 }
 
-
-/**
- * Mark the guest's debug state as inactive
+/**
+ * Checks if the hyper debug state is active
  *
  * @returns boolean
  * @param   pVM         VM handle.
  */
+VMMDECL(bool) CPUMIsHyperDebugStateActive(PVMCPU pVCpu)
+{
+    return (pVCpu->cpum.s.fUseFlags & CPUM_USE_DEBUG_REGS_HYPER) != 0;
+}
+
+
+/**
+ * Mark the guest's debug state as inactive
+ *
+ * @returns boolean
+ * @param   pVM         VM handle.
+ */
 VMMDECL(void) CPUMDeactivateGuestDebugState(PVMCPU pVCpu)
 {
@@ -1942,4 +1953,15 @@
 }
 
+
+/**
+ * Mark the hypervisor's debug state as inactive
+ *
+ * @returns boolean
+ * @param   pVM         VM handle.
+ */
+VMMDECL(void) CPUMDeactivateHyperDebugState(PVMCPU pVCpu)
+{
+    pVCpu->cpum.s.fUseFlags &= ~CPUM_USE_DEBUG_REGS_HYPER;
+}
 
 /**
Index: /trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp	(revision 21251)
+++ /trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp	(revision 21252)
@@ -404,17 +404,6 @@
      * DR7 contains 0x400 right now.
      */
-#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
-    AssertCompile((uintptr_t)&pVCpu->cpum.s.Host.dr3 - (uintptr_t)&pVCpu->cpum.s.Host.dr0 == sizeof(uint64_t) * 3);
-    cpumR0LoadDRx(&pVCpu->cpum.s.Host.dr0);
-#else
-    ASMSetDR0(pVCpu->cpum.s.Host.dr0);
-    ASMSetDR1(pVCpu->cpum.s.Host.dr1);
-    ASMSetDR2(pVCpu->cpum.s.Host.dr2);
-    ASMSetDR3(pVCpu->cpum.s.Host.dr3);
-#endif
-    ASMSetDR6(pVCpu->cpum.s.Host.dr6);
-    ASMSetDR7(pVCpu->cpum.s.Host.dr7);
-
-    pVCpu->cpum.s.fUseFlags &= ~CPUM_USE_DEBUG_REGS;
+    CPUMR0LoadHostDebugState(pVM, pVCpu);
+    Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_USE_DEBUG_REGS));
     return VINF_SUCCESS;
 }
@@ -431,4 +420,43 @@
  */
 VMMR0DECL(int) CPUMR0LoadGuestDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, bool fDR6)
+{
+    /* Save the host state. */
+    CPUMR0SaveHostDebugState(pVM, pVCpu);
+    Assert(ASMGetDR7() == X86_DR7_INIT_VAL);
+
+    /* Activate the guest state DR0-3; DR7 is left to the caller. */
+#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
+    if (CPUMIsGuestInLongModeEx(pCtx))
+    {
+        /* Restore the state on entry as we need to be in 64 bits mode to access the full state. */
+        pVCpu->cpum.s.fUseFlags |= CPUM_SYNC_DEBUG_STATE;
+    }
+    else
+#endif
+    {
+#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
+        cpumR0LoadDRx(&pCtx->dr[0]);
+#else
+        ASMSetDR0(pCtx->dr[0]);
+        ASMSetDR1(pCtx->dr[1]);
+        ASMSetDR2(pCtx->dr[2]);
+        ASMSetDR3(pCtx->dr[3]);
+#endif
+        if (fDR6)
+            ASMSetDR6(pCtx->dr[6]);
+    }
+
+    pVCpu->cpum.s.fUseFlags |= CPUM_USE_DEBUG_REGS;
+    return VINF_SUCCESS;
+}
+
+/**
+ * Save the host debug state
+ *
+ * @returns VBox status code.
+ * @param   pVM         VM handle.
+ * @param   pVCpu       VMCPU handle.
+ */
+VMMR0DECL(int) CPUMR0SaveHostDebugState(PVM pVM, PVMCPU pVCpu)
 {
     /* Save the host state. */
@@ -448,10 +476,60 @@
     ASMSetDR7(X86_DR7_INIT_VAL);
 
+    return VINF_SUCCESS;
+}
+
+/**
+ * Load the host debug state
+ *
+ * @returns VBox status code.
+ * @param   pVM         VM handle.
+ * @param   pVCpu       VMCPU handle.
+ */
+VMMR0DECL(int) CPUMR0LoadHostDebugState(PVM pVM, PVMCPU pVCpu)
+{
+    Assert(pVCpu->cpum.s.fUseFlags & (CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HYPER));
+
+    /*
+     * Restore the host's debug state. DR0-3, DR6 and only then DR7!
+     * DR7 contains 0x400 right now.
+     */
+#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
+    AssertCompile((uintptr_t)&pVCpu->cpum.s.Host.dr3 - (uintptr_t)&pVCpu->cpum.s.Host.dr0 == sizeof(uint64_t) * 3);
+    cpumR0LoadDRx(&pVCpu->cpum.s.Host.dr0);
+#else
+    ASMSetDR0(pVCpu->cpum.s.Host.dr0);
+    ASMSetDR1(pVCpu->cpum.s.Host.dr1);
+    ASMSetDR2(pVCpu->cpum.s.Host.dr2);
+    ASMSetDR3(pVCpu->cpum.s.Host.dr3);
+#endif
+    ASMSetDR6(pVCpu->cpum.s.Host.dr6);
+    ASMSetDR7(pVCpu->cpum.s.Host.dr7);
+
+    pVCpu->cpum.s.fUseFlags &= ~(CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HYPER);
+    return VINF_SUCCESS;
+}
+
+
+/**
+ * Lazily sync in the hypervisor debug state
+ *
+ * @returns VBox status code.
+ * @param   pVM         VM handle.
+ * @param   pVCpu       VMCPU handle.
+ * @param   pCtx        CPU context
+ * @param   fDR6        Include DR6 or not
+ */
+VMMR0DECL(int) CPUMR0LoadHyperDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, bool fDR6)
+{
+    /* Save the host state. */
+    CPUMR0SaveHostDebugState(pVM, pVCpu);
+    Assert(ASMGetDR7() == X86_DR7_INIT_VAL);
+
     /* Activate the guest state DR0-3; DR7 is left to the caller. */
 #if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
     if (CPUMIsGuestInLongModeEx(pCtx))
     {
-        /* Restore the state on entry as we need to be in 64 bits mode to access the full state. */
-        pVCpu->cpum.s.fUseFlags |= CPUM_SYNC_DEBUG_STATE;
+        AssertFailed();
+        return VERR_NOT_IMPLEMENTED;
     }
     else
@@ -459,18 +537,19 @@
     {
 #ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
-        cpumR0LoadDRx(&pCtx->dr[0]);
+        AssertFailed();
+        return VERR_NOT_IMPLEMENTED;
 #else
-        ASMSetDR0(pCtx->dr[0]);
-        ASMSetDR1(pCtx->dr[1]);
-        ASMSetDR2(pCtx->dr[2]);
-        ASMSetDR3(pCtx->dr[3]);
+        ASMSetDR0(CPUMGetHyperDR0(pVCpu));
+        ASMSetDR1(CPUMGetHyperDR1(pVCpu));
+        ASMSetDR2(CPUMGetHyperDR2(pVCpu));
+        ASMSetDR3(CPUMGetHyperDR3(pVCpu));
 #endif
         if (fDR6)
-            ASMSetDR6(pCtx->dr[6]);
-    }
-
-    pVCpu->cpum.s.fUseFlags |= CPUM_USE_DEBUG_REGS;
-    return VINF_SUCCESS;
-}
-
-
+            ASMSetDR6(CPUMGetHyperDR6(pVCpu));
+    }
+
+    pVCpu->cpum.s.fUseFlags |= CPUM_USE_DEBUG_REGS_HYPER;
+    return VINF_SUCCESS;
+}
+
+
Index: /trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp	(revision 21251)
+++ /trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp	(revision 21252)
@@ -753,4 +753,22 @@
         pVMCB->guest.u64DR6 = pCtx->dr[6];
 
+#ifdef DEBUG
+        /* Sync the hypervisor debug state now if any breakpoint is armed. */
+        if (    CPUMGetHyperDR7(pVCpu) & (X86_DR7_ENABLED_MASK|X86_DR7_GD)
+            &&  !CPUMIsHyperDebugStateActive(pVCpu)
+            &&  !DBGFIsStepping(pVCpu))
+        {
+            /* Save the host and load the hypervisor debug state. */
+            int rc = CPUMR0LoadHyperDebugState(pVM, pVCpu, pCtx, false /* exclude DR6 */);
+            AssertRC(rc);
+
+            /* DRx intercepts remain enabled. */
+
+            /* Override dr6 & dr7 with the hypervisor values. */
+            pVMCB->guest.u64DR7 = CPUMGetHyperDR7(pVCpu);
+            pVMCB->guest.u64DR6 = CPUMGetHyperDR6(pVCpu);
+        }
+        else
+#endif
         /* Sync the debug state now if any breakpoint is armed. */
         if (    (pCtx->dr[7] & (X86_DR7_ENABLED_MASK|X86_DR7_GD))
@@ -2620,4 +2638,11 @@
     Assert(pVM->hwaccm.s.svm.fSupported);
 
+#ifdef DEBUG
+    if (CPUMIsHyperDebugStateActive(pVCpu))
+    {
+        CPUMR0LoadHostDebugState(pVM, pVCpu);
+    }
+    else
+#endif
     /* Save the guest debug state if necessary. */
     if (CPUMIsGuestDebugStateActive(pVCpu))
Index: /trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp	(revision 21251)
+++ /trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp	(revision 21252)
@@ -1588,4 +1588,22 @@
         AssertRC(rc);
 
+#ifdef DEBUG
+        /* Sync the hypervisor debug state now if any breakpoint is armed. */
+        if (    CPUMGetHyperDR7(pVCpu) & (X86_DR7_ENABLED_MASK|X86_DR7_GD)
+            &&  !CPUMIsHyperDebugStateActive(pVCpu)
+            &&  !DBGFIsStepping(pVCpu))
+        {
+            /* Save the host and load the hypervisor debug state. */
+            rc = CPUMR0LoadHyperDebugState(pVM, pVCpu, pCtx, true /* include DR6 */);
+            AssertRC(rc);
+
+            /* DRx intercepts remain enabled. */
+
+            /* Override dr7 with the hypervisor value. */
+            rc = VMXWriteVMCS64(VMX_VMCS64_GUEST_DR7, CPUMGetHyperDR7(pVCpu));
+            AssertRC(rc);
+        }
+        else
+#endif
         /* Sync the debug state now if any breakpoint is armed. */
         if (    (pCtx->dr[7] & (X86_DR7_ENABLED_MASK|X86_DR7_GD))
@@ -3800,4 +3818,11 @@
     Assert(pVM->hwaccm.s.vmx.fSupported);
 
+#ifdef DEBUG
+    if (CPUMIsHyperDebugStateActive(pVCpu))
+    {
+        CPUMR0LoadHostDebugState(pVM, pVCpu);
+    }
+    else
+#endif
     /* Save the guest debug state if necessary. */
     if (CPUMIsGuestDebugStateActive(pVCpu))
