1 以x265视频编码器中的汇编为例, 计划打印calc_satd_16x8的中间计算过程
编译好x265 ,设置断点。
(gdb) b common/x86/pixel-a.asm:13550
No symbol table is loaded. Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (common/x86/pixel-a.asm:13550) pending.
cglobal calc_satd_16x8 ; function to compute satd cost for 16 columns, 8 rows
call pixel_satd_16x8_internal_avx512
ret
pxor m6, m6
vbroadcasti128 m0, [r0]
vbroadcasti128 m4, [r2]
vbroadcasti128 m1, [r0 + r1]
vbroadcasti128 m5, [r2 + r3]
pmaddubsw m4, m7;m7 = 11111111,1-11-11-11-11-1 断点设置的这一行
2 然后输入参数运行编码
(gdb) r src_576x1024_30.yuv --input-res 576x1024 --fps 30 --preset slow -o abc.265
Starting program: /data/x265/source/x265 src_576x1024_30.yuv --input-res 576x1024 --fps 30 --preset slow -o abc.265
跳到断点位置
3 打印寄存器的值
(gdb) p /x $ymm7
$2 = {v8_float = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_double = {0x0, 0x0, 0x8000000000000000, 0x8000000000000000}, v32_int8 = {0x1 <repeats 17 times>,
0xff, 0x1, 0xff, 0x1, 0xff, 0x1, 0xff, 0x1, 0xff, 0x1, 0xff, 0x1, 0xff, 0x1, 0xff}, v16_int16 = {0x101, 0x101, 0x101, 0x101, 0x101, 0x101, 0x101, 0x101,
0xff01, 0xff01, 0xff01, 0xff01, 0xff01, 0xff01, 0xff01, 0xff01}, v8_int32 = {0x1010101, 0x1010101, 0x1010101, 0x1010101, 0xff01ff01, 0xff01ff01, 0xff01ff01,
0xff01ff01}, v4_int64 = {0x101010101010101, 0x101010101010101, 0xff01ff01ff01ff01, 0xff01ff01ff01ff01}, v2_int128 = {0x1010101010101010101010101010101,
0xff01ff01ff01ff01ff01ff01ff01ff01}}
(gdb) p /x $ymm0
$3 = {v8_float = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_double = {0x0, 0x0, 0x0, 0x0}, v32_int8 = {0x7d, 0x93, 0xa8, 0xac, 0xac, 0xaa, 0xa8, 0xa7, 0xa8,
0xa9, 0xa9, 0xa8, 0xa8, 0xaa, 0xab, 0xa4, 0x7d, 0x93, 0xa8, 0xac, 0xac, 0xaa, 0xa8, 0xa7, 0xa8, 0xa9, 0xa9, 0xa8, 0xa8, 0xaa, 0xab, 0xa4}, v16_int16 = {
0x937d, 0xaca8, 0xaaac, 0xa7a8, 0xa9a8, 0xa8a9, 0xaaa8, 0xa4ab, 0x937d, 0xaca8, 0xaaac, 0xa7a8, 0xa9a8, 0xa8a9, 0xaaa8, 0xa4ab}, v8_int32 = {0xaca8937d,
0xa7a8aaac, 0xa8a9a9a8, 0xa4abaaa8, 0xaca8937d, 0xa7a8aaac, 0xa8a9a9a8, 0xa4abaaa8}, v4_int64 = {0xa7a8aaacaca8937d, 0xa4abaaa8a8a9a9a8, 0xa7a8aaacaca8937d,
0xa4abaaa8a8a9a9a8}, v2_int128 = {0xa4abaaa8a8a9a9a8a7a8aaacaca8937d, 0xa4abaaa8a8a9a9a8a7a8aaacaca8937d}}
(gdb) p /x
$4 = {v8_float = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_double = {0x0, 0x0, 0x0, 0x0}, v32_int8 = {0x7d, 0x93, 0xa8, 0xac, 0xac, 0xaa, 0xa8, 0xa7, 0xa8,
0xa9, 0xa9, 0xa8, 0xa8, 0xaa, 0xab, 0xa4, 0x7d, 0x93, 0xa8, 0xac, 0xac, 0xaa, 0xa8, 0xa7, 0xa8, 0xa9, 0xa9, 0xa8, 0xa8, 0xaa, 0xab, 0xa4}, v16_int16 = {
0x937d, 0xaca8, 0xaaac, 0xa7a8, 0xa9a8, 0xa8a9, 0xaaa8, 0xa4ab, 0x937d, 0xaca8, 0xaaac, 0xa7a8, 0xa9a8, 0xa8a9, 0xaaa8, 0xa4ab}, v8_int32 = {0xaca8937d,
0xa7a8aaac, 0xa8a9a9a8, 0xa4abaaa8, 0xaca8937d, 0xa7a8aaac, 0xa8a9a9a8, 0xa4abaaa8}, v4_int64 = {0xa7a8aaacaca8937d, 0xa4abaaa8a8a9a9a8, 0xa7a8aaacaca8937d,
0xa4abaaa8a8a9a9a8}, v2_int128 = {0xa4abaaa8a8a9a9a8a7a8aaacaca8937d, 0xa4abaaa8a8a9a9a8a7a8aaacaca8937d}}
(gdb) p /x [rdi]
A syntax error in expression, near `[rdi]'.
(gdb) p /x $[rdi]
No symbol "rdi" in current context.
(gdb) p /x $rdi
$5 = 0x7fffc827b500
(gdb) p /x (char*)$rdi
$6 = 0x7fffc827b500
(gdb) p /x (char*)$rdi@16
Only values in memory can be extended with '@'.
(gdb) p /x *(char*)$rdi@16
$7 = {0x7d, 0x93, 0xa8, 0xac, 0xac, 0xaa, 0xa8, 0xa7, 0xa8, 0xa9, 0xa9, 0xa8, 0xa8, 0xaa, 0xab, 0xa4}
(gdb) p /x *(char*)$rdi@18
$8 = {0x7d, 0x93, 0xa8, 0xac, 0xac, 0xaa, 0xa8, 0xa7, 0xa8, 0xa9, 0xa9, 0xa8, 0xa8, 0xaa, 0xab, 0xa4, 0x98, 0x94}
(gdb)
4 总结
如果要打印寄存器的值,直接
p $reg
如果要以hex打印
p /x $reg
如果要打印寄存器指向的内容
p /x (char*)$rdi@16 打印寄存器只想的数据块的前16个字节。