Kristian D'Amato
Kristian D'Amato

Reputation: 4046

Strange debugger problem?

I have created this datastructure:

class Event
{
public:
    Event(EVENT_TYPE type, void* pSender = 0, int content1 = 0,  
        int content2 = 0, int content3 = 0, int content4 = 0);
    ~Event(void);

// ... some functions

protected:
    EVENT_TYPE itsType;
    void* itsPointerToSender;
    int itsContent_1;
    int itsContent_2;
    int itsContent_3;
    int itsContent_4;
    int numStacked;
};

whose constructor is simply

Event::Event(EVENT_TYPE type, void* pSender, int content1, int content2, int content3, int content4)
    :   itsType(type),
    itsPointerToSender(pSender),
    itsContent_1(content1),
    itsContent_2(content2),
    itsContent_3(content3),
    itsContent_4(content4),
    numStacked(0)
{
}

For some strange reason I can't understand, the VS debugger cannot and will not show me whatever is contained in itsContent_4. If I put a watch on the variable, itsContent_4 gives me a symbol "itsContent_4" not found while doing the same thing with itsContent_3 works perfectly. I'm not sure the variable even exists as far as the compiler is concerned!

Am I missing something here?

Edit: Now it seems (even stranger) that changing the order of the variables in the declaration creates an even bigger mess! I tried placing itsContent_4 before itsContent_1 and now itsContent_1 is being initialized with the value intended for itsContent_4! What is going on here? I'm suspecting something to do with naming, so I'll try renaming them all and see what happens.

Edit 2: Yes, apparently changing the variable names to itsContent_a instead of itsContent_1 and so forth works perfectly. Is there some restriction as to using numbers in a variable name?

Upvotes: 0

Views: 169

Answers (2)

Hans Passant
Hans Passant

Reputation: 942438

Sounds to me like the debugger is using the wrong .pdb file. Tools + Options, Debugging, General, ensure that "Require source files to exactly match the original version" is checked.

While debugging with a breakpoint active, use Debug + Windows + Modules and right-click your executable in the list. Click "Symbol Load Information" to find out where the debugger found the .pdb file.

Another possible mishap is that this class is defined in a separately compiled executable, like a DLL, which was compiled with incompatible settings. So that the layout of the object no longer matches. That's not that likely in this case.

Upvotes: 3

Andy Johnson
Andy Johnson

Reputation: 8179

Check that you're not trying to debug a release build. In a release build the optimiser can remove unused variabled and change the order in which statements are executed. This can be confusing when debugging.

Upvotes: 1

Related Questions