CodeBlocks Breakpoints Ignoring Scope

流过昼夜 提交于 2019-12-12 01:45:14

问题


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.

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

回答1:


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.



来源:https://stackoverflow.com/questions/15730453/codeblocks-breakpoints-ignoring-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!