为什么GDB“跳回”当用c源代码进行调试时 [英] Why is GDB "jumping back" when debugging with c source codes

查看:166
本文介绍了为什么GDB“跳回”当用c源代码进行调试时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在我发现gdb有时会在各行之间跳来跳去,比如考虑c源代码如下所示:

  char * XXX; 
int a;
...

if(...)
{

}

当我到达 if if 子句时,我输入 n 它会跳回到 int a 部分。这是为什么?



如果我再次执行该命令,它会在中输入括号,如果。如果可能的话,我想避免那部分,直接输入if(当然,如果条件匹配)

解决方案


当我到达if子句时,我键入n,它将跳回到int的一个部分。为什么会这样?


由于您的代码是通过优化编译的,编译器可以(并且经常)重新安排你的程序以这样的方式:属于不同源代码行的指令是交错的(代码运动优化尝试(除其他之外)将加载指令移到很长时间才需要它们的结果;这有助于隐藏存储器延迟)。 >

如果您使用的是 gcc-4.8 或更高版本,请使用 -Og 。否则,请参阅这个回答。


I'm debugging the goldfish android kernel (version 3.4), with kernel sources.

Now I found that gdb sometimes jump back and forth between lines, e.g consider c source code like the following:

char *XXX;
int a;
...

if (...)
{

}

When I reached the if clause, I type in n and it will jump back to the int a part. Why is that?

If I execute that command again, it would enter the brackets in the if.

If possible, I want to avoid that part, and enter the if directly (of course, if condition matches)

解决方案

When I reached the if clause, I type in n and it will jump back to the int a part. Why is that?

Because your code is compiled with optimization on, and the compiler can (and often does) re-arrange instructions of your program in such a way that instructions "belonging" to different source lines are interleaved (code motion optimizations attempt (among other things) to move load instructions to long before their results are needed; this helps to hide memory latency).

If you are using gcc-4.8 or later, build your sources with -Og. Else, see this answer.

这篇关于为什么GDB“跳回”当用c源代码进行调试时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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