繁体   English   中英

如何使用 GDB 将 AVX 寄存器显示为双精度?

[英]How to display AVX registers as doubles with GDB?

我试图在 Mandelbrot 程序中使用 AVX,但它无法正常工作。

我尝试调试它,但 GDB 拒绝向我显示 YMM 寄存器中的浮点值。 这是最小的例子

电话 c

#include <stdio.h>
extern void loadnum(void);
extern double input[4];
extern double output[4];

int main(void)
{
       /*
       input[0] = 1.1;
       input[1] = 2.2;
       input[2] = 3.3;
       input[3] = 3.14159;
       */
       
       printf("%f %f %f %f\n",input[0],input[1],input[2],input[3]);
       
       loadnum();
       
       printf("%f %f %f %f\n",output[0],output[1],output[2],output[3]);
       
       return 0;
}

l.asm

 section .data

global input
global output

 align 32
input   dq 1.1,2.2,3.3,3.14159
output  dq 0,0,0,0

 section .text

global loadnum

loadnum:
        vmovapd  ymm0, [input]
        vmovapd  [output],ymm0
        
        ret

它是如何编译的

OBJECTS = t.o l.o
CFLAGS = -c -O2 -g -no-pie -mavx -Wall

t:  $(OBJECTS)
    gcc -g -no-pie $(OBJECTS) -o t

t.o:    t.c
    gcc $(CFLAGS) t.c

l.o:    l.asm
    nasm -felf64 -gdwarf l.asm

output 是

> 1.100000 2.200000 3.300000 3.141590
> 1.100000 2.200000 3.300000 3.141590

这表明它正在按预期加载和存储这些双打,但在 gdb 中它显示

> gdb t (followed by some boilerplate)
> Reading symbols from t...
> (gdb) b loadnum
> Breakpoint 1 at 0x4011b0: file l.asm, line 15.
> (gdb) run
> Starting program: /somedir/t 
> 1.100000 2.200000 3.300000 3.141590

> Breakpoint 1, loadnum () at l.asm:15
> 15            vmovapd  ymm0, [input]
> (gdb) n
> 16            vmovapd  [output],ymm0
> (gdb) 

然后我说

> (gdb) info all-registers

这出现了。

> ymm0 (blah blah) v4_double = {0x1, 0x2, 0x3, 0x3}

当我希望它显示

> ymm0 (blah blah) v4_double = {1.100000 2.200000 3.300000 3.141590}
None of the other fields show anything like that, unless you want to parse the floating point bits
> v4_int64 = {0x3ff199999999999a, 0x400199999999999a, 0x400a666666666666, 0x400921f9f01b866e}

我怎样才能解决这个问题?

p $ymm0.v4_doubleprint命令)默认为十进制格式。

p /whatever用于其他格式,例如p /x $ymm0.v4_int64以查看位模式的十六进制。 help p了解更多。


display $ymm0.v4_double可以作为layout reg + tui reg vec的替代品,在某些版本中存在错误/损坏,并且对于像 ymm0-15 这样广泛和众多的寄存器,总是无法使用的不同格式的混乱。 它采用与p rint 相同的选项,并在每个提示之前打印。 undisplay 1undisplay (all) 禁用您设置的某些表达式。)

如果您想跟踪多个寄存器,它可能会在 TUI 模式下变得混乱( layout asmlayout reg + layout next to see integer regs and disassembly),所以您可能更喜欢使用非 TUI 模式,要么不使用首先layout ,或tui dis

(在调试手写的 asm 时,我几乎总是想查看反汇编,而不是源代码;但也许对于一个复杂的算法,我有时会希望看到带有注释的源代码,以提醒在某个特定的值应该是什么/意味着什么观点。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM