2012-03-02 22 views
0

對於靜態std :: forward_list,調試器只顯示第1個元素。VS2010調試器在靜態std :: forward_list上失敗,任何解決方法?

非靜態std :: forward_list或靜態std :: list工作正常。

在我可以使用的調試器中有什麼解決辦法嗎?

#include "stdafx.h" 
#include <forward_list> 
#include <list> 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    static std::forward_list<int> sfl; 
    sfl.push_front(1); 
    sfl.push_front(2); 

    std::forward_list<int> fl; 
    fl.push_front(1); 
    fl.push_front(2); 

    static std::list<int> sl; 
    sl.push_front(1); 
    sl.push_front(2); 

    //Break here. 
    //In a debugger watch window: 
    // 'sfl' only shows the '2' element 
    // 'fl' & 'sl' shows all elements. 
    return 0; 
} 

回答

0

我相信這是Visual Studio的調試器可視化工具中的一個錯誤。最接近的解決辦法,我想出了是修改autoexp.datforward_list項(通常在%VSINSTALLDIR%\Common7\Packages\Debugger\找到)

文件應該有以下內容的部分:

;------------------------------------------------------------------------------ 
; std::forward_list from <forward_list> 
;------------------------------------------------------------------------------ 
std::forward_list<*>{ 
    preview (
     #(
      "(", 
      #list(
       head: $e._Myhead, 
       next: _Next 
      ) : $e._Myval, 
      ")" 
     ) 
    ) 

    children (
     #list(
      head: $e._Myhead, 
      next: _Next 
     ) : $e._Myval 
    ) 
} 


更換搭配:

;------------------------------------------------------------------------------ 
; std::forward_list from <forward_list> 
;------------------------------------------------------------------------------ 
std::forward_list<*>{ 
    preview (
     #(
      "(", 
      #(
       $e._Myhead->_Myval, 
       ",", 
       #list(
        head: $e._Myhead->_Next, 
        next: _Next 
       ) : $e._Myval, 
      ), 
      ")" 
     ) 
    ) 

    children (
     #(
      [actual 0]: $e._Myhead->_Myval, 
      #list(
       head: $e._Myhead->_Next, 
       next: _Next 
      ) : $e._Myval 
     ) 
    ) 
} 


這並不是一個很好的解決方案。它將孩子顯示爲[actual 0], [0], [1], ...而不是[0], [1], [2], ...,即元素x標記爲[x-1]

但是,您可以修改autoexp.dat而不關閉Visual Studio,您只需重新啓動調試器。所以我建議只要你需要調試一個特定的問題就使用這個黑客,然後恢復到原來的autoexp.dat

相關問題