Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common commands in Xcode

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the common commands in Xcode". In daily operation, I believe many people have doubts about the common commands in Xcode. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the common commands in Xcode?" Next, please follow the editor to study!

1. P command

-- ('expression -') Evaluate an expression on the current thread.

Displays any returned value with LLDB's default formatting.

The p command is an abbreviation for the print command, which allows you to view the values of the basic data types, but if you use the p command to view an object, only the pointer address of the object is returned. The p command can be followed by variables, constants and expressions. (❌ but cannot use macro ❌)

2. Po command

The po command can be understood as printing objects. The function is similar to the p command, so you can also print constants, variables, objects returned by print expressions, and so on. (❌ also cannot print macro ❌)

P and po usage examples

Of course, for these printing functions, in addition to using the command, we can also use the left area and right click on the variable-> print Description of "xxx":

Paste_Image.png

Of course, there are other ways to print:

3.expr command

Expr is the abbreviation of expression. Using the expr command, you can dynamically execute the assignment expression and print out the result when debugging. 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 an else case.

(lldb) p I

(NSInteger)

17 = 5

(lldb) po I

five

4.call command

Above are the values of dynamically modified variables, and Xcode also supports dynamic calls to functions. By executing this command in the console, you can modify the view on the interface without modifying the code or recompiling. Here is an example of dynamically removing a child view of cell:

(lldb) po cell.contentView.subviews

(

)

(lldb) call [label removeFromSuperview]

(lldb) po cell.contentView.subviews

(

)

5.bt command

The bt command prints out the stack information for the thread, which is a little more detailed than what Debug Navigator on the left sees.

The bt command prints 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) + 2757at FifthViewController.m:91, queue = 'com.apple.main-thread', stop reason = breakpoint 6.1* frame # 0: 0x000000010d204125 TestDemo- [FifthViewController tableView:cellForRowAtIndexPath:] (self=0x00007f91f4e153c0, _ cmd= "tableView:cellForRowAtIndexPath:", tableView=0x00007f91f5889600, indexPath=0xc000000000400016) + 2757at FifthViewController.m:91

Frame # 1: 0x0000000111d0a7b5 UIKit- [UITableView _ createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 757 frame # 2: 0x0000000111d0aa13 UIKit- [UITableView _ createPreparedCellForGlobalRow:willDisplay:] + 74

Frame # 3: 0x0000000111cde47d UIKit- [UITableView _ updateVisibleCellsNow:isRecursive:] + 3295 frame # 4: 0x0000000111d13d95 UIKit- [UITableView _ performWithCachedTraitCollection:] + 110

Frame # 5: 0x0000000111cfa5ef UIKit- [UITableView layoutSubviews] + 222frame # 6: 0x0000000111c61f50 UIKit- [UIView (CALayerDelegate) layoutSublayersOfLayer:] + 1237

Frame # 7: 0x00000001117a5cc4 QuartzCore- [CALayer layoutSublayers] + 146frame # 8: 0x0000000111799788 QuartzCoreCA::Layer::layout_if_needed (CA::Transaction) + 366

Frame # 9: 0x0000000111799606 QuartzCoreCA::Layer::layout_and_display_if_needed (CA::Transaction*) + 24 frame # 10: 0x0000000111727680 QuartzCoreCA::Context::commit_transaction (CA::Transaction) + 280

Frame # 11: 0x0000000111754767 QuartzCoreCA::Transaction::commit () + 475 frame # 12: 0x00000001117550d7 QuartzCoreCA::Transaction::observer_callback (_ _ CFRunLoopObserver, unsigned long, void) + 113

Frame # 13: 0x0000000110743e17 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 frame # 14: 0x0000000110743d87 CoreFoundation__CFRunLoopDoObservers + 391

Frame # 15: 0x0000000110728b9e CoreFoundation__CFRunLoopRun + 1198 frame # 16: 0x0000000110728494 CoreFoundationCFRunLoopRunSpecific + 420

Frame # 17: 0x0000000114390a6f GraphicsServicesGSEventRunModal + 161 frame # 18: 0x0000000111b9d964 UIKitUIApplicationMain + 159

Frame # 19: 0x000000010d21294f TestDemomain (argc=1, argv=0x00007fff529fe620) + 111at main.m:14 frame # 20: 0x000000011458a68d libdyld.dylibstart + 1

(lldb)

The bt all command prints stack information for all threads. If there is too much information printed out, it will not be displayed!

6.image command

The image list command lists all the module in the current App (this module is useful in subsequent symbol breakpoints), and you can see the code location for an address. In addition to image list, there are image add, image lookup and other commands, which can be checked by yourself. When you encounter crash, look at the thread stack and only see the address of the stack frame. Using the image lookup-address address, you can easily locate the line of code corresponding to this address.

Breakpoint

Breakpoints in Xcode are also very knowledgeable, such as ordinary breakpoints, conditional breakpoints, symbolic breakpoints, abnormal breakpoints, and so on.

1. Ordinary breakpoint

To hit a normal breakpoint, just find the corresponding line and click on the left side of the code (line number).

two。 Conditional breakpoint

Conditional breakpoints are useful breakpoints, especially in for loops. If we need to add breakpoints at I = 5 and not at other times, then we can use conditional breakpoints. The conditional breakpoint is right-click on the normal breakpoint, and select Edit Breakpoint..., to set another condition.

Edit normal breakpoints

Add condition

3. Symbolic breakpoint

A symbolic breakpoint is a Symbolic Breakpoint, which is actually a breakpoint for a specific function, which can be an OC function or a C++ function. The places added are as follows:

Symbolic breakpoint

Symbolic breakpoint condition

The Symbol field can be filled in [class name, method name] or method name, and module is also optional, which is the module listed in the above image command. For example, if we fill in only one viewDidLoad, we will break the point at the viewDidLoad of all classes (including third-party libraries).

Symbolic breakpoints are useful when debugging modules that do not have source code, such as debugging a third-party Lib library, or modules of the system, you can set breakpoints at the corresponding functions, you can roughly debug the running flow of the program, and you can also check the parameter information at the breakpoint.

4. Abnormal breakpoint

If the program crashes, we can hit an exception breakpoint so that the breakpoint will be triggered when the crash occurs, it is easy to locate the problem, and we can see more crash-related information, such as Log, function call stack.

Abnormal breakpoint

The condition of an exception breakpoint can be modified

Note: some programs or functions may use exceptions to organize program logic, such as calling AVAudioPlayer, which causes breakpoints to be triggered when running to AVAudioPlayer. We can modify the Exception parameter or cancel the exception breakpoint to solve the problem.

5.Watch breakpoint

Triggers when a variable changes. Create a Watch breakpoint:

At this point, the study of "what are the common commands in Xcode" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development