Article View: gnu.gdb.bug
Article #8770variable values incorrectly reported
From: Jim Blandy
Date: Thu, 03 Dec 1992 10:19
Date: Thu, 03 Dec 1992 10:19
78 lines
2758 bytes
2758 bytes
I'm running GDB 4.7 and GCC 2.3.2, using the decstation-ultrix4.2
configuration.
GDB incorrectly prints the value of variables under certain
circumstances.
Compile the following program using 'gcc -g -O foo.c -o foo':
/* This program attempts to demonstrate a bug in the way GCC writes out
debugging information in optimized code, or in the way GDB reads it. */
#include <stdio.h>
void
foo (int *x)
{
int y = *x;
printf ("y's value is: %d\n", y);
y *= 2;
printf ("Twice y's value is: %d\n", y);
printf ("At this point, x probably doesn't have a valid value anymore.\n");
}
main ()
{
int x;
x = 5;
foo (&x);
}
Then start running GDB on it:
totoro$ gdb foo
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.7, Copyright 1992 Free Software Foundation, Inc...
(gdb) break foo
Breakpoint 1 at 0x4001bc: file foo.c, line 9.
(gdb) run
Starting program: /u/jimb/foo
Breakpoint 1, foo (x=0x7fffbd58) at foo.c:9
9 int y = *x;
(gdb) p *x
$1 = 5
(gdb) next
11 printf ("y's value is: %d\n", y);
(gdb) next
y's value is: 5
13 printf ("Twice y's value is: %d\n", y);
(gdb) next
Twice y's value is: 10
15 printf ("At this point, x probably doesn't have a valid value anymore.\n");
(gdb) print y
$2 = 5
(gdb) print x
$3 = (int *) 0x17
(gdb)
The value of y should be 10, and the value of x should be the same as
reported when foo was entered. If x and y cannot be printed because
the optimizer has used their registers or stack slots for something
else, GDB should say so, rather than printing misleading values.
This example is contrived, but in real code I found this bug very
confusing; the pointer x was overwritten not by an obviously bogus
value like 0x17 but by another valid pointer value, making it look as
if the structure x pointed to had been trashed.
Perhaps GCC is not writing the correct debugging information; if so,
please tell me so I can forward this report to
bug-gcc@prep.ai.mit.edu.
Technical Details
Message-ID:
<9212032019.AA10527@totoro.cs.oberlin.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!totoro.cs.oberlin.edu!jimbShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5053,35dc9d5809b054fb,start X-Google-Attributes: gidf5053,public X-Google-ArrivalTime: 1992-12-03 21:24:37 PST Newsgroups: gnu.gdb.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!totoro.cs.oberlin.edu!jimb From: jimb@totoro.cs.oberlin.edu (Jim Blandy) Subject: variable values incorrectly reported Message-ID: <9212032019.AA10527@totoro.cs.oberlin.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 3 Dec 1992 10:19:37 GMT Approved: bug-gdb@prep.ai.mit.edu Lines: 79