2017-04-09 3 views
0

노드 이름이 unordered_map입니다. 다음과 같이 선언한다 : 다음과 같이LLDB에서 C++ 객체의 메소드를 호출하면 결과가 제공되지 않습니다.

unordered_map<T,shared_ptr<Vertex<T>>> nodes 

정점 선언 된 클래스입니다 :

template<typename T> 
struct Vertex { 

    Vertex(T pLabel) : label(pLabel) {}; 

    void addEdge(T destination,int weight) { 
     edges[destination] = weight; 
    } 

    T label; 
    unordered_map<T, int> edges; 
}; 

나는 다음과 같이 정점의 unoredered_map을 받아들이는 방법이있다.

template<typename T> 
void getMinSpanningTree(unordered_map<T,shared_ptr<Vertex<T>>>& nodes, T first, int infinityMarker) { 

    cout << nodes.size() << endl; 

    if(nodes.size() == 0) { 
     return; 
    } 
    ... 
    ... 

나는 LLDB의 실행을 중지하고 입력 할 때 다음

다음과 같은 출력
(lldb) expr nodes.size() 

내가 얻을 : 나는을하는 방법을 잘 그래서

(lldb) expr nodes.size() 
error: Couldn't lookup symbols: 
    __ZNKSt3__113unordered_mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEENS_10shared_ptrI6VertexIS6_EEENS_4hashIS6_EENS_8equal_toIS6_EENS4_INS_4pairIKS6_SA_EEEEE4sizeEv 

을 아니에요 디버거가 대답을 올바르게 출력합니다. 출력 콘솔에 다음과 같은 라인을위한 표준 출력, 인쇄 5 : 나는 기능과 클래스를 사용하고 있습니다 방법은 다음과

cout << nodes.size() << endl; 

가있다 : 노드를 인쇄

int main(int argc, const char * argv[]) { 

    shared_ptr<Vertex<string>> v1 = make_shared<Vertex<string>>("V1"); 
    shared_ptr<Vertex<string>> v2 = make_shared<Vertex<string>>("V2"); 
    shared_ptr<Vertex<string>> v3 = make_shared<Vertex<string>>("V3"); 
    shared_ptr<Vertex<string>> v4 = make_shared<Vertex<string>>("V4"); 
    shared_ptr<Vertex<string>> v5 = make_shared<Vertex<string>>("V5"); 

    v1->addEdge("V2", 1); 
    v1->addEdge("V3", 3); 

    v2->addEdge("V1", 1); 
    v2->addEdge("V3", 3); 
    v2->addEdge("V4", 6); 

    v3->addEdge("V1", 3); 
    v3->addEdge("V2", 3); 
    v3->addEdge("V4", 4); 
    v3->addEdge("V5", 2); 

    v5->addEdge("V2", 3); 


    unordered_map<string,shared_ptr<Vertex<string>>> vertices; 
    vertices[v1->label] = v1; 
    vertices[v2->label] = v2; 
    vertices[v3->label] = v3; 
    vertices[v4->label] = v4; 
    vertices[v5->label] = v5; 

    getMinSpanningTree(vertices,v1->label,numeric_limits<int>::max()); 

    return 0; 
} 

을, 모든 것을 덤프 보인다 :

(std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > > >) $0 = size=5 { 
    [0] = { 
    __cc = { 
     first = "V5" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c68 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208c68 
     } 
    } 
    __nc = { 
     first = "V5" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c68 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208c68 
     } 
    } 
    } 
    [1] = { 
    __cc = { 
     first = "V4" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208748 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208748 
     } 
    } 
    __nc = { 
     first = "V4" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208748 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208748 
     } 
    } 
    } 
    [2] = { 
    __cc = { 
     first = "V2" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c08 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208c08 
     } 
    } 
    __nc = { 
     first = "V2" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c08 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208c08 
     } 
    } 
    } 
    [3] = { 
    __cc = { 
     first = "V3" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x00000001002086e8 strong=2 weak=1 { 
     __ptr_ = 0x00000001002086e8 
     } 
    } 
    __nc = { 
     first = "V3" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x00000001002086e8 strong=2 weak=1 { 
     __ptr_ = 0x00000001002086e8 
     } 
    } 
    } 
    [4] = { 
    __cc = { 
     first = "V1" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208ba8 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208ba8 
     } 
    } 
    __nc = { 
     first = "V1" 
     second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208ba8 strong=2 weak=1 { 
     __ptr_ = 0x0000000100208ba8 
     } 
    } 
    } 
} 
+0

GDB는 훌륭한 디버깅 도구, 당신은 쉽게 자습서를 조회 또는 문서를 – chbchb55

+0

내 플랫폼을 읽을 수 있습니다 맥 OS X 및 I입니다 Xcode를 사용하십시오. 현재 기본 디버거는 LLDB이며 신속하고 Objective-C에서 매우 잘 작동합니다. C++을 효율적으로 디버깅 할 수 있기를 원합니다. 따라서 GDB로 전환하고 싶지는 않습니다. 생산성이 될 수있는 유일한 방법이 아니면요. – user1044328

+1

[인쇄/디버깅 libC++ STL with XCode/LLDB] 가능한 복제본 (http://stackoverflow.com/questions/39680320/printing-debugging-libc-stl-with-xcode-lldb) – jtbandes

답변

0

나는 이것이 위의 jtbandes 링크에서 설명한 것과 동일한 문제임을 확신합니다. 나는 당신의 예를 컴파일 할 경우, 다음을 수행하십시오

> nm a.out | grep size 
> 

이과 일치하는 데이터가 존재하지 않는, 더 size 기능이 생성되지 않았 음을 보여주는. 컴파일러는 일반적으로 템플릿 함수 인스턴스화를 사용하지 않으므로 코드에서 사용하지 않으면 실제로 "크기"를 호출하여 방출 가능성을 높여야합니다. 그러나 그 변화에도 불구하고, 나는 아직도이 방법이 생성 된 것을 보지 못했다. 오히려 사용법은 항상 인라인됩니다.

디버거는 함수의 인라인 버전을 올바르게 호출 할 가능성이 거의 없습니다. 여기 당신을 도울 수있는 일이별로 없습니다. clumber에 버그가 있습니다 & -O0에서 인라인 할 때 공격적이지 않으므로 STL과 관련이 있습니다. 이것이이 문제에 대한 유일한 실용적인 해결책입니다.

링크 된 문제점에서 제안 된 해결 방법은 클래스 선언을 전달하는 것이 었습니다. 그러나 나는 컴파일러를 통과 한이 클래스의 포워드 선언으로 성공을 거두지 못했습니다. 어쩌면 C++을 가진 누군가가 할 수 있을까요?

print 또는 frame variable은지도 요소를보고 크기를 인쇄 할 수 있지만 별도의 메커니즘 인 lldb "데이터 포맷터"를 통해 수행됩니다. 당신이 작동하는 방법에 대한 자세한 내용을 알고 싶은 경우에, 참조가 여기에 있습니다 :

http://lldb.llvm.org/varformats.html

관련 문제