C++ Windbg c++;如何打印矢量内容

C++ Windbg c++;如何打印矢量内容,c++,debugging,vector,windbg,C++,Debugging,Vector,Windbg,我有下面的代码片段 Class Filters { vector<int> numbers; } Filters f1; 类过滤器{向量数;} 过滤器f1; 我需要调试f1.number中的内容 Windbg> ??f1.numbers class std::vector<bool,std::allocator<bool> > +0x000 _Myvec : std::vector<unsigned int,s

我有下面的代码片段

Class Filters {    vector<int> numbers; }

Filters f1;
类过滤器{向量数;}
过滤器f1;
我需要调试f1.number中的内容

Windbg>
??f1.numbers
class std::vector<bool,std::allocator<bool> >
   +0x000 _Myvec           : std::vector<unsigned int,std::allocator<unsigned int> >
   +0x018 _Mysize          : 7

Windbg>
??f1.numbers._Myvec._Mypair._Myval2
class std::_Vector_val<std::_Simple_types<unsigned int> >
   +0x000 _Myfirst         : 0x00000089`006cf220  -> 0x7e
   +0x008 _Mylast          : 0x00000089`006cf224  -> 0x5c
   +0x010 _Myend           : 0x00000089`006cf224  -> 0x5c

Windbg>
!stl f1.numbers
<NULL>
Windbg>
??f1.1数字
类std::vector
+0x000\u Myvec:std::vector
+0x018 _Mysize:7
Windbg>
??f1.编号。\u Myvec.\u Mypair.\u Myval2
类别标准::_Vector_val
+0x000\u Myfirst:0x00000089`006cf220->0x7e
+0x008_Mylast:0x00000089`006cf224->0x5c
+0x010\u Myend:0x00000089`006cf224->0x5c
Windbg>
!stl f1.1编号
如何打印内部的7个元素

0:000> lsa .
     1: #include <iostream>
     2: #include <vector>
     3: using namespace std;
     4: int main() {
     5:     vector<int> v = {7, 5, 16, 8};
>    6:     v.push_back(25); 
     7:     v.push_back(13);
     8:     for(int n : v) { std::cout << n << '\n'; }
     9: }
步骤2:执行两次推回以查看其余部分

0:000> p
0:000> p
0:000> ?? v._Mypair._Myval2._Myfirst[4]
int 0n25
0:000> ?? v._Mypair._Myval2._Myfirst[5]
int 0n13
0:000> ?? v._Mypair._Myval2._Myfirst[6]
int 0n-1414812757
或者使用这个表达式

0:000> dd /c 1 @@c++(*(int *)&(v._Mypair._Myval2._Myfirst)) L? ((@@c++(*(int *)&(v._Mypair._Myval2._Mylast))) - (@@c++(*(int *)&(v._Mypair._Myval2._Myfirst))))/@@(sizeof(int)))
0044ac00  00000007
0044ac04  00000005
0044ac08  00000010
0044ac0c  00000008
0044ac10  00000019
0044ac14  0000000d
或者,如果您有更高版本的windbg,其中可以使用natvis javascript等,您只需使用dx命令即可

0:000> dx v
v                 : { size=6 } [Type: std::vector<int,std::allocator<int> >]
    [<Raw View>]     [Type: std::vector<int,std::allocator<int> >]
    [capacity]       : 6
    [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<int>,std::_Vector_val<std::_Simple_types<int> >,1>]
    [0]              : 7 [Type: int]
    [1]              : 5 [Type: int]
    [2]              : 16 [Type: int]
    [3]              : 8 [Type: int]
    [4]              : 25 [Type: int]
    [5]              : 13 [Type: int]
在windbg中

