Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xtensa: dump userspace code around the exception PC

In the absence of other debug facilities dumping user code around the
unhandled exception address may help debugging the issue.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>

+26
+8
arch/xtensa/Kconfig.debug
··· 38 38 help 39 39 This option allows you to set the stack depth that the kernel 40 40 prints in stack traces. 41 + 42 + config PRINT_USER_CODE_ON_UNHANDLED_EXCEPTION 43 + bool "Dump user code around unhandled exception address" 44 + help 45 + Enable this option to display user code around PC of the unhandled 46 + exception (starting at address aligned on 16 byte boundary). 47 + This may simplify finding faulting code in the absence of other 48 + debug facilities.
+18
arch/xtensa/kernel/traps.c
··· 175 175 die(str, regs, err); 176 176 } 177 177 178 + #ifdef CONFIG_PRINT_USER_CODE_ON_UNHANDLED_EXCEPTION 179 + static inline void dump_user_code(struct pt_regs *regs) 180 + { 181 + char buf[32]; 182 + 183 + if (copy_from_user(buf, (void __user *)(regs->pc & -16), sizeof(buf)) == 0) { 184 + print_hex_dump(KERN_INFO, " ", DUMP_PREFIX_NONE, 185 + 32, 1, buf, sizeof(buf), false); 186 + 187 + } 188 + } 189 + #else 190 + static inline void dump_user_code(struct pt_regs *regs) 191 + { 192 + } 193 + #endif 194 + 178 195 /* 179 196 * Unhandled Exceptions. Kill user task or panic if in kernel space. 180 197 */ ··· 207 190 "\tEXCCAUSE is %ld\n", 208 191 current->comm, task_pid_nr(current), regs->pc, 209 192 regs->exccause); 193 + dump_user_code(regs); 210 194 force_sig(SIGILL); 211 195 } 212 196