gpt4 book ai didi

debugging - gdb:SSE 寄存器输出格式

转载 作者:行者123 更新时间:2023-12-04 06:26:00 24 4
gpt4 key购买 nike

当我使用 print 输出 SSE 寄存器时我得到了预期的结果:

(gdb) p $xmm0
$1 = {
v4_float = {0, 0, 0, 0},
v2_double = {0, 0},
v16_int8 = {0 <repeats 16 times>},
v8_int16 = {0, 0, 0, 0, 0, 0, 0, 0},
v4_int32 = {0, 0, 0, 0},
v2_int64 = {0, 0},
uint128 = 0
}

但是,如果我使用 info registers $xmm0一切都是十六进制的:
(gdb) i r $xmm0
xmm0 {
v4_float = {0x0, 0x0, 0x0, 0x0},
v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>},
v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
v4_int32 = {0x0, 0x0, 0x0, 0x0},
v2_int64 = {0x0, 0x0},
uint128 = 0x00000000000000000000000000000000
}

有什么方法可以获得与我从 print 得到的输出相同的输出吗? ?

编辑:
也许是一个不相关的问题,但我如何解释 v4_float 的值?
一个例子:
(gdb) i r $xmm0
xmm0 {
v4_float = {0x1, 0x0, 0x0, 0x0},
v2_double = {0x0, 0x0},
v16_int8 = {0x0, 0x0, 0xa0, 0x3f, 0x0 <repeats 12 times>},
v8_int16 = {0x0, 0x3fa0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
v4_int32 = {0x3fa00000, 0x0, 0x0, 0x0},
v2_int64 = {0x3fa00000, 0x0},
uint128 = 0x0000000000000000000000003fa00000
}

不应该 v4_float[0]v4_int32[0]都是 0x3fa00000 ( 1.25f )?如果我使用 print我正确得到 v4_float = {1.25, 0, 0, 0} .那么为什么是 v4_float[0] = 0x1使用时 info registers ?

最佳答案

Is there any way to get the same output as I get from print?, No



但是我对此做了一些研究,所以想把它贴在这里以供将来引用。以下是有关命令“ info all-registers 和特殊寄存器的信息。

Some machines have special registers whose contents can be interpreted in several different ways. For example, modern x86-based machines have SSE and MMX registers that can hold several values packed together in several different formats.

The info registers command shows the canonical names. For example, on the SPARC,info registers displays the processor status register as $psr but you can also refer to it as $ps; and on x86-based machines $ps is an alias for the eflags register. gdb always considers the contents of an ordinary register as an integer when the register is examined in this way.



看起来gdb在显示寄存器时有限制(由于各种原因,如不同类型的机器和其他原因)。我们还应该记住,寄存器不是您程序的简单变量,而是它对于程序的特殊和唯一性程序,看起来十六进制是显示这些寄存器的自然格式。然而,只要有可能,gdb 就会以两种格式显示通用寄存器值的内容。为了说明它,请考虑以下输出:
//We can see that gdb is displaying the registers in both format(hex and decimal)
//and in some cases hex and hex format.
(gdb) info r
rax 0x7ffff7dd6568 140737351869800
rbx 0x0 0
rcx 0x400620 4195872
rdx 0x7fffffffe218 140737488347672
rsi 0x7fffffffe208 140737488347656
rdi 0x1 1
rbp 0x7fffffffe120 0x7fffffffe120
rsp 0x7fffffffe070 0x7fffffffe070
r8 0x4006b0 4196016
.............................
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
//gdb would interpret the registers in the normal variable types. However if
// we want to display it in decimal rather in hex format.
(gdb) p $rsp
$24 = (void *) 0x7fffffffe070
(gdb) p/d $rsp
$25 = 140737488347248

还有另一个重要的设置可以更改数字显示的默认基数。

set output-radix base

Set the default base for numeric display. Supported choices for base are decimal 8, 10, or 16. base must itself be specified either unambiguously or using the current input radix.



这可用于更改 GDB 中普通变量/数字的默认显示。然而,这些设置也不会改变寄存器的默认 View (使用信息寄存器时)。但是,当我们使用 print 命令显示它时,它会将普通变量和寄存器的默认值从十进制更改为十六进制。为了说明这一点,请考虑我们有一个局部变量(结果)。
(gdb) show output-radix 10
Default output radix for printing of values is 10.
(gdb) p ii
$26 = (int *) 0x400369
(gdb) p result
$27 = 0
(gdb) info r $xmm0
xmm0 {
v4_float = {0x0, 0x0, 0x0, 0x0},
v2_double = {0x0, 0x0},
v16_int8 = {0xff, 0x0 <repeats 15 times>},
v8_int16 = {0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
v4_int32 = {0xff, 0x0, 0x0, 0x0},
v2_int64 = {0xff, 0x0},
uint128 = 0x000000000000000000000000000000ff
}
(gdb) p $xmm0
$28 = {
v4_float = {3.57331108e-43, 0, 0, 0},
v2_double = {1.2598673968951787e-321, 0},
v16_int8 = {-1, 0 <repeats 15 times>},
v8_int16 = {255, 0, 0, 0, 0, 0, 0, 0},
v4_int32 = {255, 0, 0, 0},
v2_int64 = {255, 0},
uint128 = 255
}
(gdb) set output-radix 16
Output radix now set to decimal 16, hex 10, octal 20.
(gdb) p result
$29 = 0x0
(gdb) info r $xmm0
xmm0 {
v4_float = {0x0, 0x0, 0x0, 0x0},
v2_double = {0x0, 0x0},
v16_int8 = {0xff, 0x0 <repeats 15 times>},
v8_int16 = {0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
v4_int32 = {0xff, 0x0, 0x0, 0x0},
v2_int64 = {0xff, 0x0},
uint128 = 0x000000000000000000000000000000ff
}
(gdb) p $xmm0
$30 = {
v4_float = {3.57331108e-43, 0, 0, 0},
v2_double = {1.2598673968951787e-321, 0},
v16_int8 = {0xff, 0x0 <repeats 15 times>},
v8_int16 = {0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
v4_int32 = {0xff, 0x0, 0x0, 0x0},
v2_int64 = {0xff, 0x0},
uint128 = 0x000000000000000000000000000000ff
}

所以看起来,在使用 info register 命令时无法更改格式。但是如果我们想使用打印命令显示寄存器,它的默认值
格式可以改变,因为 GDB 确实将寄存器视为普通寄存器,因此以不同的格式显示它。因此,我们应该在调试 session 中使用这两种类型的命令来显示不同情况下的寄存器。

关于debugging - gdb:SSE 寄存器输出格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22824618/

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