Bug 9580 - printing negative values of constant values (with value 128-255)
Summary: printing negative values of constant values (with value 128-255)
Status: RESOLVED WORKSFORME
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.8
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-09 17:58 UTC by matszpk
Modified: 2011-08-18 12:52 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
test.cc (94 bytes, application/octet-stream)
, matszpk
Details
testNeg_readelf.txt (864 bytes, text/plain)
2011-08-10 16:09 UTC, John T. Kerich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description matszpk 2008-07-09 17:58:01 UTC
[Converted from Gnats 2475]

when defined const value such as:
const int a=128;
gdb print value:
-128 instead 128 when
enter command "p a".

Release:
gdb-6.8

Environment:
Gentoo Linux 2008.0 AMD64
Comment 1 Tom Tromey 2010-01-20 20:20:39 UTC
I couldn't reproduce.

If you still have this bug, please upload a complete source file showing
it, plus the command line you used to compile.
Also, try a newer gdb.
Comment 2 John T. Kerich 2011-08-10 15:53:40 UTC
#include <stdio.h>

static const int z = 128;
static int y = 128;

int main( int argc, char * argv [] )
{
    int ret = 0;

    printf( "%d\n", z );

    return( ret );
}

g++ -c -I. -g -Wall testNeg.C -o testNeg.o
testNeg.C:4: warning: 'y' defined but not used
g++ -MM -I. -g -Wall testNeg.C > .deps/testNeg.d
g++ -o testNeg testNeg.o                 

(gdb) run
Starting program: /home/jkerich/CC_tools/testNeg 
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x2aaaaaaab000
128

Breakpoint 1, main (argc=1, argv=0x7fffffffe1b8) at testNeg.C:12
12          return( ret );
(gdb) print z
$1 = -128
(gdb) print y
$2 = -128
(gdb) quit
Comment 3 John T. Kerich 2011-08-10 15:59:53 UTC
This bug is still happening on our Linux 2.6.18-238.12.1.el5 #1 SMP Sat May 7 20:18:50 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux boxes using version 7.0.1 

GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-32.el5_6.2)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...

I have included test program, how I compiled it, debugger output and print commands showing 128 being displayed as -128.

Please email if there is a fix.  john.t.kerich@nasa.gov
Comment 4 Tom Tromey 2011-08-10 16:03:44 UTC
Created attachment 5892 [details]
testNeg_readelf.txt

I can't reproduce on my F15 box.

It is possible that the problem is in the compiler.
The output from "readelf -wi" on the executable would help
diagnose that.
It is also possible that the bug was fixed in a more recent gdb.
Comment 5 John T. Kerich 2011-08-10 16:09:33 UTC
I ran the readelf -wi testNeg > testNeg_readelf.txt, see attached.  Hope that helps.

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov

-----Original Message-----
From: tromey at redhat dot com [mailto:sourceware-bugzilla@sourceware.org] 
Sent: Wednesday, August 10, 2011 12:04 PM
To: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC]
Subject: [Bug c++/9580] printing negative values of constant values (with value 128-255)

http://sourceware.org/bugzilla/show_bug.cgi?id=9580

--- Comment #4 from Tom Tromey <tromey at redhat dot com> 2011-08-10 16:03:44 UTC ---
I can't reproduce on my F15 box.

It is possible that the problem is in the compiler.
The output from "readelf -wi" on the executable would help
diagnose that.
It is also possible that the bug was fixed in a more recent gdb.
Comment 6 John T. Kerich 2011-08-10 16:15:35 UTC
P.S.
Compiling with the -gstabs+ fixes the problem, but there is a side effect in valgrind tool.  The file/line numbers that normally are printed out on the stack list disappear, so we really don't want to use it because you need to see the line numbers to know what valgrind is talking about.  The other way is to cast the variable for the gdb print command, ex. "print (int)y". It then prints out 128 correctly, but then you need to know this is a const variable first.

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov


-----Original Message-----
From: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC] 
Sent: Wednesday, August 10, 2011 12:09 PM
To: 'tromey at redhat dot com'
Subject: RE: [Bug c++/9580] printing negative values of constant values (with value 128-255)

I ran the readelf -wi testNeg > testNeg_readelf.txt, see attached.  Hope that helps.

John T. Kerich
Columbus Technologies and Services, Inc Nasa GSFC Building 13 Room 141 Cube 4 8800 Greenbelt Road Greenbelt, MD 20771 Tel. #: (301) 286-5138 Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov

-----Original Message-----
From: tromey at redhat dot com [mailto:sourceware-bugzilla@sourceware.org]
Sent: Wednesday, August 10, 2011 12:04 PM
To: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC]
Subject: [Bug c++/9580] printing negative values of constant values (with value 128-255)

http://sourceware.org/bugzilla/show_bug.cgi?id=9580

--- Comment #4 from Tom Tromey <tromey at redhat dot com> 2011-08-10 16:03:44 UTC --- I can't reproduce on my F15 box.

It is possible that the problem is in the compiler.
The output from "readelf -wi" on the executable would help diagnose that.
It is also possible that the bug was fixed in a more recent gdb.