0:000> ?? v._Mypair._Myval2._Myfirst
int * 0x0044abd8
0:000> ?? v._Mypair._Myval2._Myfirst[0]
int 0n7
0:000> ?? v._Mypair._Myval2._Myfirst[1]
int 0n5
0:000> ?? v._Mypair._Myval2._Myfirst[2]
int 0n16
0:000> ?? v._Mypair._Myval2._Myfirst[3]
int 0n8
0:000> ?? v._Mypair._Myval2._Myfirst[4]
int 0n-1414812757
0:000> lsa .
     1: #include <iostream>
     2: #include <vector>
     3: using namespace std;
     4: int main() {
     5:     vector<int> v = {7, 5, 16, 8};
     6:     v.push_back(25); 7:     v.push_back(13);
     8:     for(int n : v) { std::cout << n << '\n'; }
    10:     vector<string> w = {"seven", "five", "sixteen", "eight"};
    11:     w.push_back("twenty five"); 
    12:     w.push_back("thirteen");
>   13:     cout << w[0].c_str() << '\n';
    15: }
0:000> dx v ; dx w
v                  : { size=6 } [Type: std::vector<int,std::allocator<int> >]
    [<Raw View>]     [Type: std::vector<int,std::allocator<int> >]
    [capacity]       : 6
    [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<int>,std::_Vector_val<std::_Simple_types<int> >,1>]
    [0]              : 7 [Type: int]
    [1]              : 5 [Type: int]
    [2]              : 16 [Type: int]
    [3]              : 8 [Type: int]
    [4]              : 25 [Type: int]
    [5]              : 13 [Type: int]
w                 : { size=6 } [Type: std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >]
    [<Raw View>]     [Type: std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >]
    [capacity]       : 6
    [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >,1>]
    [0]              : "seven" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [1]              : "five" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [2]              : "sixteen" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [3]              : "eight" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [4]              : "twenty five" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [5]              : "thirteen" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
