Is there a way to set a breakpoint at the start of

2020-04-02 07:46发布

问题:

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).