Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 230
Popcorn Avatar asked Jun 21 '13 17:06

Popcorn


4 Answers

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

screenshot for steps 1 and 2

Step 3:
In Symbol, type NSLog.

screenshot for step 3

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

Fo Xcode 5, see this.

like image 61
Pang Avatar answered Nov 01 '22 07:11

Pang


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

enter image description here

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.

like image 33
Yedy Avatar answered Nov 01 '22 07:11

Yedy


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

like image 4
Matthias Bauch Avatar answered Nov 01 '22 07:11

Matthias Bauch


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

like image 2
Alessandro Vendruscolo Avatar answered Nov 01 '22 07:11

Alessandro Vendruscolo