Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分析gdb中的浮点值_Gdb - Fatal编程技术网

分析gdb中的浮点值

分析gdb中的浮点值,gdb,Gdb,示例代码: int main() { float x = 456.876; printf ("\nx = %f\n", x); return 0; } 在gdb中,我执行以下代码: Breakpoint 1, main () at sample_float.c:5 5 float x = 456.876; (gdb) n 7 printf ("\nx = %f\n",

示例代码:

int main()
{
        float x = 456.876;

        printf ("\nx = %f\n", x);

        return 0;
}
在gdb中,我执行以下代码:

Breakpoint 1, main () at sample_float.c:5   
5               float x = 456.876;   
(gdb) n    
7               printf ("\nx = %f\n", x);   
(gdb) p &x   
$1 = (float *) 0x7fffffffd9dc   
(gdb) x/4fb &x   
0x7fffffffd9dc: 33      112     -28     67   
是否可以使用:x/fb命令as:456.876查看地址x处的值


谢谢。

也许我误解了你的问题,但你可以这么做

p/f x


这就是你想要的吗?

同意上面的答案,但要理解为什么你会得到这样的结果

(gdb) x/4fb &x   
0x7fffffffd9dc: 33      112     -28     67 
从gdb手册

x/3uh 0x54320'是一个显示三个半字(h)内存的请求,格式为无符号十进制整数(
u'),从地址0x54320开始

因此,x/4fb&x将字节格式化为浮点4次不将4个字节作为浮点。

您可以使用命令x(代表“检查”)检查多种格式的内存, 独立于程序的数据类型。 x/nfu地址 x地址 x n、 f、和u都是可选参数,用于指定要显示的内存量和格式化方式;addr是一个表达式,给出要开始显示内存的地址。如果对nfu使用默认值,则无需键入斜杠“/”。有几个命令为addr设置了方便的默认值。 n、 重复计数 重复计数为十进制整数;默认值为1。它指定要显示的内存量(以u为单位计数)。 f、 显示格式 显示格式是打印、`s'(以null结尾的字符串)或`i'(机器指令)使用的格式之一。默认值最初为“x”(十六进制)。 每次使用x或print时,默认设置都会更改。 u、 单位大小单位大小为以下任意一种 b:字节。 h:半字(两个字节)。 w:字(四个字节)。这是初始默认值。 g:巨字(八个字节)。
或者
x/fw&x
如果您真的想更明确地说明尺寸。非常感谢,这正是我想要的!在我的例子中,此示例在点后显示2位数字。但是如果我需要更多呢?谢谢你的澄清!
(gdb) x/4fb &x   
0x7fffffffd9dc: 33      112     -28     67 
You can use the command x (for "examine") to examine memory in any of several formats, independently of your program's data types. x/nfu addr x addr x n, f, and u are all optional parameters that specify how much memory to display and how to format it; addr is an expression giving the address where you want to start displaying memory. If you use defaults for nfu, you need not type the slash `/'. Several commands set convenient defaults for addr. n, the repeat count The repeat count is a decimal integer; the default is 1. It specifies how much memory (counting by units u) to display. f, the display format The display format is one of the formats used by print, `s' (null-terminated string), or `i' (machine instruction). The default is `x' (hexadecimal) initially. The default changes each time you use either x or print. u, the unit size The unit size is any of b: Bytes. h: Halfwords (two bytes). w: Words (four bytes). This is the initial default. g: Giant words (eight bytes).