dbx: Can't evaluate local variables in optimized functions

I turned on the optimization for the whole product. Now I found that I can not print the local variables declared in side the main funciton or inside the function locals.

eg.

int factorial (int n)

{

int factorial = 1;

while (n > 1)

{

factorial *= n--;

}

return factorial;

}

When I tried to print n or factorial, I would not able to do so...

Is there any way can I get the local variables printed?

Is there any compiler options to overcome this problem and printing the local variables...

I know this is an difficult question becuase the locals go to Register instead of memory. By reverting it back to memory, I may loose the efficiency I gained with this optimizations.

options : -fast -xtarget=ultra3 -xarch=v8plusa -g0

Please let me know....

#include <iostream>

#include <string>

#include <unistd.h>

#include <stdio.h>

using namespace std;

int main(int argc, char **argv)

{

FILE *fp=freopen("myfile.txt","w",stdout);

int bytes_read;

char buffer[10000];

std::cout<<"##This should be 0 15238.0.172435 written in to the 1 file with out any HICK-UPs"<<endl;

FILE *myfp=fopen("myfile.txt","r");

cerr><<"This goes to std error file"<<endl;

fseek(myfp, 0, SEEK_END);

int len = ftell(myfp);

fseek(myfp, 0, SEEK_SET);

fread(buffer,len,1,myfp);

fclose(myfp);

fclose(fp);

string mystring(buffer);

std::string::size_type location=mystring.find("15238.0.172435",0);

std::string::size_type location1=mystring.find("116530640358374636",0);

if(location != std::string::npos )

cerr><<"Buffer Read that is read from file inside the if condition \n<\n"<<buffer><<"\n>"<<endl;

if(location1 != std::string::npos )

cerr><<"Buffer Read that is read from file inside the if condition and location1 \n<\n"<<buffer><<"\n>"<<endl;

remove("myfile.txt");

return 0;

}

stopped in main (optimized) at line 8 in file "fileex.cc"

8int main(int argc, char **argv)

(dbx) cont

This goes to std error file

stopped in main (optimized) at line 27 in file "fileex.cc"

27int len = ftell(myfp);

(dbx) print len

dbx: Can't evaluate local variables in optimized functions>

[2485 byte] By [Sara_Kana] at [2007-11-26 18:22:08]
# 1

Dbx typically cannot show auto variables in optimized code. The reason is that the variables typically do not have a stable location, or might be eliminated altogether. Similarly, source code lines don't have a stable relationship to object code. The debug data emitted by Sun compilers is not enough to keep track of these issues.

We plan to provide better debugging of optimized code in a future release.

Dbx can show the value returned from a function, which in your case might be enough.

clamage45a at 2007-7-9 5:56:00 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
Thank you,
Sara_Kana at 2007-7-9 5:56:00 > top of Java-index,Development Tools,Solaris and Linux Development Tools...