LLDB sometimes displays vector data, and in other cases

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

Desired enter image description here

Other times, I get this useless view:

Undesirable enter image description here

I cannot understand what conditions force LLDB to render vectors in an undesirable way.

Question
What causes unwanted behavior? Can they be fixed without re-writing the code? Is this a bug in LLDB?

Here is an example of a short code that reproduces unwanted 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 the link to the Xcode project:
http://s000.tinyupload.com/?file_id=21020556485232357417

+4
source share
2 answers

, std::vector . , expr v , v , ... .

+3

, , , Qaru .

lldb. v:

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

size=1. , print 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 , , .

+3

Source: https://habr.com/ru/post/1690915/


All Articles