[RFC PATCH -tip 07/16] kdb: Provide original instruction modified bysw breakpoint

From: Masami Hiramatsu
Date: Sun Apr 01 2012 - 12:03:38 EST


Add kdb_get_saved_instr() for someone who needs to know
the original instruction in kernel text.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@xxxxxxxxx>
---
include/linux/kgdb.h | 1 +
kernel/debug/debug_core.c | 14 ++++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index fa39183..e1eb57c 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -209,6 +209,7 @@ extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
extern int kgdb_validate_break_address(unsigned long addr);
extern int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr);
extern int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle);
+extern int kgdb_get_saved_instr(unsigned long addr, unsigned char *buf);

/**
* kgdb_arch_late - Perform any architecture specific initalization.
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 1dc53ba..8982ba0 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -349,6 +349,20 @@ int kgdb_isremovedbreak(unsigned long addr)
return 0;
}

+int kgdb_get_saved_instr(unsigned long addr, unsigned char *buf)
+{
+ int i;
+ for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+ if (kgdb_break[i].bpt_addr == addr &&
+ kgdb_break[i].state == BP_ACTIVE) {
+ memcpy(buf, kgdb_break[i].saved_instr,
+ BREAK_INSTR_SIZE);
+ return 1;
+ }
+ }
+ return 0;
+}
+
int dbg_remove_all_break(void)
{
unsigned long addr;

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