Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* inconsistency in printing out the value of an unsigned short in gdb
@ 2007-09-25 14:19 Erik Niessen
  2007-09-25 15:57 ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Niessen @ 2007-09-25 14:19 UTC (permalink / raw)
  To: gdb

Hi all,

I have a simple program:

typedef unsigned short UInt16;
const UInt16 c_uint16 = 0xFE;
UInt16 g_uint16 = 0xFE;
const unsigned short c_ushort = 0xFE;

int main() {
    printf("c_ushort=%#X\n",c_ushort);
    printf("c_uint16=%#X\n",c_uint16);
    printf("g_uint16=%#X\n",g_uint16);
    return 0;
}
I use  g++ version 4.0 and gdb  version 6.6
g++ -g constants.cpp -o ./constants
running this exec gives the following output as expected
c_ushort=0XFE
c_uint16=0XFE
g_uint16=0XFE
But running it in gdb
gdb ./constants
(gdb) b main
(gdb) p /x c_ushort
$1 = 0xfe
(gdb) p /x g_uint16
$2 = 0xfe
(gdb) p /x c_uint16
$3 = 0xfffe

Weird why does it not print the value 0xfe like the other ones.

When I use gcc-4.0 it works as expected

Any ideas??

Cheers,
   Erik


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: inconsistency in printing out the value of an unsigned short  in gdb
  2007-09-25 14:19 inconsistency in printing out the value of an unsigned short in gdb Erik Niessen
@ 2007-09-25 15:57 ` Daniel Jacobowitz
  2007-09-26  8:33   ` Erik Niessen
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-09-25 15:57 UTC (permalink / raw)
  To: Erik Niessen; +Cc: gdb

On Tue, Sep 25, 2007 at 04:10:51PM +0200, Erik Niessen wrote:
> Any ideas??

Probably inaccurate debug information from your compiler, and
different generated code.  The value has been extended for some reason
before GDB got a chance to print it.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: inconsistency in printing out the value of an unsigned short in gdb
  2007-09-25 15:57 ` Daniel Jacobowitz
@ 2007-09-26  8:33   ` Erik Niessen
  2007-09-26 21:38     ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Niessen @ 2007-09-26  8:33 UTC (permalink / raw)
  To: gdb

Hi Daniel,

Thanks for your fast reply. I tried with different versions of g++
(3.4.6, 4.0, 4.0.4) they all have the same problem.
Is there a way how I can check the produced debug info for example via objdump?
So that I can convince the g++ people otherwise they will point their
finger at gdb.

Cheers,

Erik

On 9/25/07, Daniel Jacobowitz <drow@false.org> wrote:
> On Tue, Sep 25, 2007 at 04:10:51PM +0200, Erik Niessen wrote:
> > Any ideas??
>
> Probably inaccurate debug information from your compiler, and
> different generated code.  The value has been extended for some reason
> before GDB got a chance to print it.
>
> --
> Daniel Jacobowitz
> CodeSourcery
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: inconsistency in printing out the value of an unsigned short  in gdb
  2007-09-26  8:33   ` Erik Niessen
@ 2007-09-26 21:38     ` Daniel Jacobowitz
  2007-09-27 11:27       ` Erik Niessen
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-09-26 21:38 UTC (permalink / raw)
  To: Erik Niessen; +Cc: gdb

On Wed, Sep 26, 2007 at 09:35:55AM +0200, Erik Niessen wrote:
> Hi Daniel,
> 
> Thanks for your fast reply. I tried with different versions of g++
> (3.4.6, 4.0, 4.0.4) they all have the same problem.
> Is there a way how I can check the produced debug info for example via objdump?

Try readelf -wi.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: inconsistency in printing out the value of an unsigned short in gdb
  2007-09-26 21:38     ` Daniel Jacobowitz
@ 2007-09-27 11:27       ` Erik Niessen
  2007-09-27 12:15         ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Niessen @ 2007-09-27 11:27 UTC (permalink / raw)
  To: Erik Niessen, gdb

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

I ran the readelf -wi on my executable. The output file is attached.
Looking at this debug info all the 3 variables are of type short
unsigned int 2 byte size.
So it looks that the debug info generated by the compiler is correct?

Cheers,
Erik


On 9/26/07, Daniel Jacobowitz <drow@false.org> wrote:
> On Wed, Sep 26, 2007 at 09:35:55AM +0200, Erik Niessen wrote:
> > Hi Daniel,
> >
> > Thanks for your fast reply. I tried with different versions of g++
> > (3.4.6, 4.0, 4.0.4) they all have the same problem.
> > Is there a way how I can check the produced debug info for example via objdump?
>
> Try readelf -wi.
>
> --
> Daniel Jacobowitz
> CodeSourcery
>

[-- Attachment #2: constants++.txt --]
[-- Type: text/plain, Size: 8870 bytes --]

The section .debug_info contains:

  Compilation Unit @ offset 0x0:
   Length:        118
   Version:       2
   Abbrev Offset: 0
   Pointer Size:  4
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_stmt_list   : 0	
     DW_AT_low_pc      : 0x8048378	
     DW_AT_high_pc     : 0x804839a	
     DW_AT_name        : ../sysdeps/i386/elf/start.S	
     DW_AT_comp_dir    : /build/buildd/glibc-2.3.6/build-tree/glibc-2.3.6/csu	
     DW_AT_producer    : GNU AS 2.16.91	
     DW_AT_language    : 32769	(MIPS assembler)
  Compilation Unit @ offset 0x7a:
   Length:        141
   Version:       2
   Abbrev Offset: 20
   Pointer Size:  4
 <0><85>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_stmt_list   : 0x5b	
     DW_AT_high_pc     : 0x804839c	
     DW_AT_low_pc      : 0x804839c	
     DW_AT_producer    : (indirect string, offset: 0x62): GNU C 3.4.6 (Ubuntu 3.4.6-1ubuntu2)	
     DW_AT_language    : 1	(ANSI C)
     DW_AT_name        : (indirect string, offset: 0x0): init.c	
     DW_AT_comp_dir    : (indirect string, offset: 0x11): /build/buildd/glibc-2.3.6/build-tree/glibc-2.3.6/csu	
 <1><9f>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x90): unsigned int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 7	(unsigned)
 <1><a6>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x54): unsigned char	
     DW_AT_byte_size   : 1	
     DW_AT_encoding    : 8	(unsigned char)
 <1><ad>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x9d): short unsigned int	
     DW_AT_byte_size   : 2	
     DW_AT_encoding    : 7	(unsigned)
 <1><b4>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x8b): long unsigned int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 7	(unsigned)
 <1><bb>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x56): signed char	
     DW_AT_byte_size   : 1	
     DW_AT_encoding    : 6	(signed char)
 <1><c2>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x7): short int	
     DW_AT_byte_size   : 2	
     DW_AT_encoding    : 5	(signed)
 <1><c9>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 5	(signed)
 <1><d0>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x46): long long int	
     DW_AT_byte_size   : 8	
     DW_AT_encoding    : 5	(signed)
 <1><d7>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x86): long long unsigned int	
     DW_AT_byte_size   : 8	
     DW_AT_encoding    : 7	(unsigned)
 <1><de>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x4b): long int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 5	(signed)
 <1><e5>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x90): unsigned int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 7	(unsigned)
 <1><ec>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0x5d): char	
     DW_AT_byte_size   : 1	
     DW_AT_encoding    : 6	(signed char)
 <1><f3>: Abbrev Number: 4 (DW_TAG_variable)
     DW_AT_name        : (indirect string, offset: 0xb0): _IO_stdin_used	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 25	
     DW_AT_type        : <105>	
     DW_AT_external    : 1	
     DW_AT_location    : 5 byte block: 3 68 85 4 8 	(DW_OP_addr: 8048568)
 <1><105>: Abbrev Number: 5 (DW_TAG_const_type)
     DW_AT_type        : <c9>	
  Compilation Unit @ offset 0x10b:
   Length:        140
   Version:       2
   Abbrev Offset: 86
   Pointer Size:  4
 <0><116>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_stmt_list   : 0x82	
     DW_AT_name        : /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu/crti.S	
     DW_AT_comp_dir    : /build/buildd/glibc-2.3.6/build-tree/glibc-2.3.6/csu	
     DW_AT_producer    : GNU AS 2.16.91	
     DW_AT_language    : 32769	(MIPS assembler)
  Compilation Unit @ offset 0x19b:
   Length:        414
   Version:       2
   Abbrev Offset: 102
   Pointer Size:  4
 <0><1a6>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_stmt_list   : 0x12f	
     DW_AT_high_pc     : 0x804847e	
     DW_AT_low_pc      : 0x804841c	
     DW_AT_producer    : GNU C++ 3.4.6 (Ubuntu 3.4.6-1ubuntu2)	
     DW_AT_language    : 4	(C++)
     DW_AT_name        : constants.c	
     DW_AT_comp_dir    : /home/nly99047/sigma/gdb	
 <1><1ff>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0xbf): unsigned int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 7	(unsigned)
 <1><206>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : unsigned char	
     DW_AT_byte_size   : 1	
     DW_AT_encoding    : 8	(unsigned char)
 <1><217>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : short unsigned int	
     DW_AT_byte_size   : 2	
     DW_AT_encoding    : 7	(unsigned)
 <1><22d>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : long unsigned int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 7	(unsigned)
 <1><242>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : signed char	
     DW_AT_byte_size   : 1	
     DW_AT_encoding    : 6	(signed char)
 <1><251>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : short int	
     DW_AT_byte_size   : 2	
     DW_AT_encoding    : 5	(signed)
 <1><25e>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 5	(signed)
 <1><265>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : long long int	
     DW_AT_byte_size   : 8	
     DW_AT_encoding    : 5	(signed)
 <1><276>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : long long unsigned int	
     DW_AT_byte_size   : 8	
     DW_AT_encoding    : 7	(unsigned)
 <1><290>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : long int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 5	(signed)
 <1><29c>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : (indirect string, offset: 0xbf): unsigned int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 7	(unsigned)
 <1><2a3>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : char	
     DW_AT_byte_size   : 1	
     DW_AT_encoding    : 6	(signed char)
 <1><2ab>: Abbrev Number: 4 (DW_TAG_typedef)
     DW_AT_name        : UInt16	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 4	
     DW_AT_type        : <217>	
 <1><2b9>: Abbrev Number: 5 (DW_TAG_subprogram)
     DW_AT_external    : 1	
     DW_AT_name        : main	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 12	
     DW_AT_type        : <25e>	
     DW_AT_low_pc      : 0x804841c	
     DW_AT_high_pc     : 0x804847e	
     DW_AT_frame_base  : 1 byte block: 55 	(DW_OP_reg5)
 <1><2d0>: Abbrev Number: 6 (DW_TAG_namespace)
     DW_AT_sibling     : <311>	
     DW_AT_name        : ::	
     DW_AT_decl_file   : 2	
     DW_AT_decl_line   : 0	
 <2><2da>: Abbrev Number: 7 (DW_TAG_variable)
     DW_AT_name        : c_uint16	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 5	
     DW_AT_type        : <311>	
     DW_AT_declaration : 1	
     DW_AT_const_value : 254	
 <2><2ec>: Abbrev Number: 8 (DW_TAG_variable)
     DW_AT_name        : g_uint16	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 6	
     DW_AT_type        : <2ab>	
     DW_AT_external    : 1	
     DW_AT_declaration : 1	
 <2><2fe>: Abbrev Number: 7 (DW_TAG_variable)
     DW_AT_name        : c_ushort	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 8	
     DW_AT_type        : <32c>	
     DW_AT_declaration : 1	
     DW_AT_const_value : 254	
 <1><311>: Abbrev Number: 9 (DW_TAG_const_type)
     DW_AT_type        : <2ab>	
 <1><316>: Abbrev Number: 10 (DW_TAG_variable)
     DW_AT_specification: <2da>	
     DW_AT_location    : 5 byte block: 3 96 85 4 8 	(DW_OP_addr: 8048596)
 <1><321>: Abbrev Number: 10 (DW_TAG_variable)
     DW_AT_specification: <2ec>	
     DW_AT_location    : 5 byte block: 3 8 97 4 8 	(DW_OP_addr: 8049708)
 <1><32c>: Abbrev Number: 9 (DW_TAG_const_type)
     DW_AT_type        : <217>	
 <1><331>: Abbrev Number: 10 (DW_TAG_variable)
     DW_AT_specification: <2fe>	
     DW_AT_location    : 5 byte block: 3 98 85 4 8 	(DW_OP_addr: 8048598)
  Compilation Unit @ offset 0x33d:
   Length:        140
   Version:       2
   Abbrev Offset: 241
   Pointer Size:  4
 <0><348>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_stmt_list   : 0x181	
     DW_AT_name        : /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu/crtn.S	
     DW_AT_comp_dir    : /build/buildd/glibc-2.3.6/build-tree/glibc-2.3.6/csu	
     DW_AT_producer    : GNU AS 2.16.91	
     DW_AT_language    : 32769	(MIPS assembler)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: inconsistency in printing out the value of an unsigned short  in gdb
  2007-09-27 11:27       ` Erik Niessen
@ 2007-09-27 12:15         ` Daniel Jacobowitz
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-09-27 12:15 UTC (permalink / raw)
  To: Erik Niessen; +Cc: gdb

On Thu, Sep 27, 2007 at 12:41:37PM +0200, Erik Niessen wrote:
> I ran the readelf -wi on my executable. The output file is attached.
> Looking at this debug info all the 3 variables are of type short
> unsigned int 2 byte size.
> So it looks that the debug info generated by the compiler is correct?

That's not the issue.  You need to look at where the .debug_info
section says the variables live (DW_AT_location), and compare it
to what the assembly code is putting there.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-09-27 12:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-25 14:19 inconsistency in printing out the value of an unsigned short in gdb Erik Niessen
2007-09-25 15:57 ` Daniel Jacobowitz
2007-09-26  8:33   ` Erik Niessen
2007-09-26 21:38     ` Daniel Jacobowitz
2007-09-27 11:27       ` Erik Niessen
2007-09-27 12:15         ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox