【问题标题】:LLDB sometimes displays vector data and other times does notLLDB 有时显示矢量数据,有时不显示
【发布时间】:2018-05-30 20:31:00
【问题描述】:

在大多数情况下,在调试时,如果我有一个向量(在 Xcode 9 中),我会看到一个表示向量中值的索引列表。

希望

其他时候,我得到这种无益的表示:

不受欢迎的

我无法弄清楚是什么条件导致 LLDB 以不合需要的方式显示向量。

问题
是什么导致了不良行为?可以在不重新编写代码的情况下修复它吗?这是 LLDB 中的错误吗?

这是一个重现不良行为的简短代码示例:

#include <iostream>
#include <vector>

std::vector<int> createVector()
{
    std::vector<int> v = { 1, 2, 3 };
    return v;
}

int main(int argc, const char * argv[])
{
    const auto& v = createVector();
    std::cout << v.front() << std::endl;
    return 0;
}


这是 Xcode 项目的链接:
http://s000.tinyupload.com/?file_id=21020556485232357417

【问题讨论】:

  • 两者之间唯一明显的区别是一个完全是STL类型——一个指向整数的唯一指针向量。第二个涉及自定义或第三方库类型。也许如果 XCode 不知道如何解析 "Imxr::MxrLinked[List?]" 类型,它会放弃解析唯一的 ptr / vector ?
  • 我编辑了问题以更清楚地表明这不是问题所在。让我知道编辑是否有帮助。
  • 你用什么优化编译?

标签: c++ xcode vector xcode9 lldb


【解决方案1】:

这是 std::vector 数据摘要和格式化程序如何为参考变量工作的一个已知错误。请注意,在expr v 中,表达式解析器实际上认为 v 是一个直向量,而不是对向量的引用......这就是打印工作的原因。

【讨论】:

  • 是否有公开的错误报告?如果是这样,一个链接将完成答案。
  • Apple Bug Reporter 系统中有一个错误,但这只对提交错误的人在外部可见。我没有在llvm.org/bugs 跟踪器中找到等效的错误。如果有人在我们开始之前有时间修复它,那么添加一个是值得的。
【解决方案2】:

对不起,我在答案中添加了我的评论,因为 Stack Overflow cmets 不支持格式化。

这绝对是 lldb 的问题。您的图片不包含完整的 v 描述:

v = (const std::__1::vector<int, std::__1::allocator<int> > &) size=1

size=1 不正确。 除了lldb控制台中的打印命令正确打印v:

(lldb) p v
(const std::__1::vector<int, std::__1::allocator<int> >) $1 = size=3 {
  [0] = 1
  [1] = 2
  [2] = 3
}

Xcode 似乎使用 lldb frame var 命令来显示变量。这显示的输出与 Xcode 显示的输出完全相同:

(lldb) frame variable -T
(int) argc = 1
(const char **) argv = 0x00007fff5fbff710
(const std::__1::vector<int, std::__1::allocator<int> > &) v = size=1: {
  (std::__1::__vector_base<int, std::__1::allocator<int> >) std::__1::__vector_base<int, std::__1::allocator<int> > = {
    (std::__1::__vector_base<int, std::__1::allocator<int> >::pointer) __begin_ = 0x000000010103fa40
    (std::__1::__vector_base<int, std::__1::allocator<int> >::pointer) __end_ = 0x000000010103fa4c
    (std::__1::__compressed_pair<int *, std::__1::allocator<int> >) __end_cap_ = {
      (std::__1::__libcpp_compressed_pair_imp<int *, std::__1::allocator<int>, 2>) std::__1::__libcpp_compressed_pair_imp<int *, std::__1::allocator<int>, 2> = {
        (int *) __first_ = 0x000000010103fa4c
      }
    }
  }
}

我认为问题在于变量v 最初是在另一个堆栈帧中创建和初始化的,因此当初始向量被传递时,有关向量的一些信息在较低的堆栈帧中是未知的函数调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多