【发布时间】:2017-08-07 07:09:28
【问题描述】:
我目前正在尝试学习 swift,在编写一些虚拟代码时,我注意到 xcode 跳过了一些行,有时会停在奇怪的行上。我的环境:macos sierra,xcode 版本 8.2.1 (8C1002)
由于xcode跳过了一些行,我认为问题出在代码优化上,然后我切换到终端调试,下面是输入和输出
我用
编译swiftc -g -Onone *.swift
然后
用 lldb 加载它
lldb main
如下所示在 lint 18 上设置断点并使用“r”运行进程
17 do {
-> 18 try StaticM.teststatic2()
19 print (1)
20 }catch {
21
(lldb) thread step-in
Process 963 stopped
* thread #1: tid = 0x86e1, 0x0000000100001f6a main`static StaticM.teststatic2(self=main.StaticM, $error=Error @ 0x00007fff5fbffac0) throws -> () + 26 at staticExt.swift:13, queue = 'com.apple.main-thread', stop reason = step in
frame #0: 0x0000000100001f6a main`static StaticM.teststatic2(self=main.StaticM, $error=Error @ 0x00007fff5fbffac0) throws -> () + 26 at staticExt.swift:13
10 public extension StaticM {
11 @discardableResult
12 public static func teststatic2() throws {
-> 13 var asdf=2;
14 let sdfgsdfg=2;
15 print(sdfgsdfg);
16 print (asdf);
(lldb) n
Process 963 stopped
* thread #1: tid = 0x86e1, 0x0000000100001f72 main`static StaticM.teststatic2(self=main.StaticM, $error=Error @ 0x00007fff5fbffac0) throws -> () + 34 at staticExt.swift:15, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x0000000100001f72 main`static StaticM.teststatic2(self=main.StaticM, $error=Error @ 0x00007fff5fbffac0) throws -> () + 34 at staticExt.swift:15
12 public static func teststatic2() throws {
13 var asdf=2;
14 let sdfgsdfg=2;
-> 15 print(sdfgsdfg);
16 print (asdf);
17 asdf += 1;
18 }
(lldb) process continue
Process 963 resuming
2
2
1
Process 963 exited with status = 0 (0x00000000)
(lldb)
问题是,我在 lldb 中使用“n”进入下一行后,为什么 lldb 会跳过 staticExt.swift 的第 14 行并直接跳到第 15 行?
另外,有时在尝试调试其他程序时,我在 xcode 中单击“step-in”,它停在 func 的声明行而不是代码块中的第一行,我单击 stepover,它返回到调用者 func 行,而不是执行该 func 的第一行。
总而言之,程序可以工作,但为什么 lldb 即使使用 -Onone 和 -g 也会跳转? 你能告诉我在哪里可以找到更多信息吗? 非常感谢。
【问题讨论】: