使用 GNU 调试器,如何单步执行 __asm__ 语句?
__asm__("\n\
movl $1, %eax\n\
");
如何单步执行 __asm__
以便打印寄存器以查看它们存储的内容?现在,我在 __asm__
行上打了一个中断,然后尝试按 stepi
或 si
,但它没有单步进入 movl
行。我做错了什么?
__asm__("\n\
movl $1, %eax\n\
");
How can I step through __asm__
so I can print the registers to see what they are storing? Right now, I put a break on the __asm__
line and then I tried pressing stepi
or si
and it's not stepping into the movl
line. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
si
正在跳过movl
指令(您可以通过输入display/i $pc
并观察来验证这一点输出如何变化。没有发生的事情(可能会让你感到困惑)是更新源代码,因为你的 asm() 内部的代码没有任何行号注释,所以 GDB 可以。不知道应该显示哪一行
。编译器将此类注释放入程序集中。但是,如果您希望行号正确,则必须自己添加这些注释(这通常不值得麻烦)。
The
si
is stepping over themovl
instruction (you can verify this by typingdisplay/i $pc
and observing how the output changes.What isn't happening (and what likely confused you) is update to the source. That's because your code inside asm() does not have any line-number annotations, so GDB can't tell which line(s) it should be displaying.
Normally, the compiler puts such annotations into the assembly. But here you've bypassed the compiler. If you want line numbers to be correct, you'll have to add these annotations yourself (which usually isn't worth the trouble).