Skip to contentSkip to conversation

RFC ONLY - kdb for kgdb

PATCH In review Jason Wessel 6 participants 22 messages May 8, 2009 – May 19, 2009

Subsystems (20)
lore
Share & tools
lore

Jason Wessel

author maintainer
#0 lore raw

cover RFC ONLY - kdb for kgdb

This patch series is a request for comments on several levels.

1) Do people find kdb useful? (See * and **)
2) Would kdb folks be willing to use it if it was a front end to kgdb?
3) Does kdb have a future in the mainline kernel?
4) Is this a reasonable approach to have some level of unification to end up with a more robust kernel debugger?

* This is not meant to be a religious war

** This will never replace printk :-)

What follows is a series of patches to the development kernel which enable kdb as a front end to kgdb for arm, mips, powerpc, and x86. This is a very raw prototype, but enough of it it works such that folks can try it out.

To get the most basic functionality, you only need the first 2 patches in the series. The remainder of the patches go on to incrementally add back some of the functionality that was removed from kdb. I made an attempt to try to make the first part just the generic set of changes required to get kdb working on 1 or more archs.

The kdb front end works a little differently than if you were to take the original kdb patch set from:

ftp://oss.sgi.com/projects/kdb/download/v4.4/

In the kernel .config you should enable the following options:

CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_KGDB_LOW_LEVEL_TRAP=y
CONFIG_KGDB_KDB=y
CONFIG_KGDB_KDB_PRIMARY=y
CONFIG_KDB_KEYBOARD=y
CONFIG_KDB_USB=y

If you were using the serial port with kdb before, now you just use the kgdboc mechanism with no differences at all. IE use you kernel command line with:

console=ttyS0,115200 kgdboc=ttyS0 kgdbwait

That will get you access to kdb just after the console has been registered. If you want to use the keyboard, you could use:

console=tty0 kgdboc=kdb kgdbwait

You can also use the keyboard and or serial console:

console=ttyS0,115200 console=tty0 kgdboc=kdb,ttyS0

In terms of breaking into the debugger after the system is up, you must use the sysrq-g sequence. That means you could run:
echo g > /proc/sysrq-trigger

Or you can use the SysRq key on your key board. On a typical laptop you might have to do the following:

press and hold ALT -- You will be holding this the whole time
press and hold FN
press and release the key with the SysRq label
release FN
press and release g
release ALT

I have also found on some PS/2 keyboards you have press alt again after resuming the system because the key up event got lost somewhere.

Once you are in kdb you can run help to see a limited list of commands.

You can also still connect gdb or re-enter kdb without leaving the exception state. To get out of kgdb mode you can type "$3#33", or to get into kgdb mode from kdb, you can type "kgdb". Also from gdb you can issue commands to the kdb front end, via gdb's montior command. For instance you could issue "monitor lsmod". Allowing the gdb monitor extension was certainly another motivation behind the prototype.

Quoted 1 line

From here it is a matter of deciding if it is worth continuing down

this route.

The evaulation of this project will definitely cause some further cleanup and improvement to kgdb, regardless of if this effort is carried forward. Two of the patches in this series are patches likely to get integrated into kgdb's code base and do not bear the "RFC ONLY" indication.

Thanks,
Jason.

You can find the development branch for this here:

http://git.kernel.org/?p=linux/kernel/git/jwessel/linux-2.6-kgdb.git;a=shortlog;h=kdb_prototype

or grab a static version of the patches here:

http://kernel.org/pub/linux/kernel/people/jwessel/branches/kdb_prototype.tar.bz2

short log info follows:

Jason Wessel (13):
RFC ONLY - kdb: core for kgdb backend
RFC ONLY - kgdb: core changes to support kdb
RFC ONLY - kgdb,8250,pl011: Return immediately from console poll RFC ONLY - kgdb: gdb "monitor" -> kdb passthrough
RFC ONLY - kgdboc,keyboard: Keyboard driver for kdb with kgdb
kgdb: remove post_primary_code references
RFC ONLY - x86,kgdb: Add low level debug hook
RFC ONLY - arm,kgdb: Add hook to catch an oops with debugger RFC ONLY - powerpc,kgdb: Introduce low level trap catching RFC ONLY - mips,kgdb: kdb low level trap catch and stack trace
kgdb: Add the ability to schedule a breakpoint via a tasklet RFC ONLY - kgdb,kdb: use async breakpoint for sysrq for usb RFC ONLY - usb,keyboard: uchi, echi, and ochi polling keyboard urbs

 Makefile                              |    1 +
 arch/arm/include/asm/kgdb.h           |    2 +
 arch/arm/include/asm/kmap_types.h     |    1 +
 arch/arm/kernel/kgdb.c                |   13 +
 arch/arm/kernel/traps.c               |    5 +
 arch/mips/include/asm/kgdb.h          |    2 +
 arch/mips/include/asm/kmap_types.h    |    3 +-
 arch/mips/kernel/kgdb.c               |   27 +-
 arch/mips/kernel/traps.c              |   14 +
 arch/powerpc/include/asm/kmap_types.h |    1 +
 arch/powerpc/kernel/kgdb.c            |   12 +-
 arch/powerpc/kernel/traps.c           |    7 +
 arch/x86/include/asm/kgdb.h           |    3 +
 arch/x86/include/asm/kmap_types.h     |    3 +-
 arch/x86/kernel/kgdb.c                |   56 +-
 arch/x86/kernel/traps.c               |    6 +
 drivers/char/Makefile                 |    1 +
 drivers/char/kdb_keyboard.c           |  407 ++++
 drivers/char/kdb_keyboard.h           |  143 ++
 drivers/hid/usbhid/hid-core.c         |   26 +
 drivers/hid/usbhid/usbkbd.c           |   13 +
 drivers/serial/8250.c                 |    4 +-
 drivers/serial/amba-pl011.c           |    6 +-
 drivers/serial/kgdboc.c               |   80 +-
 drivers/usb/core/hcd.c                |   14 +
 drivers/usb/core/hcd.h                |    4 +
 drivers/usb/host/ehci-hcd.c           |   42 +
 drivers/usb/host/ehci-pci.c           |    6 +
 drivers/usb/host/ehci-q.c             |  225 ++
 drivers/usb/host/ohci-hcd.c           |   66 +
 drivers/usb/host/ohci-pci.c           |    6 +-
 drivers/usb/host/ohci-q.c             |   63 +
 drivers/usb/host/uhci-hcd.c           |   36 +
 drivers/usb/host/uhci-q.c             |   51 +
 fs/proc/meminfo.c                     |  145 ++
 fs/proc/mmu.c                         |   16 +-
 include/linux/kdb.h                   |  172 ++
 include/linux/kdbprivate.h            |  611 ++++++
 include/linux/keyboard.h              |    2 +
 include/linux/kgdb.h                  |   25 +-
 include/linux/serial_core.h           |    1 +
 init/main.c                           |   26 +
 kdb/.gitignore                        |    1 +
 kdb/Makefile                          |   48 +
 kdb/kdb_bp.c                          |  863 ++++++++
 kdb/kdb_bt.c                          |  209 ++
 kdb/kdb_cmds                          |   32 +
 kdb/kdb_io.c                          |  895 ++++++++
 kdb/kdbmain.c                         | 3669 +++++++++++++++++++++++++++++++++
 kdb/kdbsupport.c                      | 1120 ++++++++++
 kernel/kallsyms.c                     |   22 +
 kernel/kgdb.c                         |  321 +++-
 kernel/module.c                       |   19 +-
 kernel/panic.c                        |    6 +
 kernel/printk.c                       |   14 +
 kernel/sched.c                        |   93 +-
 kernel/signal.c                       |   49 +
 lib/Kconfig.kgdb                      |   37 +
 mm/hugetlb.c                          |   22 +
 mm/swapfile.c                         |   22 +
 60 files changed, 9697 insertions(+), 92 deletions(-)
 create mode 100644 drivers/char/kdb_keyboard.c
 create mode 100644 drivers/char/kdb_keyboard.h
 create mode 100644 include/linux/kdb.h
 create mode 100644 include/linux/kdbprivate.h
 create mode 100644 kdb/.gitignore
 create mode 100644 kdb/Makefile
 create mode 100644 kdb/kdb_bp.c
 create mode 100644 kdb/kdb_bt.c
 create mode 100644 kdb/kdb_cmds
 create mode 100644 kdb/kdb_io.c
 create mode 100644 kdb/kdbmain.c
 create mode 100644 kdb/kdbsupport.c
author maintainer
#1 lore raw

PATCH 1/13 RFC ONLY - kdb: core for kgdb back end

This is an RFC patch. This work is by no means in its final form, nor is it in a form that would be suitible for upstream merging. This is an early prototype of a kdb frontend talking to a kgdb backend. It is meant to foster some discussion around the usefulness of merging kdb and kgdb together, as well as experiment with changes to kgdb's core to improve robustness and functionality.

This patch contains the kdb core and some instrumentation into the core kernel which kdb requires in order to gather information for some of its reporting functions.

This work is directly derived from kdb v4.4 found at:

ftp://oss.sgi.com/projects/kdb/download/v4.4/

This particular patch is not even close to sanitized with sparse, or checkpatch.pl. This is more or less a very raw port of the original kdb which attempts to break down kdb into a architecture independent front end to attach to kgdb.

The original starting point for the 2.6.29 kernel was:
"129 files changed, 57952 insertions(+), 10 deletions(-)"

You can imagine some stuff got severly chopped in order to get it down to ~8000 lines worth changes. Things like the x86 disasembler, kdump/kexec analysis, x86 specific backtracer, usb support, and even the scrolling pager got tossed overboard.

There is a lot of clean up that can happen with in the kdb internals as a result of the integration as well as to improve modularity. It seems that it would be nice to have a modular front end for kgdb which you can add additional commands for other post mortem activities. Part of the motivation behind adding another front end to kgdb is to make the built in kernel debugger better and join the user base of kdb and kgdb vs further fragmentation.

With all the disclaimers out of the way, it can be noted that this is a working prototype for 4 architechtures, and it is reasonably easy to add more.

---
 Makefile                              |    1 +
 arch/arm/include/asm/kmap_types.h     |    1 +
 arch/mips/include/asm/kmap_types.h    |    3 +-
 arch/powerpc/include/asm/kmap_types.h |    1 +
 arch/x86/include/asm/kmap_types.h     |    3 +-
 fs/proc/meminfo.c                     |  145 ++
 fs/proc/mmu.c                         |   16 +-
 include/linux/kdb.h                   |  171 ++
 include/linux/kdbprivate.h            |  610 ++++++
 init/main.c                           |   26 +
 kdb/.gitignore                        |    1 +
 kdb/Makefile                          |   48 +
 kdb/kdb_bp.c                          |  863 ++++++++
 kdb/kdb_bt.c                          |  209 ++
 kdb/kdb_cmds                          |   32 +
 kdb/kdb_io.c                          |  890 ++++++++
 kdb/kdbmain.c                         | 3666 +++++++++++++++++++++++++++++++++
 kdb/kdbsupport.c                      | 1120 ++++++++++
 kernel/kallsyms.c                     |   22 +
 kernel/module.c                       |   19 +-
 kernel/panic.c                        |    6 +
 kernel/printk.c                       |   14 +
 kernel/sched.c                        |   93 +-
 kernel/signal.c                       |   49 +
 mm/hugetlb.c                          |   22 +
 mm/swapfile.c                         |   22 +
 26 files changed, 8045 insertions(+), 8 deletions(-)
 create mode 100644 include/linux/kdb.h
 create mode 100644 include/linux/kdbprivate.h
 create mode 100644 kdb/.gitignore
 create mode 100644 kdb/Makefile
 create mode 100644 kdb/kdb_bp.c
 create mode 100644 kdb/kdb_bt.c
 create mode 100644 kdb/kdb_cmds
 create mode 100644 kdb/kdb_io.c
 create mode 100644 kdb/kdbmain.c
 create mode 100644 kdb/kdbsupport.c
Makefile +1 -0
index b18afad..b2c349a 100644
@@ -647,6 +647,7 @@ export mod_strip_cmd
 
 ifeq ($(KBUILD_EXTMOD),)
 core-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/ block/
+core-$(CONFIG_KGDB_KDB) += kdb/
 
 vmlinux-dirs	:= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
 		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
arch/arm/include/asm/kmap_types.h +1 -0
index d16ec97..93cc780 100644
@@ -19,6 +19,7 @@ enum km_type {
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
 	KM_L2_CACHE,
+	KM_KDB,
 	KM_TYPE_NR
 };
 
