Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLDB sometimes displays vector data and other times does not

In most cases when debugging, if I have a vector (in Xcode 9), I am shown a list of indices representing the values in the vector.

Desired enter image description here

Other times, I get this unhelpful representation:

Undesired enter image description here

I am unable to figure out what conditions cause LLDB to display vectors in the undesirable way.

Question
What is causing the undesired behavior? Can it be fixed without re-writing the code? Is this a bug in LLDB?

Here is a short code example that reproduces the undesired behavior:

#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;
}


Here is a link to the Xcode project:
http://s000.tinyupload.com/?file_id=21020556485232357417

like image 538
Matthew James Briggs Avatar asked Dec 17 '17 05:12

Matthew James Briggs


1 Answers

This is a known bug in how the std::vector data summary & formatters work for reference variables. Note that in the expr v the expression parser actually considers v to be a straight vector, not a reference to a vector... That's why that printing works.

like image 134
Jim Ingham Avatar answered Oct 01 '22 21:10

Jim Ingham