Common debugging commands for IOS development

Source: Internet
Author: User

After XCode4.0, the compiler is LLVM, and the console debug command prefix is LLDB

First, LLVM Introduction

LLVM is the framework of the architecture compiler (compiler), written in C + +, to optimize the compile time (compile-time), Link time (link-time), run time (run-time), and idle time of programs written in any programming language ( Idle-time), keep the developer open and compatible with existing scripts.

Second, for developers interested in compiling technology, LLVM offers many advantages:

the modern designThe design of the LLVM is highly modular, making its code clearer and easier to troubleshoot problems. Language-independent intermediate codeOn the one hand, this makes it possible to connect different languages to each other through LLVM, and enables LLVM to interact and integrate closely with the IDE. On the other hand, the release of intermediate code rather than the target code can better exploit its potential on the target system without harming the i.e. Target code is generated on the target system for the native hardware environment, but it is possible to conduct row-level debugging directly through the intermediate code. as a library of tools and functionsThe tools provided by LLVM can be used to make it easier to implement an optimization compiler or VM for a new programming language, or to introduce some of the better tuning/debugging features for an existing programming language. Third, the use of the premise:

1. Since it is a debug command, of course, the program mode should choose Debug mode.

2. In debug mode, if your program crashes in operation (Crash), then congratulations, the opportunity to use LLDB debugging.

After the two conditions are met, the console (that is, the Log Output window all output) automatically hits a (LLDB) command, where you can debug.

The four common debugging commands

Po

PO is a shorthand for print-object, which can be used to print all NSObject objects. Sample code:

(LLDB) PO self.view

<UITableView:0xdb00200; frame = (0 20; 320 460); Clipstobounds = YES; AutoResize = w+h; Gesturerecognizers = <NSArray:0x8b3ca50>; Layer = <CALayer:0x8b3c110>; Contentoffset: {0, 0}>

(LLDB) po Self

<RootViewController:0x9813e90>

P

P is a shorthand for print and can be used for printing all simple types, such as int, float, struct, etc. Sample code:

[OBJC]View Plaincopyprint?
    1. ITEMDATA&NBSP;ITEM;&NBSP;&NBSP;
    2.          item.nmainid=1;  
    3.         item .nsubid=2;&NBSP;&NBSP;
    4.         item.pszTitle= @ "Hello";   
    5. &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
    6.         nsrect rect=nsmakerect (0,  10, 1 0, 10);   

Debug commands and Output results:

(LLDB) Print rect

(nsrect) $ = (x=0, y=10), (width=10, height=10)

(LLDB) P Item

(itemdata) $ = {

Psztitle = 0x0000000100001370 @ "Hello"

Nmainid = 1

Nsubid = 2

}

Pager

Call is the meaning of the invocation. In fact, the above PO and P also have the function of calling. The call is typically used only when no display output is required, or when the method has no return value

Bt

Xcode will automatically output the last Call stack

Of course there are other commands (and GDB commands are common):

[CPP]View Plaincopy Command ExplanationBreak NUM sets a breakpoint on the specified line. BT displays all the call stack frames.    This command can be used to display the order in which functions are called. Clear removes breakpoints that are set on a specific source file, on a specific line. Its usage is: Clear filename:num.continue continue to execute the program being debugged.    This command is used when the program stops running because of processing a signal or a breakpoint. Display EXPR Displays the value of an expression every time the program stops.    An expression consists of a variable defined by a program. FileFile Loads the specified executable file for debugging. Help NAME displays assistance information for the specified command. Infobreak Displays the list of current breakpoints, including the number of times the breakpoint was reached. info files               Displays detailed information about the files being debugged.    info func                 Displays all the function names.    info local                Displays the local variable information in the function.    info prog                 Displays the execution status of the program being debugged.    info var                  displays all the global and static variable names.    kill                      terminates the program that is being debugged.    list                      Displays the source code snippet.   &NBSP;MAKE&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;            run  make  tool without exiting  gdb .    next                      executes a line of source code forward without stepping into other functions.    print EXPR                Displays the value of expression  EXPR .     print-object             Print an object    print  (int) name prints a typePrint-object [artist description] calls a function set artist = @"Test" sets the value of a variableWhatis view the data types of the variable note: Learn from the blogs of richard_ columns and liangguo03 columns
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.