Article View: gnu.gdb.bug
Article #1841printing: functions returning double
From: James R. Van Zandt
Date: Wed, 12 Jun 2002 19:41
Date: Wed, 12 Jun 2002 19:41
60 lines
2621 bytes
2621 bytes
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
Technical Details
Message-ID:
<ae884i$muu$1@vanzandt-pc.mitre.org>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!news.gtei.net!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!spool0901.news.uu.net!wendy-fate.uu.net!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5053,927b9626b81e13ba,start X-Google-Attributes: gidf5053,public X-Google-ArrivalTime: 2002-06-12 12:45:16 PST x-uunet-gateway: mr1.ash.ops.us.uu.net from bug-gdb to gnu.gdb.bug; Wed, 12 Jun 2002 19:41:14 GMT Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!news.gtei.net!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!spool0901.news.uu.net!wendy-fate.uu.net!not-for-mail From: jrv@mitre.org (James R. Van Zandt) Subject: printing: functions returning double Date: 12 Jun 2002 15:41:06 -0400 Organization: MITRE Corporation Message-ID: <ae884i$muu$1@vanzandt-pc.mitre.org> Reply-To: jrv@mitre.org X-BadReturnPath: jrv@vanzandt-pc.mitre.org rewritten as jrv@mitre.org using "Reply-To" header Approved: bug-gdb-request@mail.gnu.org Newsgroups: gnu.gdb.bug Sender: bug-gdb-request@mail.gnu.org Lines: 61