【问题标题】:Confusing LLDB output令人困惑的 LLDB 输出
【发布时间】:2013-07-20 22:12:46
【问题描述】:

我的 C 知识在这里可能存在漏洞,但我有点困惑为什么会发生这种情况。

(lldb) p lineGroup
(NSInteger) $17 = -1
(lldb) p (lineGroup > 4)
(bool) $18 = true
(lldb) p (lineGroup < 0 )
(bool) $19 = false
(lldb) p (-1 < 0)
(bool) $20 = true
(lldb) p ((int)lineGroup < 0 )
(bool) $21 = false
(lldb) p ((int)lineGroup > 4)
(bool) $22 = true
(lldb) 

lineGroup 变量赋值如下:

- (void)gotLineGroupInformation:(NSString *)lineGroupString
{
    NSInteger lineGroup = [lineGroupString integerValue];
    if(lineGroup >= 0)
    {
        // Always gets called
    }
    else
    {
        // Never gets called
    }
}

谢谢, 安迪

【问题讨论】:

  • 你编译的架构是什么?如果是 64 位,则 NSInteger 将是 64 位,而 int 将是 32 位。
  • 您的问题只是关于明显错误的调试器输出吗?还是您的代码没有按预期工作?

标签: objective-c c lldb


【解决方案1】:

lldb 问题似乎与Objective C integer comparison error 中的完全相同:

Carl Norum 在回复中说:

已确认 - 这是 lldb IR 解释器中的错误。

这里是修复它的补丁的链接:http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20130520/008569.html


关于您的代码,我尝试通过此测试重现错误但没有成功:

NSString *lineGroupString = @"-1";
NSInteger lineGroup = [lineGroupString integerValue];
if(lineGroup >= 0)
{
    NSLog(@"positive");
}
else
{
    NSLog(@"negative"); // This log is correctly called every time
}

也许您应该尝试使用NSLog 进行调试(尤其是在输入函数后lineGroupString 的值是多少?)。

【讨论】:

  • 是的,这是“Objective C 整数比较错误”的 dup 问题。 Xcode 4.6.x 中的 lldb-179 有 Andy 在此处报告的错误;它固定在树 lldb svn 源的顶部。 Xcode 4.6.x 之后的任何 Xcode 版本都将包含该修复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-03
  • 1970-01-01
  • 1970-01-01
  • 2018-05-21
  • 2010-12-23
  • 2014-09-23
  • 2016-12-10
相关资源
最近更新 更多