arch/mips/include/asm/kmap_types.h +2 -1
index 806aae3..ec3f7a7 100644
@@ -22,7 +22,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)	KM_KDB,
+D(14)	KM_TYPE_NR
 };
 
 #undef D
arch/powerpc/include/asm/kmap_types.h +1 -0
index b6bac6f..96ae0f2 100644
@@ -26,6 +26,7 @@ enum km_type {
 	KM_SOFTIRQ1,
 	KM_PPC_SYNC_PAGE,
 	KM_PPC_SYNC_ICACHE,
+	KM_KDB,
 	KM_TYPE_NR
 };
 
arch/x86/include/asm/kmap_types.h +2 -1
index 5759c16..9e7a73f 100644
@@ -21,7 +21,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)	KM_KDB,
+D(14)	KM_TYPE_NR
 };
 
 #undef D
fs/proc/meminfo.c +145 -0

151 lines not on this page · raw message

fs/proc/mmu.c +14 -2
index 8ae221d..7fdb075 100644
@@ -14,11 +14,21 @@
 #include <asm/pgtable.h>
 #include "internal.h"
 
+#ifdef	CONFIG_KGDB_KDB
+#include <linux/kdb.h>
+#endif
+
 void get_vmalloc_info(struct vmalloc_info *vmi)
 {
 	struct vm_struct *vma;
 	unsigned long free_area_size;
 	unsigned long prev_end;
+#ifdef CONFIG_KGDB_KDB
+	int get_lock = !KDB_IS_RUNNING();
+#else
+#define	get_lock 1
+#endif
+
 
 	vmi->used = 0;
 
@@ -30,7 +40,8 @@ void get_vmalloc_info(struct vmalloc_info *vmi)
 
 		prev_end = VMALLOC_START;
 
-		read_lock(&vmlist_lock);
+		if (get_lock)
+			read_lock(&vmlist_lock);
 
 		for (vma = vmlist; vma; vma = vma->next) {
 			unsigned long addr = (unsigned long) vma->addr;
@@ -55,6 +66,7 @@ void get_vmalloc_info(struct vmalloc_info *vmi)
 		if (VMALLOC_END - prev_end > vmi->largest_chunk)
 			vmi->largest_chunk = VMALLOC_END - prev_end;
 
-		read_unlock(&vmlist_lock);
+		if (get_lock)
+			read_unlock(&vmlist_lock);
 	}
 }
include/linux/kdb.h new file +171 -0

171 lines not on this page · raw message

include/linux/kdbprivate.h new file +610 -0

610 lines not on this page · raw message

init/main.c +26 -0
index 3bbf93b..5b16c8b 100644
@@ -62,6 +62,7 @@
 #include <linux/sched.h>
 #include <linux/signal.h>
 #include <linux/idr.h>
+#include <linux/kdb.h>
 #include <linux/ftrace.h>
 #include <linux/async.h>
 #include <trace/boot.h>
@@ -190,6 +191,26 @@ static const char *panic_later, *panic_param;
 
 extern struct obs_kernel_param __setup_start[], __setup_end[];
 
+#ifdef	CONFIG_KGDB_KDB
+static int __init kdb_setup(char *str)
+{
+	if (strcmp(str, "on") == 0) {
+		kdb_on = 1;
+	} else if (strcmp(str, "on-nokey") == 0) {
+		kdb_on = 2;
+	} else if (strcmp(str, "off") == 0) {
+		kdb_on = 0;
+	} else if (strcmp(str, "early") == 0) {
+		kdb_on = 1;
+		kdb_flags |= KDB_FLAG_EARLYKDB;
+	} else
+		printk(KERN_ERR "kdb flag %s not recognised\n", str);
+	return 0;
+}
+
+__setup("kdb=", kdb_setup);
+#endif	/* CONFIG_KGDB_KDB */
+
 static int __init obsolete_checksetup(char *line)
 {
 	struct obs_kernel_param *p;
@@ -666,6 +687,11 @@ asmlinkage void __init start_kernel(void)
 	pgtable_cache_init();
 	prio_tree_init();
 	anon_vma_init();
+
+#ifdef	CONFIG_KGDB_KDB
+	kdb_init();
+#endif	/* CONFIG_KGDB_KDB */
+
 #ifdef CONFIG_X86
 	if (efi_enabled)
 		efi_enter_virtual_mode();
kdb/.gitignore new file +1 -0
new file mode 100644
index 0000000..396d12e
@@ -0,0 +1 @@
+gen-kdb_cmds.c
kdb/Makefile new file +48 -0

48 lines not on this page · raw message

kdb/kdb_bp.c new file +863 -0

863 lines not on this page · raw message

kdb/kdb_bt.c new file +209 -0

209 lines not on this page · raw message

kdb/kdb_cmds new file +32 -0
new file mode 100644
index 0000000..343955c
@@ -0,0 +1,32 @@
+# Initial commands for kdb, alter to suit your needs.
+# These commands are executed in kdb_init() context, no SMP, no
+# processes.  Commands that require process data (including stack or
+# registers) are not reliable this early.  set and bp commands should
+# be safe.  Global breakpoint commands affect each cpu as it is booted.
+
+# Standard debugging information for first level support, just type archkdb
+# or archkdbcpu or archkdbshort at the kdb prompt.
+
+defcmd archkdb "" "First line arch debugging"
+  set BTSYMARG 1
+  set BTARGS 9
+  pid R
+  -archkdbcommon
+  -bta
+endefcmd
+
+defcmd archkdbcpu "" "archkdb with only tasks on cpus"
+  set BTSYMARG 1
+  set BTARGS 9
+  pid R
+  -archkdbcommon
+  -btc
+endefcmd
+
+defcmd archkdbshort "" "archkdb with less detailed backtrace"
+  set BTSYMARG 0
+  set BTARGS 0
+  pid R
+  -archkdbcommon
+  -bta
+endefcmd
kdb/kdb_io.c new file +890 -0

794 lines not on this page · raw message

kdb/kdbmain.c new file +3666 -0

3,666 lines not on this page · raw message

kdb/kdbsupport.c new file +1120 -0

1,120 lines not on this page · raw message

kernel/kallsyms.c +22 -0
index 374faf9..be88346 100644

Lines of this file are not shown. View the raw message.

kernel/module.c +16 -3
index e797812..0523b4c 100644

Lines of this file are not shown. View the raw message.

kernel/panic.c +6 -0
index 874ecf1..fdb7e5b 100644

Lines of this file are not shown. View the raw message.

kernel/printk.c +14 -0
index 5052b54..2c3e8ea 100644

Lines of this file are not shown. View the raw message.

kernel/sched.c +92 -1

93 lines not on this page · raw message

kernel/signal.c +49 -0

49 lines not on this page · raw message

mm/hugetlb.c +22 -0
index 28c655b..5e65f6a 100644

Lines of this file are not shown. View the raw message.

mm/swapfile.c +22 -0
index 312fafe..7e3a336 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.6.3.rc0.1.gf800

Part of the diff is not shown here. View the raw message.

author maintainer
#2 lore raw

PATCH 2/13 RFC ONLY - kgdb: core changes to support kdb

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

These are the minimum changes to the kgdb core in order to enable an API to add on a different kgdb front end instead of the gdb stub driver.

This patch introduces the comm_passthrough which is simply an alternate frontend that gets to talk to the kgdb I/O drivers instead of the gdb stub.

You can switch back and forth between kdb or the gdb stub mode of operation dynamically. From gdb stub mode you can blindly type "$3#33", or from the kdb mode you can enter "kgdb" to switch to the gdb stub.

The logic in the kgdb core depends on the kdb mode to to look for the typical gdb connection sequences and return with KGDB_PASS_EVENT. That should allow a reasonably seemless transition without leaving the kernel exception state. The two gdb queries are the "?" and "qSupported" query.

---
 arch/arm/kernel/kgdb.c     |    5 +
 arch/mips/kernel/kgdb.c    |    5 +
 arch/powerpc/kernel/kgdb.c |    5 +
 arch/x86/kernel/kgdb.c     |    5 +
 include/linux/kgdb.h       |    3 +
 kernel/kgdb.c              |  202 ++++++++++++++++++++++++++++++++++++++++++--
 lib/Kconfig.kgdb           |   14 +++
 7 files changed, 233 insertions(+), 6 deletions(-)
arch/arm/kernel/kgdb.c +5 -0
index ba8ccfe..bb17e9b 100644
@@ -97,6 +97,11 @@ sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
 	gdb_regs[_CPSR]		= thread_regs->ARM_cpsr;
 }
 
+void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
+{
+	regs->ARM_pc = pc;
+}
+
 static int compiled_break;
 
 int kgdb_arch_handle_exception(int exception_vector, int signo,
arch/mips/kernel/kgdb.c +5 -0
index 6e152c8..54f2d40 100644
@@ -179,6 +179,11 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
 	*(ptr++) = regs->cp0_epc;
 }
 
+void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
+{
+	regs->cp0_epc = pc;
+}
+
 /*
  * Calls linux_debug_hook before the kernel dies. If KGDB is enabled,
  * then try to fall into the debugger
arch/powerpc/kernel/kgdb.c +5 -0
index fe8f71d..e8207a3 100644
@@ -315,6 +315,11 @@ void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
 	       (unsigned long)(((void *)gdb_regs) + NUMREGBYTES));
 }
 
+void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
+{
+	regs->nip = pc;
+}
+
 /*
  * This function does PowerPC specific procesing for interfacing to gdb.
  */
arch/x86/kernel/kgdb.c +5 -0
index eedfaeb..6d2503d 100644
@@ -572,6 +572,11 @@ unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
 	return instruction_pointer(regs);
 }
 
+void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
+{
+	regs->ip = ip;
+}
+
 struct kgdb_arch arch_kgdb_ops = {
 	/* Breakpoint instruction: */
 	.gdb_bpt_instr		= { 0xcc },
include/linux/kgdb.h +3 -0
index 6adcc29..3e838d6 100644
@@ -263,6 +263,7 @@ extern struct kgdb_arch		arch_kgdb_ops;
 
 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
 
+extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
 extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
 extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
 
@@ -271,6 +272,8 @@ extern int kgdb_mem2hex(char *mem, char *buf, int count);
 extern int kgdb_hex2mem(char *buf, char *mem, int count);
 
 extern int kgdb_isremovedbreak(unsigned long addr);
+extern int kgdb_remove_sw_break(unsigned long addr);
+extern int kgdb_set_sw_break(unsigned long addr);
 
 extern int
 kgdb_handle_exception(int ex_vector, int signo, int err_code,
kernel/kgdb.c +196 -6

258 lines not on this page · raw message

lib/Kconfig.kgdb +14 -0
index 9b5d1d7..59b47b9 100644
@@ -57,4 +57,18 @@ config KGDB_TESTS_BOOT_STRING
 	  information about other strings you could use beyond the
 	  default of V1F100.
 
+config KGDB_KDB
+	bool "KGDB_KDB: include kdb frontend for kgdb"
+	default n
+	help
+	  KDB frontend for kernel
+
+config KGDB_KDB_PRIMARY
+	bool "KGDB_KDB: Make kdb the default debugger"
+	depends on KGDB_KDB
+	default y
+	help
+	  KDB will be the active debugger instead of the typical kgdb
+	  frontend.
+
 endif # KGDB
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#3 lore raw

PATCH 3/13 RFC ONLY - kgdb,8250,pl011: Return immediately from console poll

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

The design of kdb required that every device that can provide input to kdb have a polling routine that exits immediately if there is no character available.

This is required in order to get the page scrolling mechanism working, it is also a reasonable requirement for future kgdb I/O drivers because that allows for the possibility of multiple input channels.

NO_POLL_CHAR will be the return code to the polling routine when ever there is no character available. There are several other console polling drivers which can be modified, but for the prototype only the 8250 and pl011 driver have been changed to make use of this.

---
 drivers/serial/8250.c       |    4 +-
 drivers/serial/amba-pl011.c |    6 ++--
 include/linux/kgdb.h        |    3 ++
 include/linux/serial_core.h |    1 +
 kernel/kgdb.c               |   47 +++++++++++++++++++++++++++++++++++++-----
 5 files changed, 50 insertions(+), 11 deletions(-)
drivers/serial/8250.c +2 -2
index b4b3981..03f815b 100644
@@ -1884,8 +1884,8 @@ static int serial8250_get_poll_char(struct uart_port *port)
 	struct uart_8250_port *up = (struct uart_8250_port *)port;
 	unsigned char lsr = serial_inp(up, UART_LSR);
 
-	while (!(lsr & UART_LSR_DR))
-		lsr = serial_inp(up, UART_LSR);
+	if (!(lsr & UART_LSR_DR))
+		return NO_POLL_CHAR;
 
 	return serial_inp(up, UART_RX);
 }
drivers/serial/amba-pl011.c +3 -3
index 8b2b970..fb2ed6a 100644
@@ -318,9 +318,9 @@ static int pl010_get_poll_char(struct uart_port *port)
 	struct uart_amba_port *uap = (struct uart_amba_port *)port;
 	unsigned int status;
 
-	do {
-		status = readw(uap->port.membase + UART01x_FR);
-	} while (status & UART01x_FR_RXFE);
+	status = readw(uap->port.membase + UART01x_FR);
+	if (status & UART01x_FR_RXFE)
+		return NO_POLL_CHAR;
 
 	return readw(uap->port.membase + UART01x_DR);
 }
include/linux/kgdb.h +3 -0
index 3e838d6..967803d 100644
@@ -283,4 +283,7 @@ extern int kgdb_nmicallback(int cpu, void *regs);
 extern int			kgdb_single_step;
 extern atomic_t			kgdb_active;
 
+#ifdef CONFIG_KGDB_SERIAL_CONSOLE
+extern void __init early_kgdboc_init(void);
+#endif /* CONFIG_KGDB_SERIAL_CONSOLE */
 #endif /* _KGDB_H_ */
include/linux/serial_core.h +1 -0
index 57a97e5..6fda5b8 100644
@@ -232,6 +232,7 @@ struct uart_ops {
 #endif
 };
 
+#define NO_POLL_CHAR		0x00ff0000
 #define UART_CONFIG_TYPE	(1 << 0)
 #define UART_CONFIG_IRQ		(1 << 1)
 
kernel/kgdb.c +41 -6

116 lines not on this page · raw message

Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#4 lore raw

PATCH 4/13 RFC ONLY - kgdb: gdb "monitor" -> kdb passthrough

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

One of the driving forces behind integrating another front end to kgdb is to allow front end commands to be accessible via gdb's monitor command. It is true that you could write gdb macros to get certain data, but you may want to just use gdb to access the commands that are available in the kdb front end.

This patch implements the Rcmd gdb stub packet. In gdb you access this with the "monitor" command. For instance you could type "monitor help", "monitor lsmod" or "monitor ps A" etc...

There is no error checking or command restrictions on what you can and cannot access at this point. Doing something like trying to set breakpoints with the monitor command is going to cause nothing but problems. Perhaps in the future only the commands that are actually known to work with the gdb monitor command will be available.

---
 include/linux/kgdb.h |    3 ++-
 kdb/kdb_io.c         |   13 +++++++++----
 kernel/kgdb.c        |   28 +++++++++++++++++++++++++---
 3 files changed, 36 insertions(+), 8 deletions(-)
include/linux/kgdb.h +2 -1
index 967803d..0299b79 100644
@@ -279,7 +279,8 @@ extern int
 kgdb_handle_exception(int ex_vector, int signo, int err_code,
 		      struct pt_regs *regs);
 extern int kgdb_nmicallback(int cpu, void *regs);
-
+extern int kgdb_use_passthrough;
+extern void kgdb_msg_write(const char *s, int len);
 extern int			kgdb_single_step;
 extern atomic_t			kgdb_active;
 
kdb/kdb_io.c +9 -4
index e7c3b40..d00f05c 100644
@@ -24,6 +24,7 @@
 #include <linux/kdb.h>
 #include <linux/kdbprivate.h>
 #include <linux/kallsyms.h>
+#include <linux/kgdb.h>
 
 static struct console *kdbcons;
 
@@ -698,10 +699,14 @@ kdb_printit:
 	else
 #endif
 
-	while (c) {
-		c->write(c, kdb_buffer, strlen(kdb_buffer));
-		touch_nmi_watchdog();
-		c = c->next;
+	if (!kgdb_use_passthrough && kgdb_connected) {
+		kgdb_msg_write(kdb_buffer, strlen(kdb_buffer));
+	} else {
+		while (c) {
+			c->write(c, kdb_buffer, strlen(kdb_buffer));
+			touch_nmi_watchdog();
+			c = c->next;
+		}
 	}
 	if (logging) {
 		saved_loglevel = console_loglevel;
kernel/kgdb.c +25 -3
index 2f093bc..484f106 100644
@@ -100,9 +100,9 @@ static int kgdb_use_con;
 
 /* Controls for using the kgdb passthrough */
 #ifdef CONFIG_KGDB_KDB_PRIMARY
-static int kgdb_use_passthrough = 1;
+int kgdb_use_passthrough = 1;
 #else /* ! CONFIG_KGDB_KDB_PRIMARY */
-static int kgdb_use_passthrough;
+int kgdb_use_passthrough;
 #endif /* CONFIG_KGDB_KDB_PRIMARY */
 #define KGDB_PASS_EVENT -12345
 
@@ -963,12 +963,15 @@ static inline int shadow_pid(int realpid)
 
 static char gdbmsgbuf[BUFMAX + 1];
 
-static void kgdb_msg_write(const char *s, int len)
+void kgdb_msg_write(const char *s, int len)
 {
 	char *bufptr;
 	int wcount;
 	int i;
 
+	if (len == 0)
+		len = strlen(s);
+
 	/* 'O'utput */
 	gdbmsgbuf[0] = 'O';
 
@@ -1270,6 +1273,25 @@ static void gdb_cmd_query(struct kgdb_state *ks)
 			kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr));
 		}
 		break;
+#ifdef CONFIG_KGDB_KDB
+	case 'R':
+		if (strncmp(remcom_in_buffer, "qRcmd,", 6) == 0) {
+			int len = strlen(remcom_in_buffer + 6);
+
+			if ((len % 2) != 0) {
+				strcpy(remcom_out_buffer, "E01");
+				break;
+			}
+			kgdb_hex2mem(remcom_in_buffer + 6,
+				     remcom_out_buffer, len);
+			len = len / 2;
+			remcom_out_buffer[len++] = 0;
+
+			kdb_parse(remcom_out_buffer);
+			strcpy(remcom_out_buffer, "OK");
+		}
+		break;
+#endif
 	}
 }
 
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#5 lore raw

PATCH 5/13 RFC ONLY - kgdboc,keyboard: Keyboard driver for kdb with kgdb

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

This patch adds in the kdb PS/2 keyboard driver. This was mostly a direct port from the original kdb where I cleaned up the code against checkpatch.pl and added the glue to stitch it into kgdb.

This patch also enables early kdb debug via kgdbwait and the keyboard.

All the access to configure kdb using either a serial console or the keyboard is done via kgdboc.

If you want to use only the keyboard and want to break in early you would add to your kernel command arguments:

kgdboc=kbd kgdbwait

If you wanted serial and or the keyboard access you could use:

kgdboc=kbd,ttyS0

You can also configure kgdboc as a kernel module or at runtime with the sysfs where you can activate and deactivate kgdb.

Turn it on:
echo kbd,ttyS0 > /sys/module/kgdboc/parameters/kgdboc

Turn it off:
echo "" > /sys/module/kgdboc/parameters/kgdboc

---
 drivers/char/Makefile       |    1 +
 drivers/char/kdb_keyboard.c |  208 +++++++++++++++++++++++++++++++++++++++++++
 drivers/char/kdb_keyboard.h |  143 +++++++++++++++++++++++++++++
 drivers/serial/kgdboc.c     |   68 +++++++++++++--
 include/linux/keyboard.h    |    2 +
 kdb/kdbmain.c               |    3 +
 lib/Kconfig.kgdb            |    7 ++
 7 files changed, 425 insertions(+), 7 deletions(-)
 create mode 100644 drivers/char/kdb_keyboard.c
 create mode 100644 drivers/char/kdb_keyboard.h
drivers/char/Makefile +1 -0
index 9caf5b5..5ae13d2 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEGACY_PTYS)	+= pty.o
 obj-$(CONFIG_UNIX98_PTYS)	+= pty.o
 obj-y				+= misc.o
 obj-$(CONFIG_VT)		+= vt_ioctl.o vc_screen.o selection.o keyboard.o
+obj-$(CONFIG_KDB_KEYBOARD)	+= kdb_keyboard.o
 obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
 obj-$(CONFIG_HW_CONSOLE)	+= vt.o defkeymap.o
 obj-$(CONFIG_AUDIT)		+= tty_audit.o
drivers/char/kdb_keyboard.c new file +208 -0

208 lines not on this page · raw message

drivers/char/kdb_keyboard.h new file +143 -0

143 lines not on this page · raw message

drivers/serial/kgdboc.c +61 -7

123 lines not on this page · raw message

include/linux/keyboard.h +2 -0
index a3c984d..74e0753 100644
@@ -28,6 +28,8 @@ extern const int NR_TYPES;
 extern const int max_vals[];
 extern unsigned short *key_maps[MAX_NR_KEYMAPS];
 extern unsigned short plain_map[NR_KEYS];
+extern unsigned short shift_map[NR_KEYS];
+extern unsigned short ctrl_map[NR_KEYS];
 
 struct keyboard_notifier_param {
 	struct vc_data *vc;	/* VC on which the keyboard press was done */
kdb/kdbmain.c +3 -0
index b445a17..a995269 100644
@@ -3643,6 +3643,9 @@ kdb_init(void)
 
 	kdb_initial_cpu = -1;
 	//	kdb_wait_for_cpus_secs = max(10, 2*num_online_cpus());
+#if defined(CONFIG_KDB_KEYBOARD) && defined(CONFIG_KGDB_SERIAL_CONSOLE)
+ 	early_kgdboc_init();
+#endif /* CONFIG_KDB_KEYBOARD && CONFIG_KGDB_SERIAL_CONSOLE */
 }
 // HACK have to sort through these later, some probably are not needed
 EXPORT_SYMBOL_GPL(kdb_register);
lib/Kconfig.kgdb +7 -0
index 59b47b9..772e14b 100644
@@ -71,4 +71,11 @@ config KGDB_KDB_PRIMARY
 	  KDB will be the active debugger instead of the typical kgdb
 	  frontend.
 
+config KDB_KEYBOARD
+	bool "KGDB_KDB: keyboard as input device"
+	depends on VT && KGDB_KDB
+	default y
+	help
+	  KDB can use a PS/2 type keyboard for an input device
+
 endif # KGDB
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#6 lore raw

PATCH 6/13 kgdb: remove post_primary_code references

Remove all the references to the kgdb_post_primary_code. This function serves no useful purpose because you can obtain the same information from the "struct kgdb_state *ks" from with in the debugger, if for some reason you want the data.

Also remove the unintentional duplicate assignment for ks->ex_vector.

---
 arch/x86/kernel/kgdb.c |   29 -----------------------------
 include/linux/kgdb.h   |   14 --------------
 kernel/kgdb.c          |    8 --------
 3 files changed, 0 insertions(+), 51 deletions(-)
arch/x86/kernel/kgdb.c +0 -29
index 6d2503d..a61a138 100644
@@ -45,20 +45,8 @@
 
 #include <asm/apicdef.h>
 #include <asm/system.h>
-
 #include <asm/apic.h>
 
