kgdb for mainline kernel: i386-lite [patch 2/3]
-Amit
arch/i386/Kconfig +2 -0
@@ -1253,6 +1253,8 @@ If you say Y here, various routines which may sleep will become very noisy if they are called with a spinlock held. +source "kernel/Kconfig.kgdb" + config FRAME_POINTER bool "Compile the kernel with frame pointers" help
arch/i386/kernel/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_ACPI_SRAT) += srat.o obj-$(CONFIG_HPET_TIMER) += time_hpet.o obj-$(CONFIG_EFI) += efi.o efi_stub.o +obj-$(CONFIG_KGDB) += kgdb.o EXTRA_AFLAGS := -traditional
arch/i386/kernel/irq.c +3 -0
@@ -34,6 +34,7 @@#include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/kallsyms.h> +#include <linux/kgdb.h> #include <asm/atomic.h> #include <asm/io.h>
@@ -508,6 +509,8 @@irq_exit (); +kgdb_process_breakpoint (); +return 1 ; }
arch/i386/kernel/kgdb.c +373 -0
373 lines not on this page · raw message
arch/i386/kernel/nmi.c +13 -1
@@ -25,6 +25,7 @@#include <linux/module.h> #include <linux/nmi.h> #include <linux/sysdev.h> +#include <linux/debugger.h> #include <asm/smp.h> #include <asm/mtrr.h>
@@ -420,14 +421,25 @@int sum, cpu =smp_processor_id (); sum = irq_stat[cpu].apic_timer_irqs; +if (atomic_read (&debugger_active)) { -if (last_irq_sums[cpu] == sum) { +/* +* The machine is in debugger, hold this cpu if already +* not held. +*/ +debugger_nmihook (cpu, regs); + alert_counter[cpu] =0 ; + + }else if (last_irq_sums[cpu] == sum) {/* * Ayiee, looks like this CPU is stuck ... * wait a few IRQs (5 seconds) before doing the oops ... */ alert_counter[cpu]++;if (alert_counter[cpu] ==5 *nmi_hz) { + + CHK_DEBUGGER(2,SIGSEGV,0,regs,) + spin_lock(&nmi_print_lock);/* * We are in trouble anyway, lets at least try
arch/i386/kernel/signal.c +2 -1
@@ -580,7 +580,8 @@* have been cleared if the watchpoint triggered * inside the kernel. */ - __asm__("movl %0,%%db7" : :"r" (current->thread.debugreg[7 ])); +if (current->thread.debugreg[7 ]) + __asm__("movl %0,%%db7" : :"r" (current->thread.debugreg[7 ]));/* Whee! Actually deliver the signal. */ handle_signal (signr, &info, oldset, regs);
arch/i386/kernel/traps.c +15 -6
@@ -51,6 +51,7 @@#include <linux/irq.h> #include <linux/module.h> +#include <linux/debugger.h> #include "mach_traps.h"
@@ -256,6 +257,7 @@ {static int die_counter; + CHK_DEBUGGER(1,SIGTRAP,err,regs,) console_verbose(); spin_lock_irq(&die_lock); bust_spinlocks(1);
@@ -330,6 +332,7 @@#define DO_ERROR (trapnr, signr, str, name) \ asmlinkage void do_##name(struct pt_regs * regs, long error_code) \ { \ + CHK_DEBUGGER(trapnr,signr,error_code,regs,)\ do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \ }
@@ -347,7 +350,10 @@#define DO_VM86_ERROR (trapnr, signr, str, name) \ asmlinkage void do_##name(struct pt_regs * regs, long error_code) \ { \ + CHK_DEBUGGER(trapnr,signr,error_code,regs,goto skip_trap)\ do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \ +skip_trap: \ + return; \ }#define DO_VM86_ERROR_INFO (trapnr, signr, str, name, sicode, siaddr) \
@@ -547,7 +553,7 @@ tsk->thread.debugreg[6 ] = condition;/* Mask out spurious TF errors due to lazy TF clearing */ -if (condition &DR_STEP ) { +if (condition &DR_STEP && !debugger_step) {/* * The TF error should be masked out only if the current * process is not traced and if the TRAP flag has been set
@@ -570,11 +576,13 @@ info.si_errno =0 ; info.si_code =TRAP_BRKPT ; -/* If this is a kernel mode trap, save the user PC on entry to -* the kernel, that's what the debugger can make sense of. -*/ - info.si_addr = ((regs->xcs &3 ) ==0 ) ? (void *)tsk->thread.eip : - (void *)regs->eip; + +/* If this is a kernel mode trap, we need to reset db7 to allow us +* to continue sanely */ +if ((regs->xcs &3 ) ==0 ) + goto clear_dr7; + + info.si_addr = (void *)regs->eip;force_sig_info (SIGTRAP , &info, tsk);/* Disable additional traps. They'll be re-enabled when
@@ -584,6 +592,7 @@ __asm__("movl %0,%%db7" :/* no output */ :"r" (0 )); + CHK_DEBUGGER(1,SIGTRAP,error_code,regs,) return; debug_vm86:
arch/i386/mm/fault.c +9 -0
@@ -2,6 +2,11 @@* linux/arch/i386/mm/fault.c * * Copyright (C) 1995 Linus Torvalds +* +* Change History +* +* Tigran Aivazian <[email protected]> Remote debugging support. +* */ #include <linux/signal.h>
@@ -21,6 +26,7 @@#include <linux/vt_kern.h> /* For unblank_screen() */ #include <linux/highmem.h> #include <linux/module.h> +#include <linux/debugger.h> #include <asm/system.h> #include <asm/uaccess.h>
@@ -399,6 +405,8 @@if (is_prefetch (regs, address))return ; + CHK_DEBUGGER(14, SIGSEGV,error_code, regs,) +/* * Oops. The kernel tried to access some bad page. We'll have to * terminate things with extreme prejudice.
@@ -406,6 +414,7 @@bust_spinlocks (1 ); +if (address <PAGE_SIZE )printk (KERN_ALERT "Unable to handle kernel NULL pointer dereference" );else
include/asm-i386/kgdb.h +49 -0
49 lines not on this page · raw message
include/asm-i386/processor.h +2 -0
@@ -425,6 +425,8 @@unsigned int saved_fs, saved_gs;/* IO permissions */ unsigned long *io_bitmap_ptr; +void * debuggerinfo; + };#define INIT_THREAD { \