Can GDB correctly parse C-style floating point hexadecimal numbers?

I can't get GDB to correctly print some C-style floating point hexadecimal numbers, see:

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 Copyright (C) 2014 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-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word". (gdb) p 0xa.0p-4 $1 = 6 

Here $1 should be 0.625 , but my GDB seems to see 0xa.0p as decimal 10 and does the subsequent addition with -4 . What happened to the fact that I asked GDB to print? I could not find the relevant documentation on how GDB handles hex floats.

+6
source share
1 answer

What is wrong with the fact that I ask GDB to print?

This seems to be a bug with gdb.

Negative floating point hexadecimal constants give wrong result with gdb.

I tried with the latest initial release of gdb 7.9 (February 20, 2015) on Linux and hexadecimal floating point constants with a positive exponent are supported:

 (gdb) p/f 0x00.1p0 $1 = 0.0625 (gdb) p/f 0x00.1p1 $2 = 0.125 

but if the indicator is negative, then the result is incorrect:

 (gdb) p/f 0x00.1p-1 $3 = -0.9375 

The correct and expected result is 0.031250 .

+3
source

Source: https://habr.com/ru/post/985877/


All Articles