[PATCH] arm kgdb: fix breakpoint for thumb2

Johannes Stezenbach js at sig21.net
Mon Feb 14 01:59:49 PST 2022


Entering kdb via SysRq-G with CONFIG_THUMB2_KERNEL=y
on Cortex-A7 in Qemu results in an Ooops, and it is
not possible to continue because of "Catastrophic error detected".
The root cause is using an arm breakpoint instruction in
thumb code.

For the breakpoint instruction I used this reference:
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdbserver/linux-aarch32-low.cc#l31
0xf7fxaxxx are UDF encoding T2 instructions
(32bit, permanently undefined).

Signed-off-by: Johannes Stezenbach <js at sig21.net>
---

Wrt arm GDB_BREAKINST maybe it is also needed to use something like

#ifdef CONFIG_AEABI
#define GDB_BREAKINST		0xe7f001f0
#else
#define GDB_BREAKINST		0xef9f0001
#endif

but I could not test if it makes a difference

diff --git a/arch/arm/include/asm/kgdb.h b/arch/arm/include/asm/kgdb.h
index 8de1100d1067..7e6ed3171b54 100644
--- a/arch/arm/include/asm/kgdb.h
+++ b/arch/arm/include/asm/kgdb.h
@@ -34,16 +34,22 @@
  * make our lives much much simpler. :)
  */
 #define BREAK_INSTR_SIZE	4
+#ifdef CONFIG_THUMB2_KERNEL
+#define GDB_BREAKINST		0xf7f0a000
+#define KGDB_BREAKINST		0xf7f0a001
+#define KGDB_COMPILED_BREAK	0xf7f0a002
+#else
 #define GDB_BREAKINST		0xef9f0001
 #define KGDB_BREAKINST		0xe7ffdefe
 #define KGDB_COMPILED_BREAK	0xe7ffdeff
+#endif
 #define CACHE_FLUSH_IS_SAFE	1
 
 #ifndef	__ASSEMBLY__
 
 static inline void arch_kgdb_breakpoint(void)
 {
-	asm(__inst_arm(0xe7ffdeff));
+	asm(__inst_arm_thumb32(KGDB_COMPILED_BREAK, KGDB_COMPILED_BREAK));
 }
 
 extern void kgdb_handle_bus_error(void);



More information about the linux-arm-kernel mailing list