Skip to contentSkip to conversation

xen debugger (kdb/xdb/hdb) patch for c/s 25467

DISCUSSION Mukesh Rathor 3 participants 5 messages Aug 29, 2012 – Sep 5, 2012

lore
Share & tools
lore
#0 lore raw

Hi Guys,

Thanks for the interest in the xen hypervisor debugger, prev known as kdb. Btw. I'm gonna rename it to xdb for xen-debugger or hdb for hypervisor debugger. KDB is confusing people with linux kdb debugger and I often get emails where people think they need to apply linux kdb patch also...

Anyways, attaching patch that is cleaned up of my debug code that I accidentally left in prev posting. Should apply cleanly to c/s 25467.

JFYI... http://xenbits.xen.org/ext/debuggers.hg/ has gotten outdated, I wasn't sure if anyone was even looking at it. But, it looks like there is much interest, so I will just submit patch to Keir for his feedback on merging it in xen.

Please voice your opinion here. Good seeing all at the summit :).

Thanks,
Mukesh

#1 lore raw
Quoted 3 lines · On Wed, 29 Aug 2012 14:35:12 -0700 Mukesh Rathor <[email protected]>…

Anyways, attaching patch that is cleaned up of my debug code that I accidentally left in prev posting. Should apply cleanly to c/s 25467.

really attaching this time :).

xen/Makefile +2 -1
diff -r 32034d1914a6 xen/Makefile
@@ -61,6 +61,7 @@
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C xsm clean
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C crypto clean
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) clean
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C kdb clean
 	rm -f include/asm *.o $(TARGET) $(TARGET).gz $(TARGET)-syms *~ core
 	rm -f include/asm-*/asm-offsets.h
 	[ -d tools/figlet ] && rm -f .banner*
@@ -129,7 +130,7 @@
 	  echo ""; \
 	  echo "#endif") <$< >$@
 
-SUBDIRS = xsm arch/$(TARGET_ARCH) common drivers
+SUBDIRS = xsm arch/$(TARGET_ARCH) common drivers kdb
 define all_sources
     ( find include/asm-$(TARGET_ARCH) -name '*.h' -print; \
       find include -name 'asm-*' -prune -o -name '*.h' -print; \
xen/Rules.mk +3 -0
diff -r 32034d1914a6 xen/Rules.mk
@@ -10,6 +10,7 @@
 crash_debug   ?= n
 frame_pointer ?= n
 lto           ?= n
+kdb           ?= n
 
 include $(XEN_ROOT)/Config.mk
 
@@ -40,6 +41,7 @@
 ALL_OBJS-y               += $(BASEDIR)/xsm/built_in.o
 ALL_OBJS-y               += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
 ALL_OBJS-$(x86)          += $(BASEDIR)/crypto/built_in.o
+ALL_OBJS-$(kdb)          += $(BASEDIR)/kdb/built_in.o
 
 CFLAGS-y                += -g -D__XEN__ -include $(BASEDIR)/include/xen/config.h
 CFLAGS-$(XSM_ENABLE)    += -DXSM_ENABLE
@@ -53,6 +55,7 @@
 CFLAGS-$(HAS_ACPI)      += -DHAS_ACPI
 CFLAGS-$(HAS_PASSTHROUGH) += -DHAS_PASSTHROUGH
 CFLAGS-$(frame_pointer) += -fno-omit-frame-pointer -DCONFIG_FRAME_POINTER
+CFLAGS-$(kdb)           += -DXEN_KDB_CONFIG
 
 ifneq ($(max_phys_cpus),)
 CFLAGS-y                += -DMAX_PHYS_CPUS=$(max_phys_cpus)
xen/arch/x86/hvm/svm/entry.S +11 -0
diff -r 32034d1914a6 xen/arch/x86/hvm/svm/entry.S
@@ -59,12 +59,23 @@
         get_current(bx)
         CLGI
 
+#ifdef XEN_KDB_CONFIG
+#if defined(__x86_64__)
+        testl $1, kdb_session_begun(%rip)
+#else
+        testl $1, kdb_session_begun
+#endif
+        jnz  .Lkdb_skip_softirq
+#endif
         mov  VCPU_processor(r(bx)),%eax
         shl  $IRQSTAT_shift,r(ax)
         lea  addr_of(irq_stat),r(dx)
         testl $~0,(r(dx),r(ax),1)
         jnz  .Lsvm_process_softirqs
 
+#ifdef XEN_KDB_CONFIG
+.Lkdb_skip_softirq:
+#endif
         testb $0, VCPU_nsvm_hap_enabled(r(bx))
 UNLIKELY_START(nz, nsvm_hap)
         mov  VCPU_nhvm_p2m(r(bx)),r(ax)
xen/arch/x86/hvm/svm/svm.c +8 -0
diff -r 32034d1914a6 xen/arch/x86/hvm/svm/svm.c
@@ -2170,6 +2170,10 @@
         break;
 
     case VMEXIT_EXCEPTION_DB:
+#ifdef XEN_KDB_CONFIG
+        if (kdb_handle_trap_entry(TRAP_debug, regs))
+	    break;
+#endif
         if ( !v->domain->debugger_attached )
             goto exit_and_crash;
         domain_pause_for_debugger();
@@ -2182,6 +2186,10 @@
         if ( (inst_len = __get_instruction_length(v, INSTR_INT3)) == 0 )
             break;
         __update_guest_eip(regs, inst_len);
+#ifdef XEN_KDB_CONFIG
+        if (kdb_handle_trap_entry(TRAP_int3, regs))
+            break;
+#endif
         current->arch.gdbsx_vcpu_event = TRAP_int3;
         domain_pause_for_debugger();
         break;
xen/arch/x86/hvm/svm/vmcb.c +30 -0
diff -r 32034d1914a6 xen/arch/x86/hvm/svm/vmcb.c
@@ -315,6 +315,36 @@
     register_keyhandler('v', &vmcb_dump_keyhandler);
 }
 
+#if defined(XEN_KDB_CONFIG)
+/* did == 0 : display for all HVM domains. domid 0 is never HVM.
+ *  * vid == -1 : display for all HVM VCPUs
+ *   */
+void kdb_dump_vmcb(domid_t did, int vid)
+{
+    struct domain *dp;
+    struct vcpu *vp;
+
+    rcu_read_lock(&domlist_read_lock);
+    for_each_domain (dp) {
+        if (!is_hvm_or_hyb_domain(dp) || dp->is_dying)
+            continue;
+        if (did != 0 && did != dp->domain_id)
+            continue;
+
+        for_each_vcpu (dp, vp) {
+            if (vid != -1 && vid != vp->vcpu_id)
+                continue;
+
+            kdbp("  VMCB [domid: %d  vcpu:%d]:\n", dp->domain_id, vp->vcpu_id);
+            svm_vmcb_dump("kdb", vp->arch.hvm_svm.vmcb);
+            kdbp("\n");
+        }
+        kdbp("\n");
+    }
+    rcu_read_unlock(&domlist_read_lock);
+}
+#endif
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/hvm/vmx/entry.S +11 -0
diff -r 32034d1914a6 xen/arch/x86/hvm/vmx/entry.S
@@ -124,12 +124,23 @@
         get_current(bx)
         cli
 
+#ifdef XEN_KDB_CONFIG
+#if defined(__x86_64__)
+        testl $1, kdb_session_begun(%rip)
+#else
+        testl $1, kdb_session_begun
+#endif
+        jnz  .Lkdb_skip_softirq
+#endif
         mov  VCPU_processor(r(bx)),%eax
         shl  $IRQSTAT_shift,r(ax)
         lea  addr_of(irq_stat),r(dx)
         cmpl $0,(r(dx),r(ax),1)
         jnz  .Lvmx_process_softirqs
 
+#ifdef XEN_KDB_CONFIG
+.Lkdb_skip_softirq:
+#endif
         testb $0xff,VCPU_vmx_emulate(r(bx))
         jnz .Lvmx_goto_emulator
         testb $0xff,VCPU_vmx_realmode(r(bx))
xen/arch/x86/hvm/vmx/vmcs.c +221 -0

233 lines not on this page · raw message