-/*
- * Put the error code here just in case the user cares:
- */
-static int gdb_x86errcode;
-
-/*
- * Likewise, the vector number here (since GDB only gets the signal
- * number through the usual means, and that's not very specific):
- */
-static int gdb_x86vector = -1;
-
 /**
  *	pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
  *	@gdb_regs: A pointer to hold the registers in the order GDB wants.
@@ -311,23 +299,6 @@ void kgdb_disable_hw_debug(struct pt_regs *regs)
 	set_debugreg(0UL, 7);
 }
 
-/**
- *	kgdb_post_primary_code - Save error vector/code numbers.
- *	@regs: Original pt_regs.
- *	@e_vector: Original error vector.
- *	@err_code: Original error code.
- *
- *	This is needed on architectures which support SMP and KGDB.
- *	This function is called after all the slave cpus have been put
- *	to a know spin state and the primary CPU has control over KGDB.
- */
-void kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)
-{
-	/* primary processor is completely in the debugger */
-	gdb_x86vector = e_vector;
-	gdb_x86errcode = err_code;
-}
-
 #ifdef CONFIG_SMP
 /**
  *	kgdb_roundup_cpus - Get other CPUs into a holding pattern
include/linux/kgdb.h +0 -14
index 0299b79..8ecf20f 100644
@@ -35,20 +35,6 @@ struct pt_regs;
 extern int kgdb_skipexception(int exception, struct pt_regs *regs);
 
 /**
- *	kgdb_post_primary_code - (optional) Save error vector/code numbers.
- *	@regs: Original pt_regs.
- *	@e_vector: Original error vector.
- *	@err_code: Original error code.
- *
- *	This is usually needed on architectures which support SMP and
- *	KGDB.  This function is called after all the secondary cpus have
- *	been put to a know spin state and the primary CPU has control over
- *	KGDB.
- */
-extern void kgdb_post_primary_code(struct pt_regs *regs, int e_vector,
-				  int err_code);
-
-/**
  *	kgdb_disable_hw_debug - (optional) Disable hardware debugging hook
  *	@regs: Current &struct pt_regs.
  *
kernel/kgdb.c +0 -8
index 484f106..6d31c0c 100644
@@ -233,12 +233,6 @@ int __weak kgdb_skipexception(int exception, struct pt_regs *regs)
 	return 0;
 }
 
-void __weak
-kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)
-{
-	return;
-}
-
 /**
  *	kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
  *	@regs: Current &struct pt_regs.
@@ -1632,7 +1626,6 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
 	ks->cpu			= raw_smp_processor_id();
 	ks->ex_vector		= evector;
 	ks->signo		= signo;
-	ks->ex_vector		= evector;
 	ks->err_code		= ecode;
 	ks->kgdb_usethreadid	= 0;
 	ks->linux_regs		= regs;
@@ -1724,7 +1717,6 @@ acquirelock:
 	 * At this point the primary processor is completely
 	 * in the debugger and all secondary CPUs are quiescent
 	 */
-	kgdb_post_primary_code(ks->linux_regs, ks->ex_vector, ks->err_code);
 	kgdb_deactivate_sw_breakpoints();
 	kgdb_single_step = 0;
 	kgdb_contthread = current;
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#7 lore raw

PATCH 7/13 RFC ONLY - x86,kgdb: Add low level debug hook

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

The only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a triple fault is to have a low level "first opportunity handler" in the int3 exception handler.

Generally this will be something the vast majority of folks will not need, but for those who need it, it is added as a kernel .config option called KGDB_LOW_LEVEL_TRAP.

Since this is an RFC, the question would be how to implement this as an "alternative? The idea is that you want the calls to be always be NOP's unless a kgdb I/O driver has been loaded.

---
 arch/x86/include/asm/kgdb.h |    3 +++
 arch/x86/kernel/kgdb.c      |   22 +++++++++++++++++++++-
 arch/x86/kernel/traps.c     |    6 ++++++
 include/linux/kgdb.h        |    1 +
 kernel/kgdb.c               |    2 +-
 lib/Kconfig.kgdb            |    9 +++++++++
 6 files changed, 41 insertions(+), 2 deletions(-)
arch/x86/include/asm/kgdb.h +3 -0
index e6c6c80..006da36 100644
@@ -76,4 +76,7 @@ static inline void arch_kgdb_breakpoint(void)
 #define BREAK_INSTR_SIZE	1
 #define CACHE_FLUSH_IS_SAFE	1
 
+extern int kgdb_ll_trap(int cmd, const char *str,
+			struct pt_regs *regs, long err, int trap, int sig);
+
 #endif /* _ASM_X86_KGDB_H */
arch/x86/kernel/kgdb.c +21 -1
index a61a138..8c652f7 100644
@@ -462,7 +462,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
 			return NOTIFY_DONE;
 	}
 
-	if (kgdb_handle_exception(args->trapnr, args->signr, args->err, regs))
+	if (kgdb_handle_exception(args->trapnr, args->signr, cmd, regs))
 		return NOTIFY_DONE;
 
 	/* Must touch watchdog before return to normal operation */
@@ -470,6 +470,26 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
 	return NOTIFY_STOP;
 }
 
+#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
+int kgdb_ll_trap(int cmd, const char *str,
+		 struct pt_regs *regs, long err, int trap, int sig)
+{
+	struct die_args args = {
+		.regs	= regs,
+		.str	= str,
+		.err	= err,
+		.trapnr	= trap,
+		.signr	= sig,
+
+	};
+
+	if (!kgdb_io_module_registered)
+		return NOTIFY_DONE;
+
+	return __kgdb_notify(&args, cmd);
+}
+#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
+
 static int
 kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
 {
arch/x86/kernel/traps.c +6 -0
index a1d2883..5525c23 100644
@@ -16,6 +16,7 @@
 #include <linux/uaccess.h>
 #include <linux/utsname.h>
 #include <linux/kdebug.h>
+#include <linux/kgdb.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/ptrace.h>
@@ -460,6 +461,11 @@ void restart_nmi(void)
 /* May run on IST stack. */
 dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
 {
+#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
+	if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
+			== NOTIFY_STOP)
+		return;
+#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
 #ifdef CONFIG_KPROBES
 	if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
 			== NOTIFY_STOP)
include/linux/kgdb.h +1 -0
index 8ecf20f..166cd07 100644
@@ -59,6 +59,7 @@ struct uart_port;
 void kgdb_breakpoint(void);
 
 extern int kgdb_connected;
+extern int kgdb_io_module_registered;
 
 extern atomic_t			kgdb_setting_breakpoint;
 extern atomic_t			kgdb_cpu_doing_single_step;
kernel/kgdb.c +1 -1
index 6d31c0c..da738a2 100644
@@ -85,7 +85,7 @@ int				kgdb_connected;
 EXPORT_SYMBOL_GPL(kgdb_connected);
 
 /* All the KGDB handlers are installed */
-static int			kgdb_io_module_registered;
+int			kgdb_io_module_registered;
 
 /* Guard for recursive entry */
 static int			exception_level;
lib/Kconfig.kgdb +9 -0
index 772e14b..617f797 100644
@@ -57,6 +57,15 @@ config KGDB_TESTS_BOOT_STRING
 	  information about other strings you could use beyond the
 	  default of V1F100.
 
+config KGDB_LOW_LEVEL_TRAP
+       bool "KGDB: Allow debugging with traps in notifiers"
+       depends on X86
+       default n
+       help
+         This will add an extra call back to kgdb for the breakpoint
+         exception handler on which will will allow kgdb to step
+         through a notify handler.
+
 config KGDB_KDB
 	bool "KGDB_KDB: include kdb frontend for kgdb"
 	default n
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#8 lore raw

PATCH 8/13 RFC ONLY - arm,kgdb: Add hook to catch an oops with debugger

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

Add in a low level hook to catch calls to die() in the debugger.

After the debugger is done, the standard system rules will be in play for the original exception.

The kdb debugger wanted a chance to catch these sorts of exceptions for analysis.

---
 arch/arm/include/asm/kgdb.h |    2 ++
 arch/arm/kernel/kgdb.c      |    8 ++++++++
 arch/arm/kernel/traps.c     |    5 +++++
 3 files changed, 15 insertions(+), 0 deletions(-)
arch/arm/include/asm/kgdb.h +2 -0
index 67af4b8..5a2e60e 100644
@@ -95,6 +95,8 @@ extern int kgdb_fault_expected;
 #define _PC			15
 #define _CPSR			(GDB_MAX_REGS - 1)
 
+int kgdb_die_hook(int cmd, const char *str, struct pt_regs *regs, int err);
+
 /*
  * So that we can denote the end of a frame for tracing,
  * in the simple case:
arch/arm/kernel/kgdb.c +8 -0
index bb17e9b..3c0e5e5 100644
@@ -10,6 +10,7 @@
  *           Deepak Saxena <[email protected]>
  */
 #include <linux/kgdb.h>
+#include <linux/notifier.h>
 #include <asm/traps.h>
 
 /* Make a local copy of the registers passed into the handler (bletch) */
@@ -189,6 +190,13 @@ void kgdb_arch_exit(void)
 	unregister_undef_hook(&kgdb_compiled_brkpt_hook);
 }
 
+int kgdb_die_hook(int cmd, const char *str, struct pt_regs *regs, int err)
+{
+	if (kgdb_handle_exception(1, err, cmd, regs))
+		return NOTIFY_DONE;
+	return NOTIFY_STOP;
+}
+
 /*
  * Register our undef instruction hooks with ARM undef core.
  * We regsiter a hook specifically looking for the KGB break inst
arch/arm/kernel/traps.c +5 -0
index 57eb0f6..e649019 100644
@@ -21,6 +21,9 @@
 #include <linux/hardirq.h>
 #include <linux/init.h>
 #include <linux/uaccess.h>
+#include <linux/kgdb.h>
+#include <linux/kdebug.h>
+#include <linux/notifier.h>
 
 #include <asm/atomic.h>
 #include <asm/cacheflush.h>
@@ -248,6 +251,8 @@ NORET_TYPE void die(const char *str, struct pt_regs *regs, int err)
 {
 	struct thread_info *thread = current_thread_info();
 
+	kgdb_die_hook(DIE_OOPS, str, regs, err);
+
 	oops_enter();
 
 	console_verbose();
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#9 lore raw

PATCH 9/13 RFC ONLY - powerpc,kgdb: Introduce low level trap catching

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

The only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a recursive fault is to have a low level "first opportunity handler" low level program_check_exception() handler.

The other change here is to make sure that kgdb_handle_exception() is called with correct parameters when catching an oops, because kdb needs to know if the entry was an oops, single step, or breakpoint exception.

---
 arch/powerpc/kernel/kgdb.c  |    7 +++++--
 arch/powerpc/kernel/traps.c |    7 +++++++
 lib/Kconfig.kgdb            |    2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)
arch/powerpc/kernel/kgdb.c +5 -2
index e8207a3..d0ef25c 100644
@@ -20,6 +20,7 @@
 #include <linux/smp.h>
 #include <linux/signal.h>
 #include <linux/ptrace.h>
+#include <linux/kdebug.h>
 #include <asm/current.h>
 #include <asm/processor.h>
 #include <asm/machdep.h>
@@ -115,7 +116,9 @@ void kgdb_roundup_cpus(unsigned long flags)
 /* KGDB functions to use existing PowerPC64 hooks. */
 static int kgdb_debugger(struct pt_regs *regs)
 {
-	return kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
+	if (kgdb_handle_exception(1, computeSignal(TRAP(regs)), DIE_OOPS, regs))
+		return 0;
+	return 1;
 }
 
 static int kgdb_handle_breakpoint(struct pt_regs *regs)
@@ -123,7 +126,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)
 	if (user_mode(regs))
 		return 0;
 
-	if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
+	if (kgdb_handle_exception(1, SIGTRAP, 0, regs) != 0)
 		return 0;
 
 	if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
arch/powerpc/kernel/traps.c +7 -0
index 678fbff..ae409df 100644
@@ -812,12 +812,19 @@ void __kprobes program_check_exception(struct pt_regs *regs)
 		return;
 	}
 	if (reason & REASON_TRAP) {
+
+#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
+		if (debugger_bpt(regs))
+			return;
+#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
 		/* trap exception */
 		if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
 				== NOTIFY_STOP)
 			return;
+#ifndef CONFIG_KGDB_LOW_LEVEL_TRAP
 		if (debugger_bpt(regs))
 			return;
+#endif /* ! CONFIG_KGDB_LOW_LEVEL_TRAP */
 
 		if (!(regs->msr & MSR_PR) &&  /* not user-mode */
 		    report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
lib/Kconfig.kgdb +1 -1
index 617f797..a2f63be 100644
@@ -59,7 +59,7 @@ config KGDB_TESTS_BOOT_STRING
 
 config KGDB_LOW_LEVEL_TRAP
        bool "KGDB: Allow debugging with traps in notifiers"
-       depends on X86
+       depends on X86 || PPC
        default n
        help
          This will add an extra call back to kgdb for the breakpoint
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#10 lore raw

PATCH 10/13 RFC ONLY - mips,kgdb: kdb low level trap catch and stack trace

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

The only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a recursive fault is to have a low level "first opportunity handler" do_trap_or_bp() handler.

Generally this will be something the vast majority of folks will not need, but for those who need it, it is added as a kernel .config option called KGDB_LOW_LEVEL_TRAP.

Also added was a die notification for oops such that kdb can catch an oops for analysis.

There appeared no obvious way to pass the struct pt_regs from the original exception back to the stack back tracer, so a special case was added to show_stack() for when kdb is active because you generally desire to generally look at the back trace of the original exception.

---
 arch/mips/include/asm/kgdb.h |    2 ++
 arch/mips/kernel/kgdb.c      |   22 +++++++++++++++++++++-
 arch/mips/kernel/traps.c     |   14 ++++++++++++++
 lib/Kconfig.kgdb             |    2 +-
 4 files changed, 38 insertions(+), 2 deletions(-)
arch/mips/include/asm/kgdb.h +2 -0
index 48223b0..19002d6 100644
@@ -38,6 +38,8 @@ extern int kgdb_early_setup;
 extern void *saved_vectors[32];
 extern void handle_exception(struct pt_regs *regs);
 extern void breakinst(void);
+extern int kgdb_ll_trap(int cmd, const char *str,
+			struct pt_regs *regs, long err, int trap, int sig);
 
 #endif				/* __KERNEL__ */
 
arch/mips/kernel/kgdb.c +21 -1
index 54f2d40..a4e546a 100644
@@ -202,7 +202,7 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
 	if (atomic_read(&kgdb_active) != -1)
 		kgdb_nmicallback(smp_processor_id(), regs);
 
-	if (kgdb_handle_exception(trap, compute_signal(trap), 0, regs))
+	if (kgdb_handle_exception(trap, compute_signal(trap), cmd, regs))
 		return NOTIFY_DONE;
 
 	if (atomic_read(&kgdb_setting_breakpoint))
@@ -216,6 +216,26 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
 	return NOTIFY_STOP;
 }
 
