GDB在微妙的线条下,或下一步 [英] GDB on subtle lines when next or step

查看:170
本文介绍了GDB在微妙的线条下,或下一步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GDB来调试嵌入式linux目标板。在目标板上,gdbserver正在运行剥离的二进制应用程序。在PC端,我运行附带调试符号的应用程序。



从PC通过以太网连接我做目标远程ip:端口,并且有一个健康的连接到gdbserver。我在一些功能中添加断点并继续。当我在简单的功能中触发外部事件和程序中断时,调试器会按预期方式成功中断。在这一点上,奇怪的行为开始了。当我在GDB控制台中执行步骤或下一步,而不是下一行时,它将转到上一行,而不是向前两行,并向后退回两行。每次我做下一步,或继续这一步。没有循环或跳转,代码应该一行一行,但不会。为什么GDB的行为呢?

解决方案

这是适用于高级优化的代码的正常行为。除非你真的打算调试优化器,否则在调试器中执行优化的代码几乎没用。



手册


您调试使用-g -O编译的程序,请记住,优化程序已重新排列代码;调试器会显示你真正在那里。执行路径与您的源文件不完全匹配时,不要太惊讶!



I use GDB to debug an embedded linux target board. On target board gdbserver is running the stripped binary application. On PC side I run application which has debug symbols attached.

From PC via ethernet connection I do "target remote ip:port" and there is a healthy connection to gdbserver. I add break points in some functions and continue. Debugger successfully break as expected when I trigger external event and program breaks in my simple function. Weird behaviour starts at this point. When I do step or next in GDB console instead of next line it goes to previous line than goes to two lines forward and goes back two lines backward. Each time I do next or step this continues. There is no loops or jumps, code should just go line by line but it doesn't. Why GDB behaves like this? What should I do to solve this problem.

解决方案

This is normal behaviour for code to which a high level of optimisation has been applied. Unless you are actually intending to debug the optimiser, executing optimised code in a debugger is almost useless.

From the manual:

When you debug a program compiled with ‘-g -O’, remember that the optimizer has rearranged your code; the debugger shows you what is really there. Do not be too surprised when the execution path does not exactly match your source file!

这篇关于GDB在微妙的线条下,或下一步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