xen/arch/x86/hvm/vmx/vmx.c +22 -2
diff -r 32034d1914a6 xen/arch/x86/hvm/vmx/vmx.c
@@ -2183,11 +2183,14 @@
         printk("reason not known yet!");
         break;
     }
-
+#if defined(XEN_KDB_CONFIG)
+    kdbp("\n************* VMCS Area **************\n");
+    kdb_dump_vmcs(curr->domain->domain_id, (curr)->vcpu_id);
+#else
     printk("************* VMCS Area **************\n");
     vmcs_dump_vcpu(curr);
     printk("**************************************\n");
-
+#endif
     domain_crash(curr->domain);
 }
 
@@ -2415,6 +2418,12 @@
             write_debugreg(6, exit_qualification | 0xffff0ff0);
             if ( !v->domain->debugger_attached || cpu_has_monitor_trap_flag )
                 goto exit_and_crash;
+
+#if defined(XEN_KDB_CONFIG)
+            /* TRAP_debug: IP points correctly to next instr */
+            if (kdb_handle_trap_entry(vector, regs))
+                break;
+#endif
             domain_pause_for_debugger();
             break;
         case TRAP_int3: 
@@ -2423,6 +2432,13 @@
             if ( v->domain->debugger_attached )
             {
                 update_guest_eip(); /* Safe: INT3 */            
+#if defined(XEN_KDB_CONFIG)
+                /* vmcs.IP points to bp, kdb expects bp+1. Hence after the above
+                 * update_guest_eip which updates to bp+1. works for gdbsx too 
+                 */
+                if (kdb_handle_trap_entry(vector, regs))
+                    break;
+#endif
                 current->arch.gdbsx_vcpu_event = TRAP_int3;
                 domain_pause_for_debugger();
                 break;
@@ -2707,6 +2723,10 @@
     case EXIT_REASON_MONITOR_TRAP_FLAG:
         v->arch.hvm_vmx.exec_control &= ~CPU_BASED_MONITOR_TRAP_FLAG;
         vmx_update_cpu_exec_control(v);
+#if defined(XEN_KDB_CONFIG)
+        if (kdb_handle_trap_entry(TRAP_debug, regs))
+            break;
+#endif
         if ( v->arch.hvm_vcpu.single_step ) {
           hvm_memory_event_single_step(regs->eip);
           if ( v->domain->debugger_attached )
xen/arch/x86/irq.c +26 -0
diff -r 32034d1914a6 xen/arch/x86/irq.c
@@ -2305,3 +2305,29 @@
     return is_hvm_domain(d) && pirq &&
            pirq->arch.hvm.emuirq != IRQ_UNBOUND; 
 }
+
+#ifdef XEN_KDB_CONFIG
+void kdb_prnt_guest_mapped_irqs(void)
+{
+    int irq, j;
+    char affstr[NR_CPUS/4+NR_CPUS/32+2];    /* courtesy dump_irqs() */
+
+    kdbp("irq  vec  aff  type  domid:mapped-pirq pairs  (all in decimal)\n");
+    for (irq=0; irq < nr_irqs; irq++) {
+        irq_desc_t  *dp = irq_to_desc(irq);
+        struct arch_irq_desc *archp = &dp->arch;
+        irq_guest_action_t *actp = (irq_guest_action_t *)dp->action;
+
+        if (!dp->handler ||dp->handler==&no_irq_type || !(dp->status&IRQ_GUEST))
+            continue;
+
+        cpumask_scnprintf(affstr, sizeof(affstr), dp->affinity);
+        kdbp("[%3ld] %3d %3s %-13s ", irq, archp->vector, affstr,
+             dp->handler->typename);
+        for (j=0; j < actp->nr_guests; j++)
+            kdbp("%03d:%04d ", actp->guest[j]->domain_id,
+                 domain_irq_to_pirq(actp->guest[j], irq));
+        kdbp("\n");
+    }
+}
+#endif
xen/arch/x86/setup.c +12 -0
diff -r 32034d1914a6 xen/arch/x86/setup.c
@@ -47,6 +47,13 @@
 #include <xen/cpu.h>
 #include <asm/nmi.h>
 
+#ifdef XEN_KDB_CONFIG
+#include <asm/debugger.h>
+
+int opt_earlykdb=0;
+boolean_param("earlykdb", opt_earlykdb);
+#endif
+
 /* opt_nosmp: If true, secondary processors are ignored. */
 static bool_t __initdata opt_nosmp;
 boolean_param("nosmp", opt_nosmp);
@@ -1242,6 +1249,11 @@
 
     trap_init();
 
+#ifdef XEN_KDB_CONFIG
+    kdb_init();
+    if (opt_earlykdb)
+        kdb_trap_immed(KDB_TRAP_NONFATAL);
+#endif
     rcu_init();
     
     early_time_init();
xen/arch/x86/smp.c +9 -4
diff -r 32034d1914a6 xen/arch/x86/smp.c
@@ -273,7 +273,7 @@
  * Structure and data for smp_call_function()/on_selected_cpus().
  */
 
-static void __smp_call_function_interrupt(void);
+static void __smp_call_function_interrupt(struct cpu_user_regs *regs);
 static DEFINE_SPINLOCK(call_lock);
 static struct call_data_struct {
     void (*func) (void *info);
@@ -321,7 +321,7 @@
     if ( cpumask_test_cpu(smp_processor_id(), &call_data.selected) )
     {
         local_irq_disable();
-        __smp_call_function_interrupt();
+        __smp_call_function_interrupt(NULL);
         local_irq_enable();
     }
 
@@ -390,7 +390,7 @@
     this_cpu(irq_count)++;
 }
 
-static void __smp_call_function_interrupt(void)
+static void __smp_call_function_interrupt(struct cpu_user_regs *regs)
 {
     void (*func)(void *info) = call_data.func;
     void *info = call_data.info;
@@ -411,6 +411,11 @@
     {
         mb();
         cpumask_clear_cpu(cpu, &call_data.selected);
+#ifdef XEN_KDB_CONFIG
+        if (info && !strcmp(info, "XENKDB")) {           /* called from kdb */
+                (*(void (*)(struct cpu_user_regs *, void *))func)(regs, info);
+        } else
+#endif
         (*func)(info);
     }
 
@@ -421,5 +426,5 @@
 {
     ack_APIC_irq();
     perfc_incr(ipis);
-    __smp_call_function_interrupt();
+    __smp_call_function_interrupt(regs);
 }
xen/arch/x86/time.c +40 -0
diff -r 32034d1914a6 xen/arch/x86/time.c
@@ -2007,6 +2007,46 @@
 }
 __initcall(setup_dump_softtsc);
 
+#ifdef XEN_KDB_CONFIG
+void kdb_time_resume(int update_domains)
+{
+        s_time_t now;
+        int ccpu = smp_processor_id();
+        struct cpu_time *t = &this_cpu(cpu_time);
+
+        if (!plt_src.read_counter)            /* not initialized for earlykdb */
+                return;
+
+        if (update_domains) {
+                plt_stamp = plt_src.read_counter();
+                platform_timer_stamp = plt_stamp64;
+                platform_time_calibration();
+                do_settime(get_cmos_time(), 0, read_platform_stime());
+        }
+        if (local_irq_is_enabled())
+                kdbp("kdb BUG: enabled in time_resume(). ccpu:%d\n", ccpu);
+
+        rdtscll(t->local_tsc_stamp);
+        now = read_platform_stime();
+        t->stime_master_stamp = now;
+        t->stime_local_stamp  = now;
+
+        update_vcpu_system_time(current);
+
+        if (update_domains)
+                set_timer(&calibration_timer, NOW() + EPOCH);
+}
+
+void kdb_dump_time_pcpu(void)
+{
+    int cpu;
+    for_each_online_cpu(cpu) {
+        kdbp("[%d]: cpu_time: %016lx\n", cpu, &per_cpu(cpu_time, cpu));
+        kdbp("[%d]: cpu_calibration: %016lx\n", cpu, 
+             &per_cpu(cpu_calibration, cpu));
+    }
+}
+#endif
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +5 -1
diff -r 32034d1914a6 xen/arch/x86/traps.c
@@ -225,7 +225,7 @@
 
 #else
 
-static void show_trace(struct cpu_user_regs *regs)
+void show_trace(struct cpu_user_regs *regs)
 {
     unsigned long *frame, next, addr, low, high;
 
@@ -3326,6 +3326,10 @@
     if ( nmi_callback(regs, cpu) )
         return;
 
+#ifdef XEN_KDB_CONFIG
+    if (kdb_enabled && kdb_handle_trap_entry(TRAP_nmi, regs))
+        return;
+#endif
     if ( nmi_watchdog )
         nmi_watchdog_tick(regs);
 
xen/arch/x86/x86_64/compat/entry.S +4 -0
diff -r 32034d1914a6 xen/arch/x86/x86_64/compat/entry.S
@@ -95,6 +95,10 @@
 /* %rbx: struct vcpu */
 ENTRY(compat_test_all_events)
         cli                             # tests must not race interrupts
+#ifdef XEN_KDB_CONFIG
+        testl $1, kdb_session_begun(%rip)
+        jnz   compat_restore_all_guest
+#endif
 /*compat_test_softirqs:*/
         movl  VCPU_processor(%rbx),%eax
         shlq  $IRQSTAT_shift,%rax
xen/arch/x86/x86_64/entry.S +11 -0
diff -r 32034d1914a6 xen/arch/x86/x86_64/entry.S
@@ -184,6 +184,10 @@
 /* %rbx: struct vcpu */
 test_all_events:
         cli                             # tests must not race interrupts
+#ifdef XEN_KDB_CONFIG                   /* 64bit dom0 will resume here */
+        testl $1, kdb_session_begun(%rip)
+        jnz   restore_all_guest
+#endif
 /*test_softirqs:*/  
         movl  VCPU_processor(%rbx),%eax
         shl   $IRQSTAT_shift,%rax
@@ -546,6 +550,13 @@
 
 ENTRY(int3)
         pushq $0
+#ifdef XEN_KDB_CONFIG
+        pushq %rax
+        GET_CPUINFO_FIELD(CPUINFO_processor_id, %rax)
+        movq  (%rax), %rax
+        lock  bts %rax, kdb_cpu_traps(%rip)
+        popq  %rax
+#endif
         movl  $TRAP_int3,4(%rsp)
         jmp   handle_exception
 
xen/common/domain.c +11 -1
diff -r 32034d1914a6 xen/common/domain.c
@@ -530,6 +530,14 @@
 {
     struct vcpu *v;
 
+#ifdef XEN_KDB_CONFIG
+    if (reason == SHUTDOWN_crash) {
+        if ( IS_PRIV(d) )
+            kdb_trap_immed(KDB_TRAP_FATAL);
+        else
+            kdb_trap_immed(KDB_TRAP_NONFATAL);
+    }
+#endif
     spin_lock(&d->shutdown_lock);
 
     if ( d->shutdown_code == -1 )
@@ -624,7 +632,9 @@
     for_each_vcpu ( d, v )
         vcpu_sleep_nosync(v);
 
-    send_global_virq(VIRQ_DEBUGGER);
+    /* send VIRQ_DEBUGGER to guest only if gdbsx_vcpu_event is not active */
+    if (current->arch.gdbsx_vcpu_event == 0)
+        send_global_virq(VIRQ_DEBUGGER);
 }
 
 /* Complete domain destroy after RCU readers are not holding old references. */
xen/common/sched_credit.c +31 -0
diff -r 32034d1914a6 xen/common/sched_credit.c
@@ -1475,6 +1475,33 @@
     printk("\n");
 }
 
+#ifdef XEN_KDB_CONFIG
+static void kdb_csched_dump(int cpu)
+{
+    struct csched_pcpu *pcpup = CSCHED_PCPU(cpu);
+    struct vcpu *scurrvp = (CSCHED_VCPU(current))->vcpu;
+    struct list_head *tmp, *runq = RUNQ(cpu);
+
+    kdbp("    csched_pcpu: %p\n", pcpup);
+    kdbp("    curr csched:%p {vcpu:%p id:%d domid:%d}\n", (current)->sched_priv,
+         scurrvp, scurrvp->vcpu_id, scurrvp->domain->domain_id);
+    kdbp("    runq:\n");
+
+    /* next is top of struct, so screw stupid, ugly hard to follow macros */
+    if (offsetof(struct csched_vcpu, runq_elem.next) != 0) {
+        kdbp("next is not first in struct csched_vcpu. please fixme\n");
+        return;        /* otherwise for loop will crash */
+    }
+    for (tmp = runq->next; tmp != runq; tmp = tmp->next) {
+
+        struct csched_vcpu *csp = (struct csched_vcpu *)tmp;
+        struct vcpu *vp = csp->vcpu;
+        kdbp("      csp:%p pri:%02d vcpu: {p:%p id:%d domid:%d}\n", csp,
+             csp->pri, vp, vp->vcpu_id, vp->domain->domain_id);
+    };
+}
+#endif
+
 static void
 csched_dump_pcpu(const struct scheduler *ops, int cpu)
 {
@@ -1484,6 +1511,10 @@
     int loop;
 #define cpustr keyhandler_scratch
 
+#ifdef XEN_KDB_CONFIG
+    kdb_csched_dump(cpu);
+    return;
+#endif
     spc = CSCHED_PCPU(cpu);
     runq = &spc->runq;
 
xen/common/schedule.c +19 -0
diff -r 32034d1914a6 xen/common/schedule.c
@@ -1454,6 +1454,25 @@
     schedule();
 }
 
+#ifdef XEN_KDB_CONFIG
+void kdb_print_sched_info(void)
+{
+    int cpu;
+
+    kdbp("Scheduler: name:%s opt_name:%s id:%d\n", ops.name, ops.opt_name,
+         ops.sched_id);
+    kdbp("per cpu schedule_data:\n");
+    for_each_online_cpu(cpu) {
+        struct schedule_data *p =  &per_cpu(schedule_data, cpu);
+        kdbp("  cpu:%d  &(per cpu)schedule_data:%p\n", cpu, p);
+        kdbp("         curr:%p sched_priv:%p\n", p->curr, p->sched_priv);
+        kdbp("\n");
+        ops.dump_cpu_state(&ops, cpu);
+        kdbp("\n");
+    }
+}
+#endif
+
 #ifdef CONFIG_COMPAT
 #include "compat/schedule.c"
 #endif
xen/common/symbols.c +18 -0
diff -r 32034d1914a6 xen/common/symbols.c
@@ -168,3 +168,21 @@
 
     spin_unlock_irqrestore(&lock, flags);
 }
+
+#ifdef XEN_KDB_CONFIG
+/*
+ *  * Given a symbol, return its address 
+ *   */
+unsigned long address_lookup(char *symp)
+{
+    int i, off = 0;
+    char namebuf[KSYM_NAME_LEN+1];
+
+    for (i=0; i < symbols_num_syms; i++) {
+        off = symbols_expand_symbol(off, namebuf);
+        if (strcmp(namebuf, symp) == 0)                  /* found it */
+            return symbols_address(i);
+    }
+    return 0;
+}
+#endif
xen/common/timer.c +42 -0

48 lines not on this page · raw message

xen/drivers/char/console.c +27 -0
diff -r 32034d1914a6 xen/drivers/char/console.c
@@ -295,6 +295,21 @@
 {
     static int switch_code_count = 0;
 
+#ifdef XEN_KDB_CONFIG
+    /* if ctrl-\ pressed and kdb handles it, return */
+    if (kdb_enabled && c == 0x1c) {
+        if (!kdb_session_begun) {
+            if (kdb_keyboard(regs))
+                return;
+        } else {
+            kdbp("Sorry... kdb session already active.. please try again..\n");
+            return;
+        }
+    }
+    if (kdb_session_begun)      /* kdb should already be polling */
+        return;                 /* swallow chars so they don't buffer in dom0 */
+#endif
+
     if ( switch_code && (c == switch_code) )
     {
         /* We eat CTRL-<switch_char> in groups of 3 to switch console input. */
@@ -710,6 +725,18 @@
     atomic_dec(&print_everything);
 }
 
+#ifdef XEN_KDB_CONFIG
+void console_putc(char c)
+{
+    serial_putc(sercon_handle, c);
+}
+
+int console_getc(void)
+{
+    return serial_getc(sercon_handle);
+}
+#endif
+
 /*
  * printk rate limiting, lifted from Linux.
  *
xen/include/asm-x86/debugger.h +9 -1
diff -r 32034d1914a6 xen/include/asm-x86/debugger.h
@@ -39,7 +39,11 @@
 #define DEBUGGER_trap_fatal(_v, _r) \
     if ( debugger_trap_fatal(_v, _r) ) return;
 
-#if defined(CRASH_DEBUG)
+#if defined(XEN_KDB_CONFIG)
+#define debugger_trap_immediate() kdb_trap_immed(KDB_TRAP_NONFATAL)
+#define debugger_trap_fatal(_v, _r) kdb_trap_fatal(_v, _r)
+
+#elif defined(CRASH_DEBUG)
 
 #include <xen/gdbstub.h>
 
@@ -70,6 +74,10 @@
 {
     struct vcpu *v = current;
 
+#ifdef XEN_KDB_CONFIG
+    if (kdb_handle_trap_entry(vector, regs))
+        return 1;
+#endif
     if ( guest_kernel_mode(v, regs) && v->domain->debugger_attached &&
          ((vector == TRAP_int3) || (vector == TRAP_debug)) )
     {
xen/include/xen/lib.h +3 -0
diff -r 32034d1914a6 xen/include/xen/lib.h
@@ -116,4 +116,7 @@
 struct cpu_user_regs;
 void dump_execstate(struct cpu_user_regs *);
 
+#ifdef XEN_KDB_CONFIG
+#include "../../kdb/include/kdb_extern.h"
+#endif
 #endif /* __LIB_H__ */
xen/include/xen/sched.h +4 -1
diff -r 32034d1914a6 xen/include/xen/sched.h
@@ -576,11 +576,14 @@
 unsigned long hypercall_create_continuation(
     unsigned int op, const char *format, ...);
 void hypercall_cancel_continuation(void);
-
+#ifdef XEN_KDB_CONFIG
+#define hypercall_preempt_check() (0)
+#else
 #define hypercall_preempt_check() (unlikely(    \
         softirq_pending(smp_processor_id()) |   \
         local_events_need_delivery()            \
     ))