--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: ------- You are on the CC list for the bug.
Comment 7 Tom Tromey 2011-08-10 19:31:24 UTC
The debuginfo looks fine to me.
Can you try a newer version of gdb?
Comment 8 John T. Kerich 2011-08-10 20:17:26 UTC
I will have to check with my SA, we only download from RedHat for RH 5.

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov


-----Original Message-----
From: tromey at redhat dot com [mailto:sourceware-bugzilla@sourceware.org] 
Sent: Wednesday, August 10, 2011 3:31 PM
To: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC]
Subject: [Bug c++/9580] printing negative values of constant values (with value 128-255)

http://sourceware.org/bugzilla/show_bug.cgi?id=9580

--- Comment #7 from Tom Tromey <tromey at redhat dot com> 2011-08-10 19:31:24 UTC ---
The debuginfo looks fine to me.
Can you try a newer version of gdb?
Comment 9 John T. Kerich 2011-08-11 16:10:06 UTC
We tried the test program on a sun sparc 2.6 OS and the bug did not happen so it looks like it is related to the version of the RH OS we are running.  Are SA says there is a newer version of gdb 7.1? that Red Hat has and our SA is going to install that today for us to try.  I will let you know if there is any change.

P.S.
We are 64 bit OS here.  Could that have something to do with it?

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov


-----Original Message-----
From: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC] 
Sent: Wednesday, August 10, 2011 4:17 PM
To: 'tromey at redhat dot com'
Subject: RE: [Bug c++/9580] printing negative values of constant values (with value 128-255)

I will have to check with my SA, we only download from RedHat for RH 5.

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov


-----Original Message-----
From: tromey at redhat dot com [mailto:sourceware-bugzilla@sourceware.org] 
Sent: Wednesday, August 10, 2011 3:31 PM
To: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC]
Subject: [Bug c++/9580] printing negative values of constant values (with value 128-255)

http://sourceware.org/bugzilla/show_bug.cgi?id=9580

--- Comment #7 from Tom Tromey <tromey at redhat dot com> 2011-08-10 19:31:24 UTC ---
The debuginfo looks fine to me.
Can you try a newer version of gdb?
Comment 10 John T. Kerich 2011-08-11 16:48:57 UTC
My SA now says that gdb (gdb.x86_64 0:7.0.1-32.el5_6.2 ) is the current version of Redhat 5.6 so I can't update.

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov


-----Original Message-----
From: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC] 
Sent: Thursday, August 11, 2011 12:09 PM
To: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC]; 'tromey at redhat dot com'
Subject: RE: [Bug c++/9580] printing negative values of constant values (with value 128-255)

We tried the test program on a sun sparc 2.6 OS and the bug did not happen so it looks like it is related to the version of the RH OS we are running.  Are SA says there is a newer version of gdb 7.1? that Red Hat has and our SA is going to install that today for us to try.  I will let you know if there is any change.

P.S.
We are 64 bit OS here.  Could that have something to do with it?

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov


-----Original Message-----
From: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC] 
Sent: Wednesday, August 10, 2011 4:17 PM
To: 'tromey at redhat dot com'
Subject: RE: [Bug c++/9580] printing negative values of constant values (with value 128-255)

I will have to check with my SA, we only download from RedHat for RH 5.

John T. Kerich
Columbus Technologies and Services, Inc 
Nasa GSFC
Building 13 Room 141 Cube 4
8800 Greenbelt Road
Greenbelt, MD 20771
Tel. #: (301) 286-5138
Fax #: (301) 286-7475
Email: john.t.kerich@nasa.gov


-----Original Message-----
From: tromey at redhat dot com [mailto:sourceware-bugzilla@sourceware.org] 
Sent: Wednesday, August 10, 2011 3:31 PM
To: Kerich, John T. (GSFC-444.0)[COLUMBUS TECHNOLOGIES AND SERVICES INC]
Subject: [Bug c++/9580] printing negative values of constant values (with value 128-255)

http://sourceware.org/bugzilla/show_bug.cgi?id=9580

--- Comment #7 from Tom Tromey <tromey at redhat dot com> 2011-08-10 19:31:24 UTC ---
The debuginfo looks fine to me.
Can you try a newer version of gdb?
Comment 11 Jan Kratochvil 2011-08-18 12:52:40 UTC
FSF GDB has it fixed by:

commit 2f22c795e000ddecc31a0c31043781ec9dc400c3
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Jul 28 20:05:00 2010 +0000

        * dwarf2read.c (dwarf2_const_value_data): Never sign extend.

+/* Given an attr with a DW_FORM_dataN value in host byte order,
+   zero-extend it as appropriate for the symbol's type.  The DWARF
+   standard (v4) is not entirely clear about the meaning of using
+   DW_FORM_dataN for a constant with a signed type, where the type is
+   wider than the data.  The conclusion of a discussion on the DWARF
+   list was that this is unspecified.  We choose to always zero-extend
+   because that is the interpretation long in use by GCC.  */

FSF GDB bugtracker is not used for RHEL backporting.
Please file it to Red Hat RHEL Bugzilla if you wish a backport.
I can confirm this bug is present in:
RHEL-6.1 gdb-7.2-48.el6.x86_64
RHEL-5.6 gdb-7.0.1-32.el5_6.2.x86_64