与LLDB一起观看for循环中的变量i

Watching variable i in a for loop with lldb

本文关键字:变量 循环 for LLDB 一起观      更新时间:2023-10-16

刚刚切换到lldb,我试图做相当于gdb的 watch i,在我的代码中,我在a内go。

(lldb) f
frame #0: 0x0000000100000664 a.out`MaxPairwiseProduct(numbers=size=5) + 4 at max_pairwise_product.cpp:19 [opt]
   16     // Find max value in vector
   17     
   18     for (int i=1; i<numbers.size(); i++) {
-> 19       if (numbers[i] > numbers[i-1]) {
   20         second_max = max;
   21         max = numbers[i];
   22         if (numbers[i] < max && numbers[i] > second_max)
(lldb) 

如上所述,int i已被声明。

检查我有哪些观察点

(lldb) watchpoint list -b
Number of supported hardware watchpoints: 4
No watchpoints currently set.
(lldb) 

现在试图将观察点设置为i(根据LLDB参考)我得到

(lldb) wa s v i
error: Watchpoint creation failed (addr=0xffffffffffffffff, size=0, variable expression='i').
error: cannot set a watchpoint with watch_size of 0
(lldb) 

我不明白为什么是变量。谷歌搜索错误无济于事,因为大多数问题似乎与达到最大观察点的数量有关,这不是我上面可以看出的。任何帮助将不胜感激!

我更改了将程序编译为clang++ -Wall -g -o max_pairwise max_pairwise.cpp的方式,它开始向我显示正确的信息,包括跟踪i

的值