GDB wrong values for vector.size()

霸气de小男生 提交于 2019-11-29 14:53:26

What may be wrong?

It's a bug in your compiler, or in your GDB. It does not reproduce on Linux using g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3 and GDB 7.4:

(gdb) n
7       stack.push_back(1);
1: stack.size() = 0
(gdb) 
8       stack.push_back(1); //stack.size() becomes 467369971 after this
1: stack.size() = 1
(gdb) 
9       stack.push_back(1);
1: stack.size() = 2
(gdb) 
10      stack.push_back(1);
1: stack.size() = 3
(gdb) 
11      stack.push_back(1);
1: stack.size() = 4
(gdb) 
12      stack.push_back(1); //stack.size() becomes 467369971 after this
1: stack.size() = 5
(gdb) 
13      stack.push_back(1);
1: stack.size() = 6
(gdb) 
14      stack.push_back(1);
1: stack.size() = 7
(gdb) 
15      return 0;
1: stack.size() = 8
(gdb) 
16  }
(gdb) q

Unfortunately, figuring out which tool is to blame here will be somewhat hard: you'll need to examine the debuginfo generated. Instead you may try to reproduce the problem with different versions of GCC and GDB. If varying GCC causes the bug to disappear, it's probably a bug in GCC. If varying GDB version makes the bug disappear, it's probably a GDB bug.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!