简体   繁体   English

xcode 4.3.3 gdb或lldb调试器跳转

[英]xcode 4.3.3 gdb or lldb debugger jumps

We have a strange error with our debuggers when running the debugger on a phone in release mode. 在发布模式下在手机上运行调试器时,调试器出现一个奇怪的错误。 Whether we are using gdb or lldb with xcode 4.3.3, the code will land on breakpoints even though the code's PC is not really pointing at that spot. 无论我们在xcode 4.3.3上使用gdb还是lldb,即使代码的PC并没有真正指向该位置,该代码也会在断点处着陆。

Example fake code: 伪造代码示例:

if (true) {
    // set breakpoint-A here
} else {
    // set breakpoint-B here
}

// set another breakpoint-C here. //在此处设置另一个断点C。

It will land in breakpoint-B and then jump to breakpoint-A. 它将降落到断点B,然后跳到断点A。

Is the cause because we are in "release" mode and it's optimizing? 原因是因为我们处于“发布”模式并且正在优化吗?

Thanks! 谢谢!

Yes, there are three things going on here: When you build in release mode, the compiler is doing optimized code generation. 是的,这里发生了三件事:在发布模式下构建时,编译器正在优化代码生成。 The compiler may change the order that source lines are compiled into the program (as long as it doesn't change the meaning of the code), instructions between different source lines may be intermixed or rearranged, and finally there can be problems with the line table that the compiler emits. 编译器可能会更改将源代码行编译到程序中的顺序(只要不改变代码的含义),可能会混淆或重新排列不同源代码行之间的指令,最后可能会出现问题编译器发出的表。

Imagine two source lines, each which turn in to 8 assembly language instructions. 想象一下两个源代码行,每个源代码行都包含8条汇编语言指令。 The compiler may rearrange these 16 instructions (as long as it doesn't change the results of them) to keep the CPU(s) running most efficiently. 编译器可以重新排列这16条指令(只要不改变它们的结果即可),以使CPU最高效地运行。 But in this situation, what instruction should the compiler say is equivalent to line 1? 但是在这种情况下,编译器应该说什么指令等效于第1行? and what instruction should the compiler say is equivalent to line 2? 编译器应该说什么指令等效于第2行?

With optimized code debugging, if you're debugging at a source code level, you have to live with the reality that the "currently executing source line" is going to bounce around a lot while you step through your program. 使用优化的代码调试,如果您要在源代码级别进行调试,则必须忍受这样的现实:在逐步执行程序时,“当前正在执行的源代码行”会反弹很多。 Variables that seem to be in scope will appear and disappear at nonobvious times. 范围内的变量将在不明显的时间出现和消失。 The compiler's ways are tricky and hard to understand. 编译器的方法比较棘手,难以理解。 You need to debug with the assembly language code in front of you (or a source + assembly display) to really follow what's happening. 您需要使用您面前的汇编语言代码(或源代码+汇编显示)进行调试,以真正了解正在发生的事情。

There are improvements that compilers and debuggers can make to improve optimized code source-level debugging but it will probably always be a little hard to follow. 编译器和调试器可以进行一些改进,以改进优化的代码源级别的调试,但是可能总会有些困难。

Xcode also tends to jump from any return statement in a method to the first return statement in that method. Xcode也倾向于从方法中的任何return语句跳转到该方法中的第一个return语句。 (Xcode 4.3.3 still does it. I am not sure about 4.5 yet.) (Xcode 4.3.3仍会这样做。我不确定4.5。)

Just ignore that last highlighted 'return' statment. 只需忽略最后突出显示的“返回”语句即可。

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

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