벡터에 unique_ptr
을 사용하는 C++ 11 코드가 있습니다.lldb (xcode)와 lldb (독립형)
#include <vector>
#include <iostream>
#include <memory>
using namespace std;
class A
{
int x;
public:
A() {}
~A() {}
A(A& a) {}
A(int x) {this->x = x;}
int get() {return x;}
};
int main()
{
vector<unique_ptr<A>> v;
auto a = new A(10);
unique_ptr<A> pa(a);
v.push_back(move(pa)); // move(pa);
auto a2 = new A(20);
unique_ptr<A> pb(a2);
v.push_back(move(pb)); // move(pa);
for (auto& i: v)
{
cout << i->get();
}
}
Xcode를 사용하여 벡터에서 값을 디버그하고 확인할 수 있습니다. 그러나 lldb에서 clang 및 debug를 사용하여 동일한 코드를 컴파일하면 두 가지 오류가 발생합니다.
첫 번째는 STL 소스 코드에 lldb 흔적이다.
* thread #1: tid = 0x1f03, 0x0000000100001744 a.out`__gnu_cxx::__normal_iterator<std::unique_ptr<A, std::default_delete<A> >*, std::vector<std::unique_ptr<A, std::default_delete<A> >, std::allocator<std::unique_ptr<A, std::default_delete<A> > > > >::operator*() const at stl_iterator.h:740, stop reason = step over
frame #0: 0x0000000100001744 a.out`__gnu_cxx::__normal_iterator<std::unique_ptr<A, std::default_delete<A> >*, std::vector<std::unique_ptr<A, std::default_delete<A> >, std::allocator<std::unique_ptr<A, std::default_delete<A> > > > >::operator*() const at stl_iterator.h:740
737
738 // Forward iterator requirements
739 reference
-> 740 operator*() const
741 { return *_M_current; }
742
743 pointer
(lldb) n
Process 41243 stopped
두 번째 오류는 벡터 내용을 보려고 시도했을 때 세그먼테이션 오류입니다.
(lldb) p v
Segmentation fault: 11
이 명령을 컴파일에 사용했습니다.
clang++ -std=c++11 -stdlib=libc++ -g testit.cpp -o a
무엇이 좋을까요? , 어느 것이 어느 이야기하기 위해
- LLDB 표현 파서
- LLDB 데이터 포맷터
을 :