Revision f2574737

b/kvm-all.c
975 975
            ret = kvm_handle_internal_error(env, run);
976 976
            break;
977 977
#endif
978
#ifdef KVM_CAP_SET_GUEST_DEBUG
979
        case KVM_EXIT_DEBUG:
980
            DPRINTF("kvm_exit_debug\n");
981
            if (kvm_arch_debug(&run->debug.arch)) {
982
                ret = EXCP_DEBUG;
983
                break;
984
            }
985
            /* re-enter, this exception was guest-internal */
986
            ret = 0;
987
            break;
988
#endif /* KVM_CAP_SET_GUEST_DEBUG */
989 978
        default:
990 979
            DPRINTF("kvm_arch_handle_exit\n");
991 980
            ret = kvm_arch_handle_exit(env, run);
b/kvm.h
136 136

  
137 137
QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint);
138 138

  
139
int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info);
140

  
141 139
struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
142 140
                                                 target_ulong pc);
143 141

  
b/target-i386/kvm.c
1731 1731

  
1732 1732
static CPUWatchpoint hw_watchpoint;
1733 1733

  
1734
int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info)
1734
static int kvm_handle_debug(struct kvm_debug_exit_arch *arch_info)
1735 1735
{
1736
    int handle = 0;
1736
    int ret = 0;
1737 1737
    int n;
1738 1738

  
1739 1739
    if (arch_info->exception == 1) {
1740 1740
        if (arch_info->dr6 & (1 << 14)) {
1741 1741
            if (cpu_single_env->singlestep_enabled) {
1742
                handle = 1;
1742
                ret = EXCP_DEBUG;
1743 1743
            }
1744 1744
        } else {
1745 1745
            for (n = 0; n < 4; n++) {
1746 1746
                if (arch_info->dr6 & (1 << n)) {
1747 1747
                    switch ((arch_info->dr7 >> (16 + n*4)) & 0x3) {
1748 1748
                    case 0x0:
1749
                        handle = 1;
1749
                        ret = EXCP_DEBUG;
1750 1750
                        break;
1751 1751
                    case 0x1:
1752
                        handle = 1;
1752
                        ret = EXCP_DEBUG;
1753 1753
                        cpu_single_env->watchpoint_hit = &hw_watchpoint;
1754 1754
                        hw_watchpoint.vaddr = hw_breakpoint[n].addr;
1755 1755
                        hw_watchpoint.flags = BP_MEM_WRITE;
1756 1756
                        break;
1757 1757
                    case 0x3:
1758
                        handle = 1;
1758
                        ret = EXCP_DEBUG;
1759 1759
                        cpu_single_env->watchpoint_hit = &hw_watchpoint;
1760 1760
                        hw_watchpoint.vaddr = hw_breakpoint[n].addr;
1761 1761
                        hw_watchpoint.flags = BP_MEM_ACCESS;
......
1765 1765
            }
1766 1766
        }
1767 1767
    } else if (kvm_find_sw_breakpoint(cpu_single_env, arch_info->pc)) {
1768
        handle = 1;
1768
        ret = EXCP_DEBUG;
1769 1769
    }
1770
    if (!handle) {
1770
    if (ret == 0) {
1771 1771
        cpu_synchronize_state(cpu_single_env);
1772 1772
        assert(cpu_single_env->exception_injected == -1);
1773 1773

  
1774
        /* pass to guest */
1774 1775
        cpu_single_env->exception_injected = arch_info->exception;
1775 1776
        cpu_single_env->has_error_code = 0;
1776 1777
    }
1777 1778

  
1778
    return handle;
1779
    return ret;
1779 1780
}
1780 1781

  
1781 1782
void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg)
......
1851 1852
                run->ex.exception, run->ex.error_code);
1852 1853
        ret = -1;
1853 1854
        break;
1855
#ifdef KVM_CAP_SET_GUEST_DEBUG
1856
    case KVM_EXIT_DEBUG:
1857
        DPRINTF("kvm_exit_debug\n");
1858
        ret = kvm_handle_debug(&run->debug.arch);
1859
        break;
1860
#endif /* KVM_CAP_SET_GUEST_DEBUG */
1854 1861
    default:
1855 1862
        fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
1856 1863
        ret = -1;

Also available in: Unified diff