Skip to contentSkip to conversation

AArch64: KGDB support

PATCH Superseded vijay.kilari at gmail.com 3 participants 11 messages Sep 30, 2013 – Oct 11, 2013 arm64

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover AArch64: KGDB support

From: Vijaya Kumar K <[email protected]>

Based on the step-handler and break-handler hooks patch from Sandeepa (Patch 1), KGDB debugging support is added for EL1 debug in AArch64 mode. Any updates that come for Patch 1 from Sandeepa will be rebased in next version

With first patch,register layout is updated to be inline with GDB tool. Basic GDB connection, break point set/clear and info commands are supported except step/next debugging

With second patch, step/next debugging support is added, where in pc is updated to point to the instruction to be stepped and stopped.

v2:
- Moved break instruction encoding to debug-monitors.h file
- Fixed endianess of compile break instruction encoding
- Updated I/O buffer sizes
- Updated register buffer size
- Remove changes to debug_exception handler in entry.S for
- ELR update and step debugging with update pc instead of ELR
- Rebased against AArch64 upstream kernel

v1:
- Initial patch-set

Tested with Aarch64 GDB tool chain on simulator

Sandeepa Prabhu (1):
AArch64: Add single-step and breakpoint handler hooks

Vijaya Kumar K (2):
AArch64: KGDB: Add Basic KGDB support
AArch64: KGDB: Add step debugging support

 arch/arm64/include/asm/debug-monitors.h |   30 +++
 arch/arm64/include/asm/kgdb.h           |   81 ++++++++
 arch/arm64/kernel/Makefile              |    1 +
 arch/arm64/kernel/debug-monitors.c      |   95 ++++++++-
 arch/arm64/kernel/entry.S               |    6 +-
 arch/arm64/kernel/kgdb.c                |  341 +++++++++++++++++++++++++++++++
 6 files changed, 550 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm64/include/asm/kgdb.h
 create mode 100644 arch/arm64/kernel/kgdb.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/3 AArch64: Add single-step and breakpoint handler hooks

From: Sandeepa Prabhu <[email protected]>

AArch64 Single Steping and Breakpoint debug exceptions will be used by multiple debug framworks like kprobes & kgdb.

This patch implements the hooks for those frameworks to register their own handlers for handling breakpoint and single step events.

Reworked the debug exception handler in entry.S: do_dbg to pass the correct break/step address to the handlers, i.e. FAR_EL1 if exception is watchpoint, ELR_EL1 for all other debug exceptions.

---
 arch/arm64/include/asm/debug-monitors.h |   20 +++++++
 arch/arm64/kernel/debug-monitors.c      |   95 ++++++++++++++++++++++++++++++-
 arch/arm64/kernel/entry.S               |    6 +-
 3 files changed, 117 insertions(+), 4 deletions(-)
arch/arm64/include/asm/debug-monitors.h +20 -0
index a2232d0..19e429e 100644
@@ -16,6 +16,8 @@
 #ifndef __ASM_DEBUG_MONITORS_H
 #define __ASM_DEBUG_MONITORS_H
 
+#include <linux/list.h>
+
 #ifdef __KERNEL__
 
 #define	DBG_ESR_EVT(x)		(((x) >> 27) & 0x7)
@@ -62,6 +64,24 @@ struct task_struct;
 
 #define DBG_ARCH_ID_RESERVED	0	/* In case of ptrace ABI updates. */
 
+struct step_hook {
+	struct list_head node;
+	int (*fn)(struct pt_regs *regs, unsigned int esr, unsigned long addr);
+};
+
+void register_step_hook(struct step_hook *hook);
+void unregister_step_hook(struct step_hook *hook);
+
+struct break_hook {
+	struct list_head node;
+	u32 esr_val;
+	u32 esr_mask;
+	int (*fn)(struct pt_regs *regs, unsigned int esr, unsigned long addr);
+};
+
+void register_break_hook(struct break_hook *hook);
+void unregister_break_hook(struct break_hook *hook);
+
 u8 debug_monitors_arch(void);
 
 void enable_debug_monitors(enum debug_el el);
arch/arm64/kernel/debug-monitors.c +92 -3

124 lines not on this page · raw message

arch/arm64/kernel/entry.S +5 -1
index 3881fd1..9589242 100644
@@ -288,8 +288,12 @@ el1_dbg:
 	/*
 	 * Debug exception handling
 	 */
+	cmp	x24, #ESR_EL1_EC_BRK64		// if BRK64
+	cinc	x24, x24, eq			// set bit '0'
 	tbz	x24, #0, el1_inv		// EL1 only
-	mrs	x0, far_el1
+	mrs	x25, far_el1			// Watchpoint location
+	cmp	x24, #ESR_EL1_EC_WATCHPT_EL1
+	csel	x0, x25, x22, eq	// addr: x25->far_el1, x22->elr_el1
 	mov	x2, sp				// struct pt_regs
 	bl	do_debug_exception
 
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

In reply to vijay.kilari at gmail.com

From: Vijaya Kumar K <[email protected]>

Add KGDB debug support for kernel debugging.
With this patch, basic KGDB debugging is possible.GDB register layout is updated and GDB tool can establish connection with target and can set/clear breakpoints.

---
 arch/arm64/include/asm/debug-monitors.h |   10 ++
 arch/arm64/include/asm/kgdb.h           |   81 +++++++++
 arch/arm64/kernel/Makefile              |    1 +
 arch/arm64/kernel/kgdb.c                |  298 +++++++++++++++++++++++++++++++
 4 files changed, 390 insertions(+)
arch/arm64/include/asm/debug-monitors.h +10 -0
index 19e429e..ed376ce 100644
@@ -28,6 +28,16 @@
 #define DBG_ESR_EVT_HWWP	0x2
 #define DBG_ESR_EVT_BRK		0x6
 
