当前位置:首页 » IOS文章 » Swift 使用 LLDB 调试命令

Swift 使用 LLDB 调试命令

作者:KNN   日期:2020-02-16   分类:IOS文章

Swift 使用 LLDB 调试命令

打印和赋值
观察数值变量和view对象属性

1. p指令可打印其对象类型、内存地址以及该对象的值等具体信息,
2. po指令则是打印其调用description方法得到的值。
3. e 赋值指令
4. n 命令,代表 Step Over 操作。
5. s 命令,代表 Step Into 操作。
6. finish 命令,代表 Step Out 操作。
7. c 命令,代表恢复程序执行操作。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

简单变量赋值,仅仅在调试环境赋值了一个值,是局部变量,可以用print打印

(lldb) e let hello = "Hello"
you can simply use:
(lldb) p let hello = "Hello"
  • 1
  • 2
  • 3

使用"$"符号定义全局常量和变量

OC中为:
(lldb) e NSString *$a = @"c" (lldb) po $a c
Swift中变为:
(lldb) e let $a = "a"
(lldb) po $a "a"
  • 1
  • 2
  • 3
  • 4
  • 5

Swift中多行语句:输入完成敲一个空行即可开始执行

(lldb) p
Enter expressions, then terminate with an empty line to evaluate:
struct compass{var direction = "N"; var angle = 16.5}
var c = compass()
print(c)
(lldb)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

同样的你也可以向当前view添加一个layer

(lldb) p
Enter expressions, then terminate with an empty line to evaluate:
let layer = CALayer()
layer.backgroundColor = UIColor.yellow.cgColor
layer.bounds = CGRect(x:0, y:0, width:100, height:100)
layer.position = CGPoint(x:250, y:300)
layer.cornerRadius = 12.0
view.layer.addSublayer(layer)
(lldb)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

view指针赋值

(lldb) e id $view = (id) 0x7fbd71432590
  • 1

使用指针进行操作

(lldb) e (void) [$view setBackgroundColor:[UIColor redColor]]
  • 1

当然,我们运行完这条命令,界面上不会马上反应出来,我们还需要调用这个命令刷新一下:

(lldb) e (void)[CATransaction flush]
  • 1

让代码停在Swift Error 或者Objective C异常
停在Objective C异常

(lldb) br s -E  objc
Breakpoint 6: where = libobjc.A.dylib`objc_exception_throw, address = 0x000000010dededbb
  • 1
  • 2

停在Swift Error

(lldb) br s -E swift
Breakpoint 7: where = libswiftCore.dylib`swift_willThrow, address = 0x000000010e55ccc0
  • 1
  • 2

停在某一种类型的Swift Error

(lldb) br s -E swift -O EnumError
Breakpoint 8: where = libswiftCore.dylib`swift_willThrow, address = 0x000000010e55
  • 1
  • 2

ps: LLDB太强大了,有待学习,继续学习

 

文章来源网络:点击这里查看源文.

  • 上一篇:Block块/Swift闭包介绍与使用
  • 下一篇:没有了