IOS Xcode Debugging common commands and breakpoint finishing _ios

Source: Internet
Author: User
Tags print object uikit

IOS Xcode Debug Common commands and breakpoints

The debugging techniques in Xcode are closely related to our day-to-day development, and these debugging techniques often have a multiplier effect when we solve bugs, often with various breakpoints and commands. And these debugging skills are often asked in the interview, so do not know to take a look at it.

Debugging commands

In the image above, the right green area is the log output area, and some commands can be used to assist debugging in the log output area.
What are the debugging commands?

To see all of the debugging commands, you can enter them in the right area of the diagram above to help list all the debugging commands.

This article on the use of a number of relatively high frequency, the other on the view, you know it.

1. P command

--(' expression--') Evaluate an expression in the current thread.
           Displays any returned the value with Lldb ' s default formatting.

The p command is shorthand for the Print command, and the P command allows you to view values of the base data type, but if you are viewing an object using the P command, only the pointer address of the object is returned.

The P command can be followed by an expression, in addition to variables, constants. (❌ but cannot use macro ❌)

2. PO Order

The PO command can be understood as a print object. function is similar to the P command, so it is possible to print constants, variables, and to print an object returned by an expression. (❌ can also not print macros ❌)

Of course, these print functions, in addition to the use of commands, we can also use the left area, click the variable right button-> print Description of "xxx":

Of course, there are other ways to print:

3.expr command

Expr is a shorthand for expression, using the expr command to dynamically execute an assignment expression while debugging, and print out the results. We can dynamically modify the value of a variable while debugging, which is useful when debugging wants the application to execute an exception path, such as executing an else case.

(LLDB) P i 
(nsinteger) $16 = 1
(lldb) Expression i = 5
(nsinteger) $17 = 5
(lldb) po i 
5

4.call command

The above is the value of dynamically modifying variables, and Xcode also supports dynamic call functions. This command is executed on the console, and you can modify the view on the interface without modifying the code, without recompiling.

Here is an example of a dynamic removal of a child view of a cell:

(LLDB) PO cell.contentView.subviews <__nsarraym 0x60800005f5f0> (<UILabel:0x7f91f4f18c90; frame = (5 5; 300 25) ; Text = ' 2-drawing index is top ... '; userinteractionenabled = NO; tag = 1; layer = <_uilabellayer:0x60800009ff40>>, <UIImageView:0x7f91f4d20050; frame = (105 20; 85 85); opaque = NO; userinteractionenabled = NO; tag = 2; layer = <calayer:0x60000003ff60>>, <UIImageView:0x7f91f4f18f10; frame = (200 20; 85 85); opaque = NO; userinteractionenabled = NO; tag = 3; 
Layer = <CALayer:0x608000039860>>) (LLDB) call [Label Removefromsuperview] (LLDB) PO cell.contentView.subviews <__nsarraym 0x600000246de0> (<UIImageView:0x7f91f4d20050; frame = (n); opaque = NO; userinteraction Enabled = NO; tag = 2; layer = <calayer:0x60000003ff60>>, <UIImageView:0x7f91f4f18f10; frame = (200 20; 85 85); opaque = NO; userinteractionenabled = NO; tag = 3; Layer = <CALayer:0x608000039860>>)

5.BT command

btThe command can print the stack information for the thread, which is more detailed than the debug Navigator on the left.

btcommand is to print stack information for the current thread

