Mapping IEEE 754 floating point representation in GDB?

When I ask GDB to print the real one in binary, I get the following:

(gdb) p/t 5210887.5
$1 = 10011111000001100000111

According to this ,

0 10010101 00111110000011000001111

- expected value.

Alignment

         1 0011111000001100000111
0 10010101 00111110000011000001111

And it looks like GDB gives me an integer representation after rounding. The fact is that this was done with a variable at work. Using an ad in program C -

main()
{
  float f = 5210887.5;
}

and debug it -

$ gcc -g -O0 floatdec.c -o floatdec
$ gdb floatdec
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/ /floatdec...done.
(gdb) b main
Breakpoint 1 at 0x804839a: file floatdec.c, line 3.
(gdb) r
Starting program: /home/ /floatdec 

Breakpoint 1, main () at floatdec.c:3
3         float f = 5210887.5;
(gdb) s
4       }
(gdb) p f
$1 = 5210887.5
(gdb) p/t f
$2 = 10011111000001100000111

same thing, it shows me an integer representation. Isn't there a way to show gdb floating point format?

+4
source share
1 answer

The format tdoes convert the value to an integer. From gdb: Output Formats :

t
   Print as integer in binary. The letter ‘t’ stands for "two".

This is the backup code in gdb print_scalar_formatted:

if (options->format != 'f')
    val_long = unpack_long (type, valaddr);

unpack_long , float, .

, , (int32 *) .

(gdb) p f
$2 = 5210887.5
(gdb) p/t *(int32_t *)&f
$3 = 1001010100111110000011000001111
(gdb) p/t {int32_t}&f
$4 = 1001010100111110000011000001111

, , , x:

(gdb) x/tw &f
0xbffff3f4: 01001010100111110000011000001111

x86. -endian .

+3

All Articles