Xcode Advanced Debugging techniques (1) __lldb

Source: Internet
Author: User
Tags bz2
Some of the commands we can use in debugging are listed in Apple's official document, and we'll focus on some common commands

Debug local File Method (Mac OS X): (LLDB) target Create "/users/piaoyun/desktop/xx.app/contents/macos/xxxx"

Remote Debugging methods:

Device side running:

Attach process:

./debugserver *:1234-a "Yourappname"

To start a process directly:

Debugserver-x backboard *:1234/path/to/app/executable

Cases:

Debugserver-x backboard *:1234/applications/mobilenotes.app/mobilenotes

This command starts Notepad and breaks the first instruction on Dyld.


After the Mac terminal runs the LLDB command, enter the following 2 commands:
Platform Select Remote-ios
Process connect connect://your device IP address: 1234


Using USB connection method:

////////////////////////////////////////////////////////////////////////////////////////

wget http://cgit.sukimashita.com/usbmuxd.git/snapshot/usbmuxd-1.0.8.tar.bz2
Tar xjfv usbmuxd-1.0.8.tar.bz2
CD usbmuxd-1.0.8/python-client/
Python tcprelay.py-t 1234:1234

After the Mac terminal runs the LLDB command, enter the following 2 commands:

Platform Select Remote-ios

Process Connect connect://localhost:1234

////////////////////////////////////////////////////////////////////////////////////////

-(void) Loginwithusername: (NSString *) Username password: (nsstring *) password

{

NSLog (@ "Login ... username:%@ password:%@", username, password); Let's say we break the breakpoint here.

}

First, basic operation 1.1. View Level

Print view Hierarchy po [self.contentview recursivedescription] 1.2. Change a value

int a = 1;
Console expr a=2
NSLog (@ "Actual value:%d", a);
1.3.call Change the background color of view
Call [Self.view Setbackgroundcolor:[uicolor Redcolor]]
1.4. Declaring Variables
expr int $b =2 or e int $b =2
//Output  PO $b

Print (type) expression

Example:

print (int) $r 6

Print username

1.5. Print Stack

The print stack method in iOS is Nsthread callstacksymbols, there's a simple way to do this when debugging

BT  or  BT all
1.6. Change method return value

Thread return No/yes

-(BOOL) returnyes
{
    //thread return NO, you can change the function returned value returns
    YES;
} method returns a result of No  
1.7. malloc Distribution History of viewing historical objects after multithreading exceptions

First turn on the Enable Zombie Objects and Malloc Stack

(LLDB) Command script import lldb.macosx.heap
(lldb) malloc_info-s 0x7ff7206c3a70 
1.8. Register Lookup Object

Once encountered a problem, [Self.tableview Reloaddata] directly burst. At this time TableView actually no problem, how do we look for the problem.


As shown in the figure above, we finally look at the specific address that the object is assigned to in the heap by Malloc_info-s 0x00007fe99a629560, and then open all the variables on the left side of the table, and enter this address to see what this member is.

1.9. C


Continue to execute


7.s

The source level step into, the child function is encountered


8.si

Stepping, encountering a child function is entered


9.n

Source level step through, encountered child function does not enter, direct step over


10.ni

Stepping, encountering a child function not entering, direct step over


11.finish/f

Exit child function


12.thread List

Print thread list

13.image lookup-a expression, image list

Example:

Image Lookup-a $pc

Returned as follows:

ADDRESS:DEBUG[0X0000B236] (Debug.__text.__text + 1254)

Summary:debug ' main + at main.m:16

Print Load Module list

Image list [-f-o usually takes these two parameters to use]

Returned as follows:

[0] 40e417a4-f966-3db4-b028-b0272dc016a7 0x000a0000/users/piao/library/developer/xcode/deriveddata/ Debug-bdkhskdqykkoqmhjedilckzvpuls/build/products/debug-iphoneos/debug.app/debug

/users/piao/library/developer/xcode/deriveddata/debug-bdkhskdqykkoqmhjedilckzvpuls/build/products/ Debug-iphoneos/debug.app.dsym/contents/resources/dwarf/debug

[1] 011601c0-f561-3306-846b-94a7c8c841da 0x2d9e6000/users/piao/library/developer/xcode/ios DeviceSupport/7.1.2 ( 11d257)/symbols/system/library/frameworks/coregraphics.framework/coregraphics


Find a function:


For this use with debug symbols

Image Lookup-r-N <FUNC_REGEX>

For this use of no debug symbols:

Image Lookup-r-S <FUNC_REGEX>


14.disassemble-a Address

Example:

Dis-a $pc

Debug ' main at main.m:14:

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.