(LLDB) bt * thread #1: tid = 0x27363, 0x000000010d204125 testdemo '-[fifthviewcontroller tableview:cellforrowatindexpath: ] (self=0x00007f91f4e153c0, _cmd= "Tableview:cellforrowatindexpath:", tableview=0x00007f91f5889600, indexPath= 0xc000000000400016) + 2757 at fifthviewcontroller.m:91, queue = ' com.apple.main-thread ', stop reason = Breakpoint 6.1 * F Rame #0:0x000000010d204125 testdemo '-[fifthviewcontroller Tableview:cellforrowatindexpath:] (self= 0X00007F91F4E153C0, _cmd= "Tableview:cellforrowatindexpath:", tableview=0x00007f91f5889600, indexPath= 0xc000000000400016) + 2757 at fifthviewcontroller.m:91 frame #1:0x0000000111d0a7b5 uikit '-[uitableview _createPrepared CellForGlobalRow:withIndexPath:willDisplay:] + 757 frame #2:0x0000000111d0aa13 Uikit '-[uitableview _ Createpreparedcellforglobalrow:willdisplay:] + 0x0000000111cde47d frame #3: Uikit '-[uitableview _ Updatevisiblecellsnow:isrecursive:] + 3295 frame #4:0x0000000111d13d95 Uikit '-[uitableview _ Performwithcachedtraitcollection:] + the frame #5:0x0000000111cfa5ef uikit '-[uitableview layoutsubviews] + 222 frame #6:0x0000000111c61f50 UIKit '-[uiview (calayerdelegate) Layoutsublayersoflayer:] + 1237 frame #7:0x00000001117a5cc4 quartzcore '-[CALayer Layoutsublayers] + 146 frame #8:0x0000000111799788 quartzcore ' ca::layer::layout_if_needed (ca::transaction*) + 366 fra Me #9:0x0000000111799606 quartzcore ' ca::layer::layout_and_display_if_needed (ca::transaction*) + frame #10: 0x0000000111727680 Quartzcore ' ca::context::commit_transaction (ca::transaction*) + 280 frame #11:0x0000000111754767 Quartzcore ' Ca::transaction::commit () + 475 frame #12:0x00000001117550d7 quartzcore ' Ca::transaction::observer_ Callback (__cfrunloopobserver*, unsigned long, void*) + 113 frame #13:0x0000000110743e17 corefoundation ' __cfrunloop_is_ Calling_out_to_an_observer_callback_function__ + frame #14:0x0000000110743d87 corefoundation ' __ Cfrunloopdoobservers + 391 frame #15:0x0000000110728b9e corefoundation ' __cfruNlooprun + 1198 Frame #16:0x0000000110728494 corefoundation ' cfrunlooprunspecific + 420 frame #17:0x0000000114390a6f Graphicsservices ' Gseventrunmodal + 161 frame #18:0x0000000111b9d964 uikit ' Uiapplicationmain + 159 frame #19:0x000000 010d21294f Testdemo ' main (argc=1, argv=0x00007fff529fe620) + at main.m:14 frame #20:0x000000011458a68d libdyld.dylib  ' Start + 1 (lldb)

bt allThe command is to print stack information for all threads. Print out too much information, will not show!

6.image command

image listcommand to list all of the module in the current app, which is useful at the end of a symbolic breakpoint, to view the code location of an address.

In addition to image list image add , and image lookup other commands, you can view.

When you encounter crash, view the line stacks, only see the stack frame address, use image lookup –address 地址 can easily navigate to this address corresponding to the line of code.

Breakpoint

The breakpoint in Xcode is also very learned, there are common breakpoints, conditional breakpoints, symbol breakpoints, abnormal breakpoints and many other kinds.

1. Normal Breakpoint

To hit a normal breakpoint, just need to find the corresponding line, the code on the Left (line number) click on it.

2. Conditional breakpoint

A conditional breakpoint is a useful breakpoint, especially in a for loop. If we need to add a breakpoint at i = 5 o'clock, we can use a conditional breakpoint if it is not added at other times. A conditional breakpoint is the right key on a normal breakpoint, select Edit Breakpoint... , and then set a condition

3. Symbolic Breakpoint

A symbolic breakpoint is Symbolic Breakpoint , in fact, a breakpoint on a particular function, either an OC function or a C + + function. Add the following places:


The Symbol column can be filled with a [class name method name] or a method name, and module is also an optional entry, which is image the module listed in the above command.

For example, if we fill out only one viewdidload, we break the point at the viewdidload of all classes (including the third third-party).

Symbol breakpoints in debugging some of the modules do not have the source code, such as debugging a third-party provided Lib library, or the system's module, you can in the corresponding function under the breakpoint, you can probably debug the program's running process, you can also view the breakpoint when the parameter information.

4. Exception Breakpoint

If the program crashes, we can hit an exception breakpoint, which triggers a breakpoint when it crashes, easily locating the problem, and seeing more crash-related information, such as log, function call stack.

Note: Some programs or some functions may use exceptions to organize the program logic, such as calling Avaudioplayer, run to Avaudioplayer, will cause the breakpoint to be triggered. We can modify the Exception parameter, or cancel out the exception breakpoint to solve.

5.Watch Breakpoint

Triggers when a variable is changed.

To create a watch breakpoint:

There are so many breakpoints and commands in the Xcode debugging tips, and other useful additions later.

Thank you for reading, I hope to help you, thank you for your support for this site!

Related Article

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.