Is there a way to set a breakpoint at the start of any NSLog statement?

£可爱£侵袭症+ 提交于 2019-12-19 13:45:32

问题


Some part of a big code base is printing out weird NSLog statements, and I'm trying to detect where it's coming from. Is there a way to put 1 breakpoint at the start of every NSLog call so I can see where it's being called from, rather than manually have to put breakpoints on all places that call NSLog?


回答1:


In Xcode 6:

Step 1:
On the Navigator on the left, go to Breakpoint Navigator (command ⌘ + 7):

Step 2:
Click the + button on the bottom left (Add a new breakpoint),
then choose Add Symbolic Breakpoint...:

Step 3:
In Symbol, type NSLog.

Alternatively, you can do the same thing in DebugBreakpointsCreate Symbolic Breakpoint.

Fo Xcode 5, see this.




回答2:


If you want to break on a certain log message you can use:

This example will break on every log containing the word "Warning".

Update: On newer devices use $x0. Simulator and older use $r0. $arg0 should do for all cases.




回答3:


In the breakpoint navigator (command+6) add (on the bottom, there is a Plus symbol) a symbolic breakpoint and use NSLog as symbol.




回答4:


According to this you can set that kind of breakpoint by doing so in the lldb console:

breakpoint set --name NSLog

One way to do this using Xcode could be to put a breakpoint in the main function or on you AppDelegate applicationDidFinishLaunchin (read: as soon as possible). Then, you run your app, and when it pauses on said breakpoint, you have access to the lldb console: you type the above line and hit return, and lldb prints something like this:

Breakpoint 3: where = Foundation`NSLog, address = 0x32a3da08

At this point, you resume your app, and it will pause again when NSLog is called (pay attention to the call stack using the Debug Navigator).



来源:https://stackoverflow.com/questions/17240698/is-there-a-way-to-set-a-breakpoint-at-the-start-of-any-nslog-statement

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