Why is GDB “jumping back” when debugging with c source codes

后端 未结 1 370
余生分开走
余生分开走 2021-01-12 21:16

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 sourc

相关标签:
1条回答
  • 2021-01-12 21:40

    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.

    0 讨论(0)
提交回复
热议问题