+#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
+int kgdb_ll_trap(int cmd, const char *str,
+		 struct pt_regs *regs, long err, int trap, int sig)
+{
+	struct die_args args = {
+		.regs	= regs,
+		.str	= str,
+		.err	= err,
+		.trapnr	= trap,
+		.signr	= sig,
+
+	};
+
+	if (!kgdb_io_module_registered)
+		return NOTIFY_DONE;
+
+	return kgdb_mips_notify(NULL, cmd, &args);
+}
+#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
+
 static struct notifier_block kgdb_notifier = {
 	.notifier_call = kgdb_mips_notify,
 };
arch/mips/kernel/traps.c +14 -0
index e83da17..fbf427e 100644
@@ -24,6 +24,8 @@
 #include <linux/interrupt.h>
 #include <linux/ptrace.h>
 #include <linux/kgdb.h>
+#include <linux/kdb.h>
+#include <linux/kdbprivate.h>
 #include <linux/kdebug.h>
 
 #include <asm/bootinfo.h>
@@ -186,6 +188,11 @@ void show_stack(struct task_struct *task, unsigned long *sp)
 			regs.regs[29] = task->thread.reg29;
 			regs.regs[31] = 0;
 			regs.cp0_epc = task->thread.reg31;
+#ifdef CONFIG_KGDB_KDB
+		} else if (atomic_read(&kgdb_active) != -1 &&
+			   kdb_current_regs) {
+			memcpy(&regs, kdb_current_regs, sizeof(regs));
+#endif /* CONFIG_KGDB_KDB */
 		} else {
 			prepare_frametrace(&regs);
 		}
@@ -360,6 +367,8 @@ void __noreturn die(const char * str, const struct pt_regs * regs)
 	unsigned long dvpret = dvpe();
 #endif /* CONFIG_MIPS_MT_SMTC */
 
+	notify_die(DIE_OOPS, str, (struct pt_regs *)regs, SIGSEGV, 0, 0);
+
 	console_verbose();
 	spin_lock_irq(&die_lock);
 	bust_spinlocks(1);
@@ -701,6 +710,11 @@ static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
 	siginfo_t info;
 	char b[40];
 
+#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
+	if (kgdb_ll_trap(DIE_TRAP, str, regs, code, 0, 0) == NOTIFY_STOP)
+		return;
+#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
+
 	if (notify_die(DIE_TRAP, str, regs, code, 0, 0) == NOTIFY_STOP)
 		return;
 
lib/Kconfig.kgdb +1 -1
index a2f63be..b5d3637 100644
@@ -59,7 +59,7 @@ config KGDB_TESTS_BOOT_STRING
 
 config KGDB_LOW_LEVEL_TRAP
        bool "KGDB: Allow debugging with traps in notifiers"
-       depends on X86 || PPC
+       depends on X86 || PPC || MIPS
        default n
        help
          This will add an extra call back to kgdb for the breakpoint
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#11 lore raw

PATCH 11/13 kgdb: Add the ability to schedule a breakpoint via a tasklet

Some kgdb I/O modules require the ability to create a breakpoint tasklet, such as kgdboc and external modules such as kgdboe. The breakpoint tasklet is used as an asynchronous entry point into the debugger which will have a different function scope than the current execution path where it might not be safe to have an inline breakpoint inside the kgdb I/O driver.

---
 include/linux/kgdb.h |    1 +
 kernel/kgdb.c        |   26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)
include/linux/kgdb.h +1 -0
index 166cd07..1fa0bcc 100644
@@ -270,6 +270,7 @@ extern int kgdb_use_passthrough;
 extern void kgdb_msg_write(const char *s, int len);
 extern int			kgdb_single_step;
 extern atomic_t			kgdb_active;
+extern void kgdb_schedule_breakpoint(void);
 
 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
 extern void __init early_kgdboc_init(void);
kernel/kgdb.c +26 -0
index da738a2..f303410 100644
@@ -136,6 +136,7 @@ atomic_t			kgdb_active = ATOMIC_INIT(-1);
  */
 static atomic_t			passive_cpu_wait[NR_CPUS];
 static atomic_t			cpu_in_kgdb[NR_CPUS];
+static atomic_t			kgdb_break_tasklet_var;
 atomic_t			kgdb_setting_breakpoint;
 
 struct task_struct		*kgdb_usethread;
@@ -1862,6 +1863,31 @@ static void kgdb_unregister_callbacks(void)
 	}
 }
 
+/*
+ * There are times a tasklet needs to be used vs a compiled in
+ * break point so as to cause an exception outside a kgdb I/O module,
+ * such as is the case with kgdboe, where calling a breakpoint in the
+ * I/O driver itself would be fatal.
+ */
+static void kgdb_tasklet_bpt(unsigned long ing)
+{
+	kgdb_breakpoint();
+	atomic_set(&kgdb_break_tasklet_var, 0);
+}
+
+static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
+
+void kgdb_schedule_breakpoint(void)
+{
+	if (atomic_read(&kgdb_break_tasklet_var) ||
+		atomic_read(&kgdb_active) != -1 ||
+		atomic_read(&kgdb_setting_breakpoint))
+		return;
+	atomic_inc(&kgdb_break_tasklet_var);
+	tasklet_schedule(&kgdb_tasklet_breakpoint);
+}
+EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
+
 static void kgdb_initial_breakpoint(void)
 {
 	kgdb_break_asap = 0;
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#12 lore raw

PATCH 12/13 RFC ONLY - kgdb,kdb: use async breakpoint for sysrq for usb

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

For kdb, the usb keyboard will become disabled if you use a sysrq sequence to enter kdb. Using a tasklet solves the problem.

---
 kernel/kgdb.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
kernel/kgdb.c +11 -1
index f303410..034f6eb 100644
@@ -1817,8 +1817,18 @@ static void sysrq_handle_gdb(int key, struct tty_struct *tty)
 		printk(KERN_CRIT "Entering KGDB\n");
 #endif
 	}
-
+#ifdef CONFIG_KDB_USB
+	/* XXX FIX ME XXX
+	 * For now force the sysrq break point to be in a tasklet
+	 * else if you send it from a usb keyboard, the keyboard cannot be
+	 * used to interact with kdb because all the locks for the USB hcd
+	 * device will be held.  This probably needs a run time check
+	 * against what i/o driver submitted the breakpoint request.
+	 */
+	kgdb_schedule_breakpoint();
+#else /* ! CONFIG_KDB_USB */
 	kgdb_breakpoint();
+#endif /* CONFIG_KDB_USB */
 }
 
 static struct sysrq_key_op sysrq_gdb_op = {
Signature · 1 line
1.6.3.rc0.1.gf800
author maintainer
#13 lore raw

PATCH 13/13 RFC ONLY - usb,keyboard: uchi, echi, and ochi polling keyboard urbs

This is a RFC patch. The work to possibly merge kdb and kgdb is being evaluated and this patch is considered only a proof of concept or prototype.

This is a direct port of the kdb usb polling code, with some clean up for checkpatch.pl. I would rate this particular patch in the "highly experimental/controversial" classification.

Based on the ehci and ochi implementations from the kdb 4.4, I added a uhci implementation, because that was the only usb keyboard type I had at the time. The uhci polling code "appears to work", but has problems in that it does not seem to remove the urbs completely from the queue on resume from debugging mode. I am not actually certain if the ehci and ochi drivers have the same problem because I was not able to test them.

As I understand it from reading the original ehci and uhci polling implementation, the concept is to poll the queue for a particular urb and process only that urb from the driver queue. At the same time, the poll code attempts to leave everything else alone. Assuming that is the intent behind this code, that means only the usb keyboard(s) stay alive while kdb is active.

Perhaps we can get further comments from the original authors at some point down the road. :-)

---
 drivers/char/kdb_keyboard.c   |  199 ++++++++++++++++++++++++++++++++++++
 drivers/hid/usbhid/hid-core.c |   26 +++++
 drivers/hid/usbhid/usbkbd.c   |   13 +++
 drivers/serial/kgdboc.c       |   12 ++
 drivers/usb/core/hcd.c        |   14 +++
 drivers/usb/core/hcd.h        |    4 +
 drivers/usb/host/ehci-hcd.c   |   42 ++++++++
 drivers/usb/host/ehci-pci.c   |    6 +
 drivers/usb/host/ehci-q.c     |  225 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/host/ohci-hcd.c   |   66 ++++++++++++
 drivers/usb/host/ohci-pci.c   |    6 +-
 drivers/usb/host/ohci-q.c     |   63 ++++++++++++
 drivers/usb/host/uhci-hcd.c   |   36 +++++++
 drivers/usb/host/uhci-q.c     |   51 +++++++++
 include/linux/kdb.h           |    1 +
 include/linux/kdbprivate.h    |    1 +
 lib/Kconfig.kgdb              |    7 ++
 17 files changed, 771 insertions(+), 1 deletions(-)
drivers/char/kdb_keyboard.c +199 -0
index 6dcbb07..6cc4636 100644
@@ -11,6 +11,7 @@
 
 #ifdef	CONFIG_VT_CONSOLE
 #include <linux/kdb.h>
+#include <linux/kdbprivate.h>
 #include <linux/keyboard.h>
 #include <linux/ctype.h>
 #include <linux/module.h>
@@ -20,6 +21,204 @@
 
 static int kbd_exists;
 
