LLDB动态调试

2020-04-12  本文已影响0人  lmfei
进入断点模式

常用指令

breakpoint list / break l
当前断点
breakpoint set --name getNum
breakpoint set --selector touchesBegan:withEvent:
breakpoint set --func-regex getNu
breakpoint delete 8
breakpoint disable 2  /  breakpoint dis 2
breakpoint enable 2
(lldb) p num
(NSInteger) $0 = 3
(lldb) po num
3
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
  * frame #0: 0x000000010f426710 LLDB调试`-[ViewController getNum](self=0x00007fd805d107d0, _cmd="getNum") at ViewController.m:29:13
    frame #1: 0x000000010f4266bb LLDB调试`-[ViewController touchesBegan:withEvent:](self=0x00007fd805d107d0, _cmd="touchesBegan:withEvent:", touches=1 element, event=0x0000600000d85320) at ViewController.m:24:21
(lldb) up
frame #1: 0x000000010f4266bb LLDB调试`-[ViewController touchesBegan:withEvent:](self=0x00007fd805d107d0, _cmd="touchesBegan:withEvent:", touches=1 element, event=0x0000600000d85320) at ViewController.m:24:21
   21   
   22   - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
   23       NSLog(@"我来了");
-> 24       NSInteger num = [self getNum];
                            ^
   25       NSLog(@"%ld", num);
   26   }
   27   
(lldb) down
frame #0: 0x000000010f426710 LLDB调试`-[ViewController getNum](self=0x00007fd805d107d0, _cmd="getNum") at ViewController.m:29:13
   26   }
   27   
   28   - (NSInteger)getNum {
-> 29       return  arc4random()%10+1;
                    ^
   30   }
   31   
   32   @end
frame select 5
frame variable
(lldb) image list
[  0] B9970493-7622-3728-A35A-BADBEAA5978D 0x0000000106935000 /Users/liumingfei/Library/Developer/Xcode/DerivedData/LLDB调试-dtexkkvfffircsgsiivncltrmcgy/Build/Products/Debug-iphonesimulator/LLDB调试.app/LLDB调试 
[  1] CE635DB2-D47E-3C05-A0A3-6BD982E7E750 0x0000000110338000 /usr/lib/dyld 
[  2] 528E1F55-F655-3533-99B9-7EAE1DAE5D07 0x000000010693f000 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/dyld_sim 
[  3] 30153EA5-45E2-334A-99DF-6E79D88AB4D0 0x0000000106c2b000 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation 
[  4] 83003EB9-EC0F-3743-871E-ED786CDAAFC7 0x0000000107207000 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libobjc.A.dylib 
[  5] 5D4D8F98-6E5B-31E1-94EA-3839C26E223F 0x0000000107b3d000 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libSystem.B.dylib 
(lldb) image lookup -t LObject
1 match found in /Users/liumingfei/Library/Developer/Xcode/DerivedData/LLDB调试-dtexkkvfffircsgsiivncltrmcgy/Build/Products/Debug-iphonesimulator/LLDB调试.app/LLDB调试:
id = {0x40000002b}, name = "LObject", byte-size = 24, decl = LObject.h:13, compiler_type = "@interface LObject : NSObject{
    NSString * _flag;
    NSInteger _tag;
}
@property ( getter = flag,setter = setFlag:,readwrite,copy,nonatomic ) NSString * flag;
@property ( getter = tag,setter = setTag:,assign,readwrite,nonatomic ) NSInteger tag;
@end"
@interface LObject : NSObject

@property (nonatomic, copy) NSString *flag;
@property (nonatomic, assign) NSInteger tag;
- (void)lDescribtion;

@end

@interface ViewController ()
@property (nonatomic, retain) LObject *to;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.to = [[LObject alloc] init];
    self.to.tag = 22;
    self.to.flag = @"normal";
    NSLog(@"我来了");
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    self.to.flag = @"special";
}

@end

1.添加内存断点
在NSLog处加断点,然后控制台执行指令watchpoint set variable self->_to->_flag

(lldb) watchpoint set variable self->_to->_flag
Watchpoint created: Watchpoint 1: addr = 0x6000018e7448 size = 8 state = enabled type = w
    watchpoint spec = 'self->_to->_flag'
    new value: 0x00000001016cc078
2020-03-26 10:17:21.657879+0800 LLDB调试[80028:2548356] 我来了

Watchpoint 1 hit:
old value: 0x00000001016cc078
new value: 0x00000001016cc0b8
(lldb) po 0x00000001016cc078
normal

(lldb) po 0x00000001016cc0b8
special
  1. 通过内存地址添加断点
    还是在NSLog处添加断点,然后获取flag的内存地址,在通过watchpoint set expression下断点
(lldb) p &self->_to->_flag
(NSString **) $0 = 0x0000600003da8328
(lldb) watchpoint set expression 0x0000600003da8328
Watchpoint created: Watchpoint 1: addr = 0x600003da8328 size = 8 state = enabled type = w
    new value: 4495532152
2020-03-26 10:31:12.151198+0800 LLDB调试[80318:2565697] 我来了

Watchpoint 1 hit:
old value: 4495532152
new value: 4495532216
(lldb) po 4495532152
normal

(lldb) po 4495532216
special

生活如此美好,今天就点到为止。。。

上一篇 下一篇

猜你喜欢

热点阅读