“return” from method while stepping?

女生的网名这么多〃 提交于 2019-12-19 05:16:54

问题


I would like to exit out the current method that I'm stepping through.

-(void)helloWorld {
    NSLog(@"Hello");
    // I would like to return here, so that "World" isn't printed.
    NSLog(@"World");  
}

I have tried the following, but without luck.

(lldb) expr return
<no result>

Is this possible with lldb?


回答1:


When you are debugging using Xcode and when your program is paused at a breakpoint, you can drag the little green arrow to any other line in the function. E.g. in the following code:

if I want to skip the NSLog(@"B"), I can simply drag the green arrow from line 20 to line 23, which means the function will simply "return" from anywhere I want.




回答2:


Unfortunately in Xcode 4.5.x there is no way to force an early return from a function. In the current lldb sources over at http://lldb.llvm.org/ there is a newly added command, thread return, which does what you want - it includes the ability to specify the return value of the function. This won't be in Xcode until the next major release, though.




回答3:


I just added a breakpoint at the line mentioned below:

var computed: Bool { 
   return device.time == 10 // added breakpoint here
}

and got the following error:

error: Error returning from frame 0 of thread 1: We only support setting simple integer and float return types at present..

Seems to work for only those two types



来源:https://stackoverflow.com/questions/12872167/return-from-method-while-stepping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!