[PATCH v2] ARM: Remove the special printing format of pc and lr in __show_regs()

From: Zhen Lei
Date: Mon Aug 15 2022 - 05:23:56 EST


When CONFIG_KALLSYMS is set, the parsed symbols of 'pc' and 'lr' are
printed. Otherwise, the raw content of 'pc' and 'lr' are printed in the
lines: "PC is at" and "LR is at". If at this point they are printed in
format [<%08lx>], the subsequent printing of 'pc' and 'lr' does not need
to follow this format again. This allows the register list to be printed
neatly.

For example:
CONFIG_KALLSYMS=y before:
PC is at test+0x58/0x74
LR is at test+0x28/0x74
pc : [<802f3868>] lr : [<802f3838>] psr: 60000013
sp : cabc5da8 ip : 00002ff4 fp : 00000001
r10: 81951018 r9 : 00400cc0 r8 : 7ffff000

CONFIG_KALLSYMS=n after:
PC is at [<802f369c>]
LR is at [<802f366c>]
pc : 802f369c lr : 802f366c psr: 60000013
sp : cabd9da8 ip : 00002ff4 fp : 00000001
r10: 827e6018 r9 : 00400cc0 r8 : 7ffff000

Signed-off-by: Zhen Lei <thunder.leizhen@xxxxxxxxxx>
---
KernelVersion: v6.0-rc1
arch/arm/kernel/process.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

v1 --> v2:
On the basis of v1, print the instruction pointers in the lines of
"PC is at" and "LR is at" in format [<%08lx>] if CONFIG_KALLSYMS=n,
as is done in dump_backtrace_entry(). To make sure that tools like
scripts/decode_stacktrace.sh can output the symbols of 'pc' and 'lr'.

v1:
Change the format of "pc:" and "lr:" from [<%08lx>] to %08lx.

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 96f3fbd51764292..f9f4e31393a6f56 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -134,9 +134,15 @@ void __show_regs(struct pt_regs *regs)

show_regs_print_info(KERN_DEFAULT);

+#ifdef CONFIG_KALLSYMS
printk("PC is at %pS\n", (void *)instruction_pointer(regs));
printk("LR is at %pS\n", (void *)regs->ARM_lr);
- printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n",
+#else
+ printk("PC is at [<%08lx>]\n", instruction_pointer(regs));
+ printk("LR is at [<%08lx>]\n", regs->ARM_lr);
+#endif
+
+ printk("pc : %08lx lr : %08lx psr: %08lx\n",
regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr);
printk("sp : %08lx ip : %08lx fp : %08lx\n",
regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
--
2.25.1