GDB version 6.8 was released just a few days ago. I’m happy to have made my small contribution to it, mostly with development of decimal floating point debugging support. From the NEWS file:
“GDB now supports debugging C and C++ programs which use the Decimal Floating Point extension. In addition, the PowerPC target now has a set of pseudo-registers to inspect decimal float values stored in two consecutive float registers.”
The feature was actually developed by several folks. Ben Elliston started working on the feature, and then passed it on to Wu Zhou. I took up where Wu Zhou left and implemented more complete support for decimal float types. Luis Machado also helped me and posted some patches of his own. The work amounted to a total of about 12 patches.
It means that you can now use GDB (version 6.8 or later) to debug programs which make use of the proposed C extension for decimal floating-point arithmetic (i.e., the _Decimal32, _Decimal64 and _Decimal128 types). The first GCC release with support for this extension was GCC 4.2.
Why is decimal floating point useful? It avoids the unexpected surprises and rounding errors which inevitably come with binary floating point. It’s not that decimal float is more exact or precise, it’s just that it behaves just like we are used to and were thought in school in terms of representation and rounding.
GDB itself can provide an example:
(gdb) p 1.2l
$1 = 1.2000000000000000000433680868994202
(gdb) ptype 1.2l
type = long double
(gdb) p 1.2dl
$2 = 1.2
(gdb) ptype 1.2dl
type = _Decimal128
You can see that the actual value used to represent 1.2 in binary floating point is slightly larger than 1.2. Why is that? It’s because to express 0.2 in binary float you need an infinite number of digits, so what ends up being stored is the closest number possible to represent in binary. The difference is almost nothing, but this error will propagate in computations and eventually be big enough to be noticed. That’s why in some application domains (e.g., finance and civil construction), you are actually required by law to use decimal floating point to perform calculations.
More information about decimal float can be found in Mike Cowlishaw’s page.