关于条件断点的奇怪gdb行为(a&;b不等于b&;a) 我有一个小的C++程序: // test.cpp #include <vector> #include <iostream> using namespace std; template class vector<int>; int main() { vector<int> v; for (size_t i = 0; i < 10; ++i) { if (!v.empty()) cout << v[0] << endl; //<== Add a cond breakpoint here later v.clear(); for (size_t j = 0; j < i; ++j) v.push_back(i); } return 0; }
用gdb启动程序,并在第13行添加一个条件断点。条件为“v.size()==3&&v[0]==3”,如下所示。然而,这种情况并不像预期的那样起作用。当条件不满足时,它停止关于条件断点的奇怪gdb行为(a&;b不等于b&;a) 我有一个小的C++程序: // test.cpp #include <vector> #include <iostream> using namespace std; template class vector<int>; int main() { vector<int> v; for (size_t i = 0; i < 10; ++i) { if (!v.empty()) cout << v[0] << endl; //<== Add a cond breakpoint here later v.clear(); for (size_t j = 0; j < i; ++j) v.push_back(i); } return 0; },c++,gcc,gdb,C++,Gcc,Gdb,用gdb启动程序,并在第13行添加一个条件断点。条件为“v.size()==3&&v[0]==3”,如下所示。然而,这种情况并不像预期的那样起作用。当条件不满足时,它停止 (gdb) b 13 if v.size() == 3 && v[0] == 3 Breakpoint 1 at 0x400ca1: file test.cpp, line 13. (gdb) info b Num Type Disp Enb Address W
(gdb) b 13 if v.size() == 3 && v[0] == 3
Breakpoint 1 at 0x400ca1: file test.cpp, line 13.
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000400ca1 in main() at test.cpp:13
stop only if v.size() == 3 && v[0] == 3
运行该程序后,将显示一条错误消息:
...
Error in testing breakpoint condition:
Cannot access memory at address 0x0
Breakpoint 1, main () at test.cpp:13
13 cout << v[0] << endl;
但是,如果我将条件断点替换为“v[0]==3&&v.size()==3”,则一切正常
(gdb) p v.size()
$2 = 3
第一个条件有什么问题?
[更新]
我在Ubuntu14.04上分别将gcc和gdb升级到6.1.0和7.10(都是从源代码构建的),但这个问题仍然存在
$g++-v
使用内置规格。收集\u GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/6.1.0/LTO-WRAPPER
目标:x86_64-pc-linux-gnu配置为:../gcc-6.1.0/configure
-前缀= /USR——使能语言= C、C++——禁用多库——禁用引导程序——用系统ZLIB线程模型:POSIX GCC版本1.1.0(GCC)
$gdb-v
GNU gdb(gdb)7.10
我将gdb升级到7.11.1(通过切换到Ubuntu 16.04.1 LTE),这个问题消失了
对于这个gdb版本,自然支持打印std::vector
,这很好
(gdb) print v
$3 = std::vector of length 3, capacity 4 = {3, 3, 3}
我将gdb升级到7.11.1(通过切换到Ubuntu 16.04.1 LTE),这个问题消失了
对于这个gdb版本,自然支持打印std::vector
,这很好
(gdb) print v
$3 = std::vector of length 3, capacity 4 = {3, 3, 3}
无法使用GDB 7.11.1复制。你用的是什么版本?在我的系统上一切都很好。gcc 6.1.0,gdb 7.10.1。我相信在Ubuntu 14.04.3上默认为7.7。刚才我从这个位置升级到了7.10http://ftp.gnu.org/gnu/gdb/。重建gdb。不幸的是,我可以观察到同样的问题。我更新到gdb 7.10和gcc 6.1.0。我仍然可以看到这个问题。无法使用GDB 7.11.1复制。你用的是什么版本?在我的系统上一切都很好。gcc 6.1.0,gdb 7.10.1。我相信在Ubuntu 14.04.3上默认为7.7。刚才我从这个位置升级到了7.10http://ftp.gnu.org/gnu/gdb/。重建gdb。不幸的是,我可以观察到同样的问题。我更新到gdb 7.10和gcc 6.1.0。我仍然可以看到这个问题。
(gdb) print v
$3 = std::vector of length 3, capacity 4 = {3, 3, 3}