+#ifdef	CONFIG_KDB_USB
+
+/* support up to 8 USB keyboards (probably excessive, but...) */
+#define KDB_USB_NUM_KEYBOARDS   8
+struct kdb_usb_kbd_info kdb_usb_kbds[KDB_USB_NUM_KEYBOARDS];
+
+static unsigned char kdb_usb_keycode[256] = {
+	   0,   0,   0,   0,  30,  48,  46,  32,  18,  33,  34,  35,  23,
+	  36,  37,  38,	 50,  49,  24,  25,  16,  19,  31,  20,  22,  47,
+	  17,  45,  21,  44,   2,   3,   4,   5,   6,   7,   8,   9,  10,
+	  11,  28,   1,  14,  15,  57,  12,  13,  26,  27,  43,  84,  39,
+	  40,  41,  51,  52,  53,  58,  59,  60,  61,  62,  63,  64,  65,
+	  66,  67,  68,  87,  88,  99,  70, 119, 110, 102, 104, 111, 107,
+	 109, 106, 105, 108, 103,  69,  98,  55,  74,  78,  96,  79,  80,
+	  81,  75,  76,  77,  71,  72,  73,  82,  83,  86, 127, 116, 117,
+	  85,  89,  90,  91,  92,  93,  94,  95, 120, 121, 122, 123, 134,
+	 138, 130, 132, 128, 129, 131, 137, 133, 135, 136, 113,	115, 114,
+	   0,   0,   0, 124,   0, 181, 182, 183, 184, 185, 186, 187, 188,
+	 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,   0,   0,   0,
+	   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+	   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+	   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+	   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+	   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+	   0,   0,   0,  29,  42,  56, 125,  97,  54, 100, 126, 164, 166,
+	 165, 163, 161, 115, 114, 113, 150, 158, 159, 128, 136, 177, 178,
+	 176, 142, 152, 173, 140
+};
+
+/*
+ * kdb_usb_keyboard_attach()
+ * Attach a USB keyboard to kdb.
+ */
+int
+kdb_usb_keyboard_attach(struct urb *urb, unsigned char *buffer, void *poll_func)
+{
+	int     i;
+	int     rc = -1;
+
+	if (kdb_no_usb)
+		return 0;
+
+	/*
+	 * Search through the array of KDB USB keyboards (kdb_usb_kbds)
+	 * looking for a free index. If found, assign the keyboard to
+	 * the array index.
+	 */
+
+	for (i = 0; i < KDB_USB_NUM_KEYBOARDS; i++) {
+		if (kdb_usb_kbds[i].urb) /* index is already assigned */
+			continue;
+
+		/* found a free array index */
+		kdb_usb_kbds[i].urb = urb;
+		kdb_usb_kbds[i].buffer = buffer;
+		kdb_usb_kbds[i].poll_func = poll_func;
+
+		rc = 0; /* success */
+
+		break;
+	}
+
+	return rc;
+}
+EXPORT_SYMBOL_GPL(kdb_usb_keyboard_attach);
+
+/*
+ * kdb_usb_keyboard_detach()
+ * Detach a USB keyboard from kdb.
+ */
+int
+kdb_usb_keyboard_detach(struct urb *urb)
+{
+	int     i;
+	int     rc = -1;
+
+	if (kdb_no_usb)
+		return 0;
+
+	/*
+	 * Search through the array of KDB USB keyboards (kdb_usb_kbds)
+	 * looking for the index with the matching URB. If found,
+	 * clear the array index.
+	 */
+
+	for (i = 0; i < KDB_USB_NUM_KEYBOARDS; i++) {
+		if (kdb_usb_kbds[i].urb != urb)
+			continue;
+
+		/* found it, clear the index */
+		kdb_usb_kbds[i].urb = NULL;
+		kdb_usb_kbds[i].buffer = NULL;
+		kdb_usb_kbds[i].poll_func = NULL;
+		kdb_usb_kbds[i].caps_lock = 0;
+
+		rc = 0; /* success */
+
+		break;
+	}
+
+	return rc;
+}
+EXPORT_SYMBOL_GPL(kdb_usb_keyboard_detach);
+
+/*
+ * get_usb_char
+ * This function drives the USB attached keyboards.
+ * Fetch the USB scancode and decode it.
+ */
+int
+kdb_get_usb_char(void)
+{
+	int     i;
+	int     ret;
+	unsigned char keycode, spec;
+
+	if (kdb_no_usb)
+		return -1;
+
+	/*
+	 * Loop through all the USB keyboard(s) and return
+	 * the first character obtained from them.
+	 */
+
+	for (i = 0; i < KDB_USB_NUM_KEYBOARDS; i++) {
+		/* skip uninitialized keyboard array entries */
+		if (!kdb_usb_kbds[i].urb || !kdb_usb_kbds[i].buffer ||
+		    !kdb_usb_kbds[i].poll_func)
+			continue;
+
+		/* Transfer char */
+		ret = (*kdb_usb_kbds[i].poll_func)(kdb_usb_kbds[i].urb);
+		if (ret == -EBUSY && kdb_usb_kbds[i].poll_ret != -EBUSY)
+			kdb_printf("NOTICE: USB HD driver BUSY. "
+				   "USB keyboard has been disabled.\n");
+
+		kdb_usb_kbds[i].poll_ret = ret;
+
+		if (ret < 0) /* error or no characters, try the next kbd */
+			continue;
+
+		spec = kdb_usb_kbds[i].buffer[0];
+		keycode = kdb_usb_kbds[i].buffer[2];
+		kdb_usb_kbds[i].buffer[0] = (char)0;
+		kdb_usb_kbds[i].buffer[2] = (char)0;
+
+		if (kdb_usb_kbds[i].buffer[3]) {
+			kdb_usb_kbds[i].buffer[3] = (char)0;
+			continue;
+		}
+
+		/* A normal key is pressed, decode it */
+		if (keycode)
+			keycode = kdb_usb_keycode[keycode];
+
+		/* 2 Keys pressed at one time ? */
+		if (spec && keycode) {
+			switch (spec) {
+			case 0x2:
+			case 0x20: /* Shift */
+				return shift_map[keycode];
+			case 0x1:
+			case 0x10: /* Ctrl */
+				return ctrl_map[keycode];
+			case 0x4:
+			case 0x40: /* Alt */
+				break;
+			}
+		} else if (keycode) { /* If only one key pressed */
+			switch (keycode) {
+			case 0x1C: /* Enter */
+				return 13;
+
+			case 0x3A: /* Capslock */
+				kdb_usb_kbds[i].caps_lock =
+					!(kdb_usb_kbds[i].caps_lock);
+				break;
+			case 0x0E: /* Backspace */
+				return 8;
+			case 0x0F: /* TAB */
+				return 9;
+			case 0x77: /* Pause */
+				break;
+			default:
+				if (!kdb_usb_kbds[i].caps_lock)
+					return plain_map[keycode];
+				else
+					return shift_map[keycode];
+			}
+		}
+	}
+
+	/* no chars were returned from any of the USB keyboards */
+
+	return -1;
+}
+#endif	/* CONFIG_KDB_USB */
+
 /*
  * Check if the keyboard controller has a keypress for us.
  * Some parts (Enter Release, LED change) are still blocking polled here,
drivers/hid/usbhid/hid-core.c +26 -0
index 900ce18..d82dfc8 100644
@@ -36,6 +36,7 @@
 #include <linux/hiddev.h>
 #include <linux/hid-debug.h>
 #include <linux/hidraw.h>
+#include <linux/kdb.h>
 #include "usbhid.h"
 
 /*
@@ -47,6 +48,7 @@
 #define DRIVER_DESC "USB HID core driver"
 #define DRIVER_LICENSE "GPL"
 
+
 /*
  * Module parameters.
  */
@@ -1037,6 +1039,14 @@ static void usbhid_stop(struct hid_device *hid)
 
 	if (WARN_ON(!usbhid))
 		return;
+#ifdef CONFIG_KDB_USB
+	/*
+	 * If the URB was for a Keyboard, detach it from kdb.
+	 * If the URB was for another type of device, just
+	 * allow kdb_usb_keyboard_detach() to silently fail.
+	 */
+	kdb_usb_keyboard_detach(usbhid->urbin);
+#endif
 
 	clear_bit(HID_STARTED, &usbhid->iofl);
 	spin_lock_irq(&usbhid->lock);	/* Sync with error handler */
@@ -1176,6 +1186,22 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
 		goto err_free;
 	}
 
+#ifdef CONFIG_KDB_USB
+	/* Attach USB keyboards to kdb */
+	if (intf->cur_altsetting->desc.bInterfaceProtocol ==
+	    USB_INTERFACE_PROTOCOL_KEYBOARD) {
+		int ret;
+		struct usbhid_device *usbhid = hid->driver_data;
+
+		ret = kdb_usb_keyboard_attach(usbhid->urbin, usbhid->inbuf,
+		    usb_hcd_get_kdb_poll_func(interface_to_usbdev(intf)));
+
+		if (ret == -1)
+			printk(KERN_ERR ": FAILED to register keyboard (%s) "
+				"with KDB\n", hid->phys);
+	}
+#endif /* CONFIG_KDB_USB */
+
 	return 0;
 err_free:
 	kfree(usbhid);
drivers/hid/usbhid/usbkbd.c +13 -0
index b342926..7ecbf6f 100644
@@ -30,6 +30,7 @@
 #include <linux/init.h>
 #include <linux/usb/input.h>
 #include <linux/hid.h>
+#include <linux/kdb.h>
 
 /*
  * Version Information
@@ -292,6 +293,14 @@ static int usb_kbd_probe(struct usb_interface *iface,
 	usb_fill_int_urb(kbd->irq, dev, pipe,
 			 kbd->new, (maxp > 8 ? 8 : maxp),
 			 usb_kbd_irq, kbd, endpoint->bInterval);
+
+#ifdef CONFIG_KDB_USB
+	/* Attach keyboard to kdb */
+	kdb_usb_keyboard_attach(kbd->irq, kbd->new,
+				usb_hcd_get_kdb_poll_func(dev));
+
+#endif /* CONFIG_KDB_USB */
+
 	kbd->irq->transfer_dma = kbd->new_dma;
 	kbd->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
