I've been trying to debug a little thingie, and almost went insane while trying to do so. After several hours of figuring out the problem, I finally have a snippet of code that is the root of my problem:
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
std::vector<int> foo = std::vector<int>();
foo.push_back(0);
foo.push_back(11);
foo.push_back(222);
foo.push_back(3333);
std::stack<int> bar = std::stack<int>();
cout << endl << foo.size() << endl << endl;
return 0;
}
With this compiled, using:
g++ -std=c++11 -ggdb -O0 -pedantic -Wall -Wextra -Wno-nonnull -fkeep-inline-functions
I then try the following:
(gdb) br 18
Breakpoint 1 at 0x40170c: file ./....cpp, line 18.
(gdb) r
Starting program: ...
[New Thread 15620.0x3c3c]
Breakpoint 1, main () at ./....cpp:18
18 cout << endl << foo.size() << endl << endl;
(gdb) p foo.size()
$1 = 4293588256
(gdb) c
Continuing.
4
[Inferior 1 (process 15620) exited normally]
(gdb)
Apparenly, 4 is now equal to 4293588256. What the bloody hell is going on? Also, if I break the program before the stack is created, GDB shows the size properly.
EDIT: I am on windows 8.1, versions of stuffs are: G++ 4.8.1; GDB 7.6.1
Turns out this really is a problem of either GDB 7.6.1 or G++ 4.8.1. Updating GDB to 7.8.1 and G++ to version 4.9.2 solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With