* Re: Quick question about "print EXPR"
[not found] <E1ClxlM-0003ME-7B@monty-python.gnu.org>
@ 2005-02-08 16:42 ` Andrew Cagney
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Cagney @ 2005-02-08 16:42 UTC (permalink / raw)
To: Brian Desany; +Cc: 'Peter Barada', gdb
Brian Desany wrote:
[sorry, going backwards through my e-mail]
>>Brian Desany wrote:
>>
>>>>Did you include <math.h> in your program?
>>>
>>>
>>>Yep, I did (the program itself works properly).
>>>
>>>FWIW the only lines of the program that aren't listed in my
>>
>>original post are:
>>
>>>#include <stdio.h>
>>>#include <math.h>
>>>
>>>And just in case it matters, I compiled using the command
>>
>>"cc -lm -g test.c".
>>
>>>If I compile with "gcc -lm -g test.c", "p floor(whatever)"
>>
>>is always
>>
>>>16 (rather than 1 as in the original post).
>>
>>Wonder if GDB can see this. What does:
>>
>>(gdb) ptype floor
>>
>>print?
>
>
> type = int ()
Which hopefully explains why things go wrong - GDB doesn't know the
function's signature and hence invokes it incorrectly. Here GDB is
probably pulling the return value out of an integer register instead of
floating-point register or stack address (as you step through the code
that integer register's value would change and hence the value would
change).
There are two things from here:
- is the debug info stabs?
I believe that only dwarf>=2 debug info can describe the above.
=> Should GDB issue a warning when calling a function with no visible
prototype?
- is the debug info dwarf
Check the input file (you'll need to look at binutils's readelf program)
to see if the info is there. Beyond that we'd have to think out why GDB
can't see it.
Andrew
> I was wrong about "p floor(whatever)" always returning a constant value. It
> returns a different value depending apparently on what line of the program
> I'm currently stopped on:
>
> Breakpoint 1, main (argc=1, argv=0xbfffcf54) at test.c:9
> 9 yada = 2.5;
> (gdb) p floor(123.456)
> $1 = 0
> (gdb) n
> 10 haha = floor(yada);
> (gdb) p floor(123.456)
> $2 = 0
> (gdb) n
> 11 printf("%0.1f %0.1f\n",yada, haha);
> (gdb) p floor(123.456)
> $3 = 3199
> (gdb) n
> 2.5 -0.0
> 12 return 0;
> (gdb) p floor(123.456)
> $4 = 9
> (gdb)
>
>
>>Andrew
>>
>>
>>>[bdesany]$ cc -v
>>>Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
>>>gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
>>
>>[bdesany]$ gcc
>>
>>>-v Reading specs from
>>>/home/bdesany/sys/lib/gcc/i686-pc-linux-gnu/3.4.2/specs
>>>Configured with: ./configure --prefix=/home/bdesany/sys
>>
>>Thread model:
>>
>>>posix gcc version 3.4.2
>>>
>>>Thanks-
>>>-Brian.
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <1103746608.31531.ezmlm@sources.redhat.com>]
* Quick question about "print EXPR"
[not found] <1103746608.31531.ezmlm@sources.redhat.com>
@ 2004-12-22 20:25 ` Brian Desany
2004-12-22 20:40 ` Peter Barada
0 siblings, 1 reply; 6+ messages in thread
From: Brian Desany @ 2004-12-22 20:25 UTC (permalink / raw)
To: gdb
I read in the docs that "print EXPR" should work with function calls.
Why is it that no matter what argument I pass to "print floor(234.567)", I always get an answer of
"1"?
...
7 yada = 2.5;
(gdb) n
8 haha = floor(yada);
(gdb)
9 printf("%0.1f %0.1f\n",yada, haha);
(gdb) p yada
$1 = 2.5
(gdb) p haha
$2 = 2
(gdb) p floor(yada)
$3 = 1
(gdb) l
4 int main(int argc, char *argv[]) {
5 double yada;
6 double haha;
7 yada = 2.5;
8 haha = floor(yada);
9 printf("%0.1f %0.1f\n",yada, haha);
10 return 0;
11 }
...
Thanks-
-Brian.
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Quick question about "print EXPR"
2004-12-22 20:25 ` Brian Desany
@ 2004-12-22 20:40 ` Peter Barada
2004-12-22 20:47 ` Brian Desany
0 siblings, 1 reply; 6+ messages in thread
From: Peter Barada @ 2004-12-22 20:40 UTC (permalink / raw)
To: brian; +Cc: gdb
>Why is it that no matter what argument I pass to "print floor(234.567)", I always get an answer of
>"1"?
Did you include <math.h> in your program? If not you don't have a
prototype for floor that indicates it takes a double and returns a
double...
--
Peter Barada
peter@the-baradas.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Quick question about "print EXPR"
2004-12-22 20:40 ` Peter Barada
@ 2004-12-22 20:47 ` Brian Desany
2005-01-04 20:26 ` Andrew Cagney
0 siblings, 1 reply; 6+ messages in thread
From: Brian Desany @ 2004-12-22 20:47 UTC (permalink / raw)
To: Peter Barada, brian; +Cc: gdb
> Did you include <math.h> in your program?
Yep, I did (the program itself works properly).
FWIW the only lines of the program that aren't listed in my original post are:
#include <stdio.h>
#include <math.h>
And just in case it matters, I compiled using the command "cc -lm -g test.c".
If I compile with "gcc -lm -g test.c", "p floor(whatever)" is always 16 (rather than 1 as in the
original post).
[bdesany]$ cc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
[bdesany]$ gcc -v
Reading specs from /home/bdesany/sys/lib/gcc/i686-pc-linux-gnu/3.4.2/specs
Configured with: ./configure --prefix=/home/bdesany/sys
Thread model: posix
gcc version 3.4.2
Thanks-
-Brian.
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Quick question about "print EXPR"
2004-12-22 20:47 ` Brian Desany
@ 2005-01-04 20:26 ` Andrew Cagney
2005-01-04 23:06 ` Brian Desany
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2005-01-04 20:26 UTC (permalink / raw)
To: Brian Desany; +Cc: Peter Barada, gdb
Brian Desany wrote:
>>Did you include <math.h> in your program?
>
>
> Yep, I did (the program itself works properly).
>
> FWIW the only lines of the program that aren't listed in my original post are:
> #include <stdio.h>
> #include <math.h>
>
> And just in case it matters, I compiled using the command "cc -lm -g test.c".
> If I compile with "gcc -lm -g test.c", "p floor(whatever)" is always 16 (rather than 1 as in the
> original post).
Wonder if GDB can see this. What does:
(gdb) ptype floor
print?
Andrew
> [bdesany]$ cc -v
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
> [bdesany]$ gcc -v
> Reading specs from /home/bdesany/sys/lib/gcc/i686-pc-linux-gnu/3.4.2/specs
> Configured with: ./configure --prefix=/home/bdesany/sys
> Thread model: posix
> gcc version 3.4.2
>
> Thanks-
> -Brian.
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Take Yahoo! Mail with you! Get it on your mobile phone.
> http://mobile.yahoo.com/maildemo
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Quick question about "print EXPR"
2005-01-04 20:26 ` Andrew Cagney
@ 2005-01-04 23:06 ` Brian Desany
0 siblings, 0 replies; 6+ messages in thread
From: Brian Desany @ 2005-01-04 23:06 UTC (permalink / raw)
To: 'Andrew Cagney'; +Cc: 'Peter Barada', gdb
> Brian Desany wrote:
> >>Did you include <math.h> in your program?
> >
> >
> > Yep, I did (the program itself works properly).
> >
> > FWIW the only lines of the program that aren't listed in my
> original post are:
> > #include <stdio.h>
> > #include <math.h>
> >
> > And just in case it matters, I compiled using the command
> "cc -lm -g test.c".
> > If I compile with "gcc -lm -g test.c", "p floor(whatever)"
> is always
> > 16 (rather than 1 as in the original post).
>
> Wonder if GDB can see this. What does:
>
> (gdb) ptype floor
>
> print?
type = int ()
I was wrong about "p floor(whatever)" always returning a constant value. It
returns a different value depending apparently on what line of the program
I'm currently stopped on:
Breakpoint 1, main (argc=1, argv=0xbfffcf54) at test.c:9
9 yada = 2.5;
(gdb) p floor(123.456)
$1 = 0
(gdb) n
10 haha = floor(yada);
(gdb) p floor(123.456)
$2 = 0
(gdb) n
11 printf("%0.1f %0.1f\n",yada, haha);
(gdb) p floor(123.456)
$3 = 3199
(gdb) n
2.5 -0.0
12 return 0;
(gdb) p floor(123.456)
$4 = 9
(gdb)
>
> Andrew
>
> > [bdesany]$ cc -v
> > Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> > gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
> [bdesany]$ gcc
> > -v Reading specs from
> > /home/bdesany/sys/lib/gcc/i686-pc-linux-gnu/3.4.2/specs
> > Configured with: ./configure --prefix=/home/bdesany/sys
> Thread model:
> > posix gcc version 3.4.2
> >
> > Thanks-
> > -Brian.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-02-08 16:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <E1ClxlM-0003ME-7B@monty-python.gnu.org>
2005-02-08 16:42 ` Quick question about "print EXPR" Andrew Cagney
[not found] <1103746608.31531.ezmlm@sources.redhat.com>
2004-12-22 20:25 ` Brian Desany
2004-12-22 20:40 ` Peter Barada
2004-12-22 20:47 ` Brian Desany
2005-01-04 20:26 ` Andrew Cagney
2005-01-04 23:06 ` Brian Desany
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).