From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <199705141858.MAA14718@novak.lanl.gov> Date: Wed, 14 May 1997 12:58:31 -0600 From: Richard Holmes Subject: Re: gdb problem Michal, Michal Jaegermann wrote: >Richard Holmes wrote: >> >> I compiled the following code with gcc 2.7.2.1 using the -g flag >Contrary to what you may be told in other places it is very often >to your advantage to use a mild optimization (like -O) with gcc >when using -g. It cleans up a generated code. I'll keep this in mind. It may help somewhere down the line, although it shouldn't make a difference here. >> >> >> #include >> double f(); >> >> int main(void) >> { >> double x; >> >> x = f(); >> >> printf("x = %lf\n", x); >> } >> >> double f() >> { >> return 1.0; >> } >> >> >> It will print the proper value , 1.0000, if I run it. If, however, >> I use gdb I can get some strange behavior. >Looks like a bug in a debugger. Debuggers usually work by inserting >a special code in breakpoint locations and restoring an old contents >when a breakpoint is hit. Something is not restored properly. Maybe >wrong sizes? The problem is likely compounded by the fact that >'x' above is prime candidate for a removal by a compiler (just a >location on a stack). Why this hiccup is important? This is important because I'm debugging a much more complicated program and gdb reports strange values for certain down in the deepest functions. I don't know whether to believe gdb or not. >You may always >break inside 'f()' and type 'finish' to see a returned value. This also does not work. gdb tells me the correct return value when I type finish, but if I step to the 'printf' line and print x I get garbage. >> printf("x = %lf\n", x); >BTW, there is NO "%lf" print specifier in ANSI C. The above is >technically an error, although most compilers will swallow it (but >try -Wall, which is always a good idea and on Alpha double that :-). Wow, I just looked this up in my second edition of K&R and you're right. I never knew this. >Michal Thanks Michal, Rich --------------------------------------- Richard Holmes Los Alamos National Laboratory Group XTA MS B220 Los Alamos, NM 87545 (505) 667-3598 holmes@lanl.gov -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com