【问题标题】:Watching variable i in a for loop with lldb使用 lldb 在 for 循环中观察变量 i
【发布时间】:2017-02-22 11:31:56
【问题描述】:

刚刚切换到 lldb,我正在尝试做与 gdb 的 watch i 等效的操作,因为我在代码中的 for 循环中。

(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 reference)我得到了

(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) 

我不明白为什么会这样,因为变量已被声明。谷歌搜索错误并没有多大帮助,因为大多数问题似乎与达到最大观察点数有关,这不是我的情况,如上所示。任何帮助将不胜感激!

【问题讨论】:

    标签: c++ lldb


    【解决方案1】:

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

    【讨论】:

    • 当引用的变量在当前位置不可用时,这可能是一个错误的错误消息(而不是提供信息性错误消息)。您重建的命令行示例没有任何优化,我猜您在第一个示例中确实有它。或者您在两次运行之间的程序中的不同点停止。您肯定应该收到有关问题所在的错误消息,而不是这种行为,但 lldb 中的观察点有点粗糙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    相关资源
    最近更新 更多