+#endif
 
 extern struct domain *domain_list;
 
xen/kdb/Makefile new file +5 -0
diff -r 32034d1914a6 xen/kdb/Makefile
@@ -0,0 +1,5 @@
+
+obj-y		+= kdbmain.o kdb_cmds.o kdb_io.o 
+
+subdir-y += x86 guest
+
xen/kdb/README new file +243 -0

243 lines not on this page · raw message

xen/kdb/guest/Makefile new file +3 -0
diff -r 32034d1914a6 xen/kdb/guest/Makefile
@@ -0,0 +1,3 @@
+
+obj-y           := kdb_guest.o
+
xen/kdb/guest/kdb_guest.c new file +342 -0

342 lines not on this page · raw message

xen/kdb/include/kdb_extern.h new file +66 -0

66 lines not on this page · raw message

xen/kdb/include/kdbdefs.h new file +86 -0

86 lines not on this page · raw message

xen/kdb/include/kdbinc.h new file +69 -0

69 lines not on this page · raw message

xen/kdb/include/kdbproto.h new file +80 -0

80 lines not on this page · raw message

xen/kdb/kdb_cmds.c new file +3789 -0

1,249 lines not on this page · raw message

xen/kdb/kdb_io.c new file +174 -0

174 lines not on this page · raw message

