如何使用self和enum在Swift中设置条件断点的条件?

mra*_*iao 13 debugging enums ios lldb swift

我有一个HTTP方法的枚举:

enum HTTPMethod: String {
  case GET = "GET"
  case POST = "POST"
}
Run Code Online (Sandbox Code Playgroud)

我有一个请求类和一个请求包装类:

class Request {
  let method: HTTPMethod = .GET
}

class RequestWrapper {
  let request: Request

  func compareToRequest(incomingRequest: NSURLRequest) -> Bool {

     // Next line is where the conditional breakpoint set.
     return request.method.rawValue == incomingRequest.HTTPMethod
  }
}
Run Code Online (Sandbox Code Playgroud)

我在行上设置了一个条件断点:

return request.method.rawValue == incomingRequest.HTTPMethod
Run Code Online (Sandbox Code Playgroud)

条件:

self.request.method == HTTPMethod.POST
Run Code Online (Sandbox Code Playgroud)

然后调试器在该行停止并显示错误消息:

Stopped due to an error evaluating condition of breakpoint 1.1:     
"self.request.method == HTTPMethod.POST"
Couldn't parse conditional expression:
<EXPR>:1:1: error: use of unresolved identifier 'self'
self.request.HTTPMethod == HTTPMethod.POST
Run Code Online (Sandbox Code Playgroud)

如果我删除self并将条件更改为:

request.method == HTTPMethod.POST
Run Code Online (Sandbox Code Playgroud)

错误消息如下所示:

Stopped due to an error evaluating condition of breakpoint 1.1:  
"request.method == HTTPMethod.POST"
Couldn't parse conditional expression:
<EXPR>:1:1: error: could not find member 'method'
request.method == HTTPMethod.POST
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题?

更新:

它能够检查self.request.method使用LLDB命令的值:

fr v self.request.method
Run Code Online (Sandbox Code Playgroud)

如果我使用局部常量来存储值,调试器可以停在正确的位置:

// Use a local constant to store the HTTP method
let method = request.method

// Condition of breakpoint
method == HTTPMethod.POST
Run Code Online (Sandbox Code Playgroud)

更新2:

我正在使用Xcode 6.3.1

Jim*_*ham 2

这显然是一个 lldb 错误。您没有提及您正在使用的工具版本。如果您没有使用 6.3.1 或更高版本,请再次尝试使用它。如果您仍然遇到问题,请通过http://bugreporter.apple.com提交错误。

请注意,frame varexpr是完全不同的野兽。 frame var仅直接使用 DWARF 调试信息打印局部变量的值,但不是表达式计算器。例如,它不知道该怎么做==。我想如果你这样做:

(lldb) self.request.method == HTTPMethod.POST
Run Code Online (Sandbox Code Playgroud)

当停在该断点处时,您会看到相同的效果。

表达式解析器必须发挥额外的技巧,冒充类的方法(通过 self 等获得透明引用才能工作),并且要做到这一点有点棘手。显然,我们在您的案例中没有正确完成这项工作。