Gdb is not omnipotent, but it is absolutely impossible without gdb. Here is a brief introduction to the most basic gdb commands in iOS development.
Po
Po is short for print-object and can be used to print all NSObject objects. Example:
(Gdb) po self
<LauncherViewController: 0x552c570>
(Gdb) po [self view]
<UIView: 0x544eb80; frame = (0 0; 320 411); autoresize = W + H; layer = <CALayer: 0x544ebb0>
(Gdb) print-object [self view]
<UIView: 0x544eb80; frame = (0 0; 320 411); autoresize = W + H; layer = <CALayer: 0x544ebb0>
P
P is short for print and can be used to print all simple types, such as int, float, and struct. Example:
(Gdb) p self
$1 = (LauncherViewController *) 0x552c570
(Gdb) p [[self view] size]
Unable to call function "objc_msgSend" at 0x1e7e08c: no return typeinformation available.
To call this function anyway, you can cast the return typeexplicitly (e.g. 'print (float) fabs (3.0 )')
(Gdb) p (CGSize) [[self view] size]
$1 = {
Length = 320,
Height = 411
}
(Gdb) print (CGSize) [[self view] size]
$2 = {
Length = 320,
Height = 411
}
Call
Call is called. In fact, the above po and p also have the calling function. Therefore, call is generally used only when no output is displayed or the method does not return a value. Example:
(Gdb) call [[self view] sizeToFit]
Unable to call function "objc_msgSend" at 0x1e7e08c: no return typeinformation available.
To call this function anyway, you can cast the return typeexplicitly (e.g. 'print (float) fabs (3.0 )')
(Gdb) call (void) [[self view] sizeToFit]
(Gdb) call [[self view] size]
Unable to call function "objc_msgSend" at 0x1e7e08c: no return typeinformation available.
To call this function anyway, you can cast the return typeexplicitly (e.g. 'print (float) fabs (3.0 )')
(Gdb) call (void) [[self view] size]
**************************************** **************************************** ******************************
The Xcode debugger provides you with a GDB interface, which is an open-source debugger of GNU. You can do anything in the visual interface of Xcode. However, if you need it, you can use the GDB command in the command line.
Enter the GDB command line in a debugging task:
Click Console Drawer in the toolbar to open the Console.
You can view the commands that the Xcode debugger sends to GDB in the console, or you can directly enter the GDB command in the console. In the console window, click and enter the command at the gdb prompt.