Mac OS X Apple applications debugging. Switching from GDB to LLDB ?

Hi list!

I'm a GDB user that want to switch to LLDB, but something is preventing me to switch for the moment: I can't find how to debug (analyze) Apple applications such as Calendars.app or Contacts.app on Mac OS X.

Using GDB, i'm used to do something like this :

$ gdb /Applications/Calendar.app
(gdb) run
Starting program: /Applications/Calendar.app/Contents/MacOS/Calendar
Reading symbols for shared libraries ++++++++ ............
(gdb) fb alloc
[0] cancel
[1] all

Non-debugging symbols:
[2] +[ABDeprecatedObject alloc]
[3] +[CALDate(Private) alloc]
[4] +[CalAutoCompleteOperation alloc]
[5] +[NSHashTable alloc]
[6] +[NSKnownKeysDictionary alloc]
[7] +[NSKnownKeysDictionary1 alloc]
[8] +[NSKnownKeysMappingStrategy alloc]
[9] +[NSKnownKeysMappingStrategy1 alloc]
[10] +[NSLeafProxy alloc]
[11] +[NSManagedObject alloc]
[12] +[NSMapTable alloc]
[13] +[NSObject alloc]
[14] +[NSPasteboard alloc]
[15] +[NSProxy alloc]
[16] +[NSTemporaryObjectID alloc]
[17] +[NSUserNotification alloc]
[18] +[_CDSnapshot alloc]
[19] +[_NSCoreManagedObjectID alloc]
[20] +[_NSFaultingMutableArray alloc]
[21] +[_NSFaultingMutableOrderedSet alloc]
[22] +[_NSFaultingMutableSet alloc]
[23] +[_PFBatchFaultingArray alloc]
[24] +[_PFCachedNumber alloc]
[25] +[_PFFetchedResultOrderedSetWrapper alloc]
[26] +[_PFString alloc]
[27] +[__CFHashTable alloc]
[28] +[__CFMapTable alloc]

I can then make GDB break on the method i'm interested in.

Using LLDB, i've not been able to do the same :

$ lldb /Applications/Calendar.app
(lldb) Current executable set to '/Applications/Calendar.app' (x86_64).
(lldb) run
Process 54986 launched: '/Applications/Calendar.app/Contents/MacOS/Calendar' (x86_64)

(lldb) breakpoint set -S alloc // i've also tried -n "-[NSObject alloc]
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.

And then run the app. Unfortunately LLDB does not break, when OF COURSE, -[NSObject alloc] is called very often in a Cocoa application...
After reading http://lldb.llvm.org/symbols.html, I realize that I don't have any dSYM file to provide to LLDB since I'm not the author of the app :slight_smile: but how does GDB without dSYM file ? is the dSYM file embedded in the binary ?

So, shortly, how can I make LLDB make an *Apple* Cocoa app break on simple ObjC method calls like I did with GDB ?

Thanks for your help

I'm in fact not interested in NSObject alloc, but other instance method :wink: and it does not work either.
Anyway "breakpoint set -S alloc" should work for class and instance methods.

Remember the problem is not in *my* app, but Apple apps...

The best work around is to use the "--func-regex" option to setting breakpoints:

% xcrun lldb /Applications/Calculator.app
(lldb) breakpoint set --func-regex 'alloc]'
Breakpoint 2: 1781 locations.

Please file a bug against the "lldb" component as this should be fixed. If I set a breakpoint by selector in this same debug session:

(lldb) breakpoint set -S alloc
Breakpoint 1: 24 locations.

This should be the same number of locations as "breakpoint set --func-regex 'alloc]'", but obviously it isn't.

"--func-regex" will allow you to use a regular expression to catch the things you are interested in without error. You can also limit breakpoints to certain shared libraries to limit the number of "alloc" breakpoints you get:

(lldb) breakpoint set --func-regex 'alloc]' --shlib AppKit --shlib Calendar
Breakpoint 3: 680 locations.