gpt4 book ai didi

c++ - 如何在 GDB 中以十六进制打印 double 的位?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:57 26 4
gpt4 key购买 nike

我以为它会是 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 机器上,我正在调试使用 gcc 4.4(未优化,w/-g)构建的 C++ 代码

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中,double和unsigned long大小相同,可以先把double转成unsigned long,再打印。

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

或者你可以

x/8x &row.DBL_NPIO2.m_value

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

关于c++ - 如何在 GDB 中以十六进制打印 double 的位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56799703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com