Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to use a python-enabled gdb MinGW-builds . And I run into an error. This is a rather simple code, and It works fine when debugging under 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>
4       using namespace std;
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;
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>
                I find gdb on Windows very unreliable. More often than not it just hangs on me at a random moment, and I have to go to the task manager to kill it.
– n. m.
                Aug 18, 2013 at 3:13
                I just tested your code, it is fine under "GNU gdb (GDB) Red Hat Enterprise Linux (7.2-48.el6)" environment. The value of v[0] is printed correctly.
– CS Pei
                Aug 18, 2013 at 5:12
                @JohnSmith I tested it under CentOS 6.4 gdb 7.2-60.e16_4.1, it also works fine. I wonder if this problem is Windows specific, or MinGW-builds&Win7 specific?
– duleshi
                Aug 18, 2013 at 5:38
                this was a life saver. Recompiled my library without optimization and I was able to read the contents of every member variable, even private ones.
– Gubatron
                Apr 1, 2015 at 23:41
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.