0:000>lsa。
1:#包括
2:#包括
3:使用名称空间标准;
4:int main(){
5:向量v={7,5,16,8};
6:v.向后推(25);7:v.向后推(13);

8:(int n:v){sd::cOUT <代码>类过滤器 >不是C++。
0:000> lsa .
     1: #include <iostream>
     2: #include <vector>
     3: using namespace std;
     4: int main() {
     5:     vector<int> v = {7, 5, 16, 8};
     6:     v.push_back(25); 7:     v.push_back(13);
     8:     for(int n : v) { std::cout << n << '\n'; }
    10:     vector<string> w = {"seven", "five", "sixteen", "eight"};
    11:     w.push_back("twenty five"); 
    12:     w.push_back("thirteen");
>   13:     cout << w[0].c_str() << '\n';
    15: }
0:000> dx v ; dx w
v                  : { size=6 } [Type: std::vector<int,std::allocator<int> >]
    [<Raw View>]     [Type: std::vector<int,std::allocator<int> >]
    [capacity]       : 6
    [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<int>,std::_Vector_val<std::_Simple_types<int> >,1>]
    [0]              : 7 [Type: int]
    [1]              : 5 [Type: int]
    [2]              : 16 [Type: int]
    [3]              : 8 [Type: int]
    [4]              : 25 [Type: int]
    [5]              : 13 [Type: int]
w                 : { size=6 } [Type: std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >]
    [<Raw View>]     [Type: std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >]
    [capacity]       : 6
    [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >,1>]
    [0]              : "seven" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [1]              : "five" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [2]              : "sixteen" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [3]              : "eight" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [4]              : "twenty five" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
    [5]              : "thirteen" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
typedef struct _MYSTRUCT {
    int intie;
    string stringie;
    double doblee;
}Mystruct,*PMystruct;

xxxxxx
    vector<Mystruct> y = {{1,"one",1.0}, {5,"five",5.0}, {16,"sixteen",16.0}};
    y.push_back({25,"twenty five",25.0}); 
    for(int i = 0 ; i < 3; i++){
    cout << "{ " << y[i].intie <<"  "<<y[i].stringie.c_str() << "   "<< y[i].doblee <<" } \n";
    }   
0:000> lsp -a 4 ; lsa .
WARNING: Source line display is disabled
At the prompt, display 2 source lines before and 2 after
For lsa commands, display 2 source lines before
For ls and lsa commands, display 4 source lines
    28:     
    29:     vector<Mystruct> y = {{1,"one",1.0}, {5,"five",5.0}, {16,"sixteen",16.0}};
>   30:     y.push_back({25,"twenty five",25.0}); 
    31:     for(int i = 0 ; i < 3; i++){
0:000> dx -r4 y
y                 : { size=4 } [Type: std::vector<_MYSTRUCT,std::allocator<_MYSTRUCT> >]
    [<Raw View>]     [Type: std::vector<_MYSTRUCT,std::allocator<_MYSTRUCT> >]
    [capacity]       : 4
    [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<_MYSTRUCT>,std::_Vector_val<std::_Simple_types<_MYSTRUCT> >,1>]
        [<Raw View>]     [Type: std::_Compressed_pair<std::allocator<_MYSTRUCT>,std::_Vector_val<std::_Simple_types<_MYSTRUCT> >,1>]
    [0]              [Type: _MYSTRUCT]
        [+0x000] intie            : 1 [Type: int]
        [+0x004] stringie         : "one" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [<Raw View>]     [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [size]           : 0x3 [Type: unsigned int]
            [capacity]       : 0xf [Type: unsigned int]
            [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
                [<Raw View>]     [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
            [0]              : 111 'o' [Type: char]
            [1]              : 110 'n' [Type: char]
            [2]              : 101 'e' [Type: char]
        [+0x020] doblee           : 1.000000 [Type: double]
    [1]              [Type: _MYSTRUCT]
        [+0x000] intie            : 5 [Type: int]
        [+0x004] stringie         : "five" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [<Raw View>]     [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [size]           : 0x4 [Type: unsigned int]
            [capacity]       : 0xf [Type: unsigned int]
            [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
                [<Raw View>]     [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
            [0]              : 102 'f' [Type: char]
            [1]              : 105 'i' [Type: char]
            [2]              : 118 'v' [Type: char]
            [3]              : 101 'e' [Type: char]
        [+0x020] doblee           : 5.000000 [Type: double]
    [2]              [Type: _MYSTRUCT]
        [+0x000] intie            : 16 [Type: int]
        [+0x004] stringie         : "sixteen" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [<Raw View>]     [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [size]           : 0x7 [Type: unsigned int]
            [capacity]       : 0xf [Type: unsigned int]
            [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
                [<Raw View>]     [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
            [0]              : 115 's' [Type: char]
            [1]              : 105 'i' [Type: char]
            [2]              : 120 'x' [Type: char]
            [3]              : 116 't' [Type: char]
            [4]              : 101 'e' [Type: char]
            [5]              : 101 'e' [Type: char]
            [6]              : 110 'n' [Type: char]
        [+0x020] doblee           : 16.000000 [Type: double]
    [3]              [Type: _MYSTRUCT]
        [+0x000] intie            : 25 [Type: int]
        [+0x004] stringie         : "twenty five" [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [<Raw View>]     [Type: std::basic_string<char,std::char_traits<char>,std::allocator<char> >]
            [size]           : 0xb [Type: unsigned int]
            [capacity]       : 0xf [Type: unsigned int]
            [allocator]      : allocator [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
                [<Raw View>]     [Type: std::_Compressed_pair<std::allocator<char>,std::_String_val<std::_Simple_types<char> >,1>]
            [0]              : 116 't' [Type: char]
            [1]              : 119 'w' [Type: char]
            [2]              : 101 'e' [Type: char]
            [3]              : 110 'n' [Type: char]
            [4]              : 116 't' [Type: char]
            [5]              : 121 'y' [Type: char]
            [6]              : 32 ' ' [Type: char]
            [7]              : 102 'f' [Type: char]
            [8]              : 105 'i' [Type: char]
            [9]              : 118 'v' [Type: char]
            [10]             : 101 'e' [Type: char]
        [+0x020] doblee           : 25.000000 [Type: double]