Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Richard Holmes <holmes@novak.lanl.gov>
Subject: Re: gdb problem
Date: Wed, 14 May 1997 12:58:31 -0600	[thread overview]
Message-ID: <199705141858.MAA14718@novak.lanl.gov> (raw)

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 <stdio.h>
>> 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

             reply	other threads:[~1997-05-14 18:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-14 18:58 Richard Holmes [this message]
1997-05-14 19:09 ` gdb problem Kortelainen Mika
  -- strict thread matches above, loose matches on Subject: below --
1997-05-14  2:10 Richard Holmes
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox