variables does not contain right values in debug mode !  
Author Message
Julian V





PostPosted: Visual C++ General, variables does not contain right values in debug mode ! Top

Hello,

while I was trying to use one the INTEL MKL solvers, I found some weird behavior in the debug mode. I then simplified the sample code to where it does not use any external dependencies and it just simple c++ (while keeping with same structure as my original code).

I am using Microsoft Visual Studio 2005 Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework Version 2.0.50727 Professional Microsoft Visual C++ 2005 77626-009-0000007-41387

I have three source files: (i have the full project and source files at http://www.hide-link.com/ size ( 153 kb) it compiles and links without any errors for me.
the working directory is \test\501\

at the end is a snippet of the code in pardiso_sym_c_test1.cpp

when I go to breakpoint #1, i put some of the variables in the watch window and i get the following:
for a,b,n,ia,ja : CXX0069: Error: variable needs stack frame. why is that
for x: CXX0017: Error: symbol "x" not found. why is the error different for x both b and x were declared in the same line !

when I go to breakpoint #2, i get the following:
for a and b : 0x00000000
for n: 4206624
for x: CXX0017: Error: symbol "x" not found. why
for ia: 0x00403024 envp . why didn't ia and ja get the same value as a and b
for ja: 0x00403028 argv

when I go to breakpoint #3, i get the following:
both a AND b get changed to: 0x008fba18 . why is that only a was supposed to be changed !
I go to breakpoint #4, and still for x: CXX0017: Error: symbol "x" not found. why is that i just initialized memory for x! why is it not showing that
these are only a few of the problems i don't understand.. maybe if someone can explain these to my, the other might explained on its own.

I would greatly appreciate any help in figuring this out!
thanks,
Julian.

int main_pardiso_sym_c_test( void ) {

int n;

int *ia;

int *ja;

double *a;

/* RHS and solution vectors. */

double *b, *x;

cout << "reading matrix" << endl; <===== breakpoint #1

readMatrix("GlobalStiffness.txt", ia, ja, a, n); <===== breakpoint #2

x=new doubleNo; <===== breakpoint #3

cout << "reading load vector" << endl; <===== breakpoint #4

readLoadVector("LoadVector.txt", b, n); <===== breakpoint #5

cout << "finished reading load vector" << endl; <===== breakpoint #6

int mtype;

mtype = 2; /* Real PSD symmetric matrix */

cout << mtype << endl;

int nrhs = 1; /* Number of right hand sides. */

...



Visual C++16  
 
 
JeroGrav





PostPosted: Visual C++ General, variables does not contain right values in debug mode ! Top

I'm not sure if it will solve all of your problems but I would suggest that you look at your variable declarations.

At breakpoint 1, all the variables except for n are undefined. They are pointers that are not pointing at anything. In a debug build they should all be zeroed out - or set to the special uninitialised code that the de**** recognises. I can't remember which.

so try doing

int *b = NULL, *x = NULL;

and see what you get.

Also, while n is defined, in a release build, its value is undefined. Debug builds will init it to 0 but release builds won't.

So unless you are passing n in as an output param of readMatrix() it will probably break.

Hope that helps.

Jero



 
 
Mike Danes





PostPosted: Visual C++ General, variables does not contain right values in debug mode ! Top

I see that the project you posted is in Release mode. In fact it does not even compile in Debug mode. In Release mode due to compiler optimization, watches and other de**** feature may not work as expected. For example you declare x, you assign new double[ n ] to it but after that you don't use it anywhere. You can be sure that the compiler will remove it completly from the generate code so the de**** won't find it anymore. Same thing about "needs stack frame". The de**** needs a stack frame pointer but the compiler optimizes it away. This also prevents the de**** to read correctly the variable values.
 
 
Julian V





PostPosted: Visual C++ General, variables does not contain right values in debug mode ! Top

God ! I can't believe i spent so much time trying to figure out why it was doing that ! you are right... it was because it was in release mode... (it doesn't link in debug mode of the additional dependency from before i simplified the program)
I guess sometimes you just need a fresh pair of eyes ! i had been working on fixing that program for so long that i was going blind !

I got thrown off because whenever i try to 'debug' in release mode, i always (used to) get warned by the dialog box saying "Debugging information for '****.exe' cannot be found or does not match.Binary was not built with debug information." this time however i did not get that message.. and so in my mind I just assumed it was in debug mode. Well, not any more !

thank you very much for taking a look at this.

Julian.


 
 
Mike Danes





PostPosted: Visual C++ General, variables does not contain right values in debug mode ! Top

"i always (used to) get warned by the dialog box saying "Debugging information for '****.exe' cannot be found or does not match.Binary was not built with debug information." this time however i did not get that message.."

The explanation for this may be that VS 2005 defaults to creating debug information even in release mode. Older version did not.


 
 
Julian V





PostPosted: Visual C++ General, variables does not contain right values in debug mode ! Top

The explanation for this may be that VS 2005 defaults to creating debug information even in release mode. Older version did not.

You are probably right. I do have VS2005 projects that still give me this warning... but they were converted from VC6 projects, so that may be why.

thanks!