A different KGDB stub
PATCH 4/6 A different KGDB stub
The following is the i386-specific bits to this KGDB stub.
arch/i386/Kconfig | 2 arch/i386/kernel/Makefile | 1 arch/i386/kernel/entry.S | 39 +++ arch/i386/kernel/i386-stub.c | 442 +++++++++++++++++++++++++++++++++++++++++++ arch/i386/kernel/irq.c | 9 arch/i386/kernel/nmi.c | 14 + arch/i386/kernel/signal.c | 3 arch/i386/kernel/traps.c | 21 +- arch/i386/mm/fault.c | 15 + include/asm-i386/kgdb.h | 53 +++++ include/asm-i386/processor.h | 2 11 files changed, 588 insertions(+), 13 deletions(-)
arch/i386/Kconfig +2 -0
@@ -1253,6 +1253,8 @@ config DEBUG_SPINLOCK_SLEEP 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-y += sysenter.o vsyscall.o obj-$(CONFIG_ACPI_SRAT) += srat.o obj-$(CONFIG_HPET_TIMER) += time_hpet.o obj-$(CONFIG_EFI) += efi.o efi_stub.o +obj-$(CONFIG_KGDB) += i386-stub.o EXTRA_AFLAGS := -traditional
arch/i386/kernel/entry.S +37 -2
@@ -226,7 +226,7 @@ need_resched: jz restore_all movl $PREEMPT_ACTIVE,TI_PRE_COUNT(%ebp) sti - call schedule + call user_schedule movl $0,TI_PRE_COUNT(%ebp) cli jmp need_resched
@@ -308,7 +308,7 @@ work_pending: testb $_TIF_NEED_RESCHED, %cl jz work_notifysig work_resched: - call schedule + call user_schedule cli # make sure we don't miss an interrupt # setting need_resched or sigpending # between sampling and the iret
@@ -399,7 +399,17 @@ vector=vector+1 ALIGN common_interrupt: SAVE_ALL + movl %esp, %eax +/* Create a fake function call followed by a fake function prologue to fool + * gdb into believing that this is a normal function call. */ + pushl EIP(%eax) + +common_interrupt_1: + pushl %ebp + movl %esp, %ebp + pushl %eax call do_IRQ + addl $12, %esp jmp ret_from_intr #define BUILD_INTERRUPT(name, nr) \
@@ -606,6 +616,31 @@ ENTRY(spurious_interrupt_bug) pushl $do_spurious_interrupt_bug jmp error_code +#ifdef CONFIG_KGDB_THREAD +ENTRY(kern_schedule) + pushl %ebp + movl %esp, %ebp + pushl %ss + pushl %ebp + pushfl + pushl %cs + pushl 4(%ebp) + pushl %eax + pushl %es + pushl %ds + pushl %eax + pushl (%ebp) + pushl %edi + pushl %esi + pushl %edx + pushl %ecx + pushl %ebx + call kern_do_schedule + movl %ebp, %esp + pop %ebp + ret +#endif + .data ENTRY(sys_call_table) .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
arch/i386/kernel/i386-stub.c +442 -0
442 lines not on this page · raw message
arch/i386/kernel/irq.c +6 -3
@@ -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>
@@ -410,7 +411,7 @@ void enable_irq(unsigned int irq)* SMP cross-CPU interrupts have their own specific * handlers). */ -asmlinkage unsigned int do_IRQ(struct pt_regs regs) +asmlinkage unsigned int do_IRQ(struct pt_regs *regs) {/* * We ack quickly, we don't want the irq controller
@@ -422,7 +423,7 @@ asmlinkage unsigned int do_IRQ(struct pt* 0 return value means that this irq is already being * handled by some other CPU. (or is disabled) */ -int irq = regs.orig_eax &0xff ;/* high bits used in ret_from_ code */ +int irq = regs->orig_eax &0xff ;/* high bits used in ret_from_ code */ irq_desc_t *desc = irq_desc + irq;struct irqaction * action;unsigned int status;
@@ -488,7 +489,7 @@ asmlinkage unsigned int do_IRQ(struct ptirqreturn_t action_ret;spin_unlock (&desc->lock); - action_ret =handle_IRQ_event (irq, ®s, action); + action_ret =handle_IRQ_event (irq, regs, action);spin_lock (&desc->lock);if (!noirqdebug)note_interrupt (irq, desc, action_ret);
@@ -508,6 +509,8 @@ out:irq_exit (); +kgdb_process_breakpoint (); +return 1 ; }
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 @@ void nmi_watchdog_tick (struct pt_regs *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 @@ int do_signal(struct pt_regs *regs, sigs* 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 @@ void die(const char * str, struct pt_reg {static int die_counter; + CHK_DEBUGGER(1,SIGTRAP,err,regs,) console_verbose(); spin_lock_irq(&die_lock); bust_spinlocks(1);
@@ -330,6 +332,7 @@ static inline void do_trap(int trapnr, i#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 @@ asmlinkage void do_##name(struct pt_regs#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 @@ asmlinkage void do_debug(struct pt_regs 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 @@ asmlinkage void do_debug(struct pt_regs 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 @@ clear_dr7: __asm__("movl %0,%%db7" :/* no output */ :"r" (0 )); + CHK_DEBUGGER(1,SIGTRAP,error_code,regs,) return; debug_vm86:
arch/i386/mm/fault.c +15 -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>
@@ -262,6 +268,12 @@ asmlinkage void do_page_fault(struct pt_if (in_atomic () || !mm) goto bad_area_nosemaphore; +if (debugger_memerr_expected) { +/* This fault was caused by memory access through a debugger. +* Don't handle it like user accesses */ + goto no_context; + } +down_read (&mm->mmap_sem); vma =find_vma (mm, address);
@@ -399,6 +411,8 @@ no_context: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 +420,7 @@ no_context:bust_spinlocks (1 ); +if (address <PAGE_SIZE )printk (KERN_ALERT "Unable to handle kernel NULL pointer dereference" );else
include/asm-i386/kgdb.h +53 -0
53 lines not on this page · raw message
include/asm-i386/processor.h +2 -0
@@ -425,6 +426,8 @@ struct thread_struct {unsigned int saved_fs, saved_gs;/* IO permissions */ unsigned long *io_bitmap_ptr; +void * debuggerinfo; + };#define INIT_THREAD { \
Signature · 2 lines
Tom Rini http://gate.crashing.org/~trini/