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)
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?
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.
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.
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++).
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.
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.
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.
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.
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).
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?
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.
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?
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?
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.
SmasherStarting to get dizzyRegistered Userregular
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.
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.
Posts
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.
See how many books I've read so far in 2010
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.
See how many books I've read so far in 2010
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.
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.
See how many books I've read so far in 2010
http://www.thelostworlds.net/
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:
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).
See how many books I've read so far in 2010
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?
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.
See how many books I've read so far in 2010
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?
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?
See how many books I've read so far in 2010
See how many books I've read so far in 2010
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.
Workingmen of all countries, unite!
See how many books I've read so far in 2010
It doesn't sound like it's supposed to do that, but double check it to be sure.
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.
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.
See how many books I've read so far in 2010