A different KGDB stub
Subsystems (4)
PATCH 1/6 A different KGDB stub
The following is the core bits to this KGDB stub.
Makefile | 2 include/linux/bitops.h | 5 include/linux/debugger.h | 67 ++ include/linux/kgdb.h | 127 ++++ include/linux/sched.h | 13 init/main.c | 2 kernel/Kconfig.kgdb | 107 +++ kernel/Makefile | 1 kernel/kgdbstub.c | 1279 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/module.c | 10 kernel/sched.c | 22 11 files changed, 1631 insertions(+), 4 deletions(-)
Makefile +2 -0
@@ -440,6 +440,8 @@ ifndef CONFIG_FRAME_POINTER CFLAGS += -fomit-frame-pointer +else +CFLAGS += -fno-omit-frame-pointer endif ifdef CONFIG_DEBUG_INFO
include/linux/bitops.h +3 -2
@@ -108,7 +108,7 @@return (res &0x0F ) + ((res >>4 ) &0x0F ); } -static inline unsigned long generic_hweight64 (__u64 w) +static inline unsigned int generic_hweight64 (__u64 w) {#if BITS_PER_LONG <64 return generic_hweight32((unsigned int)(w >> 32)) +
@@ -120,7 +120,8 @@ res = (res &0x0F0F0F0F0F0F0F0F ) + ((res >>4 ) &0x0F0F0F0F0F0F0F0F ); res = (res &0x00FF00FF00FF00FF ) + ((res >>8 ) &0x00FF00FF00FF00FF ); res = (res &0x0000FFFF0000FFFF ) + ((res >>16 ) &0x0000FFFF0000FFFF ); -return (res &0x00000000FFFFFFFF ) + ((res >>32 ) &0x00000000FFFFFFFF ); + res = (res &0x00000000FFFFFFFF ) + ((res >>32 ) &0x00000000FFFFFFFF ); +return (unsigned int )res;#endif }
include/linux/debugger.h new file +67 -0
67 lines not on this page · raw message
include/linux/kgdb.h new file +127 -0
127 lines not on this page · raw message
include/linux/sched.h +12 -1
@@ -175,7 +175,9 @@#define MAX_SCHEDULE_TIMEOUT LONG_MAXextern signed long FASTCALL (schedule_timeout (signed long timeout)); -asmlinkage void schedule(void); +asmlinkage void do_schedule(void); +asmlinkage void kern_schedule(void); +asmlinkage void kern_do_schedule(struct pt_regs);struct namespace ;
@@ -1027,6 +1029,15 @@ }#endif /* CONFIG_SMP */ + +static inline void schedule (void ) +{ +#ifdef CONFIG_KGDB_THREAD +kern_schedule (); +#else +do_schedule (); +#endif +}#endif /* __KERNEL__ */
init/main.c +2 -0
@@ -39,6 +39,7 @@#include <linux/writeback.h> #include <linux/cpu.h> #include <linux/efi.h> +#include <linux/debugger.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -603,6 +604,7 @@smp_init ();sched_init_smp ();do_basic_setup (); +debugger_entry ();/* * check if there is an early userspace init, if yes
kernel/Kconfig.kgdb new file +107 -0
107 lines not on this page · raw message
kernel/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_COMPAT) += compat.o compat_signal.o obj-$(CONFIG_IKCONFIG) += configs.o obj-$(CONFIG_IKCONFIG_PROC) += configs.o +obj-$(CONFIG_KGDB) += kgdbstub.o ifneq ($(CONFIG_IA64),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/kgdbstub.c new file +1279 -0
1,279 lines not on this page · raw message
kernel/module.c +10 -0
@@ -744,6 +744,11 @@/* Stop the machine so refcounts can't move and disable module. */ ret =try_stop_module (mod, flags, &forced); +down (¬ify_mutex); +notifier_call_chain (&module_notify_list,MODULE_STATE_GOING , + mod); +up (¬ify_mutex); +/* Never wait if forced. */ if (!forced &&module_refcount (mod) !=0 )wait_for_zero_refcount (mod);
@@ -1775,7 +1780,12 @@if (ret <0 ) {/* Init routine failed: abort. Try to protect us from buggy refcounters. */ + mod->state =MODULE_STATE_GOING ; +down (¬ify_mutex); +notifier_call_chain (&module_notify_list,MODULE_STATE_GOING , + mod); +up (¬ify_mutex);synchronize_kernel ();if (mod->unsafe) printk(KERN_ERR "%s: module is now stuck!\n",
kernel/sched.c +21 -1
@@ -38,6 +38,7 @@#include <linux/cpu.h> #include <linux/percpu.h> #include <linux/kthread.h> +#include <linux/debugger.h> #ifdef CONFIG_NUMA #define cpu_to_node_mask (cpu) node_to_cpumask(cpu_to_node(cpu))
@@ -1904,7 +1905,7 @@/* * schedule() is the main scheduler function. */ -asmlinkage void schedule(void) +asmlinkage void do_schedule(void) {long *switch_count;task_t *prev, *next;
@@ -2076,6 +2077,23 @@EXPORT_SYMBOL (default_wake_function); +asmlinkage void user_schedule(void) +{ +#ifdef CONFIG_KGDB_THREAD + current->thread.debuggerinfo =NULL ; +#endif +do_schedule (); +} + +#ifdef CONFIG_KGDB_THREAD +asmlinkage void kern_do_schedule(struct pt_regs regs) +{ + current->thread.debuggerinfo = ®s; +do_schedule (); + current->thread.debuggerinfo =NULL ; +} +#endif +/* * The core wakeup function. Non-exclusive wakeups (nr_exclusive == 0) just * wake everything up. If it's an exclusive wakeup (nr_exclusive == small +ve
@@ -3542,6 +3560,8 @@#if defined(in_atomic)static unsigned long prev_jiffy;/* ratelimiting */ +if (atomic_read (&debugger_active)) +return ;if ((in_atomic () ||irqs_disabled ()) && system_running) {if (time_before (jiffies, prev_jiffy +HZ ) && prev_jiffy)return ;
Signature · 2 lines
Tom Rini http://gate.crashing.org/~trini/