LLDB在打印double类型的struct字段时遇到各种问题,如下所述:strange-behavior-in-lldb-when-printing-a-double-type-struct-member .

在我自己的情况下,我试图打印CLLocationCoordinate2D类型的结构 . 从Xcode 4.5.2开始,打印CLLocationCoordinate2D时出现错误 .

寻找解决这个bug的方法我在这篇博客中遇到了一个很好的宏LOG_EXPR:http://vgable.com/blog/2010/08/19/the-most-useful-objective-c-code-ive-ever-written/

它将类型记录到调试器中做得很好,但无法从调试器调用 .

在LLDB命令行界面中进行调试时,是否有人想出了一种方法来执行类似LOG_EXPR的操作,或者除了切换回GDB之外还有任何其他改进的打印方式可以处理来自命令行的任意结构?

这是我输入LLDB时发生的情况:

(lldb) p (CLLocationCoordinate2D)[self mapSetPointLatLon]
(CLLocationCoordinate2D) $4 = {
  (CLLocationDegrees) latitude = 42.4604
  (CLLocationDegrees) longitude = 42.4604
  (double) easting = 42.4604
  (double) northing = -71.5179
}

注意lldb添加的冗余和错误行 .

以下是将LOG_EXPR编译到代码中时发生的情况(在同一个断点处):

Line of Code (not debugger):

 LOG_EXPR(self.mapSetPointLatLon);

produces the correct output in the debugger output:
  2013-01-26 14:02:17.555 S6E11[79116:c07] self.mapSetPointLatLon = {latitude=42.4604,longitude=-71.5179}

在同一断点处,如果我尝试从命令行调用LOG_EXPR,则会发生以下情况:

(lldb) expr LOG_EXPR(self.mapSetPointLatLon);
error: use of undeclared identifier 'LOG_EXPR'
error: 1 errors parsing expression
(lldb)

这是另一个例子,因为事实证明有一种情况可以让调试器做正确的事情 .

这是我的代码片段,我在其中分配struct 2方式:

CLLocationCoordinate2D defloc = CLLocationCoordinate2DMake(kStartingLat, kStartingLon);
[[self.verticalPagingViewController mapPagingViewController] setMapSetPointLatLon: defloc];

如果我只打印变量就可以了 .

(lldb) p defloc
(CLLocationCoordinate2D) $1 = {
  (CLLocationDegrees) latitude = 42.4604
  (CLLocationDegrees) longitude = -71.5179
}

如果我正在转换访问器方法的返回值的类型,它将失败 .

(lldb) p (CLLocationCoordinate2D)[[self.verticalPagingViewController mapPagingViewController] mapSetPointLatLon]
(CLLocationCoordinate2D) $2 = {
  (CLLocationDegrees) latitude = 0
  (CLLocationDegrees) longitude = 0
  (double) easting = 0
  (double) northing = 0
}