首页 > gdb调试for循环,单步执行时没有经过for语句头

gdb调试for循环,单步执行时没有经过for语句头

代码类型类似于这样

    for(list<Sentence*>::iterator iter = sentenceList.begin(); iter != sentenceList.end(); ++iter)
    {
        ......
        if((++iter) != sentenceList.end())
        {
            --iter;
            ......
            continue;
        }
        else
        {
            ....
        }
        ......
    }

现在的问题是,单步执行时,执行完循环体的最后一条语句后,直接跳转到第一条语句继续执行,而不会经过for语句头。
因而整个for循环无法结束。

这是整个C++项目中的一段,我已经将编译优化选项设为-O0了,按道理说应该不会有这种情况才是啊。

11.11更新:
目前能够确定的是,由于某种不可知的原因,iter == sentenceList.end()之后,进一步自增就重新变成了sentenceList.begin()。
我在else部分加了一个--iter之后,循环终于可以结束了,但还是不知道为什么。


把源码弄上来点,不清楚病情,怎么看病。
【热门文章】
【热门文章】