The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

C++ debugger + [NEW] code help! (because of lack of debugger)

clsCorwinclsCorwin Registered User regular
edited March 2007 in Help / Advice Forum
Everytime I try and debug my program (which right now is a program to translate from infix notation to postfix notation), VC++ tells me "No symbols are loaded for any call stack frame. The source code cannot be displayed." And then wants to show me the disassembled version.

What the hell, why won't it just step over my code like a good little debugger?

clsCorwin on

Posts

  • DrFrylockDrFrylock Registered User regular
    edited March 2007
    Did you compile it with the appropriate compiler switches to include debug symbols? If you're in an IDE, there should be a checkbox somewhere that lets you compile for debug vs. compile for production, which is the same thing.

    DrFrylock on
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited March 2007
    Is this in Visual Studio? Are you running the code via Visual Studio? Make sure you're using the "Start Debugging" option (F5) and not "Start without Debugging" (Ctrl+F5).

    Generic Instructions for debugging an EXE w/ VS from Mozilla's Developer site: From the command line using VC8, type "devenv /debugexe <program name> <program arguments>". Once Visual Studio opens, select 'Start Debugging' from the 'Debug' menu.

    iTunesIsEvil on
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    See, the thing is, sometimes VC++ wants to cooperate and actuall step me over my code, and sometimes it wants to go batshit insane (thainks JDatE!) and give me the disassembly. I've never hit a switch one way or another, just set my breakpoint and try to step over (F10, for VC++).

    clsCorwin on
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    Actually, I didn't bother to hit F5 first, just F10.

    Upon hitting F5 however, I get this:
    Unhandled exception at 0x00406f0b in Reverse Polish Notation.exe: 0xC0000005: Access violation reading location 0x0143a5c0.

    With my breakpoint right at the beginning of my code. Lovely.

    clsCorwin on
  • ecco the dolphinecco the dolphin Registered User regular
    edited March 2007
    Can you make sure that you're compiling and running the *debug* build of your code, as opposed to the *release* build?

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • UndefinedMonkeyUndefinedMonkey Registered User regular
    edited March 2007
    eecc wrote: »
    Can you make sure that you're compiling and running the *debug* build of your code, as opposed to the *release* build?

    And if you have to switch over to "Debug", make sure to completely nuke your object files/binaries and rebuild everything before continuing.

    Is this a stand-alone program, or are you using DLLs/ActiveX/Internet Explorer, etc...? Maybe the error is occuring in a library somewhere that hasn't been built with debug symbols.

    UndefinedMonkey on
    This space intentionally left blank.
  • iconduckiconduck Registered User regular
    edited March 2007
    This sounds a lot like stack corruption. It's hard to track down using the visual studio debugger, but pretty easy using windbg.exe(http://www.microsoft.com/whdc/devtools/debugging/default.mspx) if you're willing to brave its arcane syntax.

    I'm writing a step by step example of how to catch this, but in the meantime check for any sort of buffer overruns in your code. strcpy's, memcpys, that sort of thing.

    iconduck on
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    I'm using a stack.cpp/stack.h and queue.cpp/queue.h, but I made them myself and have used them for other projects to no fault.

    clsCorwin on
  • blincolnblincoln Registered User regular
    edited March 2007
    I have seen that when I've been debugging C# apps that use unmanaged code when it's in the middle of doing something in a Windows DLL I've referenced, rather than my project.

    blincoln on
    Legacy of Kain: The Lost Worlds
    http://www.thelostworlds.net/
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    Well, I havn't reference any dlls or anything like that, only my 3 .cpp files and 2 .h files.


    In a related question in this project, I'm running into a problem and can't figure out why this is happening.

    I have these lines here:
    enum SYMBOL { DOLLAR, PLUS, MINUS, MUL, DIV, LEFTPAREN, RIGHTPAREN, SPACE };
    typedef int RULETABLE[LEFTPAREN + 1][RIGHTPAREN + 1];    //6x7 table 
    
    const RULETABLE rt = {{4,1,1,1,1,1,5},                    //creating 2d array 
                          {2,2,2,1,1,1,2},                    //of the rule table
                          {2,2,2,1,1,1,2},
                          {2,2,2,2,2,1,2},
                          {2,2,2,2,2,1,2},
                          {5,1,1,1,1,1,3}}; 
    
    char symbolTable[] = {'$', '+', '-', '*', '/', '(', ')', ' ' };
    
    SYMBOL toSym(char ch)            //converts char to the SYMBOL equivalent
    { 
        int s;
        SYMBOL result;
        for(s = 0; ch != symbolTable[s] && s < (int)SPACE; s++ ){}
        result = (SYMBOL)s;
        return result;
    }
    
    cout << "Stack top " << toSym( s.returnTop() ) << endl;
    cout << "Current " << toSym( currentSymbol ) << endl;
    
    rule = rt[ toSym( s.returnTop() ) ][ toSym(currentSymbol) ];
    

    These are snippets from different places in my code, but all relevant. s.returnTop() simply returns the char that is at the top of my stack.

    Now, the couts are giving the correct values, 0 and 1, respectively. However, I get 4199664 when I cout rt[ toSym( s.returnTop() ) ][ toSym(currentSymbol) ].

    This of course kills my switch statement. Why is it freaking out here?
    (This would also be easy enough to solve if my debugger were not psycho).

    clsCorwin on
  • iconduckiconduck Registered User regular
    edited March 2007
    This really sounds like (call) stack corruption, debuggers are notoriously bad at catching it.

    The simple way to catch it is to set a breakpoint at the first line in your program, and then step line by line through the program, watching the call stack each step. Or just step through the program until it crashes, that'll give you some idea of the proximate cause.

    Again, look for bad behavior on local variables. Are you passing a pointer to a locally declared class up to the caller? Anything goofy with pointers?

    iconduck on
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    I'm not using any pointers (based on my current understanding of them, at least). Just working with 2 array based queues, 1 array based stack, an enumerated type, and various functions to manipluate the data.

    I cannot just do said step over, because my Visual C++ wants to break everything down into assembly and step through that, and frankly, that aint cutten it for me.

    clsCorwin on
  • ecco the dolphinecco the dolphin Registered User regular
    edited March 2007
    1.) First off, go to:

    Build -> Configuration Manager

    Make sure that the "Active Solution Configuration" is debug, not release. If it is set to Release, set it to Debug and try debugging again.

    2.) If it is already debug, make sure that your compiler is spitting out debugging information:

    Go to the solution explorer, and right click on your solution name. Bring up the property window, go Configuration Properties -> C/C++ -> Debug Information Format. Make sure this is set to something like "Program Database for Edit & Continue (/ZI)"

    Next, go to Linker -> Debugging. Make sure that "Generate Debug Info" is set to "Yes"

    3.) Failing that, what does
    cout << rt[ 0 ][ 1 ] << endl;
    give you?

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    rt[0][1] gives me 1, as it should. Maybe I'll just use a work around, assign toSym( s.returnTop() ) to a variable row, and toSym( currentSymbol ) to a variable col, and use rt[row][col].

    Any idea why rt[toSym( s.returnTop() )][toSym( currentSymbol )] is pulling random garbage from memory? Did I accidently turn this into a pointer, or what?

    Also, changed those other settings, well, the one within properties of my .cpp file. Config was fine. Now, where are those Linker options, I can't find them anywhere?

    clsCorwin on
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    And my workaround does the same thing. Shit.

    clsCorwin on
  • Joseph StalinJoseph Stalin Registered User regular
    edited March 2007
    It sounds like you aren't returning a valid result. Verify that s is being set properly, and that result is also getting set properly. I mgiht venture a guess and say that it is not finding the symbol, but I can't say for sure. If the debugger isn't working, do this with a couple cout statements.

    Also, in your for loop in toSym, you can replace the {} with a semicolon. The brakets are unneeded if nothing happens after true a true value is found.

    Joseph Stalin on
    Let the ruling classes tremble at a Communist revolution. The proletarians have nothing to lose but their chains. They have a world to win.

    Workingmen of all countries, unite!
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    I have checked and double checked toSym, and it functions properly returning the correct result.

    clsCorwin on
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited March 2007
    The only potential error I can find is if returnTop() pops the top value off the stack instead of just reading it and leaving it on there. If that were the case you'd be using two different values for the cout and the actual statement, which would explain the discrepency.

    It doesn't sound like it's supposed to do that, but double check it to be sure.

    Smasher on
  • ecco the dolphinecco the dolphin Registered User regular
    edited March 2007
    Hmm... what about this one? It's a bit subtle, but it might be that:

    toSym() will return a maximum value of SPACE. This translates to a value of 7.

    If toSym() returned that for the row, then you're accessing row 7 of a 6 row array, and retrieving undefined values. If toSym() returns RIGHTPARAM, it'll return 6, which is also out of bounds for the row value.

    If toSym() returns SPACE for the column, that's also out of bounds.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • clsCorwinclsCorwin Registered User regular
    edited March 2007
    Yes, however SPACE is never used except for a couple if conditions within the program, its not used to reference the array at all.

    I did get that problem fixed, not sure what was the problem, but it was something in the loop effecting it.

    Compile is still crazy, even the ones at school.

    clsCorwin on
Sign In or Register to comment.