@@ -329,6 +338,10 @@ static void usb_kbd_disconnect(struct usb_interface *intf)
 
 	usb_set_intfdata(intf, NULL);
 	if (kbd) {
+#ifdef CONFIG_KDB_USB
+		/* Detach the keyboard from kdb */
+		kdb_usb_keyboard_detach(kbd->irq);
+#endif /* CONFIG_KDB_USB */
 		usb_kill_urb(kbd->irq);
 		input_unregister_device(kbd->dev);
 		usb_kbd_free_mem(interface_to_usbdev(intf), kbd);
drivers/serial/kgdboc.c +12 -0
index cac8ae7..593a67a 100644
@@ -54,7 +54,12 @@ static void cleanup_kgdboc(void)
 
 	/* Unregister the keyboard poll hook, if registered */
 	for (i = 0; i < kdb_poll_idx; i++) {
+#ifdef CONFIG_KDB_USB
+		if (kdb_poll_funcs[i] == kdb_get_kbd_char ||
+			kdb_poll_funcs[i] == kdb_get_usb_char) {
+#else /* ! CONFIG_KDB_USB */
 		if (kdb_poll_funcs[i] == kdb_get_kbd_char) {
+#endif /* CONFIG_KDB_USB */
 			kdb_poll_idx--;
 			kdb_poll_funcs[i] = kdb_poll_funcs[kdb_poll_idx];
 			kdb_poll_funcs[kdb_poll_idx] = NULL;
@@ -87,11 +92,18 @@ static int configure_kgdboc(void)
 		if (kdb_poll_idx < KDB_POLL_FUNC_MAX) {
 			kdb_poll_funcs[kdb_poll_idx] = kdb_get_kbd_char;
 			kdb_poll_idx++;
+#ifdef CONFIG_KDB_USB
+			if (kdb_poll_idx < KDB_POLL_FUNC_MAX) {
+				kdb_poll_funcs[kdb_poll_idx] = kdb_get_usb_char;
+				kdb_poll_idx++;
+			}
+#endif /* CONFIG_KDB_USB */
 			if (cptr[3] == ',')
 				cptr += 4;
 			else
 				goto do_register;
 		}
+		/* XXX must fix error handling XXX */
 	}
 #endif /* CONFIG_KDB_KEYBOARD */
 
drivers/usb/core/hcd.c +14 -0
index 42b93da..6f1935e 100644
@@ -2045,6 +2045,20 @@ usb_hcd_platform_shutdown(struct platform_device* dev)
 }
 EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
 
+#ifdef CONFIG_KDB_USB
+void *
+usb_hcd_get_kdb_poll_func(struct usb_device *udev)
+{
+	struct usb_hcd	*hcd = bus_to_hcd(udev->bus);
+
+	if (hcd && hcd->driver)
+		return (void *)(hcd->driver->kdb_poll_char);
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(usb_hcd_get_kdb_poll_func);
+#endif /* CONFIG_KDB_USB */
+
 /*-------------------------------------------------------------------------*/
 
 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
drivers/usb/core/hcd.h +4 -0
index e7d4479..a99689d 100644
@@ -224,6 +224,10 @@ struct hc_driver {
 	void	(*relinquish_port)(struct usb_hcd *, int);
 		/* has a port been handed over to a companion? */
 	int	(*port_handed_over)(struct usb_hcd *, int);
+#ifdef CONFIG_KDB_USB
+	/* KDB poll function for this HC */
+	int	(*kdb_poll_char)(struct urb *urb);
+#endif /* CONFIG_KDB_USB */
 };
 
 extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
drivers/usb/host/ehci-hcd.c +42 -0

48 lines not on this page · raw message

drivers/usb/host/ehci-pci.c +6 -0
index 5aa8bce..65779fb 100644
@@ -22,6 +22,8 @@
 #error "This file is PCI bus glue.  CONFIG_PCI must be defined."
 #endif
 
+#include <linux/kdb.h>
+
 /*-------------------------------------------------------------------------*/
 
 /* called after powerup, by probe or system-pm "wakeup" */
@@ -408,6 +410,10 @@ static const struct hc_driver ehci_pci_hc_driver = {
 	.bus_resume =		ehci_bus_resume,
 	.relinquish_port =	ehci_relinquish_port,
 	.port_handed_over =	ehci_port_handed_over,
+
+#ifdef CONFIG_KDB_USB
+	.kdb_poll_char = 	ehci_kdb_poll_char,
+#endif
 };
 
 /*-------------------------------------------------------------------------*/
drivers/usb/host/ehci-q.c +225 -0

231 lines not on this page · raw message

drivers/usb/host/ohci-hcd.c +66 -0

72 lines not on this page · raw message

drivers/usb/host/ohci-pci.c +5 -1
index f9961b4..8de9079 100644
@@ -20,7 +20,7 @@
 
 #include <linux/pci.h>
 #include <linux/io.h>
-
+#include <linux/kdb.h>
 
 /* constants used to work around PM-related transfer
  * glitches in some AMD 700 series southbridges
@@ -367,6 +367,7 @@ static int __devinit ohci_pci_start (struct usb_hcd *hcd)
 		ohci_err (ohci, "can't start\n");
 		ohci_stop (hcd);
 	}
+
 	return ret;
 }
 
@@ -464,6 +465,9 @@ static const struct hc_driver ohci_pci_hc_driver = {
 	.bus_resume =		ohci_bus_resume,
 #endif
 	.start_port_reset =	ohci_start_port_reset,
+#ifdef CONFIG_KDB_USB
+	.kdb_poll_char =	ohci_kdb_poll_char,
+#endif
 };
 
 /*-------------------------------------------------------------------------*/
drivers/usb/host/ohci-q.c +63 -0

66 lines not on this page · raw message

drivers/usb/host/uhci-hcd.c +36 -0
index cf5e4cf..8397f07 100644
@@ -40,6 +40,7 @@
 #include <linux/usb.h>
 #include <linux/bitops.h>
 #include <linux/dmi.h>
+#include <linux/kdb.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -891,6 +892,38 @@ static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
 	return frame_number + delta;
 }
 
+#ifdef CONFIG_KDB_USB
+int uhci_kdb_poll_char(struct urb *urb)
+{
+	struct uhci_hcd *uhci;
+	struct urb_priv *urbp;
+	struct uhci_qh *qh;
+
+	/* just to make sure */
+	if (!urb || !urb->dev || !urb->dev->bus || !urb->hcpriv)
+		return -1;
+
+	urbp = urb->hcpriv;
+	qh = urbp->qh;
+
+	uhci = (struct uhci_hcd *) hcd_to_uhci(bus_to_hcd(urb->dev->bus));
+
+	/* make sure */
+	if (!uhci)
+		return -1;
+
+	if (!HC_IS_RUNNING(uhci_to_hcd(uhci)->state))
+		return -1;
+
+	if (spin_is_locked(&uhci->lock))
+		return -EBUSY;
+
+	if (uhci_scan_qh_kdb(uhci, qh, urb))
+		return 0;
+	return -1;
+}
+#endif /* CONFIG_KDB_USB */
+
 static const char hcd_name[] = "uhci_hcd";
 
 static const struct hc_driver uhci_driver = {
@@ -921,6 +954,9 @@ static const struct hc_driver uhci_driver = {
 
 	.hub_status_data =	uhci_hub_status_data,
 	.hub_control =		uhci_hub_control,
+#ifdef CONFIG_KDB_USB
+	.kdb_poll_char =	uhci_kdb_poll_char,
+#endif
 };
 
 static const struct pci_device_id uhci_pci_ids[] = { {
drivers/usb/host/uhci-q.c +51 -0

54 lines not on this page · raw message

include/linux/kdb.h +1 -0
index 200af81..9d89054 100644
@@ -137,6 +137,7 @@ extern int kdb_no_usb;
 extern int kdb_usb_keyboard_attach(struct urb *urb,
 				   unsigned char *buffer, void *poll_func);
 extern int kdb_usb_keyboard_detach(struct urb *urb);
+extern void *usb_hcd_get_kdb_poll_func(struct usb_device *udev);
 
 #endif /* CONFIG_KDB_USB */
 
include/linux/kdbprivate.h +1 -0
index 8579e97..03f0004 100644
@@ -333,6 +333,7 @@ typedef int (*get_char_func)(void);
 extern get_char_func kdb_poll_funcs[];
 extern int kdb_poll_idx;
 extern int kdb_get_kbd_char(void);
+extern int kdb_get_usb_char(void);
 
 #ifndef	CONFIG_IA64
 	/*
lib/Kconfig.kgdb +7 -0
index b5d3637..1c94a2b 100644
@@ -87,4 +87,11 @@ config KDB_KEYBOARD
 	help
 	  KDB can use a PS/2 type keyboard for an input device
 
+config KDB_USB
+	bool "KGDB_KDB: Allow usb input device devices"
+	depends on VT && KGDB_KDB && KDB_KEYBOARD
+	default y
+	help
+	  KDB can use a USB keyboard for an input device
+
 endif # KGDB
Signature · 1 line
1.6.3.rc0.1.gf800
#14 lore raw

Re: [PATCH 01/13] RFC ONLY - kdb: core for kgdb back end

In reply to Jason Wessel
Quoted 11 lines · Jason Wessel

This is an RFC patch. This work is by no means in its final form, nor is it in a form that would be suitible for upstream merging. This is an early prototype of a kdb frontend talking to a kgdb backend. It is meant to foster some discussion around the usefulness of merging kdb and kgdb together, as well as experiment with changes to kgdb's core to improve robustness and functionality.

This patch contains the kdb core and some instrumentation into the core kernel which kdb requires in order to gather information for some of its reporting functions.

Just a first quick 30-seconds impression from skimming through the patch:

- The cleanups are an absolute must before doing any in-depth review. We only want to waste valuable review bandwidth on code that at least _looks_ nice and tidy.

- Many functions are way too large, with many indentation levels - they need a split-up.

- Most of the code patterns dont match core kernel standards and practices, so it's not reviewable in detail. It needs a thorough clean-up not just on the surface, but on the algorithmic level as well.

bits like:

kdb/kdbmain.c line 2889

Quoted 2 lines
kdb/kdbmain.c new file +2 -0
+		// HACK HACK HACK
+		printk(KERN_CRIT "DOH NEED TO IMPLEMENT THIS!");

need fixed.

Locking needs reviewed and fixed:

Quoted 9 lines

+/* Locking is awkward. The debug code is called from all contexts, including
+ * non maskable interrupts. A normal spinlock is not safe in NMI context. Try
+ * to get the debug allocator lock, if it cannot be obtained after a second
+ * then give up. If the lock could not be previously obtained on this cpu then
+ * only try once.
+ *
+ * sparse has no annotation for "this function _sometimes_ acquires a lock", so
+ * fudge the acquire/release notation.
+ */

Plus, if _any_ debugger front-end is considered for merging, it _must_ work with Kernel Mode Setting properly, out of X. No ifs and when.

Also, high-level file organization: i'd suggest to move it all under the kernel/debug/ hierarchy, and move kernel/kgdb.c to kernel/debug/backend/core.c or so [possibly split up a bit, it's getting quite large] and the KDB bits under kernel/debug/frontend/. We dont want multiple back-ends nor multiple front-ends. We want one good back-end and one good (built-in) front-end.

I supported and helped a debugging backend and i dont consider a front-end completely impossible either. But it will have to meet a _lot_ of stringent standards because a good kernel debugging front-end's cross section to the system is even larger than a backend's. It's a tough job to get this done.

Ingo

author maintainer
#15 lore raw

Re: [PATCH 01/13] RFC ONLY - kdb: core for kgdb back end

Quoted 7 lines · Ingo Molnar

Just a first quick 30-seconds impression from skimming through the patch:

- The cleanups are an absolute must before doing any in-depth review. We only want to waste valuable review bandwidth on code that at least _looks_ nice and tidy.

I think in depth review is still a bit off. The intent of the RFC was to gauge interest in the project of unifying the kernel debug tools.

Quoted 2 lines

- Many functions are way too large, with many indentation levels - they need a split-up.

Sure. I cleaned up one or two places just to kdb look a little more friendly, but there is a lot more slicing/dicing/refactoring that needs to occur. This initial work was nothing more than a rapid "throw away prototype". In terms of iterations, we should decide what the directory structure an naming conversion should look like (more below).

Quoted 7 lines

bits like:

kdb/kdbmain.c new file +2 -0
+        // HACK HACK HACK
+        printk(KERN_CRIT "DOH NEED TO IMPLEMENT THIS!");

need fixed.

The next version has all those type comments cleaned up correctly and in most cases the function is now implemented.

Quoted 1 line

Locking needs reviewed and fixed:

Agreed, and that will happen in a future iteration. The APIs, directory structure, and glue need some work first.

Quoted 4 lines

Plus, if _any_ debugger front-end is considered for merging, it _must_ work with Kernel Mode Setting properly, out of X. No ifs and when.

This is in the "road map". I view kernel mode setting for opening a debugger on the console to be extremely important, but it should not gate an initial merge of a debugger front end. The serial and text console alone are quite useful as interactive debug consoles.

I talked to Jesse Barnes about the state of the kernel mode setting code as well as doing some investigation of how the mode switching API worked. In the first pass, the emergency escape back to the console via kernel mode switching was completely broken. Jesse gave me patch to fix this problem in order to complete the investigation. While the emergency escape to the console now works, it is not a solution that would work for a generic kernel debugger.

The key problem today for kernel mode setting is that there is no API to allow you to atomically change and restore the console during the time you are in the exception context but before you return. The current console switching uses a separate kernel thread and all sorts of locks to manage display device. This is not an unsolvable problem, but it will require some special API to be created for use in the exception context.

On the bright side, the hook points exist in the debug framework to make use of the kernel mode setting once the console layer implents some kind of atomic kernel mode setting API.

Quoted 8 lines

Also, high-level file organization: i'd suggest to move it all under the kernel/debug/ hierarchy, and move kernel/kgdb.c to kernel/debug/backend/core.c or so [possibly split up a bit, it's getting quite large] and the KDB bits under kernel/debug/frontend/. We dont want multiple back-ends nor multiple front-ends. We want one good back-end and one good (built-in) front-end.

Do we really want that many directories? There is also the question about changing some of the function names used by kgdb today. I believe we should come to an agreement on this first, and stage all future work on top of that. This also needs to include the naming structure for the headers.

Here is an initial proposal, which I prototyped just to see what it might look like. I used the kernel/debug directory as the home to the generic kernel debug code.

The present kernel/kgdb.c breaks down into:

kernel/debug/debug_core.c - ~829 lines
* Contains the generic cpu exception handling
* Breakpoint handling
* Memory access
* If the break point code grows to much we split it later

kernel/debug/gdbstub.c - ~902 lines
* This is all the logic to implement the state machine that speaks gdb serial

kernel/debug/Makefile

kernel/debug/debug_core.h - ~35 lines
* This is a private include file for use between the gdbstub and any future frontend because no other files outside this directory should use these API calls/
* There is a cut and past of this below.

Some of what we call "kgdb" needs to get a new name because some of the API is required for the gdbstub or for anything else that might use it. Presently there is gdb serial oriented "stuff" in some of the arch specific kgdb code. In the new scheme we need a clean way to eliminate it. In theory, when done you could go so far as to compile the debugger frontend or the gdbstub.

Right now kgdb also has a number of I/O modules. They all start with kgdbXXXX, but it is the case that none of these have any knowledge of the interworking of the debugger. The I/O modules merely provide low level get and put character interfaces. So the question is if these should be renamed (ie kgdboc, kgdboe, kgdbts) to something like:

dbgoc - Debugger over console
dbgoe - Debugger over ethernet
gdbts - gdb stub test suite

The include/linux/kgdb.h would move to include/linux/debugger.h. The debugger.h would then contain the pieces that any other part of the kernel need in order to hook in, just like kgdb.h does today. APIs that are currently prefixed with kgdb_ would get moved to dbg_ or gdbstub_ depending on the true purpose of the API.

Does this sound reasonable?

If so I will post a patch series that contains the split and post a new kdb patch series at a later point.

The kdb code would go in:
kernel/debug/kdbmain.c
kernel/debug/kdbsupport.c
kernel/debug/kdb_io.c
... etc ...

Jason.

--- debug_core.h ---
/* kernel debug core data structures */

struct kgdb_state {
    int            ex_vector;
    int            signo;
    int            err_code;
    int            cpu;
    int            pass_exception;
    unsigned long        thr_query;
    unsigned long        threadid;
    long            kgdb_usethreadid;
    struct pt_regs        *linux_regs;
};
struct debuggerinfo_struct {
    void            *debuggerinfo;
    struct task_struct    *task;
};

extern struct debuggerinfo_struct kgdb_info[];
extern struct kgdb_io *dbg_io_ops;

/* kernel debug core break point routines */ extern int dbg_remove_all_break(void); extern int dbg_set_sw_break(unsigned long addr); extern int dbg_remove_sw_break(unsigned long addr); extern int dbg_activate_sw_breakpoints(void);

/* gdbstub interface functions */
extern int gdb_serial_stub(struct kgdb_state *ks); extern void gdbstub_msg_write(const char *s, int len);

#16 lore raw
In reply to Jason Wessel
Quoted 10 lines · Jason Wessel

This patch series is a request for comments on several levels.

1) Do people find kdb useful? (See * and **)
2) Would kdb folks be willing to use it if it was a front end to kgdb?
3) Does kdb have a future in the mainline kernel?
4) Is this a reasonable approach to have some level of unification to end up with a more robust kernel debugger?

