I'm trying to examine long double
array in the memory using gdb is it possible ? I do not know what suffix use with x or even p command ?
For example I have (gas syntax):
array: .tfloat 5, 6, 7
fldt array
fldt array+10
fldt array+20
and in gdb I am able to print those values directly from floating point stack:
(gdb) p $st0
$4 = 7
(gdb) p $st1
$5 = 6
(gdb) p $st2
$6 = 5
But I cannot find a way to examine all those values using array address only, like that:
(gdb) x/4gf &array
0x4000b0 <array>: -1,4916681462400413e-154 8,0952656071088246e-320
0x4000c0 <array+16>: 5,3055561114210832e-315 1,3063763415981806e-9
(I know why this one do not work, because 'g' means 8 bytes)
I can of course access those manually with a little casts and work arounds.
(gdb) p *(long double*)(*(array))
$11 = 5
(gdb) p *(long double*)(*(array+10))
$12 = 6
(gdb) p *(long double*)(*(array+20))
$13 = 7
(gdb) p *(long double*)(*(array))+1
$21 = 6
(gdb) p *(long double*)(*(array))+2
$22 = 7
But I hope I am missing something in documentation, and there is an easier way to print out full array instead of printing each element, I have array with many many more elements to inspect from time to time.
gdb --version
GNU gdb (Gentoo 7.7.1 p1) 7.7.1
The problem is, long double
is by default 96 bits due to padding and apparently gdb
only understands that format. The actual precision is 80 bits, which is why you can print them one by one, but the size influences where the next item begins in the array obviously.
As a workaround, you can add that padding too, or write a gdb
script that iterates over the elements for you.
array: .tfloat 5
.byte 0,0
.tfloat 6
.byte 0,0
.tfloat 7
.byte 0,0
(gdb) p (long double[3])array
$1 = {5, 6, 7}