Lldb Debug Commands

Source: Internet
Author: User
Tags print object uikit gdb debugger

After XCode4.0, the compiler replaced the LLVM compiler 2.0

More powerful than before:
The 1.LLVM compiler is the next area of open source compilation technology. Fully supports C, objective-c, and C + +.
The 2.LLVM is twice times faster than GCC, and the established program runs faster. Because it better utilizes the structure of the modern chip.
The 3.LLVM and Xcode 4 are fully integrated. Including keyword highlighting, code integrity, and so on, are all analyzed by the LLVM parser. This allows you to get a good idea of your code as you edit it.

After the compiler evolved, the console debug command prefix, also from the original GDB changed to Lldb, so when you see the console without gdb and appear lldb, do not panic, because we used to debug commands can still be used:

Usage Prerequisites:

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 two conditions are met, the console (that is, the Log Output window all output) will automatically hit a (lldb) command, after which you enter BT and return.

Congratulations, Xcode will automatically output the last call stack. As follows:

  1. * Thread #1: tid = 0x1f03, 0x0132edee corefoundation ' ___forwarding___ + 206, Stop reason = Exc_breakpoint (code=exc_i386_b PT, subcode=0x0)
  2. Frame #0:0x0132edee corefoundation ' ___forwarding___ + 206
  3. Frame #1:0x0132ecb2 corefoundation ' _cf_forwarding_prep_0 + 50
  4. Frame #2:0x00002e60 testmvc '-[viewctrl2 touchesbegan:withevent:] + + at viewctrl2.m:40
  5. Frame #3:0x013c9e99 corefoundation '-[nsobject performSelector:withObject:withObject:] + 73
  6. Frame #4:0x000ffc49 UIKit ' Forwardtouchmethod + 268
  7. Frame #5:0x000ffb38 UIKit '-[uiresponder touchesbegan:withevent:] + 30
  8. Frame #6:0x0003a2cf UIKit '-[uiwindow _sendtouchesforevent:] + 272
  9. Frame #7:0x0003a5e6 UIKit '-[uiwindow sendevent:] + 273
  10. Frame #8:0x00020dc4 UIKit '-[uiapplication sendevent:] + 464
  11. Frame #9:0x00014634 UIKit ' _uiapplicationhandleevent + 8196
  12. Frame #10:0x012b2ef5 graphicsservices ' purpleeventcallback + 1274
  13. Frame #11:0x0139c195 corefoundation ' __cfrunloop_is_calling_out_to_a_source1_perform_function__ + 53
  14. Frame #12:0x01300ff2 corefoundation ' __cfrunloopdosource1 + 146
  15. Frame #13:0x012ff8da corefoundation ' __cfrunlooprun + 2218
  16. Frame #14:0x012fed84 corefoundation ' cfrunlooprunspecific + 212
  17. Frame #15:0x012fec9b corefoundation ' Cfrunloopruninmode + 123
  18. Frame #16:0x012b17d8 graphicsservices ' Gseventrunmodal + 190
  19. Frame #17:0x012b188a graphicsservices ' Gseventrun + 103
  20. Frame #18:0x00012626 UIKit ' Uiapplicationmain + 1163
  21. Frame #19:0x000026fa testmvc ' main + at main.m:16
  22. Frame #20:0x00002645 testmvc ' start + 53


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

  1. Command explanation
  2. Break NUM sets a breakpoint on the specified line.
  3. BT displays all the call stack frames. This command can be used to display the order in which functions are called.
  4. Clear removes breakpoints that are set on a specific source file, on a specific line. Its usage is: Clear filename:num.
  5. 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.
  6. Display EXPR Displays the value of an expression every time the program stops. An expression consists of a variable defined by a program.
  7. The file file loads the specified executable file for debugging.
  8. Help NAME displays assistance information for the specified command.
  9. Info break Displays the list of current breakpoints, including the number of times the breakpoint was reached.
  10. Info files Displays detailed information about the files being debugged.
  11. Info func Displays all the function names.
  12. Info Local Displays the local variable information in the function.
  13. Info prog shows the execution state of the program being debugged.
  14. Info var displays all the global and static variable names.
  15. Kill terminates the program that is being debugged.
  16. The list displays the source code snippet.
  17. Make to run the Make tool without exiting GDB.
  18. Next executes a line of source code forward without stepping into other functions.
  19. Print expr Displays the value of the expression expr.
  20. Print-object Printing an Object
  21. print (int) name prints a type
  22. Print-object [artist description] Call a function
  23. Set artist = @ "Test" sets the value of the variable
  24. Whatis view the data type of the variable



The use of LLDB debugging tools, combined with a method to solve exc_bad_access errors--nszombieenabled together, is really a great tool to find crash Ah, it is convenient!

nszombieenabled can only be used in debug, release time, be sure to remove.

LLDB Command Common (Memo)

If you are going to run this in the simulator, you can enter the following in the "(LLDB)" Prompt:

(LLDB) PO $eax

LLDB is the default debugger in xcode4.3 or later versions. If you are using an older version of Xcode, you are also GDB debugger. They have some basic same commands, so if your xcode uses a "(GDB)" hint instead of a "(LLDB)" Hint, you can do it more, without problems.

The "po" command is shorthand for "print object". "$eax" is a register of Cups. In the case of an exception, this register will contain a pointer to an exception object. Note: $eax will only work in the emulator, if you debug on the device, you will need to use the "$r 0″ register.

For example, if you enter:

(LLDB) PO [$eax class]

You will see something like this:

(ID) $ = 0x01446e84 NSException

These numbers are not important, but it is clear that the NSException object you are dealing with is here.

You can call any method on this object. For example:

(LLDB) PO [$eax name]

This will output the name of the exception, here is the nsinvalidargumentexception, and:

(LLDB) PO [$eax reason]

This will output an error message:

(unsigned int) $4 = 114784400 Receiver () have no segue with identifier ' Modalsegue '

Note: When you use only the "Po $eax", this command will call the "description" method and print out the object, in which case you will get the wrong message.

Utility LLDB Command

Command name Usage description

Expr Expr expression A useful command that can dynamically execute a specified expression and print the result at debug time.
Po PO Expression Similar to expr, the object description method is called when the object is printed. It's a shorthand for print-object .
Print Print (type) expression is also a print command, you need to specify a type.
Bt BT [ALL] The print call stack is a shorthand for the thread BackTrace , plus all to print the stack of all the thread.
BR L BR L It's a shorthand for the breakpoint list .
Process Continue L Process continue Shorthand:C
Thread step-in L Thread step-in L Abbreviation:s
Thread Step-inst L Thread Step-inst L Abbreviation:si
Thread Step-over L Thread Step-over L Shorthand:n
Thread Step-over-inst L Thread Step-over-inst L Abbreviation:ni
Thread Step-out L Thread Step-out L Abbreviation:f
Thread List Thread List Abbreviation:th l

memory leak hidden hint
Potential Leak of an object allocated in line ...
data assignment hidden hint
The left operand of ... is a garbage value;
object reference hidden hint
Reference-counted object is used after it is released;

for retain, copy, Init, Release , Autorelease, etc. in the count of the use of the situation of the detailed explanation, recommend:

Http://www.cnblogs.com/andyque/archive/2011/08/08/2131236.html

Call Autorelease This means that you can use Vari in this function, but once the next run loop is called, it will be sent to the release object. Then the reference count is changed to 0, then the memory is freed. (As for how autorelease works, my understanding is that each thread has a autoreleasepool stack, which puts a lot of Autoreleasepool objects in it.) When you send a autorelease message to an object, the object is added to the Autoreleasepool at the top of the current stack. When the current Runloop is finished, the pool is destroyed and the release message is sent to all the Autorelease objects inside it. The Autoreleasepool is created at the beginning of the current runloop and pressed into the top of the stack. So what is a runloop? A UI event, a Timer call, a delegate call, will be a new runloop. )

What to do when the program crashes, as in the next two parts (English version):

Http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1

(Part-1 in Chinese) http://article.ityran.com/archives/1006

Http://www.raywenderlich.com/10505/my-app-crashed-now-what-part-2

(Part-2 in Chinese) http://article.ityran.com/archives/1143

Memory Usage Detailed Description:

Http://www.cocoachina.com/bbs/simple/?t94017.html

Lldb Debug Commands

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.