* This is not meant to be a religious war

I am just a ordinary user of linux, but I want to say that I enjoyed the kdb back when I used it. I really would like to see that in kernel.

But it would be even better to see a kdb over ethernet first (I have no serial port in my notebook....)

Best regards,
Maxim Levitsky

#17 lore raw
In reply to Jason Wessel

Hi Jason,

Quoted 3 lines · Jason Wessel

This patch series is a request for comments on several levels.

1) Do people find kdb useful? (See * and **)

Yes! Having a debugger on the main console is very handy, especially when
a) it is a pain, when it's possible (*), to setup a serial console, and
b) over ethernet, neither kgdb nor kdb is as reliable as kdb on tty0.

I won't answer the other questions since I'm definitely a user, not a developer of kernel debugger.

(*) not everybody has IPMI 2 boards with serial over lan consoles.

Quoted 14 lines

2) Would kdb folks be willing to use it if it was a front end to kgdb?
3) Does kdb have a future in the mainline kernel?
4) Is this a reasonable approach to have some level of unification to end up with a more robust kernel debugger?

* This is not meant to be a religious war

** This will never replace printk :-)

What follows is a series of patches to the development kernel which enable kdb as a front end to kgdb for arm, mips, powerpc, and x86. This is a very raw prototype, but enough of it it works such that folks can try it out.

Quoted 5 lines

To get the most basic functionality, you only need the first 2 patches in the series. The remainder of the patches go on to incrementally add back some of the functionality that was removed from kdb. I made an attempt to try to make the first part just the generic set of changes required to get kdb working on 1 or more archs.

Do you intend to support kdb modules? If yes, in which extent should they be adapted?

Thanks,

Louis

Quoted 175 lines

The kdb front end works a little differently than if you were to take the original kdb patch set from:

ftp://oss.sgi.com/projects/kdb/download/v4.4/

In the kernel .config you should enable the following options:

CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_KGDB_LOW_LEVEL_TRAP=y
CONFIG_KGDB_KDB=y
CONFIG_KGDB_KDB_PRIMARY=y
CONFIG_KDB_KEYBOARD=y
CONFIG_KDB_USB=y

If you were using the serial port with kdb before, now you just use the kgdboc mechanism with no differences at all. IE use you kernel command line with:

   console=ttyS0,115200 kgdboc=ttyS0 kgdbwait

That will get you access to kdb just after the console has been registered. If you want to use the keyboard, you could use:

console=tty0 kgdboc=kdb kgdbwait

You can also use the keyboard and or serial console:

   console=ttyS0,115200 console=tty0 kgdboc=kdb,ttyS0

In terms of breaking into the debugger after the system is up, you must use the sysrq-g sequence. That means you could run:
echo g > /proc/sysrq-trigger

Or you can use the SysRq key on your key board. On a typical laptop you might have to do the following:

press and hold ALT -- You will be holding this the whole time
press and hold FN
press and release the key with the SysRq label
release FN
press and release g
release ALT

I have also found on some PS/2 keyboards you have press alt again after resuming the system because the key up event got lost somewhere.

Once you are in kdb you can run help to see a limited list of commands.

You can also still connect gdb or re-enter kdb without leaving the exception state. To get out of kgdb mode you can type "$3#33", or to get into kgdb mode from kdb, you can type "kgdb". Also from gdb you can issue commands to the kdb front end, via gdb's montior command. For instance you could issue "monitor lsmod". Allowing the gdb monitor extension was certainly another motivation behind the prototype.

From here it is a matter of deciding if it is worth continuing down this route.

The evaulation of this project will definitely cause some further cleanup and improvement to kgdb, regardless of if this effort is carried forward. Two of the patches in this series are patches likely to get integrated into kgdb's code base and do not bear the "RFC ONLY" indication.

Thanks,
Jason.

You can find the development branch for this here:

http://git.kernel.org/?p=linux/kernel/git/jwessel/linux-2.6-kgdb.git;a=shortlog;h=kdb_prototype

or grab a static version of the patches here:

http://kernel.org/pub/linux/kernel/people/jwessel/branches/kdb_prototype.tar.bz2

short log info follows:

Jason Wessel (13):
RFC ONLY - kdb: core for kgdb backend
RFC ONLY - kgdb: core changes to support kdb
RFC ONLY - kgdb,8250,pl011: Return immediately from console poll RFC ONLY - kgdb: gdb "monitor" -> kdb passthrough
RFC ONLY - kgdboc,keyboard: Keyboard driver for kdb with kgdb
kgdb: remove post_primary_code references
RFC ONLY - x86,kgdb: Add low level debug hook
RFC ONLY - arm,kgdb: Add hook to catch an oops with debugger RFC ONLY - powerpc,kgdb: Introduce low level trap catching RFC ONLY - mips,kgdb: kdb low level trap catch and stack trace
kgdb: Add the ability to schedule a breakpoint via a tasklet RFC ONLY - kgdb,kdb: use async breakpoint for sysrq for usb RFC ONLY - usb,keyboard: uchi, echi, and ochi polling keyboard urbs

 Makefile                              |    1 +
 arch/arm/include/asm/kgdb.h           |    2 +
 arch/arm/include/asm/kmap_types.h     |    1 +
 arch/arm/kernel/kgdb.c                |   13 +
 arch/arm/kernel/traps.c               |    5 +
 arch/mips/include/asm/kgdb.h          |    2 +
 arch/mips/include/asm/kmap_types.h    |    3 +-
 arch/mips/kernel/kgdb.c               |   27 +-
 arch/mips/kernel/traps.c              |   14 +
 arch/powerpc/include/asm/kmap_types.h |    1 +
 arch/powerpc/kernel/kgdb.c            |   12 +-
 arch/powerpc/kernel/traps.c           |    7 +
 arch/x86/include/asm/kgdb.h           |    3 +
 arch/x86/include/asm/kmap_types.h     |    3 +-
 arch/x86/kernel/kgdb.c                |   56 +-
 arch/x86/kernel/traps.c               |    6 +
 drivers/char/Makefile                 |    1 +
 drivers/char/kdb_keyboard.c           |  407 ++++
 drivers/char/kdb_keyboard.h           |  143 ++
 drivers/hid/usbhid/hid-core.c         |   26 +
 drivers/hid/usbhid/usbkbd.c           |   13 +
 drivers/serial/8250.c                 |    4 +-
 drivers/serial/amba-pl011.c           |    6 +-
 drivers/serial/kgdboc.c               |   80 +-
 drivers/usb/core/hcd.c                |   14 +
 drivers/usb/core/hcd.h                |    4 +
 drivers/usb/host/ehci-hcd.c           |   42 +
 drivers/usb/host/ehci-pci.c           |    6 +
 drivers/usb/host/ehci-q.c             |  225 ++
 drivers/usb/host/ohci-hcd.c           |   66 +
 drivers/usb/host/ohci-pci.c           |    6 +-
 drivers/usb/host/ohci-q.c             |   63 +
 drivers/usb/host/uhci-hcd.c           |   36 +
 drivers/usb/host/uhci-q.c             |   51 +
 fs/proc/meminfo.c                     |  145 ++
 fs/proc/mmu.c                         |   16 +-
 include/linux/kdb.h                   |  172 ++
 include/linux/kdbprivate.h            |  611 ++++++
 include/linux/keyboard.h              |    2 +
 include/linux/kgdb.h                  |   25 +-
 include/linux/serial_core.h           |    1 +
 init/main.c                           |   26 +
 kdb/.gitignore                        |    1 +
 kdb/Makefile                          |   48 +
 kdb/kdb_bp.c                          |  863 ++++++++
 kdb/kdb_bt.c                          |  209 ++
 kdb/kdb_cmds                          |   32 +
 kdb/kdb_io.c                          |  895 ++++++++
 kdb/kdbmain.c                         | 3669 +++++++++++++++++++++++++++++++++
 kdb/kdbsupport.c                      | 1120 ++++++++++
 kernel/kallsyms.c                     |   22 +
 kernel/kgdb.c                         |  321 +++-
 kernel/module.c                       |   19 +-
 kernel/panic.c                        |    6 +
 kernel/printk.c                       |   14 +
 kernel/sched.c                        |   93 +-
 kernel/signal.c                       |   49 +
 lib/Kconfig.kgdb                      |   37 +
 mm/hugetlb.c                          |   22 +
 mm/swapfile.c                         |   22 +
 60 files changed, 9697 insertions(+), 92 deletions(-)
 create mode 100644 drivers/char/kdb_keyboard.c
 create mode 100644 drivers/char/kdb_keyboard.h
 create mode 100644 include/linux/kdb.h
 create mode 100644 include/linux/kdbprivate.h
 create mode 100644 kdb/.gitignore
 create mode 100644 kdb/Makefile
 create mode 100644 kdb/kdb_bp.c
 create mode 100644 kdb/kdb_bt.c
 create mode 100644 kdb/kdb_cmds
 create mode 100644 kdb/kdb_io.c
 create mode 100644 kdb/kdbmain.c
 create mode 100644 kdb/kdbsupport.c

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 4 lines
Dr Louis Rilling			Kerlabs
Skype: louis.rilling			Batiment Germanium
Phone: (+33|0) 6 80 89 08 23		80 avenue des Buttes de Coesmes
http://www.kerlabs.com/			35700 Rennes
#18 lore raw
Quoted 2 lines · Louis Rilling

Do you intend to support kdb modules? If yes, in which extent should they be adapted?

I think that would be a very low priority. What would be useful is the hack to load debuginfo into kdb so that it can pretty-print arbitrary structures. That alone would replace about 90% of the kdb modules I think.

And yes, that code in current kdb is even more ugly than core kdb, so it would need a major cleanup first.

#19 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 2 lines · Louis Rilling

Do you intend to support kdb modules? If yes, in which extent should they be adapted?

I think that would be a very low priority. What would be useful is the hack to load debuginfo into kdb so that it can pretty-print arbitrary structures. That alone would replace about 90% of the kdb modules I think.

And yes, that code in current kdb is even more ugly than core kdb, so it would need a major cleanup first.

I was thinking about custom KDB modules, but I agree that most of them could be replaced by pretty-print of arbitrary structures.

Thanks,

Louis

Signature · 4 lines
Dr Louis Rilling			Kerlabs
Skype: louis.rilling			Batiment Germanium
Phone: (+33|0) 6 80 89 08 23		80 avenue des Buttes de Coesmes
http://www.kerlabs.com/			35700 Rennes
#20 lore raw
In reply to Jason Wessel
Quoted 3 lines · Jason Wessel

This patch series is a request for comments on several levels.

1) Do people find kdb useful? (See * and **)

Yes.

Quoted 1 line

2) Would kdb folks be willing to use it if it was a front end to kgdb?

Yes.

Quoted 1 line

3) Does kdb have a future in the mainline kernel?

Well, if someone invest the effort to clean it up, cut it into small mergeable pieces and gets it done.

Quoted 2 lines

4) Is this a reasonable approach to have some level of unification to end up with a more robust kernel debugger?

Sounds fine to me.

Quoted 5 lines

To get the most basic functionality, you only need the first 2 patches in the series. The remainder of the patches go on to incrementally add back some of the functionality that was removed from kdb. I made an attempt to try to make the first part just the generic set of changes required to get kdb working on 1 or more archs.

Patch 1 still containes a lot random junk. E.g. all those meminfo and whatever hooks aren't required for a very basic kernel debugger.

#21 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Jason Wessel

This patch series is a request for comments on several levels.

2) Would kdb folks be willing to use it if it was a front end to kgdb?

Yes.

absolutely.

Quoted 4 lines
Quoted 1 line

3) Does kdb have a future in the mainline kernel?

Well, if someone invest the effort to clean it up, cut it into small mergeable pieces and gets it done.

I'll play with these patches later today, Jason.

Thanks for getting this patchset out.
mh