Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a symbolic breakpoint on a selector in Xcode

Tags:

xcode

lldb

There's a bug in my app which shows up with the following (partial) stacktrace:

2011-11-25 01:55:59.760 Events2[6650:403] -[Event boolValue]: unrecognized selector sent to instance 0x7fb903928670

To debug this I decided to add a symbolic breakpoint on -[Event boolValue] reasoning that when that selector is sent, the debugger would halt.

However, nothing happens. After setting the breakpoint the app just soldiers on and generates the same exception without halting.

I have defined the breakpoint as follows:

enter image description here

I'm using the LLDB debugger with Xcode 4.2

like image 650
Roger Avatar asked Nov 25 '11 02:11

Roger


People also ask

How do I add a symbolic breakpoint in Xcode?

Navigate to the second last tab on the left panel with a breakpoint picture. Click the “+” icon at the lower left of the Breakpoint Navigator and select Symbolic Breakpoint.

Why breakpoint is not working in Xcode?

See this post: Breakpoints not working in Xcode?. You might be pushing "Run" instead of "Debug" in which case your program is not running with the help of gdb, in which case you cannot expect breakpoints to work!

What is exception breakpoint in Xcode?

An exception breakpoint is a type of breakpoint that is created when some exception occurs in the code. On occurrence of such exception our application stops at that given condition causing the exception and we can access all variables in scope at that breakpoint.

Where is breakpoint navigator in Xcode?

The Breakpoint Navigator Managing breakpoints in Xcode is super simple. Enter the Breakpoint Navigator, which lives in the Navigator Panel on the left side of Xcode. Here, you will see all the breakpoints currently set in your project.


4 Answers

It looks to me like symbolic breakpoints don't work right in LLDB (I'm running the most recent released version of Xcode as of this writing, 4.3.3).

I set a symbolic breakpoint at addAnimation:forKey: in LLDB, and it never gets hit. If I switch my project to GDB, the breakpoint works as expected.

like image 193
Duncan C Avatar answered Sep 23 '22 18:09

Duncan C


I was looking for the same answer (symbolic breakpoints) and this link helped: http://www.cocoabuilder.com/archive/cocoa/308967-symbolic-breakpoints.html#308970

You have to follow this pattern (it is also given as a placeholder in Xcode breakpoint editor):

- [name_of_the_class name_of_the_method:]

For example I was looking to see who does set my left bar item and overrides my settings, I used -[UINavigationItem setLeftBarButtonItem:]

and it worked. Or this one

-[UINavigationController pushViewController:animated:]

like image 37
Canopus Avatar answered Sep 25 '22 18:09

Canopus


I would set an Symbolic breakpoint with this symbol -[NSObject doesNotRecognizeSelector:] enter image description here

which will help us to capture situations where a selector is being invoked against the wrong object.

like image 34
Bala Avatar answered Sep 26 '22 18:09

Bala


Setting a breakpoint on a selector causes lldb to halt when that selector is executed, not when it is sent. In your case, there is no selector "-[Event boolValue]", therefore this breakpoint will never be hit.

I would set an exception breakpoint on "All Objective-C Exceptions". This will be hit when the "unrecognized selector sent" exception is thrown and you can see where the problem occurs.

like image 43
Martin R Avatar answered Sep 26 '22 18:09

Martin R