mdb: Merkey's Kernel Debugger 2.6.27-rc1
PATCH 2/25 mdb: Merkey's Kernel Debugger 2.6.27-rc1
Netware style debugger for Linux written by Jeffrey Vernon Merkey
arch/x86/kernel/traps_32.c +18 -1
@@ -46,6 +46,16 @@#include <linux/edac.h> #endif +#ifdef CONFIG_MDB +#define DEBUGGER_EXCEPTION 1 +#define NMI_EXCEPTION 2 +#define BREAKPOINT_EXCEPTION 3 +#define SOFTWARE_EXCEPTION 22 + +extern unsigned char *mdb_oops; +extern int mdb (int reason,int error,void *frame); +#endif +#include <asm/arch_hooks.h> #include <asm/stacktrace.h> #include <asm/processor.h>
@@ -452,8 +462,15 @@*/ void die (const char *str,struct pt_regs *regs,long err) { -unsigned long flags =oops_begin (); +#ifdef CONFIG_MDB +unsigned long flags; + mdb_oops = (unsigned char *)str; +mdb (SOFTWARE_EXCEPTION , err, regs); + flags =oops_begin (); +#else +unsigned long flags =oops_begin (); +#endif if (die_nest_count <3 ) {report_bug (regs->ip, regs);
@@ -573,7 +590,7 @@ } DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV,
regs->ip)
-#ifndef CONFIG_KPROBES
+#if !defined(CONFIG_KPROBES) && !defined(CONFIG_MDB)
DO_VM86_ERROR(3, SIGTRAP, "int3", int3)
#endif
DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
@@ -718,6 +735,9 @@
{
if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) ==NOTIFY_STOP)
return;
+#ifdef CONFIG_MDB
+ mdb(NMI_EXCEPTION, reason, regs); // nmi is code 2
+#endif
#ifdef CONFIG_MCA
/*
* Might actually be able to figure out what the guilty party
@@ -756,6 +776,9 @@
printk(" on CPU%d, ip %08lx, registers:\n",
smp_processor_id(), regs->ip);
show_registers(regs);
+#ifdef CONFIG_MDB
+ mdb(NMI_EXCEPTION, 0, regs); // nmi is code 2
+#endif
if (do_panic)
panic("Non maskable interrupt");
console_silent();
@@ -785,6 +808,10 @@
if (!cpu)
reason = get_nmi_reason();
+#if defined(CONFIG_SMP) && defined(CONFIG_MDB)
+ if (mdb(NMI_EXCEPTION, 0, regs))
+ return;
+#endif
if (!(reason & 0xc0)) {
if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
== NOTIFY_STOP)
@@ -850,6 +877,10 @@
#ifdef CONFIG_KPROBES
void __kprobes do_int3(struct pt_regs *regs, long error_code)
{
+#ifdef CONFIG_MDB
+ if (mdb(BREAKPOINT_EXCEPTION, error_code, regs))
+ return;
+#endif
trace_hardirqs_fixup();
if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
@@ -865,6 +896,16 @@
}
#endif
+#if defined(CONFIG_MDB) && !defined(CONFIG_KPROBES) +fastcall void do_int3(struct pt_regs * regs, long error_code) +{
+#ifdef CONFIG_MDB
+ if (mdb(BREAKPOINT_EXCEPTION, error_code, regs))
+ return;
+#endif
+ do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
+}
+#endif /* CONFIG_KDB && !CONFIG_KPROBES */
/*
* Our handling of the processor debug registers is non-trivial.
* We do not clear them on entry and exit from the kernel. Therefore
@@ -895,6 +936,10 @@
trace_hardirqs_fixup();
get_debugreg(condition, 6);
+#ifdef CONFIG_MDB
+ if (mdb(DEBUGGER_EXCEPTION, error_code, regs))
+ return;
+#endif
/*
* The processor cleared BTF, so don't mark that we need it set.
By making a contribution to this project, I certify that the contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file.
Jeffrey Vernon Merkey
Quoted 4 lines · [email protected] wrote:
Netware style debugger for Linux written by Jeffrey Vernon Merkey
arch/x86/kernel/traps_32.c +0
-0
...
Quoted 4 lines
arch/x86/kernel/traps_32.c +0
-0@@ -865,6 +896,16 @@ }#endif
arch/x86/kernel/traps_32.c line 908
Quoted 10 lines
arch/x86/kernel/traps_32.c +10
-0+#if defined(CONFIG_MDB ) && !defined(CONFIG_KPROBES ) +fastcall void do_int3(struct pt_regs * regs, long error_code) +{ +#ifdef CONFIG_MDB +if (mdb (BREAKPOINT_EXCEPTION , error_code, regs)) +return ; +#endif +do_trap (3 ,SIGTRAP ,"int3" ,1 , regs, error_code,NULL ); +} +#endif /* CONFIG_KDB && !CONFIG_KPROBES */
The inner #ifdef is always true.
Quoted 4 lines
arch/x86/kernel/traps_32.c +0
-0/* * Our handling of the processor debug registers is non-trivial. * We do not clear them on entry and exit from the kernel. Therefore
arch/x86/kernel/traps_32.c line 945
Quoted 10 lines
arch/x86/kernel/traps_32.c +4
-0@@ -895,6 +936,10 @@trace_hardirqs_fixup ();get_debugreg (condition,6 ); +#ifdef CONFIG_MDB +if (mdb (DEBUGGER_EXCEPTION , error_code, regs)) +return ; +#endif /* * The processor cleared BTF, so don't mark that we need it set.
I wonder if it would be beneficial to
- include an mdb header file in source files like this one,
- in the mdb header, define mdb() as a static inline function which does nothing but return false if CONFIG_MDB is not defined.
Would get rid of the visual clutter introduced by #ifdef/#endif and catch potential syntax errors when people later modify this code. I assume that a compiler is used which eliminates code properly when mdb() is nothing but constant false...
Signature · 3 lines
Stefan Richter -=====-==--- =--- --=-- http://arcgraph.de/sr/