+/*
+ * Break point instruction encoding
+ */
+#define BREAK_INSTR_SIZE		4
+#define KGDB_BREAKINST_ESR_VAL		0xf2000000
+#define KGDB_COMPILED_BREAK_ESR_VAL	0xf2000001
+#define KGDB_ARM64_COMPILE_BRK_IMM	1
+#define CACHE_FLUSH_IS_SAFE		1
+
+
 enum debug_el {
 	DBG_ACTIVE_EL0 = 0,
 	DBG_ACTIVE_EL1,
arch/arm64/include/asm/kgdb.h new file +81 -0

81 lines not on this page · raw message

arch/arm64/kernel/Makefile +1 -0
index 7b4b564..69613bb 100644
@@ -18,6 +18,7 @@ arm64-obj-$(CONFIG_SMP)			+= smp.o smp_spin_table.o smp_psci.o
 arm64-obj-$(CONFIG_HW_PERF_EVENTS)	+= perf_event.o
 arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o
 arm64-obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
+arm64-obj-$(CONFIG_KGDB)		+= kgdb.o
 
 obj-y					+= $(arm64-obj-y) vdso/
 obj-m					+= $(arm64-obj-m)
arch/arm64/kernel/kgdb.c new file +298 -0

298 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

Quoted 21 lines · vijay.kilari at gmail.com

From: Vijaya Kumar K <[email protected]>

Add KGDB debug support for kernel debugging.
With this patch, basic KGDB debugging is possible.GDB register layout is updated and GDB tool can establish connection with target and can set/clear breakpoints.

---
 arch/arm64/include/asm/debug-monitors.h |   10 ++
 arch/arm64/include/asm/kgdb.h           |   81 +++++++++
 arch/arm64/kernel/Makefile              |    1 +
 arch/arm64/kernel/kgdb.c                |  298 +++++++++++++++++++++++++++++++
 4 files changed, 390 insertions(+)
arch/arm64/include/asm/debug-monitors.h +0 -0
index 19e429e..ed376ce 100644
@@ -28,6 +28,16 @@
 #define DBG_ESR_EVT_HWWP       0x2

arch/arm64/include/asm/debug-monitors.h line 38

Quoted 10 lines
arch/arm64/include/asm/debug-monitors.h +8 -0
 #define DBG_ESR_EVT_BRK                0x6
 
+/*
+ * Break point instruction encoding
+ */
+#define BREAK_INSTR_SIZE               4
+#define KGDB_BREAKINST_ESR_VAL         0xf2000000
+#define KGDB_COMPILED_BREAK_ESR_VAL    0xf2000001
+#define KGDB_ARM64_COMPILE_BRK_IMM     1
+#define CACHE_FLUSH_IS_SAFE            1

#define DBG_BRK_KGDB_DYN 0
#define DBG_BRK_KGDB_COMPILED 1

#define DBG_ESR_VAL_BRK(x) (0xf2000000 | ((x) & 0xffff))

Then you can use the latter to construct your ESR values dynamically and adding a new brk handler is straightforward.

Quoted 29 lines
arch/arm64/include/asm/kgdb.h new file +23 -0
new file mode 100644
index 0000000..15b36fd
@@ -0,0 +1,81 @@
+/*
+ * AArch64 KGDB support
+ *
+ * Based on arch/arm/include/kgdb.h
+ *
+ * Copyright (C) 2013 Cavium Inc.
+ * Author: Vijaya Kumar K <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ARM_KGDB_H__
+#define __ARM_KGDB_H__

arch/arm64/include/asm/kgdb.h line 33

Quoted 10 lines
arch/arm64/include/asm/kgdb.h new file +10 -0
+
+#include <linux/ptrace.h>
+#include <asm/debug-monitors.h>
+
+#ifndef        __ASSEMBLY__
+
+static inline void arch_kgdb_breakpoint(void)
+{
+       asm ("brk %0" :: "I" (KGDB_ARM64_COMPILE_BRK_IMM));
+}

Hmm, I need to find me a compiler guy, but I don't have much faith in this function in the face of inlining. Sure a breakpoint needs to happen at a specific point in the program? If so, why can't GCC re-order this asm block as it likes?

Or is there a restricted use-case for compiled breakpoints in kgdb?

arch/arm64/include/asm/kgdb.h line 43

Quoted 10 lines
arch/arm64/include/asm/kgdb.h new file +10 -0
+void
+sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
+{
+       struct pt_regs *thread_regs;
+       int regno;
+       int i;
+
+       /* Just making sure... */
+       if (task == NULL)
+               return;

Erm... that comment just raises more questions. I appreciate ARM has the same check, but why doesn't x86? Can task *actually* be NULL?

arch/arm64/include/asm/kgdb.h line 47

Quoted 4 lines
arch/arm64/include/asm/kgdb.h new file +4 -0
+
+       /* Initialize to zero */
+       for (regno = 0; regno < DBG_MAX_REG_NUM; regno++)
+               gdb_regs[regno] = 0;

memset?

arch/arm64/include/asm/kgdb.h line 52

Quoted 5 lines
arch/arm64/include/asm/kgdb.h new file +5 -0
+
+       thread_regs             = task_pt_regs(task);
+
+       for(i = 0; i < 31; i++)
+               gdb_regs[i] = thread_regs->regs[i];

memcpy?

Quoted 133 lines
arch/arm64/include/asm/kgdb.h new file +133 -0
+int kgdb_arch_handle_exception(int exception_vector, int signo,
+                              int err_code, char *remcom_in_buffer,
+                              char *remcom_out_buffer,
+                              struct pt_regs *linux_regs)
+{
+       unsigned long addr;
+       char *ptr;
+       int err;
+
+       switch (remcom_in_buffer[0]) {
+       case 'D':
+       case 'k':
+       case 'c':
+               /*
+                * Packet D (Detach), k (kill) & c (Continue) requires
+                * to continue executing. Set pc to required address.
+                * Try to read optional parameter, pc unchanged if no parm.
+                * If this was a compiled breakpoint, we need to move
+                * to the next instruction or we will just breakpoint
+                * over and over again.
+                */
+               ptr = &remcom_in_buffer[1];
+               if (kgdb_hex2long(&ptr, &addr))
+                       kgdb_arch_set_pc(linux_regs, addr);
+               else if (compiled_break == 1)
+                       kgdb_arch_set_pc(linux_regs, linux_regs->pc + 4);
+
+               compiled_break = 0;
+
+               err = 0;
+               break;
+       default:
+               err = -1;
+       }
+       return err;
+}
+
+static int
+kgdb_brk_fn(struct pt_regs *regs, unsigned int esr, unsigned long addr)
+{
+       kgdb_handle_exception(1, SIGTRAP, 0, regs);
+       return 0;
+}
+
+static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr,
+                               unsigned long addr)
+{
+       compiled_break = 1;
+       kgdb_handle_exception(1, SIGTRAP, 0, regs);
+
+       return 0;
+}
+
+static struct break_hook kgdb_brkpt_hook = {
+       .esr_mask               = 0xffffffff,
+       .esr_val                = KGDB_BREAKINST_ESR_VAL,
+       .fn                     = kgdb_brk_fn
+};
+
+static struct break_hook kgdb_compiled_brkpt_hook = {
+       .esr_mask               = 0xffffffff,
+       .esr_val                = KGDB_COMPILED_BREAK_ESR_VAL,
+       .fn                     = kgdb_compiled_brk_fn
+};
+
+static void kgdb_call_nmi_hook(void *ignored)
+{
+       kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
+}
+
+void kgdb_roundup_cpus(unsigned long flags)
+{
+       local_irq_enable();
+       smp_call_function(kgdb_call_nmi_hook, NULL, 0);
+       local_irq_disable();
+}
+
+static int __kgdb_notify(struct die_args *args, unsigned long cmd)
+{
+       struct pt_regs *regs = args->regs;
+
+       if (kgdb_handle_exception(1, args->signr, cmd, regs))
+               return NOTIFY_DONE;
+       return NOTIFY_STOP;
+}
+
+static int
+kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
+{
+       unsigned long flags;
+       int ret;
+
+       local_irq_save(flags);
+       ret = __kgdb_notify(ptr, cmd);
+       local_irq_restore(flags);
+
+       return ret;
+}
+
+static struct notifier_block kgdb_notifier = {
+       .notifier_call  = kgdb_notify,
+       .priority       = -INT_MAX,
+};
+
+
+/*
+ *     kgdb_arch_init - Perform any architecture specific initalization.
+ *
+ *     This function will handle the initalization of any architecture
+ *     specific callbacks.
+ */
+int kgdb_arch_init(void)
+{
+       int ret = register_die_notifier(&kgdb_notifier);
+
+       if (ret != 0)
+               return ret;
+
+       register_break_hook(&kgdb_brkpt_hook);
+       register_break_hook(&kgdb_compiled_brkpt_hook);
+
+       return 0;
+}
+
+/*
+ *     kgdb_arch_exit - Perform any architecture specific uninitalization.
+ *
+ *     This function will handle the uninitalization of any architecture
+ *     specific callbacks, for dynamic registration and unregistration.
+ */
+void kgdb_arch_exit(void)
+{
+       unregister_break_hook(&kgdb_brkpt_hook);

arch/arm64/include/asm/kgdb.h

Quoted 10 lines
arch/arm64/include/asm/kgdb.h new file +10 -0
+       unregister_break_hook(&kgdb_compiled_brkpt_hook);
+       unregister_die_notifier(&kgdb_notifier);
+}
+
+/*
+ * ARM instructions are always in LE.
+ * Break instruction is encoded in LE format
+ */
+struct kgdb_arch arch_kgdb_ops = {
+       .gdb_bpt_instr          = {0x00, 0x00, 0x20, 0xd4}

Again, you should probably try and encode the dynamic breakpoint immediate in here (which is sadly offset by 5 bits in the instruction encoding).

Will

#4 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

Quoted 36 lines · Will Deacon
Quoted 21 lines · vijay.kilari at gmail.com

From: Vijaya Kumar K <[email protected]>

Add KGDB debug support for kernel debugging.
With this patch, basic KGDB debugging is possible.GDB register layout is updated and GDB tool can establish connection with target and can set/clear breakpoints.

---
 arch/arm64/include/asm/debug-monitors.h |   10 ++
 arch/arm64/include/asm/kgdb.h           |   81 +++++++++
 arch/arm64/kernel/Makefile              |    1 +
 arch/arm64/kernel/kgdb.c                |  298 +++++++++++++++++++++++++++++++
 4 files changed, 390 insertions(+)
arch/arm64/include/asm/debug-monitors.h +0 -0
index 19e429e..ed376ce 100644
@@ -28,6 +28,16 @@
 #define DBG_ESR_EVT_HWWP       0x2

arch/arm64/include/asm/debug-monitors.h line 38

Quoted 10 lines
arch/arm64/include/asm/debug-monitors.h +8 -0
 #define DBG_ESR_EVT_BRK                0x6
 
+/*
+ * Break point instruction encoding
+ */
+#define BREAK_INSTR_SIZE               4
+#define KGDB_BREAKINST_ESR_VAL         0xf2000000
+#define KGDB_COMPILED_BREAK_ESR_VAL    0xf2000001
+#define KGDB_ARM64_COMPILE_BRK_IMM     1
+#define CACHE_FLUSH_IS_SAFE            1

#define DBG_BRK_KGDB_DYN 0
#define DBG_BRK_KGDB_COMPILED 1

Quoted 5 lines

#define DBG_ESR_VAL_BRK(x) (0xf2000000 | ((x) & 0xffff))

Then you can use the latter to construct your ESR values dynamically and adding a new brk handler is straightforward.

OK, agreed

Quoted 45 lines
Quoted 29 lines
arch/arm64/include/asm/kgdb.h new file +23 -0
new file mode 100644
index 0000000..15b36fd
@@ -0,0 +1,81 @@
+/*
+ * AArch64 KGDB support
+ *
+ * Based on arch/arm/include/kgdb.h
+ *
+ * Copyright (C) 2013 Cavium Inc.
+ * Author: Vijaya Kumar K <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ARM_KGDB_H__
+#define __ARM_KGDB_H__

arch/arm64/include/asm/kgdb.h line 33

Quoted 10 lines
arch/arm64/include/asm/kgdb.h new file +10 -0
+
+#include <linux/ptrace.h>
+#include <asm/debug-monitors.h>
+
+#ifndef        __ASSEMBLY__
+
+static inline void arch_kgdb_breakpoint(void)
+{
+       asm ("brk %0" :: "I" (KGDB_ARM64_COMPILE_BRK_IMM));
+}

Hmm, I need to find me a compiler guy, but I don't have much faith in this function in the face of inlining. Sure a breakpoint needs to happen at a specific point in the program? If so, why can't GCC re-order this asm block as it likes?

Quoted 2 lines

Or is there a restricted use-case for compiled breakpoints in kgdb?

As per Andrew,
arch_kgdb_breakpoint is declared as static inline for the x86, arm, tile and powerpc. Since the inline-asm does not have any output constraints it is considered volatile just like if you declare the inline-asm as volatile. The compiler might reorder some stuff around it due to all uses being explicit just like any other volatile inline-asm.

In fact, the arch_kgdb_breakpoint is called from only one place from kernel/debug/debug_core.c and there is no way for the compiler to reorder the block
as it has two write barriers around it:

        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */
Quoted 5 lines
Quoted 5 lines
arch/arm64/include/asm/kgdb.h new file +5 -0
+void
+sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
+{
+       struct pt_regs *thread_regs;
+       int regno;
Quoted 9 lines

arch/arm64/include/asm/kgdb.h line 43

Quoted 5 lines
arch/arm64/include/asm/kgdb.h new file +5 -0
+       int i;
+
+       /* Just making sure... */
+       if (task == NULL)
+               return;

Erm... that comment just raises more questions. I appreciate ARM has the same check, but why doesn't x86? Can task *actually* be NULL?

generally, the task will not be NULL. The check made because the caller (gdbstub.c)
fetches task information from gdb global structure and calls this function. This helps in case the caller fails to pass task info. I think should not be problem with this check. In fact this is legacy code

Quoted 6 lines

arch/arm64/include/asm/kgdb.h line 47

Quoted 4 lines
arch/arm64/include/asm/kgdb.h new file +4 -0
+
+       /* Initialize to zero */
+       for (regno = 0; regno < DBG_MAX_REG_NUM; regno++)
+               gdb_regs[regno] = 0;

memset?

OK. agreed

Quoted 9 lines

arch/arm64/include/asm/kgdb.h line 52

Quoted 6 lines
arch/arm64/include/asm/kgdb.h new file +5 -0
+
+       thread_regs             = task_pt_regs(task);
+
+       for(i = 0; i < 31; i++)
+               gdb_regs[i] = thread_regs->regs[i];

memcpy?

OK. agreed

Quoted 138 lines
Quoted 138 lines
arch/arm64/include/asm/kgdb.h new file +138 -0
+int kgdb_arch_handle_exception(int exception_vector, int signo,
+                              int err_code, char *remcom_in_buffer,
+                              char *remcom_out_buffer,
+                              struct pt_regs *linux_regs)
+{
+       unsigned long addr;
+       char *ptr;
+       int err;
+
+       switch (remcom_in_buffer[0]) {
+       case 'D':
+       case 'k':
+       case 'c':
+               /*
+                * Packet D (Detach), k (kill) & c (Continue) requires
+                * to continue executing. Set pc to required address.
+                * Try to read optional parameter, pc unchanged if no parm.
+                * If this was a compiled breakpoint, we need to move
+                * to the next instruction or we will just breakpoint
+                * over and over again.
+                */
+               ptr = &remcom_in_buffer[1];
+               if (kgdb_hex2long(&ptr, &addr))
+                       kgdb_arch_set_pc(linux_regs, addr);
+               else if (compiled_break == 1)
+                       kgdb_arch_set_pc(linux_regs, linux_regs->pc + 4);
+
+               compiled_break = 0;
+
+               err = 0;
+               break;
+       default:
+               err = -1;
+       }
+       return err;
+}
+
+static int
+kgdb_brk_fn(struct pt_regs *regs, unsigned int esr, unsigned long addr)
+{
+       kgdb_handle_exception(1, SIGTRAP, 0, regs);
+       return 0;
+}
+
+static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr,
+                               unsigned long addr)
+{
+       compiled_break = 1;
+       kgdb_handle_exception(1, SIGTRAP, 0, regs);
+
+       return 0;
+}
+
+static struct break_hook kgdb_brkpt_hook = {
+       .esr_mask               = 0xffffffff,
+       .esr_val                = KGDB_BREAKINST_ESR_VAL,
+       .fn                     = kgdb_brk_fn
+};
+
+static struct break_hook kgdb_compiled_brkpt_hook = {
+       .esr_mask               = 0xffffffff,
+       .esr_val                = KGDB_COMPILED_BREAK_ESR_VAL,
+       .fn                     = kgdb_compiled_brk_fn
+};
+
+static void kgdb_call_nmi_hook(void *ignored)
+{
+       kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
+}
+
+void kgdb_roundup_cpus(unsigned long flags)
+{
+       local_irq_enable();
+       smp_call_function(kgdb_call_nmi_hook, NULL, 0);
+       local_irq_disable();
+}
+
+static int __kgdb_notify(struct die_args *args, unsigned long cmd)
+{
+       struct pt_regs *regs = args->regs;
+
+       if (kgdb_handle_exception(1, args->signr, cmd, regs))
+               return NOTIFY_DONE;
+       return NOTIFY_STOP;
+}
+
+static int
+kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
+{
+       unsigned long flags;
+       int ret;
+
+       local_irq_save(flags);
+       ret = __kgdb_notify(ptr, cmd);
+       local_irq_restore(flags);
+
+       return ret;
+}
+
+static struct notifier_block kgdb_notifier = {
+       .notifier_call  = kgdb_notify,
+       .priority       = -INT_MAX,
+};
+
+
+/*
+ *     kgdb_arch_init - Perform any architecture specific initalization.
+ *
+ *     This function will handle the initalization of any architecture
+ *     specific callbacks.
+ */
+int kgdb_arch_init(void)
+{
+       int ret = register_die_notifier(&kgdb_notifier);
+
+       if (ret != 0)
+               return ret;
+
+       register_break_hook(&kgdb_brkpt_hook);
+       register_break_hook(&kgdb_compiled_brkpt_hook);
+
+       return 0;
+}
+
+/*
+ *     kgdb_arch_exit - Perform any architecture specific uninitalization.
+ *
+ *     This function will handle the uninitalization of any architecture
+ *     specific callbacks, for dynamic registration and unregistration.
+ */
+void kgdb_arch_exit(void)
+{
+       unregister_break_hook(&kgdb_brkpt_hook);
+       unregister_break_hook(&kgdb_compiled_brkpt_hook);
+       unregister_die_notifier(&kgdb_notifier);
+}
+
+/*
Quoted 9 lines

arch/arm64/include/asm/kgdb.h

Quoted 5 lines

+ * ARM instructions are always in LE.
+ * Break instruction is encoded in LE format
+ */

arch/arm64/include/asm/kgdb.h new file +2 -0
+struct kgdb_arch arch_kgdb_ops = {
+       .gdb_bpt_instr          = {0x00, 0x00, 0x20, 0xd4}

Again, you should probably try and encode the dynamic breakpoint immediate in here (which is sadly offset by 5 bits in the instruction encoding).

Yes, I propose to change like this

#define  KGDB_DYN_BRK_INS_BYTE0  ((KGDB_DYN_DGB_BRK_IMM & 0x7) << 5)
#define  KGDB_DYN_BRK_INS_BYTE1  ((KGDB_DYN_DGB_BRK_IMM & 0x7f8) >> 3)
#define  KGDB_DYN_BRK_INS_BYTE2  (0x20 | \
                                 ((KGDB_DYN_DGB_BRK_IMM & 0xf800) >> 11))

#define KGDB_DYN_BRK_INS_BYTE3 0xd4

struct kgdb_arch arch_kgdb_ops = {
        .gdb_bpt_instr          = {
                KGDB_DYN_BRK_INS_BYTE0,
                KGDB_DYN_BRK_INS_BYTE1,
                KGDB_DYN_BRK_INS_BYTE2,
                KGDB_DYN_BRK_INS_BYTE3
        }
};
Quoted 1 line

Will

#5 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

Quoted 21 lines · Vijay Kilari
Quoted 11 lines · Will Deacon

arch/arm64/include/asm/kgdb.h line 33

Quoted 4 lines · vijay.kilari at gmail.com
arch/arm64/include/asm/kgdb.h new file +4 -0
+static inline void arch_kgdb_breakpoint(void)
+{
+       asm ("brk %0" :: "I" (KGDB_ARM64_COMPILE_BRK_IMM));
+}

Hmm, I need to find me a compiler guy, but I don't have much faith in this function in the face of inlining. Sure a breakpoint needs to happen at a specific point in the program? If so, why can't GCC re-order this asm block as it likes?

Quoted 2 lines

Or is there a restricted use-case for compiled breakpoints in kgdb?

As per Andrew,
arch_kgdb_breakpoint is declared as static inline for the x86, arm, tile and powerpc. Since the inline-asm does not have any output constraints it is considered volatile just like if you declare the inline-asm as volatile. The compiler might reorder some stuff around it due to all uses being explicit just like any other volatile inline-asm.

Quoted 7 lines

In fact, the arch_kgdb_breakpoint is called from only one place from kernel/debug/debug_core.c and there is no way for the compiler to reorder the block
as it has two write barriers around it:

        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */

A write barrier just looks like a memory clobber to the compiler, which isn't enough to stop this being reordered wrt breakpoints. In fact, I don't think is actually solvable with GCC since there is no way to emit a full scheduling barrier using asm constraints (we'd need an intrinsic I think).

You could try clobbering every register, but that's filthy, and will likely cause reload to generate some dreadful spills.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
arch/arm64/kernel/kgdb.c new file +5 -0
+void
+sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
+{
+       struct pt_regs *thread_regs;
+       int regno;
Quoted 9 lines

arch/arm64/kernel/kgdb.c line 132

Quoted 5 lines
arch/arm64/kernel/kgdb.c new file +5 -0
+       int i;
+
+       /* Just making sure... */
+       if (task == NULL)
+               return;

Erm... that comment just raises more questions. I appreciate ARM has the same check, but why doesn't x86? Can task *actually* be NULL?

Quoted 5 lines

generally, the task will not be NULL. The check made because the caller (gdbstub.c)
fetches task information from gdb global structure and calls this function. This helps in case the caller fails to pass task info. I think should not be problem with this check. In fact this is legacy code

Generally or always? Afaict, either other architectures have a bug here or we have a redundant check. Regardless, it should be made consistent.

Quoted 10 lines
Quoted 10 lines

arch/arm64/kernel/kgdb.c line 297

Quoted 6 lines
arch/arm64/kernel/kgdb.c new file +6 -0
+/*
+ * ARM instructions are always in LE.
+ * Break instruction is encoded in LE format
+ */
+struct kgdb_arch arch_kgdb_ops = {
+       .gdb_bpt_instr          = {0x00, 0x00, 0x20, 0xd4}

Again, you should probably try and encode the dynamic breakpoint immediate in here (which is sadly offset by 5 bits in the instruction encoding).

Quoted 7 lines

Yes, I propose to change like this

#define  KGDB_DYN_BRK_INS_BYTE0  ((KGDB_DYN_DGB_BRK_IMM & 0x7) << 5)
#define  KGDB_DYN_BRK_INS_BYTE1  ((KGDB_DYN_DGB_BRK_IMM & 0x7f8) >> 3)
#define  KGDB_DYN_BRK_INS_BYTE2  (0x20 | \
                                 ((KGDB_DYN_DGB_BRK_IMM & 0xf800) >> 11))

#define KGDB_DYN_BRK_INS_BYTE3 0xd4

This would be cleaner if you #defined the complete instruction encoding:

#define AARCH64_BREAK_MON 0xd4200000

#define KGDB_DYN_BRK_BYTE(x)	\
	(((AARCH64_BREAK_MON | KGDB_DYN_DGB_BRK_IMM) >> (x * 8)) & 0xff)

Will

#6 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

Quoted 30 lines · Will Deacon
Quoted 21 lines · Vijay Kilari
Quoted 11 lines · Will Deacon

arch/arm64/include/asm/kgdb.h line 33

Quoted 4 lines · vijay.kilari at gmail.com
arch/arm64/include/asm/kgdb.h new file +4 -0
+static inline void arch_kgdb_breakpoint(void)
+{
+       asm ("brk %0" :: "I" (KGDB_ARM64_COMPILE_BRK_IMM));
+}

Hmm, I need to find me a compiler guy, but I don't have much faith in this function in the face of inlining. Sure a breakpoint needs to happen at a specific point in the program? If so, why can't GCC re-order this asm block as it likes?

Quoted 2 lines

Or is there a restricted use-case for compiled breakpoints in kgdb?

As per Andrew,
arch_kgdb_breakpoint is declared as static inline for the x86, arm, tile and powerpc. Since the inline-asm does not have any output constraints it is considered volatile just like if you declare the inline-asm as volatile. The compiler might reorder some stuff around it due to all uses being explicit just like any other volatile inline-asm.

Quoted 7 lines

In fact, the arch_kgdb_breakpoint is called from only one place from kernel/debug/debug_core.c and there is no way for the compiler to reorder the block
as it has two write barriers around it:

        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */
Quoted 2 lines

A write barrier just looks like a memory clobber to the compiler, which isn't enough to stop this being reordered wrt breakpoints.

Yes this will be a full schedule barrier due to the inline-asm being a volatile inline-asm (implicitly because there are no outputs). What I meant about the compiler could move around code only happens when you don't there are other implicit non schedule barrier instructions, in this case wmb is an volatile inline-asm which is also a scheduler barrier.

Quoted 6 lines

In fact, I don't
think is actually solvable with GCC since there is no way to emit a full scheduling barrier using asm constraints (we'd need an intrinsic I think).

You could try clobbering every register, but that's filthy, and will likely cause reload to generate some dreadful spills.

Actually this is enough since both inline-asms (the one for wmb and arch_kgdb_breakpoint) are going to be treated as volatile by the compiler so it will not schedule those two inline-asm with respect of each other.

Note all other targets (ARM, PPC, x86, tile, etc.) all use a static inline function which does exactly the same as what is being added here.
x86 for an example:
static inline void arch_kgdb_breakpoint(void)

{
        asm("   int $3");
}

arm:
static inline void arch_kgdb_breakpoint(void)

{
        asm(".word 0xe7ffdeff");
}

PPC:
static inline void arch_kgdb_breakpoint(void)

{
        asm(".long 0x7d821008"); /* twge r2, r2 */
}

Yes they have don't have either input or output constraints while this is adding one with an input constraint but that does not change the volatilism of the inline-asm; only the output constraint does.

Thanks,
Andrew Pinski

Quoted 50 lines
Quoted 15 lines
Quoted 15 lines

arch/arm64/kernel/kgdb.c line 132

Quoted 11 lines
arch/arm64/kernel/kgdb.c new file +10 -0
+void
+sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
+{
+       struct pt_regs *thread_regs;
+       int regno;
+       int i;
+
+       /* Just making sure... */
+       if (task == NULL)
+               return;

Erm... that comment just raises more questions. I appreciate ARM has the same check, but why doesn't x86? Can task *actually* be NULL?

Quoted 5 lines

generally, the task will not be NULL. The check made because the caller (gdbstub.c)
fetches task information from gdb global structure and calls this function. This helps in case the caller fails to pass task info. I think should not be problem with this check. In fact this is legacy code

Generally or always? Afaict, either other architectures have a bug here or we have a redundant check. Regardless, it should be made consistent.

Quoted 10 lines
Quoted 10 lines

arch/arm64/kernel/kgdb.c line 297

Quoted 6 lines
arch/arm64/kernel/kgdb.c new file +6 -0
+/*
+ * ARM instructions are always in LE.
+ * Break instruction is encoded in LE format
+ */
+struct kgdb_arch arch_kgdb_ops = {
+       .gdb_bpt_instr          = {0x00, 0x00, 0x20, 0xd4}

Again, you should probably try and encode the dynamic breakpoint immediate in here (which is sadly offset by 5 bits in the instruction encoding).

Quoted 7 lines

Yes, I propose to change like this

#define  KGDB_DYN_BRK_INS_BYTE0  ((KGDB_DYN_DGB_BRK_IMM & 0x7) << 5)
#define  KGDB_DYN_BRK_INS_BYTE1  ((KGDB_DYN_DGB_BRK_IMM & 0x7f8) >> 3)
#define  KGDB_DYN_BRK_INS_BYTE2  (0x20 | \
                                 ((KGDB_DYN_DGB_BRK_IMM & 0xf800) >> 11))

#define KGDB_DYN_BRK_INS_BYTE3 0xd4

This would be cleaner if you #defined the complete instruction encoding:

#define AARCH64_BREAK_MON 0xd4200000

#define KGDB_DYN_BRK_BYTE(x)    \
        (((AARCH64_BREAK_MON | KGDB_DYN_DGB_BRK_IMM) >> (x * 8)) & 0xff)

Will

#7 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

Hi Andrew,

Quoted 13 lines · Andrew Pinski
Quoted 11 lines · Will Deacon
Quoted 7 lines · Vijay Kilari

In fact, the arch_kgdb_breakpoint is called from only one place from kernel/debug/debug_core.c and there is no way for the compiler to reorder the block
as it has two write barriers around it:

        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */

A write barrier just looks like a memory clobber to the compiler, which isn't enough to stop this being reordered wrt breakpoints.

Quoted 6 lines

Yes this will be a full schedule barrier due to the inline-asm being a volatile inline-asm (implicitly because there are no outputs). What I meant about the compiler could move around code only happens when you don't there are other implicit non schedule barrier instructions, in this case wmb is an volatile inline-asm which is also a scheduler barrier.

volatile != scheduling barrier (example below).

Quoted 11 lines
Quoted 6 lines

In fact, I don't
think is actually solvable with GCC since there is no way to emit a full scheduling barrier using asm constraints (we'd need an intrinsic I think).

You could try clobbering every register, but that's filthy, and will likely cause reload to generate some dreadful spills.

Actually this is enough since both inline-asms (the one for wmb and arch_kgdb_breakpoint) are going to be treated as volatile by the compiler so it will not schedule those two inline-asm with respect of each other.

That's true: the asms will not be optimised away and/or moved across each other. However, other code *can* move across then, which strikes me as odd when we're dealing with breakpoints.

E.g:

8<---

#define wmb() __asm__ __volatile__ ("dsb" ::: "memory")

static inline void nop(void)

{
	asm ("nop");
}

int foo(int *bar)

{
	int baz, i;

	baz = *bar;

	for (i = 0; i < 10; ++i)
		baz++;

	wmb();
	nop();
	wmb();

	return baz;
}

--->8

Assembles to the following with GCC 4.9 for ARM:

00000000 <foo>:
0: e5900000 ldr r0, [r0]
4: f57ff04f dsb sy
8: e320f000 nop {0}
c: f57ff04f dsb sy
10: e280000a add r0, r0, #10
14: e12fff1e bx lr

So, whilst loading the parameter hazards against the memory clobber of the wmb()s, the loop (optimised to the single add) is now at the end of the function. If I wanted a breakpoint after that loop had finished, it's now no longer true.

Quoted 3 lines

Note all other targets (ARM, PPC, x86, tile, etc.) all use a static inline function which does exactly the same as what is being added here.

Agreed, I didn't mean to imply this was an issue with this particular patch. I'm just curious as to why this has been deemed acceptable by other architectures, when it doesn't look especially useful to me.

Will

#8 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

Quoted 16 lines · Will Deacon

Hi Andrew,

Quoted 13 lines · Andrew Pinski
Quoted 11 lines · Will Deacon
Quoted 7 lines · Vijay Kilari

In fact, the arch_kgdb_breakpoint is called from only one place from kernel/debug/debug_core.c and there is no way for the compiler to reorder the block
as it has two write barriers around it:

        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */

A write barrier just looks like a memory clobber to the compiler, which isn't enough to stop this being reordered wrt breakpoints.

Quoted 8 lines
Quoted 6 lines

Yes this will be a full schedule barrier due to the inline-asm being a volatile inline-asm (implicitly because there are no outputs). What I meant about the compiler could move around code only happens when you don't there are other implicit non schedule barrier instructions, in this case wmb is an volatile inline-asm which is also a scheduler barrier.

volatile != scheduling barrier (example below).

Actually it does mean that but scheduling barrier != code motion barrier; at least in GCC.

Quoted 48 lines
Quoted 5 lines
Quoted 5 lines

In fact, I don't
think is actually solvable with GCC since there is no way to emit a full scheduling barrier using asm constraints (we'd need an intrinsic I think).

Quoted 7 lines
Quoted 2 lines

You could try clobbering every register, but that's filthy, and will likely cause reload to generate some dreadful spills.

Actually this is enough since both inline-asms (the one for wmb and arch_kgdb_breakpoint) are going to be treated as volatile by the compiler so it will not schedule those two inline-asm with respect of each other.

That's true: the asms will not be optimised away and/or moved across each other. However, other code *can* move across then, which strikes me as odd when we're dealing with breakpoints.

E.g:

8<---

#define wmb() __asm__ __volatile__ ("dsb" ::: "memory")

static inline void nop(void)

{
        asm ("nop");
}

int foo(int *bar)

{
        int baz, i;

        baz = *bar;

        for (i = 0; i < 10; ++i)
                baz++;

        wmb();
        nop();
        wmb();

        return baz;
}

--->8

Assembles to the following with GCC 4.9 for ARM:

Quoted 7 lines

00000000 <foo>:

   0:   e5900000        ldr     r0, [r0]
   4:   f57ff04f        dsb     sy
   8:   e320f000        nop     {0}
   c:   f57ff04f        dsb     sy
  10:   e280000a        add     r0, r0, #10
  14:   e12fff1e        bx      lr

Yes but this is not the scheduler doing the code motion (it is SCEV Constant prop followed by TER [temporary expression replacement] which is causing the code motion to happen).

Quoted 6 lines

So, whilst loading the parameter hazards against the memory clobber of the wmb()s, the loop (optimised to the single add) is now at the end of the function. If I wanted a breakpoint after that loop had finished, it's now no longer true.

Quoted 7 lines
Quoted 3 lines

Note all other targets (ARM, PPC, x86, tile, etc.) all use a static inline function which does exactly the same as what is being added here.

Agreed, I didn't mean to imply this was an issue with this particular patch. I'm just curious as to why this has been deemed acceptable by other architectures, when it doesn't look especially useful to me.

The main reason why it is acceptable by other architectures is due to the full definition of the function itself:
void kgdb_breakpoint(void)

{
        atomic_inc(&kgdb_setting_breakpoint);
        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */
        atomic_dec(&kgdb_setting_breakpoint);
}

All of these function calls are all volatile inline-asm so there is not going to be any code motion happening. This is true in all architectures. So then you ask if kgdb_breakpoint can be inlined anywhere that we could get the breakpoint and not have the "correct" value, the answer is no and I audited each and every call to kgdb_breakpoint. If you want just add the attribute noinline to kgdb_breakpoint and the problem you mentioned about the code motion happening goes away.

Thanks,
Andrew Pinski

#9 lore raw

PATCH v2 2/3 AArch64: KGDB: Add Basic KGDB support

Hi Andrew,

Quoted 9 lines · Andrew Pinski
Quoted 8 lines · Will Deacon
Quoted 6 lines · Andrew Pinski

Yes this will be a full schedule barrier due to the inline-asm being a volatile inline-asm (implicitly because there are no outputs). What I meant about the compiler could move around code only happens when you don't there are other implicit non schedule barrier instructions, in this case wmb is an volatile inline-asm which is also a scheduler barrier.

Quoted 4 lines
Quoted 1 line

volatile != scheduling barrier (example below).

Actually it does mean that but scheduling barrier != code motion barrier; at least in GCC.

Bah, terminology. I can tell you're a compiler engineer ;)

Quoted 11 lines
Quoted 9 lines

Assembles to the following with GCC 4.9 for ARM:

00000000 <foo>:

   0:   e5900000        ldr     r0, [r0]
   4:   f57ff04f        dsb     sy
   8:   e320f000        nop     {0}
   c:   f57ff04f        dsb     sy
  10:   e280000a        add     r0, r0, #10
  14:   e12fff1e        bx      lr
Quoted 3 lines

Yes but this is not the scheduler doing the code motion (it is SCEV Constant prop followed by TER [temporary expression replacement] which is causing the code motion to happen).

Regardless, it's still not suitable for breakpoints in general.

Quoted 19 lines
Quoted 7 lines
Quoted 3 lines

Note all other targets (ARM, PPC, x86, tile, etc.) all use a static inline function which does exactly the same as what is being added here.

Agreed, I didn't mean to imply this was an issue with this particular patch. I'm just curious as to why this has been deemed acceptable by other architectures, when it doesn't look especially useful to me.

The main reason why it is acceptable by other architectures is due to the full definition of the function itself:
void kgdb_breakpoint(void)

{
        atomic_inc(&kgdb_setting_breakpoint);
        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */
        atomic_dec(&kgdb_setting_breakpoint);
}
Quoted 8 lines

All of these function calls are all volatile inline-asm so there is not going to be any code motion happening. This is true in all architectures. So then you ask if kgdb_breakpoint can be inlined anywhere that we could get the breakpoint and not have the "correct" value, the answer is no and I audited each and every call to kgdb_breakpoint. If you want just add the attribute noinline to kgdb_breakpoint and the problem you mentioned about the code motion happening goes away.

Thanks for taking a look at this. I think adding the noinline would be a good idea (as a seperate patch).

Cheers,

Will

#10 lore raw

PATCH v2 3/3 AArch64: KGDB: Add step debugging support

In reply to vijay.kilari at gmail.com

From: Vijaya Kumar K <[email protected]>

Add KGDB software step debugging support for EL1 debug in AArch64 mode.

KGDB registers step debug handler with debug monitor. On receiving 'step' command from GDB tool, target enables software step debugging and step address is updated. If no step address is received from GDB tool, target assumes next step address is current PC.

Software Step debugging is disabled when 'continue' command is received

---
 arch/arm64/kernel/kgdb.c |   59 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 8 deletions(-)
arch/arm64/kernel/kgdb.c +51 -8
index c99e04d..2d2485f 100644
@@ -152,13 +152,26 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
 
 static int compiled_break;
 
+static void kgdb_arch_update_addr(struct pt_regs *regs,
+				  char *remcom_in_buffer)
+{
+	unsigned long addr;
+	char *ptr;
+
+	ptr = &remcom_in_buffer[1];
+	if (kgdb_hex2long(&ptr, &addr))
+		kgdb_arch_set_pc(regs, addr);
+	else if (compiled_break == 1)
+		kgdb_arch_set_pc(regs, regs->pc + 4);
+
+	compiled_break = 0;
+}
+
 int kgdb_arch_handle_exception(int exception_vector, int signo,
 			       int err_code, char *remcom_in_buffer,
 			       char *remcom_out_buffer,
 			       struct pt_regs *linux_regs)
 {
-	unsigned long addr;
-	char *ptr;
 	int err;
 
 	switch (remcom_in_buffer[0]) {
@@ -173,14 +186,31 @@ int kgdb_arch_handle_exception(int exception_vector, int signo,
 		 * to the next instruction or we will just breakpoint
 		 * over and over again.
 		 */
-		ptr = &remcom_in_buffer[1];
-		if (kgdb_hex2long(&ptr, &addr))
-			kgdb_arch_set_pc(linux_regs, addr);
-		else if (compiled_break == 1)
-			kgdb_arch_set_pc(linux_regs, linux_regs->pc + 4);
+		kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
 
-		compiled_break = 0;
+		/*
+		 * Received continue command, disable single step
+		 */
+		if (kernel_active_single_step())
+			kernel_disable_single_step();
+		err = 0;
+		break;
+	case 's':
+		/* 
+		 * Update step address value with address passed
+		 * with step packet.
+		 * On debug exception return PC is copied to ELR
+		 * So just update PC.
+		 * If no step address is passed, resume from the address
+		 * pointed by PC. Do not update PC
+		 */
+		kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
 
+		/*
+		 * Enable single step handling
+		 */
+		if (!kernel_active_single_step())
+			kernel_enable_single_step(linux_regs);
 		err = 0;
 		break;
 	default:
@@ -205,6 +235,13 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr,
 	return 0;
 }
 
+static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr,
+			    unsigned long addr)
+{
+	kgdb_handle_exception(1, SIGTRAP, 0, regs);
+	return 0;
+}
+
 static struct break_hook kgdb_brkpt_hook = {
 	.esr_mask		= 0xffffffff,
 	.esr_val		= KGDB_BREAKINST_ESR_VAL,
@@ -217,6 +254,10 @@ static struct break_hook kgdb_compiled_brkpt_hook = {
 	.fn			= kgdb_compiled_brk_fn
 };
 
+static struct step_hook kgdb_step_hook = {
+	.fn			= kgdb_step_brk_fn
+};
+
 static void kgdb_call_nmi_hook(void *ignored)
 {
        kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
@@ -272,6 +313,7 @@ int kgdb_arch_init(void)
 
 	register_break_hook(&kgdb_brkpt_hook);
 	register_break_hook(&kgdb_compiled_brkpt_hook);
+	register_step_hook(&kgdb_step_hook);
 
 	return 0;
 }
@@ -286,6 +328,7 @@ void kgdb_arch_exit(void)
 {
 	unregister_break_hook(&kgdb_brkpt_hook);
 	unregister_break_hook(&kgdb_compiled_brkpt_hook);
+	unregister_step_hook(&kgdb_step_hook);
 	unregister_die_notifier(&kgdb_notifier);
 }
 
Signature · 1 line
1.7.9.5