1. Xcode built-in GDB, you can use the GDB debugging, debugging commands:
1.1 PO Command: For the abbreviation of print object, displays the text description
(LLDB) PO [$eax class]: Output the address of an exception object
(LLDB) PO [$eax name]: Output The name of this exception
(LLDB) PO [$eax reason]: This will output the error message:
(LLDB) "Po $eax": Invoke the "description" method on this object and print it out
"$eax" is a register of cup. In the case of an exception, this register will contain a pointer to an exception object. Note: $eax will only work in the simulator, if you are debugging on the device, you will need to use the "$r 0″ Register
1.2 Print command: Somewhat similar to formatted output, you can output different information about an object
For example: print (char*) [[dic description] cString], (LLDB) print (int) [Label Retaincount]
1.3 Info Command: We can view the memory address information
1.4 Info Line * Memory address: Can get information about the code lines where the memory address is located
1.5 Show Command: Displays GDB-related information. such as: Show version displays GDB version information
1.6 BT: Displays the status of the function call stack for the current process; Up num: View the details of the call; down: Returns the list of stacks; L: Displays detailed code information; p: output numeric value.
2. Add Global Breakpoint (add Exception Breakpoint):
2.1 Add steps:
1. In the bottom-left corner of the Breakpoints Navigator, click the Add button.
2. Choose Add Exception Breakpoint.
3. Choose the type of exception from the exception pop-up menu.
4. Choose the phase of the exception handling process at which and want program execution to stop.
5. Click done.
2.2 Use Scene:
The program is crash because of SIGABRT and wants to locate the line that caused crash.
3. Add a symbolic breakpoint (add symbolic Breakpoint):
3.1 Timing of breakpoint execution: Symbolic breakpoints Stop program execution time a specific function or method starts executing
3.2 Add steps:
1. Steps in the Bottom-left corner of the Breakpoint Navigator, click the Add button.
2. Choose Add symbolic Breakpoint.
3. Enter the symbol name in the symbol field.
4. Click done.
3.3 Use scene:
Set the appropriate breakpoint when you want the system to break at a specified condition.
Like what:
Objc_exception_throw: Sets a breakpoint at the point where the system throws an exception.
-[nsexception Raise]:
4. Set up nszombieenabled, mallocstacklogging, nsautoreleasefreedobjectcheckenabled, nsdebugenabled:
4.1 Setting Method:
1. Product->edit Scheme...->run...->environmentvariables.
2. Add Nszombieenabled,set the value with YES
3. Add mallocstacklogging, set the value with YES.
4. Add nsautoreleasefreedobjectcheckenabled, set the value with YES.
5. Add nsdebugenabled, set the value with YES.
4.2 Use Scene:
Primarily to resolve the exc_bad_access problem, mallocstacklogging is used to enable malloc logging (using Malloc_history ${app_pid} ${object_instance_addr}).
4.3 Issues to be aware of
Nszombieenabled can only be used when debugging, do not forget when the product is released, because Nszombieenabled will not really release Dealloc object memory.
5. Rewrite the Respondstoselector method
5.1 Implementation Mode
#ifdef _for_debug_
-(BOOL) Respondstoselector: (SEL) Aselector {
printf ("SELECTOR:%sn", [Nsstringfromselector (Aselector) utf8string]);
return [Super Respondstoselector:aselector];
}
#endif
5.2 Use Method:
You need to include the above code in each object's. m or. mm file (you should be able to use the generic implementation) and add-D _for_debug_ to other C flags (remember to add this tag only under DEBUG configuration). This way, when your program crashes, the Xcode console will accurately record the last method of object running.