xen/kdb/kdbmain.c new file +739 -0

739 lines not on this page · raw message

xen/kdb/x86/Makefile new file +3 -0
diff -r 32034d1914a6 xen/kdb/x86/Makefile

Lines of this file are not shown. View the raw message.

xen/kdb/x86/kdb_wp.c new file +310 -0

310 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/LICENSE new file +22 -0
diff -r 32034d1914a6 xen/kdb/x86/udis86-1.7/LICENSE

Lines of this file are not shown. View the raw message.

xen/kdb/x86/udis86-1.7/Makefile new file +5 -0
diff -r 32034d1914a6 xen/kdb/x86/udis86-1.7/Makefile

Lines of this file are not shown. View the raw message.

xen/kdb/x86/udis86-1.7/README new file +10 -0
diff -r 32034d1914a6 xen/kdb/x86/udis86-1.7/README

Lines of this file are not shown. View the raw message.

xen/kdb/x86/udis86-1.7/decode.c new file +1197 -0

1,197 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/decode.h new file +273 -0

273 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/extern.h new file +67 -0

67 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/input.c new file +226 -0

226 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/input.h new file +49 -0

49 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/itab.c new file +3668 -0

3,668 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/itab.h new file +719 -0

719 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/kdb_dis.c new file +204 -0

