c++ - 代码块断点忽略范围

标签 c++ debugging gdb codeblocks breakpoints

我在检查自定义数据类型的特定值的条件语句中设置了一个断点。游戏会中断,但它中断的那条线完全在我的断点范围之外。观察变量显示它只是在第一次迭代循环时中断,使我的调试条件语句完全无用。

在 Visual Studio 中,调试器会遵守范围,并且在条件语句中放置一个断点只会在该条件评估为真时停止游戏。为什么 CodeBlocks 中的 GDB 调试器不是这种情况?是因为我在 Windows 中使用 GDB 吗?这是代码:

for(int j = 0 ; j < r->components[i].size() ; j++)
    {
        itype_id type = r->components[i][j].type;
        int req = r->components[i][j].count;

        //DEBUGGING ONLY!!!!!!!!!
        if(type == itm_coffee_raw)
        {
            int pleaseStop = 0;
            if(pleaseStop == 0) //BREAKPOINT IS ON THIS LINE
                bool dontstoptillyougetenough = true;
        }

        if (itypes[type]->count_by_charges() && req > 0) //GAME BREAKS HERE
        {
            if (crafting_inv.has_charges(type, req))
            {
                has_comp = true;
                break;
            }
        }
        else if (crafting_inv.has_amount(type, abs(req)))
        {
            has_comp = true;
            break;
        }
    }

最佳答案

if 主体中的代码实际上没有做任何事情,因此编译器可以将其视为 "dead code"remove it来自优化过程中的可执行文件。这意味着有问题的代码实际上并不存在于最终的可执行文件中,因此您不能在那里放置断点。

关闭优化(通常调试时总是好的)它应该可以工作。

关于c++ - 代码块断点忽略范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15730453/

相关文章:

C++ 迭代器从 typedef std::map 声明为模板参数

multithreading - 识别linux内核模块中的错误

c - 如何将 .so 文件映射到 gdb 中的源文件

c++ - std::cout 到 QTextBrowser

c++ - 什么时候非静态 const 数据成员比 const 静态数据成员更有用?

c++ - VS2008 远程调试器 : An attempt was made to access a socket in a way forbidden by its access permissions

java - 即使 java 进程正在运行,jps 也不会返回任何输出

c# - Visual Studio 无法附加到 Unity,为什么?

c++ - 让 GDB 在回溯中扩展 arg=...

c - 为什么我在 GDB 中收到消息 "Single-stepping until exit . . . which has no line number information"?