简体   繁体   English

如何打印出 Linux 内核中的寄存器?

[英]How to print out registers in Linux kernel?

I want to print out values of a couple of registers from the linux kernel code running on ARM.我想从 ARM 上运行的 linux 内核代码中打印出几个寄存器的值。 Particularly I have the following assembly in linux -特别是我在 linux 中有以下程序集 -

e3c52007        bic     r2, r5, #7      ; 0x7
e1520003        cmp     r2, r3
0a000003        beq     c011fa60 <smem_find+0x40>

How do I print out the values of r2, r3 and r5 in kmsg?如何在 kmsg 中打印出 r2、r3 和 r5 的值? I do not want to use the variable names and want to get the values from registers.我不想使用变量名,而是想从寄存器中获取值。

I'm not that familiar with kernel development and easy ways to debug, but this would do the job I guess.我对内核开发和调试的简单方法不太熟悉,但我想这可以完成这项工作。

size_t r2, r3, r5;

asm ("str r2, %[r2]\n"
     "str r3, %[r3]\n"
     "str r5, %[r5]\n"
 : [r2]"=m" (r2), [r3]"=m" (r3), [r5]"=m" (r5));
 printk("r2=%u r3=%u r4=%u\n", r2, r3, r5);

Edit: Now with ARM assembly instead of x86 :p编辑:现在使用 ARM 程序集而不是 x86 :p

You can call show_regs(struct pt_regs * regs) .您可以调用show_regs(struct pt_regs * regs) This function will diplay all the registrs on the pt_regs structure.此函数将显示 pt_regs 结构上的所有寄存器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM