bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

printing: functions returning double


From: James R. Van Zandt
Subject: printing: functions returning double
Date: 12 Jun 2002 15:41:06 -0400

I've (re)discovered that gdb often can't print the value of a function
that returns double.  For example, with this code:

   #include <stdio.h>
   #include <math.h>
   
   double foo(double x) { return x*x; }
   
   int main() {
     extern double sin(double);
     printf("%f %f %f\n",foo(2.1), sqrt(2.1), sin(2.1));
   }
   
gdb knows the return value of foo() but not sqrt() or sin():

  GNU gdb 5.1.1
  Copyright 2002 Free Software Foundation, Inc.
  ...
  This GDB was configured as "i386-linux"...
  (gdb) break main
  Breakpoint 1 at 0x80484da: file foo.c, line 8.
  (gdb) r
  Starting program: /home/jrv/proj/rocket/foo 
  
  Breakpoint 1, main () at foo.c:8
  (gdb) n
  4.410000 1.449138 0.863209
  (gdb) p foo(2.1)
  $1 = 4.4100000000000001
  (gdb) p sqrt(2.1)
  $2 = 288
  (gdb) p sin(2.1)
  $3 = 14624
  (gdb) ptype foo
  type = double (double)
  (gdb) ptype sin
  type = int ()
  (gdb) ptype sqrt
  type = int ()
  (gdb) 

I think this should be discussed in the documentation.

What's the right way to handle this, though?  Debian package libc6-dbg
is described as "GNU C Library: Libraries with debugging symbols".  I
tried installing that and running my program with

  (gdb) run LD_LIBRARY_PATH=/usr/lib/debug

but that didn't help.  How should this work?

Is there a workaround?  E.g. a way to tell gdb with a keyboard command
that a given function returns a double?  It would be nice if you could
just point gdb to the appropriate header file.

Again, I think this ought to be discussed in the docs.  I'd be willing
to prepare a patch if I knew what to write.

                - Jim Van Zandt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]