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 drivers/char/sysrq.c | 22 include/linux/debugger.h | 72 ++ include/linux/kgdb.h | 127 ++++ include/linux/sched.h | 13 init/main.c | 2 kernel/Kconfig.kgdb | 141 +++++ kernel/Makefile | 1 kernel/kgdbstub.c | 1300 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/module.c | 10 kernel/sched.c | 22 11 files changed, 1709 insertions(+), 3 deletions(-)
Makefile +2 -0
@@ -440,6 +440,8 @@ endif ifndef CONFIG_FRAME_POINTER CFLAGS += -fomit-frame-pointer +else +CFLAGS += -fno-omit-frame-pointer endif ifdef CONFIG_DEBUG_INFO
drivers/char/sysrq.c +21 -1
@@ -31,6 +31,7 @@#include <linux/suspend.h> #include <linux/writeback.h> #include <linux/buffer_head.h> /* for fsync_bdev() */ +#include <linux/kgdb.h> /* for breakpoint() */ #include <linux/spinlock.h>
@@ -44,6 +45,25 @@ int sysrq_enabled = 1;/* Machine specific power off function */ void (*sysrq_power_off)(void ); +/* Make a breakpoint() right now. */ +#ifdef CONFIG_KGDB +#define GDB_OP &kgdb_op +static void kgdb_sysrq (int key,struct pt_regs *pt_regs,struct tty_struct *tty) +{ +printk ("kgdb sysrq\n" ); +breakpoint (); +} + +static struct sysrq_key_op kgdb_op = { + .handler = kgdb_sysrq, + .help_msg ="kGdb|Fgdb" , + .action_msg ="Debug breakpoint\n" , +}; + +#else +#define GDB_OP NULL +#endif +/* Loglevel sysrq handler */ static void sysrq_handle_loglevel (int key,struct pt_regs *pt_regs,struct tty_struct *tty)
@@ -239,7 +259,7 @@ static struct sysrq_key_op *sysrq_key_ta/* d */ NULL ,/* e */ &sysrq_term_op,/* f */ NULL , -/* g */ NULL , +/* g */ GDB_OP ,/* h */ NULL ,/* i */ &sysrq_kill_op, /* j */ NULL,
include/linux/debugger.h +72 -0
72 lines not on this page · raw message
include/linux/kgdb.h +127 -0
127 lines not on this page · raw message
include/linux/sched.h +12 -1
@@ -173,7 +173,9 @@ extern unsigned long cache_decay_ticks;#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 ;
@@ -907,6 +909,15 @@ static inline void set_task_cpu(struct t#endif /* CONFIG_SMP */ +static inline void schedule (void ) +{ +#ifdef CONFIG_KGDB_THREAD +kern_schedule (); +#else +do_schedule (); +#endif +} +#endif /* __KERNEL__ */ #endif
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>
@@ -581,6 +582,7 @@ static int init(void * unused)smp_init ();do_basic_setup (); +debugger_entry ();prepare_namespace ();
kernel/Kconfig.kgdb +141 -0
141 lines not on this page · raw message
kernel/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_COMPAT) += compat.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 +1300 -0
1,300 lines not on this page · raw message
kernel/module.c +10 -0
@@ -727,6 +727,11 @@ sys_delete_module(const char __user *nam mod->state =MODULE_STATE_GOING ;restart_refcounts (); +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);
@@ -1758,7 +1763,12 @@ sys_init_module(void __user *umod,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
@@ -37,6 +37,7 @@#include <linux/rcupdate.h> #include <linux/cpu.h> #include <linux/percpu.h> +#include <linux/debugger.h> #ifdef CONFIG_NUMA #define cpu_to_node_mask (cpu) node_to_cpumask(cpu_to_node(cpu))
@@ -1591,7 +1592,7 @@ void scheduling_functions_start_here(voi/* * schedule() is the main scheduler function. */ -asmlinkage void schedule(void) +asmlinkage void do_schedule(void) {long *switch_count;task_t *prev, *next;
@@ -1763,6 +1764,23 @@ int default_wake_function(wait_queue_t *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
@@ -2961,6 +2979,8 @@ void __might_sleep(char *file, int line)#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/
Quoted 2 lines · Tom Rini
The following is the core bits to this KGDB stub.
This still contains the kern_do_schedule() gunk. Andi raised this issue last week. He identified several other significant issues as well, but there was no followup. Could you please dig out his email and address the points which he raised? (I can't find the email - perhaps Andi could re-review this patch?)
Quoted 9 lines · Andrew Morton
Quoted 2 lines · Tom Rini
The following is the core bits to this KGDB stub.
This still contains the
kern_do_schedule()gunk. Andi raised this issue last week. He identified several other significant issues as well, but there was no followup. Could you please dig out his email and address the points which he raised? (I can't find the email - perhaps Andi could re-review this patch?)
By my read of Andi's email, the kern_do_schedule() gunk is "I really don't like this change. It is completely useless because you can get the pt_regs as well from the stack. Please don't add it. George's stub also didn't need it."
But I don't see how it does. But I'll look again tomorrow.
The next issue was about adding debuggerinfo to thread_struct. By my read of the code, it's because of the thread handling bits that Amit's version does that George's does not. So I'm not sure how it's not needed (unless all of the relevant code goes. If that's too heavy, I can remove all of that).
Next was that KGDB should use the notify_die hooks that are there, and I've done that.
Finally, the save_context_frame stuff can go (x86_64-specific stuffs) but as I don't have x86_64 hw (I'll try and whip up a toolchain tomorrow, but I leave for FOSDEM Thursday) so I didn't touch that, in hopes that someone who could test it would.
Signature · 2 lines
Tom Rini http://gate.crashing.org/~trini/
Quoted 7 lines · Tom Rini
By my read of Andi's email, the
kern_do_schedule()gunk is "I really don't like this change. It is completely useless because you can get thept_regsas well from the stack. Please don't add it. George's stub also didn't need it."But I don't see how it does. But I'll look again tomorrow.
OK, thanks. That would be appreciated, if only because the sched.c and entry.S changes have caused significant patch-conflict hassles in the past, and they're pretty ugly.
Plus the little fact that the patch which you sent broke all other
architectures: they call schedule() from assembly code, and schedule() ain't there any more.
I'll have a play with the patches which you sent, and if they don't break I'll add them to -mm and I'll kludgily fix ppc64 and ia64 (if needed). Be aware that I removed the (large amount of) trailing whitespace which they added.
Quoted 9 lines · Andrew Morton
Quoted 7 lines · Tom Rini
By my read of Andi's email, the
kern_do_schedule()gunk is "I really don't like this change. It is completely useless because you can get thept_regsas well from the stack. Please don't add it. George's stub also didn't need it."But I don't see how it does. But I'll look again tomorrow.
Quoted 7 lines
OK, thanks. That would be appreciated, if only because the
sched.candentry.Schanges have caused significant patch-conflict hassles in the past, and they're pretty ugly.Plus the little fact that the patch which you sent broke all other
architectures: they callschedule()from assembly code, andschedule()ain't there any more.
Oh yeah, that, damnit.
Quoted 4 lines
I'll have a play with the patches which you sent, and if they don't break I'll add them to -mm and I'll kludgily fix ppc64 and ia64 (if needed). Be aware that I removed the (large amount of) trailing whitespace which they added.
I guess I forgot to Lindent everything. I'll probably have new drop-in patches a few more times (as opposed to incremental to the previous) a few more times, so I'll make sure to fix that for next time.
Signature · 2 lines
Tom Rini http://gate.crashing.org/~trini/
Quoted 7 lines · Andrew Morton
Quoted 6 lines · Tom Rini
By my read of Andi's email, the
kern_do_schedule()gunk is "I really don't like this change. It is completely useless because you can get thept_regsas well from the stack. Please don't add it. George's stub also didn't need it."
Quoted 5 lines
Quoted 1 line
But I don't see how it does. But I'll look again tomorrow.
OK, thanks. That would be appreciated, if only because the
sched.candentry.Schanges have caused significant patch-conflict hassles in the past, and they're pretty ugly.
Two things:
- I've looked harder, and I still don't see some pre-exiting get pt_regs off the stack func / macro. But it would probably be generally useful since it _looks_ like there's few places it could be used. Or maybe I misread something and just missed it (not being an i386 person, it's possible :))
- The current plan for KGDB stuffs is to punt on the thread stuffs for now anyhow, so we can look at this again later.
Signature · 2 lines
Tom Rini http://gate.crashing.org/~trini/
Hi!
Quoted 1 line
The following is the core bits to this KGDB stub.
What are those weak functions good for? Can't we simply assume that any architecture that allows CONFIG_KGDB provides neccessary functions?
Pavel
PS: Also.. how to proceed? Should I split your patches into "normal" and "lite" parts and submit to Amit?
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]
Quoted 7 lines · Pavel Machek
Hi!
Quoted 1 line
The following is the core bits to this KGDB stub.
What are those weak functions good for? Can't we simply assume that any architecture that allows
CONFIG_KGDBprovides neccessary functions?
Not all arches need all functions, and that's where the weak functions come in. We could remove some of them (the *gdb*regs* type ones) as being absolutely required, but not everyone needs kgdb_arch_init. Similarly for kgdb_flush_io.
Quoted 2 lines
PS: Also.. how to proceed? Should I split your patches into "normal" and "lite" parts and submit to Amit?
Tomorrow I leave for FOSDEM, and won't have time to pick on KGDB until I get back Tuesday. What I'm going to do then, if no one beats me to it, is to merge stuff I've got into Amit's patches (the CVS versions off of sourceforge), except for netpoll-specific portions of the kgdboe patch.
Signature · 2 lines
Tom Rini http://gate.crashing.org/~trini/