2013-12-17 84 views
2

在我的代碼是這樣的有參考的載體:LLDB:打印由一個shared_ptr

shared_ptr<vector<unsigned int>> f = 
    make_shared<vector<unsigned int>>(); 

我怎麼能打印出更漂亮,我只能訪問的shared_ptr對象的矢量

frame variable f 

frame variable f.__ptr_->size() 

call to a function 'std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >::size() const' that is not present in the target 

獲取此錯誤?

回答

5

鑑於此代碼段:

#include <vector> 
#include <memory> 

using namespace std; 

int main() 
{ 
    shared_ptr<vector<unsigned int> > f = 
     make_shared<vector<unsigned int> >(); 
    f->push_back(1); 
    f->push_back(1); 
    f->push_back(1); 
    return 0; 
} 

LLDB只是爲我工作:

(lldb) fr var 
(std::__1::shared_ptr<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > >) f = 0x00000001001038c8 size=3 (strong=1 weak=1) { 
    __ptr_ = 0x00000001001038c8 size=3 
} 

更妙的是,如果我擴大_ _ptr_:

(lldb) fr var --ptr-depth=2 
(std::__1::shared_ptr<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > >) f = 0x00000001001038c8 size=3 (strong=1 weak=1) { __ptr_ = 0x00000001001038c8 size=3 { 
    [0] = 1 
    [1] = 1 
    [2] = 1 } } 
+0

哪個版本你用的是lldb嗎? – rano

+0

開源ToT –

+1

Enrico的例子在Xcode 5.0(lldb-300.2.53)下正常工作。 –