Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print or see method call stack in xcode?

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.

like image 217
Arpit B Parekh Avatar asked Mar 01 '12 12:03

Arpit B Parekh


People also ask

How can I see my call stack?

View the call stack while in the debugger While debugging, in the Debug menu, select Windows > Call Stack or press ctrl + alt + C . A yellow arrow identifies the stack frame where the execution pointer is currently located.

How do I view call stack in Visual Studio?

To open the Call Stack window in Visual Studio, from the Debug menu, choose Windows>Call Stack. To set the local context to a particular row in the stack trace display, select and hold (or double click) the first column of the row.

How do I see variables in Xcode?

See variable values in code and the variable viewer When your app pauses at a breakpoint, hover over a variable in your source code to view its current value. If the variable is an image or other type that isn't expressible as text, click the Quick Look button at the upper-right to see a preview of the variable.

How do I print a variable in Xcode?

Print a variableClick the Add Action button and select Debugger Command. Put any print command in a debug console in a text field. Make sure you prefix it with po , e.g., po print(view) . Check Automatically continue after evaluating actions.


3 Answers

When you hit a breakpoint, select the Debug navigator in the navigator area (left side of the window):

debug navigator

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.

like image 95
Caleb Avatar answered Oct 10 '22 21:10

Caleb


You can print the stack trace in the NSLog by

NSLog(@"Stack trace : %@",[NSThread callStackSymbols]); 

EDIT: Swift code

println("Stack trace: %@", NSThread.callStackSymbols()) 
like image 32
Nishant Avatar answered Oct 10 '22 22:10

Nishant


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
like image 41
elp Avatar answered Oct 10 '22 20:10

elp