iOS Dev > Learning-just left-click breakpoints? It's time to try a breakpoint like that.

Source: Internet
Author: User
Tags print object uikit

The Realm of Emptiness

Website: http://supermao.cn/duan-dian-shen-ru-liao-jie/

Click "Read original" To view this page

The code cannot be debugged without debugging, and debugging cannot have no breakpoint (break point). Xcode's breakpoint function is also becoming more and more powerful.

Basic Breakpoint

For example, this is the most commonly used breakpoint and is also the easiest to set. Left-click to set it up.

Edit Breakpoint

Breakpoints can be edited.

Breakpoints have several properties that you can set:

    • Condition

    • Ignore

    • Action

    • Options

Condition

The conditional expression can be entered here, and the breakpoint will take effect when the condition is met. For example, enter a = = 50 above. This is a very useful setting, especially when debugging in the loop, with really cool.

Ingore

Here you can set the number of ignored breakpoints.

Action

Action is the most complex and powerful feature here. The action has a type of 6. Such as

    1. AppleScript

    2. Capture GPU Frame

    3. Debugger Command

    4. Log Message

    5. Shell Command

    6. Sound

Log message and debugger Command are commonly used.

Log Message

The things you fill out here can be printed to the console. For example I made the following settings

%b will print the name of the breakpoint,%h will print the number of calls to the breakpoint, @@ 中间 Middle can enter an expression. The above settings in the console output are as follows:

...-application:didfinishlaunchingwithoptions:92 20

2015-07-28 22:19:21.905 test[981:38016] 91

-application:didfinishlaunchingwithoptions:93 20-application:didfinishlaunchingwithoptions:94 20-application: didfinishlaunchingwithoptions:95 20

2015-07-28 22:19:21.913 test[981:38016] 92

2015-07-28 22:19:21.921 test[981:38016] 93

2015-07-28 22:19:21.929 test[981:38016] 94

-application:didfinishlaunchingwithoptions:96 20

2015-07-28 22:19:21.937 test[981:38016] 95

-application:didfinishlaunchingwithoptions:97 20

2015-07-28 22:19:21.944 test[981:38016] 96

-application:didfinishlaunchingwithoptions:98 20

2015-07-28 22:19:21.952 test[981:38016] 97

-application:didfinishlaunchingwithoptions:99 20

2015-07-28 22:19:21.959 test[981:38016] 98

-application:didfinishlaunchingwithoptions:100 20

2015-07-28 22:19:21.967 test[981:38016] 99

Debugger Command

Here you can enter debug commands, which are PO (print object information), BT (print function stack), expression (expressions) these debug commands. Look at the picture to understand:

The console output is as follows:

<uiapplication:0x7fc92360b1d0>* thread #1: tid = 0xb7db, 0x0000000101d0eb11 Test '-[appdelegate application: Didfinishlaunchingwithoptions:] (self=0x00007fc923400570, _cmd=0x00000001033f3123, application=0x00007fc92360b1d0 , launchoptions=0x0000000000000000) + $ at appdelegate.m:20, queue = ' com.apple.main-thread ', stop reason = breakpoint 1. 1

* Frame #0:0x0000000101d0eb11 Test '-[appdelegate application:didfinishlaunchingwithoptions:] (self= 0x00007fc923400570, _cmd=0x00000001033f3123, application=0x00007fc92360b1d0, launchoptions=0x0000000000000000) + 97 At appdelegate.m:20 frame #1:0x0000000102c0d748 UIKit '-[uiapplication _handledelegatecallbackswithoptions: Issuspended:restorestate:] + frame #2:0x0000000102c0e357 UIKit '-[uiapplication _ Callinitializationdelegatesformainscene:transitioncontext:] + 2540 frame #3:0x0000000102c1119e UIKit '-[ UIApplication _runwithmainscene:transitioncontext:completion:] + 1349 frame #4:0x0000000102c10095 UIKit '-[ UIApplication workspacedidendtransaction:] + 179 frame #5:0x0000000107d3c5e5 frontboardservices ' __31-[FBSSerialQueue Performasync:]_block_invoke_2 + frame #6:0x00000001024da41c corefoundation ' __cfrunloop_is_calling_out_to_a_block __ + frame #7:0x00000001024d0165 corefoundation ' __cfrunloopdoblocks + 341 frame #8:0x00000001024cff25 corefoundation ' __cfrunlooprun + 2389 fraMe #9:0x00000001024cf366 corefoundation ' cfrunlooprunspecific + 470 frame #10:0x0000000102c0fb02 UIKit '-[uiapplication _run] + 413 frame #11:0x0000000102c128c0 UIKit ' Uiapplicationmain + 1282 frame #12:0x0000000101d0edbf Test ' main (Argc=1, a RGV=0X00007FFF5DEF13A8) + 111 at main.m:14 frame #13:0x0000000104dbd145 libdyld.dylib ' start + 1 frame #14:0x0000000104db d145 libdyld.dylib ' start + 1 (int) $ = 98

2015-07-28 22:36:54.654 test[1150:47067] 98

2015-07-28 22:36:54.670 test[1150:47067] 99

Options

After checking automatically continue after evaluating actions, the program will continue to run after the breakpoint has been generated. This property is quite useful in that you can enter debug information as far as the program is not paused.

Out of the basic breakpoint above, Xcode also provides the following four kinds of breakpoints, you need to click on the lower left corner of the breakpoint panel to add the + sign.

    • Exception Breakpoint

    • OpenGL ES Error Breakpoint

    • Symbolic Breakpoint

    • Test Failure Breakpoint

Exception Breakpoint

Exception Breakpoint is a very useful breakpoint entry. As the name implies, a breakpoint is generated when the program throws an exception. Usually a program crash stops at the point where it crashes, but sometimes it doesn't stop exactly where it's causing the exception. such as array out of bounds! As I've shown, it causes an array of cross-border access.

The program will crash when it runs. But the crash stopped in the main function, even if you look at the stack information can not immediately navigate to the end of the array is the cross-border access. Why does the crash fail to stop in the array where it crosses? This is because an array out-of-bounds access does not necessarily cause the program to crash, and an array out-of-bounds access causes an exception to be thrown, and the thrown exception is not processed to cause the program to crash. As a result, the crash stops inside the corefoundation framework. This time you need to set exception breakpoint to create a breakpoint to locate the error.

OpenGL ES Error Breakpoint

This is mainly OpenGL ES breakpoint debugging, this person is useless.

Symbolic Breakpoint

Symbolic breakpoint, symbolic breakpoint, is really debugging artifact ah. Breakpoints are generated when a program runs to a specific symbol. Adding breakpoints in this way does not need to be added to the source file, nor does it need to know where the breakpoint is set in the first line of the file.

Two more attribute symbol and module than normal breakpoint.

Symbol

The contents of the symbol can be as follows:


1. Method Name: All class methods that have this method name will take effect. For example initWithFrame:.
2. Methods for a particular class: The OC class and the C + + class are applicable, for example, [UIView initwithframe:] or Shap::d Raw ().
3. Function name. For example, ordinary C functions.

By setting the symbol to debug, easy to stop, how to break the breakpoint on how to break.

Test Failure Breakpoint

This type of breakpoint pauses the execution of the program when test assertion fails

iOS Dev > Learning-just left-click breakpoints? It's time to try a breakpoint like that.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.