This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Quick question about "print EXPR"


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.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]