CodeBlocks断点忽略范围 [英] CodeBlocks Breakpoints Ignoring Scope

查看:211
本文介绍了CodeBlocks断点忽略范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I set a breakpoint inside a conditional statement that checks for a certain value of a custom datatype. The game will break, but the line it breaks on is completely outside of my breakpoint's scope. Watch variables reveal that it just breaks the first time that loop is iterated through, rendering my debugging conditional statement absolutely useless.

在Visual Studio中,调试器会遵循范围,并且在条件语句中放置断点只会在条件求值为true时停止游戏。为什么在CodeBlocks中的GDB调试器不是这样?是因为我在Windows中使用GDB吗?下面是代码:

In Visual Studio, the debugger would respect scope, and placing a breakpoint inside a conditional statement would only stop the game if that conditional evaluated to true. Why is this not the case with the GDB debugger in CodeBlocks? Is it because I'm using GDB in Windows? Here's the code:

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;
        }
    }


推荐答案

代码里面的如果主体不真正做任何事情,所以编译器可以看到它死代码,并从可执行文件中将其删除在优化过程中。这意味着有问题的代码实际上不存在于最终可执行文件中,因此您不能在其中放置断点。

The code inside the if body doesn't really do anything, so the compiler could see it as "dead code" and remove it from the executable in an optimization pass. This means that the code in question doesn't actually exist in the final executable, and so you can't put a breakpoint there.

关闭优化调试一般),它应该工作。

Turn off optimizations (always good when debugging in general) and it should work.

这篇关于CodeBlocks断点忽略范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