Reputation: 1369
I working on my iPad App,
While running the code there is one method in table view.
as we know
`cellForRowAtIndexPath:`
There are several times this method can be called.
like while
scrolling table view cells.
Or table view reload data.
I have complex coding so I just want to see method call stack...
That from which method is calling cell for row at index path.
I have used NSLogs
and breakpoints but still could not get.
Upvotes: 27
Views: 52501
Reputation: 1486
Just putting the Swift 4 syntax in case if some one needs
print("Stack trace: \(Thread.callStackSymbols)")
Upvotes: 6
Reputation: 12617
You can print the stack trace in the NSLog by
NSLog(@"Stack trace : %@",[NSThread callStackSymbols]);
EDIT: Swift code
println("Stack trace: %@", NSThread.callStackSymbols())
Upvotes: 29
Reputation: 6128
Try setting a breakpoint at the entry for
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Then right click on the breakpoint and select "Log Stack Trace and Auto Continue" from the "Built-in Breakpoints" menu item.
This will automatically log the stack trace every time this function is entered and continue without having to step actually use the gdb console.
That was for Xcode 3.x For Xcode 4 the procedure is a bit different.
Command
-Option
Click on the breakpoint)Upvotes: 7
Reputation: 124997
When you hit a breakpoint, select the Debug navigator in the navigator area (left side of the window):
The Debug navigator shows you a stack trace for each thread in your app. It shows you essentially the same information you get from gdb's backtrace
command, but omits the return addresses (which normally aren't very helpful). Use the controls at the bottom of the navigator to hide or show all threads and to change the adjust the number of stack frames shown. I've got the slider set in the middle of its range in the image above, and the Debug navigator is omitting stack frames 2-18, which are all calls from one framework method to another, i.e. not my stuff.
Xcode 4 should be set up to display the Debug navigator automatically when you're debugging, but if not you can configure it to do so by going to Xcode->Behaviors->Edit Behaviors.... Then select the Run Pauses item from the list and set it to Show navigator Debug Navigator.
Upvotes: 36
Reputation: 8131
You can set a breakpoint (or pause app) and from gdb debugger write "backtrace
".
You should see stack:
(gdb) backtrace
#0 0x9022f7fe in mach_msg_trap ()
#1 0x9022ecdc in mach_msg ()
#2 0x022a310a in __CFRunLoopServiceMachPort ()
#3 0x02206550 in __CFRunLoopRun ()
#4 0x02205d84 in CFRunLoopRunSpecific ()
#5 0x02205c9b in CFRunLoopRunInMode ()
#6 0x024617d8 in GSEventRunModal ()
#7 0x0246188a in GSEventRun ()
#8 0x00c0ca16 in UIApplicationMain ()
#9 0x0000270d in main (argc=1, argv=0xbfeff550) at /Users/.........m:14
Upvotes: 19