From: Andrew Morton Signed-off-by: Andrew Morton --- i386/lib/kgdb_serial.c | 0 arch/i386/kernel/kgdb_stub.c | 21 ++++++++++++++++++++- arch/i386/kernel/nmi.c | 2 +- arch/i386/kernel/traps.c | 32 ++++++++++++++------------------ arch/i386/mm/fault.c | 5 ++--- drivers/char/keyboard.c | 6 +++--- drivers/serial/8250.c | 10 ++-------- drivers/serial/serial_core.c | 11 +++-------- include/asm-i386/bugs.h | 15 +-------------- include/asm-i386/kgdb.h | 32 ++++---------------------------- include/linux/config.h | 3 --- include/linux/kgdb.h | 22 ++++++++++++++++++++++ kernel/pid.c | 4 +--- kernel/sched.c | 2 -- 14 files changed, 73 insertions(+), 92 deletions(-) diff -puN arch/i386/kernel/kgdb_stub.c~kgdb-cleanup-includes arch/i386/kernel/kgdb_stub.c --- devel/arch/i386/kernel/kgdb_stub.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/arch/i386/kernel/kgdb_stub.c 2006-02-27 20:59:11.000000000 -0800 @@ -39,7 +39,7 @@ * * Changes to allow auto initilization. All that is needed is that it * be linked with the kernel and a break point (int 3) be executed. - * The header file defines BREAKPOINT to allow one to do + * The header file defines BREAKPOINT to allow one to do * this. It should also be possible, once the interrupt system is up, to * call putDebugChar("+"). Once this is done, the remote debugger should * get our attention by sending a ^C in a packet. George Anzinger @@ -132,6 +132,11 @@ typedef void (*Function) (void); /* poin /* Thread reference */ typedef unsigned char threadref[8]; +int kgdb_enabled; +int kgdb_irq = -1; +EXPORT_SYMBOL(kgdb_irq); +int kgdb_pid_init_done; + extern void putDebugChar(int); /* write a single character */ extern int getDebugChar(void); /* read and return a single char */ @@ -1866,3 +1871,17 @@ __setup("console=", kgdb_console_init); typedef void gdb_debug_hook(int exceptionVector, int signo, int err_code, struct pt_regs *linux_regs); gdb_debug_hook *linux_debug_hook = &kgdb_handle_exception; + +/* + * Provide the command line "gdb" initial break + */ +int __init kgdb_initial_break(char * str) +{ + kgdb_enabled = 1; + if (*str == '\0'){ + breakpoint(); + return 1; + } + return 0; +} +__setup("gdb",kgdb_initial_break); diff -puN arch/i386/kernel/nmi.c~kgdb-cleanup-includes arch/i386/kernel/nmi.c --- devel/arch/i386/kernel/nmi.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/arch/i386/kernel/nmi.c 2006-02-27 20:59:11.000000000 -0800 @@ -25,11 +25,11 @@ #include #include #include +#include #include #include #include -#include #include "mach_traps.h" diff -puN arch/i386/kernel/traps.c~kgdb-cleanup-includes arch/i386/kernel/traps.c --- devel/arch/i386/kernel/traps.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/arch/i386/kernel/traps.c 2006-02-27 20:59:11.000000000 -0800 @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef CONFIG_EISA #include @@ -57,6 +58,7 @@ #include "mach_traps.h" asmlinkage int system_call(void); +extern void sysenter_past_esp(void); struct desc_struct default_ldt[] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; @@ -107,11 +109,9 @@ int unregister_die_notifier(struct notif } EXPORT_SYMBOL(unregister_die_notifier); -#ifdef CONFIG_KGDB -extern void sysenter_past_esp(void); -#include -#include void set_intr_gate(unsigned int n, void *addr); + +#ifdef CONFIG_KGDB static void set_intr_usr_gate(unsigned int n, void *addr); /* * Should be able to call this breakpoint() very early in @@ -422,14 +422,14 @@ void die(const char * str, struct pt_reg if (nl) printk("\n"); sysfs_printk_last_file(); -#ifdef CONFIG_KGDB - /* This is about the only place we want to go to kgdb even if in - * user mode. But we must go in via a trap so within kgdb we will - * always be in kernel mode. - */ + + /* + * This is about the only place we want to go to kgdb even if in + * user mode. But we must go in via a trap so within kgdb we + * will always be in kernel mode. + */ if (user_mode(regs)) BREAKPOINT; -#endif check_remote_debug(0,SIGTRAP,err,regs,) if (notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV) != @@ -853,32 +853,28 @@ fastcall void __kprobes do_debug(struct * check for kernel mode by just checking the CPL * of CS. */ -#ifdef CONFIG_KGDB /* * I think this is the only "real" case of a TF in the kernel * that really belongs to user space. Others are * "Ours all ours!" */ - if (!user_mode(regs) && (void *)regs->eip == sysenter_past_esp) + if (kgdb_enabled && !user_mode(regs) && + (void *)regs->eip == sysenter_past_esp) goto clear_TF_reenable; -#else if (!user_mode(regs)) goto clear_TF_reenable; -#endif } -#ifdef CONFIG_KGDB /* * If this is a kernel mode trap, we need to reset db7 to allow us * to continue sanely ALSO skip the signal delivery */ - if (!user_mode(regs)) + if (kgdb_enabled && !user_mode(regs)) goto clear_dr7; /* if not kernel, allow ints but only if they were on */ - if (regs->eflags & 0x200) + if (kgdb_enabled && regs->eflags & 0x200) local_irq_enable(); -#endif /* Ok, finally something we can handle */ send_sigtrap(tsk, regs, error_code); diff -puN arch/i386/mm/fault.c~kgdb-cleanup-includes arch/i386/mm/fault.c --- devel/arch/i386/mm/fault.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/arch/i386/mm/fault.c 2006-02-27 20:59:11.000000000 -0800 @@ -17,6 +17,7 @@ #include #include #include +#include #include #include /* For unblank_screen() */ #include @@ -506,12 +507,10 @@ no_context: * Oops. The kernel tried to access some bad page. We'll have to * terminate things with extreme prejudice. */ -#ifdef CONFIG_KGDB - if (!user_mode(regs)) { + if (kgdb_enabled && !user_mode(regs)) { kgdb_handle_exception(14, SIGBUS, error_code, regs); return; } -#endif bust_spinlocks(1); diff -puN drivers/char/keyboard.c~kgdb-cleanup-includes drivers/char/keyboard.c --- devel/drivers/char/keyboard.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/drivers/char/keyboard.c 2006-02-27 20:59:11.000000000 -0800 @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -1071,9 +1072,8 @@ static void kbd_keycode(unsigned int key } if (sysrq_down && down && !rep) { handle_sysrq(kbd_sysrq_xlate[keycode], regs, tty); -#ifdef CONFIG_KGDB_SYSRQ - sysrq_down = 0; /* in case we miss the "up" event */ -#endif + if (kgdb_enabled) + sysrq_down = 0; /* in case we miss the "up" event */ return; } #endif diff -puN drivers/serial/8250.c~kgdb-cleanup-includes drivers/serial/8250.c --- devel/drivers/serial/8250.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/drivers/serial/8250.c 2006-02-27 20:59:11.000000000 -0800 @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -1495,11 +1496,6 @@ static void serial8250_break_ctl(struct spin_unlock_irqrestore(&up->port.lock, flags); } -#ifdef CONFIG_KGDB -int kgdb_irq = -1; -EXPORT_SYMBOL(kgdb_irq); -#endif - static int serial8250_startup(struct uart_port *port) { struct uart_8250_port *up = (struct uart_8250_port *)port; @@ -1507,10 +1503,8 @@ static int serial8250_startup(struct uar unsigned char lsr, iir; int retval; -#ifdef CONFIG_KGDB - if (up->port.irq == kgdb_irq) + if (kgdb_enabled && up->port.irq == kgdb_irq) return -EBUSY; -#endif up->capabilities = uart_config[up->port.type].flags; up->mcr = 0; diff -puN drivers/serial/serial_core.c~kgdb-cleanup-includes drivers/serial/serial_core.c --- devel/drivers/serial/serial_core.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/drivers/serial/serial_core.c 2006-02-27 20:59:11.000000000 -0800 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -2019,14 +2020,8 @@ uart_configure_port(struct uart_driver * { unsigned int flags; -#ifdef CONFIG_KGDB - { - extern int kgdb_irq; - - if (port->irq == kgdb_irq) - return; - } -#endif + if (kgdb_enabled && port->irq == kgdb_irq) + return; /* * If there isn't a port here, don't do anything further. diff -puN include/asm-i386/bugs.h~kgdb-cleanup-includes include/asm-i386/bugs.h --- devel/include/asm-i386/bugs.h~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/include/asm-i386/bugs.h 2006-02-27 20:59:11.000000000 -0800 @@ -22,20 +22,7 @@ #include #include #include -#ifdef CONFIG_KGDB -/* - * Provied the command line "gdb" initial break - */ -int __init kgdb_initial_break(char * str) -{ - if (*str == '\0'){ - breakpoint(); - return 1; - } - return 0; -} -__setup("gdb",kgdb_initial_break); -#endif + static int __init no_halt(char *s) { boot_cpu_data.hlt_works_ok = 0; diff -puN include/asm-i386/kgdb.h~kgdb-cleanup-includes include/asm-i386/kgdb.h --- devel/include/asm-i386/kgdb.h~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/include/asm-i386/kgdb.h 2006-02-27 20:59:11.000000000 -0800 @@ -3,23 +3,10 @@ struct pt_regs; -/* - * This file should not include ANY others. This makes it usable - * most anywhere without the fear of include order or inclusion. - * Make it so! - * - * This file may be included all the time. It is only active if - * CONFIG_KGDB is defined, otherwise it stubs out all the macros - * and entry points. - */ -#if defined(CONFIG_KGDB) && !defined(__ASSEMBLY__) - extern void breakpoint(void); -#define INIT_KGDB_INTS kgdb_enable_ints() -#ifndef BREAKPOINT #define BREAKPOINT asm(" int $3") -#endif + /* * GDB debug stub (or any debug stub) can point the 'linux_debug_hook' * pointer to its routine and it will be entered as the first thing @@ -35,18 +22,7 @@ extern void breakpoint(void); extern void kgdb_handle_exception(int trapno, int signo, int err_code, struct pt_regs *regs); extern int in_kgdb(struct pt_regs *regs); - -#else /* CONFIG_KGDB && ! __ASSEMBLY__ ,stubs follow... */ -#ifndef BREAKPOINT -#define BREAKPOINT -#endif -#define kgdb_ts(data0,data1) -static inline int in_kgdb(struct pt_regs *regs) { return 0; } -static inline void kgdb_handle_exception(int trapno, int signo, - int err_code, struct pt_regs *regs) -{ -} -#define breakpoint -#define INIT_KGDB_INTS -#endif +extern int kgdb_enabled; +extern int kgdb_irq; +extern int kgdb_pid_init_done; #endif /* __KGDB */ diff -puN include/linux/config.h~kgdb-cleanup-includes include/linux/config.h --- devel/include/linux/config.h~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/include/linux/config.h 2006-02-27 20:59:11.000000000 -0800 @@ -4,8 +4,5 @@ * autoconf.h is now included via -imacros on the commandline */ #include -#if defined(__i386__) && !defined(IN_BOOTLOADER) -#include -#endif #endif diff -puN /dev/null include/linux/kgdb.h --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ devel-akpm/include/linux/kgdb.h 2006-02-27 20:59:11.000000000 -0800 @@ -0,0 +1,22 @@ +#ifndef KGDB_H_INCLUDED +#define KGDB_H_INCLUDED + +#if defined(CONFIG_X86_32) && defined (CONFIG_KGDB) && !defined(__ASSEMBLY__) +#include +#else + +#define kgdb_enabled 0 +#define kgdb_irq 0 +#define BREAKPOINT do {} while (0) +#define kgdb_ts(data0,data1) +static inline int in_kgdb(struct pt_regs *regs) { return 0; } +static inline void kgdb_handle_exception(int trapno, int signo, + int err_code, struct pt_regs *regs) +{ +} +#define breakpoint +#endif + +extern struct task_struct *kgdb_get_idle(int cpu); + +#endif /* KGDB_H_INCLUDED */ diff -puN kernel/pid.c~kgdb-cleanup-includes kernel/pid.c --- devel/kernel/pid.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/kernel/pid.c 2006-02-27 20:59:11.000000000 -0800 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -234,9 +235,6 @@ EXPORT_SYMBOL(find_task_by_pid_type); * machine. From a minimum of 16 slots up to 4096 slots at one gigabyte or * more. */ -#ifdef CONFIG_KGDB -int kgdb_pid_init_done; /* so we don't call prior to... */ -#endif void __init pidhash_init(void) { int i, j, pidhash_size; diff -puN kernel/sched.c~kgdb-cleanup-includes kernel/sched.c --- devel/kernel/sched.c~kgdb-cleanup-includes 2006-02-27 20:59:11.000000000 -0800 +++ devel-akpm/kernel/sched.c 2006-02-27 20:59:11.000000000 -0800 @@ -3653,12 +3653,10 @@ int can_nice(const task_t *p, const int capable(CAP_SYS_NICE)); } -#ifdef CONFIG_KGDB struct task_struct *kgdb_get_idle(int this_cpu) { return cpu_rq(this_cpu)->idle; } -#endif #ifdef __ARCH_WANT_SYS_NICE diff -puN arch/i386/lib/kgdb_serial.c~kgdb-cleanup-includes arch/i386/lib/kgdb_serial.c _