diff options
Diffstat (limited to 'arch/x86/kernel/kgdb.c')
-rw-r--r-- | arch/x86/kernel/kgdb.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c index db6720edfdd0..8bfb6146f753 100644 --- a/arch/x86/kernel/kgdb.c +++ b/arch/x86/kernel/kgdb.c | |||
@@ -43,6 +43,8 @@ | |||
43 | #include <linux/smp.h> | 43 | #include <linux/smp.h> |
44 | #include <linux/nmi.h> | 44 | #include <linux/nmi.h> |
45 | #include <linux/hw_breakpoint.h> | 45 | #include <linux/hw_breakpoint.h> |
46 | #include <linux/uaccess.h> | ||
47 | #include <linux/memory.h> | ||
46 | 48 | ||
47 | #include <asm/debugreg.h> | 49 | #include <asm/debugreg.h> |
48 | #include <asm/apicdef.h> | 50 | #include <asm/apicdef.h> |
@@ -741,6 +743,64 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip) | |||
741 | regs->ip = ip; | 743 | regs->ip = ip; |
742 | } | 744 | } |
743 | 745 | ||
746 | int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) | ||
747 | { | ||
748 | int err; | ||
749 | char opc[BREAK_INSTR_SIZE]; | ||
750 | |||
751 | bpt->type = BP_BREAKPOINT; | ||
752 | err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr, | ||
753 | BREAK_INSTR_SIZE); | ||
754 | if (err) | ||
755 | return err; | ||
756 | err = probe_kernel_write((char *)bpt->bpt_addr, | ||
757 | arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE); | ||
758 | #ifdef CONFIG_DEBUG_RODATA | ||
759 | if (!err) | ||
760 | return err; | ||
761 | /* | ||
762 | * It is safe to call text_poke() because normal kernel execution | ||
763 | * is stopped on all cores, so long as the text_mutex is not locked. | ||
764 | */ | ||
765 | if (mutex_is_locked(&text_mutex)) | ||
766 | return -EBUSY; | ||
767 | text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr, | ||
768 | BREAK_INSTR_SIZE); | ||
769 | err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE); | ||
770 | if (err) | ||
771 | return err; | ||
772 | if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE)) | ||
773 | return -EINVAL; | ||
774 | bpt->type = BP_POKE_BREAKPOINT; | ||
775 | #endif /* CONFIG_DEBUG_RODATA */ | ||
776 | return err; | ||
777 | } | ||
778 | |||
779 | int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) | ||
780 | { | ||
781 | #ifdef CONFIG_DEBUG_RODATA | ||
782 | int err; | ||
783 | char opc[BREAK_INSTR_SIZE]; | ||
784 | |||
785 | if (bpt->type != BP_POKE_BREAKPOINT) | ||
786 | goto knl_write; | ||
787 | /* | ||
788 | * It is safe to call text_poke() because normal kernel execution | ||
789 | * is stopped on all cores, so long as the text_mutex is not locked. | ||
790 | */ | ||
791 | if (mutex_is_locked(&text_mutex)) | ||
792 | goto knl_write; | ||
793 | text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE); | ||
794 | err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE); | ||
795 | if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE)) | ||
796 | goto knl_write; | ||
797 | return err; | ||
798 | knl_write: | ||
799 | #endif /* CONFIG_DEBUG_RODATA */ | ||
800 | return probe_kernel_write((char *)bpt->bpt_addr, | ||
801 | (char *)bpt->saved_instr, BREAK_INSTR_SIZE); | ||
802 | } | ||
803 | |||
744 | struct kgdb_arch arch_kgdb_ops = { | 804 | struct kgdb_arch arch_kgdb_ops = { |
745 | /* Breakpoint instruction: */ | 805 | /* Breakpoint instruction: */ |
746 | .gdb_bpt_instr = { 0xcc }, | 806 | .gdb_bpt_instr = { 0xcc }, |