204 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/syn-att.c new file +211 -0

211 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/syn-intel.c new file +208 -0

208 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/syn.c new file +61 -0

61 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/syn.h new file +27 -0
diff -r 32034d1914a6 xen/kdb/x86/udis86-1.7/syn.h

Lines of this file are not shown. View the raw message.

xen/kdb/x86/udis86-1.7/types.h new file +186 -0

186 lines not on this page · raw message

xen/kdb/x86/udis86-1.7/udis86.c new file +156 -0

156 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Part of the diff is not shown here. View the raw message.

#2 lore raw

FYI - I applied this against the tip, and turned it on (and debug off)
- but I get link errors:

ld -melf_x86_64 -T xen.lds -N prelink.o \
/data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/common/symbols-dummy.o
-o /data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/.xen-syms.0 prelink.o: In function `kdb_cmdf_f':
/data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/kdb/kdb_cmds.c:510:
undefined reference to `show_trace' /data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/kdb/kdb_cmds.c:510:(.text+0x11f6b9):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol `show_trace'
ld: /data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/.xen-syms.0:
hidden symbol `show_trace' isn't defined
ld: final link failed: Bad value
make[5]: *** [/data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/xen-syms] Error 1
make[5]: Leaving directory `/data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/arch/x86'
make[4]: *** [/data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/xen] Error 2

Quoted 10 lines · Mukesh Rathor
Quoted 3 lines · On Wed, 29 Aug 2012 14:35:12 -0700 Mukesh Rathor <[email protected]>…

Anyways, attaching patch that is cleaned up of my debug code that I accidentally left in prev posting. Should apply cleanly to c/s 25467.

really attaching this time :).

#3 lore raw
Quoted 15 lines · On Wed, 5 Sep 2012 12:02:13 -0400 Ben Guthro <[email protected]> wrote:

FYI - I applied this against the tip, and turned it on (and debug off)
- but I get link errors:

ld -melf_x86_64 -T xen.lds -N prelink.o \
/data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/common/symbols-dummy.o
-o /data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/.xen-syms.0 prelink.o: In function `kdb_cmdf_f':
/data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/kdb/kdb_cmds.c:510:
undefined reference to `show_trace' /data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/kdb/kdb_cmds.c:510:(.text+0x11f6b9):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol `show_trace'
ld: /data/home/bguthro/dev/orc-newdev.git/orc-xen/xen-4.2/xen/.xen-syms.0:
hidden symbol `show_trace' isn't defined
ld: final link failed: Bad value

It's prob static. Just un-static it :). Missed in patch because we might have it that way here already in our tree.

LMK. thanks. Mukesh

#4 lore raw
In reply to Mukesh Rathor
Quoted 11 lines · Mukesh Rathor

Hi Guys,

Thanks for the interest in the xen hypervisor debugger, prev known as kdb. Btw. I'm gonna rename it to xdb for xen-debugger or hdb for hypervisor debugger. KDB is confusing people with linux kdb debugger and I often get emails where people think they need to apply linux kdb patch also...

Anyways, attaching patch that is cleaned up of my debug code that I accidentally left in prev posting. Should apply cleanly to c/s 25467.

Quoted 6 lines

JFYI... http://xenbits.xen.org/ext/debuggers.hg/ has gotten outdated, I wasn't sure if anyone was even looking at it. But, it looks like there is much interest, so I will just submit patch to Keir for his feedback on merging it in xen.

Please voice your opinion here. Good seeing all at the summit :).

Split off the support bits you need scattered into Xen from the main bulk of the debugger. Then we can review and apply those trickiest bits first.

-- Keir

Quoted 9 lines

Thanks,
Mukesh

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel