我如何在GDB中打印十六进制的双重位

How do I print the bits of a double in hex, in GDB?

本文关键字:十六进制 打印 GDB      更新时间:2023-10-16

我认为这是 p/x,但会产生奇怪的结果。这是一个错误还是我做错了什么?

(gdb) ptype row.DBL_NPIO2.m_value
type = double
(gdb) p row.DBL_NPIO2.m_value
$6 = -1.5707963267948966
(gdb) p/x row.DBL_NPIO2.m_value
$7 = 0xffffffffffffffff
(gdb) print (double)0xffffffffffffffff
$8 = 1.844674407370955e+19

这是在CentOS5 x86机器上

mattheww@SEN-CentOS5: ~$ uname -a
Linux SEN-CentOS5 2.6.18-238.9.1.el5 #1 SMP Tue Apr 12 18:10:13 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
mattheww@SEN-CentOS5: ~$ gdb --version
GNU gdb (GDB) CentOS (7.0.1-45.el5.centos)
Copyright (C) 2009 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.

在x86_64中,双重和未签名的长度具有相同的尺寸,您可以将双重转换为无签名长,然后打印。

p /x *(unsigned long*)&row.DBL_NPIO2.m_value

或者您可以

x/8x &row.DBL_NPIO2.m_value

将打印从低地址到高地址的字节。