4
我想使用啓用python的gdb MinGW-builds。我遇到了一個錯誤。這是一個相當簡單的代碼,它在MSVC下調試時工作正常。簡單代碼導致錯誤閱讀變量:無法訪問內存地址
D:\CppProject\c1\bin\Debug>gdb c1.exe
GNU gdb (GDB) 7.6
(copyright, license, bug report, etc omitted here)
Reading symbols from D:\CppProject\c1\bin\Debug\c1.exe...done.
(gdb) l
1 #include <iostream>
2 #include <vector>
3
4 using namespace std;
5
6 int main()
7 {
8 vector<string> v;
9 v.push_back("first");
10 v.push_back("second");
(gdb)
11 cout<<v[0]<<endl;
12 cout<<v[1]<<endl;
13
14 return 0;
15 }
(gdb) break 11
Breakpoint 1 at 0x4016c9: file D:\CppProject\c1\main.cpp, line 11.
(gdb) run
Starting program: D:\CppProject\c1\bin\Debug\c1.exe
[New Thread 1256.0xbe8]
Breakpoint 1, main() at D:\CppProject\c1\main.cpp:11
11 cout<<v[0]<<endl;
(gdb) p v
$1 = std::vector of length 2, capacity 2 = {"first", "second"}
(gdb) p v[0]
$2 = <error reading variable: Cannot access memory at address 0x29a2ca50>
不知道這是否有任何影響,但你應該'#include' –
@ColonelPanic沒有區別,gdb錯誤仍然發生。 – duleshi
我在Windows上發現gdb非常不可靠。多數情況下,它隨時隨地都掛在我身上,我必須去任務經理去殺死它。 –